Diffstat (limited to 'frontend/gamma/js/JQTouch/extensions/jqt.actionsheet.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/JQTouch/extensions/jqt.actionsheet.js | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/frontend/gamma/js/JQTouch/extensions/jqt.actionsheet.js b/frontend/gamma/js/JQTouch/extensions/jqt.actionsheet.js new file mode 100644 index 0000000..2a5f8d1 --- a/dev/null +++ b/frontend/gamma/js/JQTouch/extensions/jqt.actionsheet.js | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | |||
3 | _/ _/_/ _/_/_/_/_/ _/ | ||
4 | _/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/ | ||
5 | _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ | ||
6 | _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ | ||
7 | _/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/ | ||
8 | _/ | ||
9 | _/ | ||
10 | |||
11 | Documentation and issue tracking on Google Code <http://code.google.com/p/jqtouch/> | ||
12 | |||
13 | (c) 2012 by jQTouch project members. | ||
14 | See LICENSE.txt for license. | ||
15 | |||
16 | Author: Thomas Yip | ||
17 | */ | ||
18 | |||
19 | /* | ||
20 | |||
21 | _/ _/_/ _/_/_/_/_/ _/ | ||
22 | _/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/ | ||
23 | _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ | ||
24 | _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ | ||
25 | _/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/ | ||
26 | _/ | ||
27 | _/ | ||
28 | |||
29 | Documentation and issue tracking on Google Code <http://code.google.com/p/jqtouch/> | ||
30 | |||
31 | (c) 2012 by jQTouch project members. | ||
32 | See LICENSE.txt for license. | ||
33 | |||
34 | Author: Thomas Yip | ||
35 | */ | ||
36 | |||
37 | (function($) { | ||
38 | var src = $("head script").last().attr("src") || ''; | ||
39 | var scriptpath = src.split('?')[0].split('/').slice(0, -1).join('/')+'/'; | ||
40 | var csspath = scriptpath + 'jqt.actionsheet.css'; | ||
41 | var link = $('<link href="' + csspath + '" rel="stylesheet">'); | ||
42 | $('head').append($(link)); | ||
43 | |||
44 | function hide(callback) { | ||
45 | var $target = $(this); | ||
46 | var data = $(this).data('actionsheet'); | ||
47 | var $source = data.source; | ||
48 | |||
49 | var timeout; | ||
50 | |||
51 | function cleanup() { | ||
52 | clearTimeout(timeout); | ||
53 | |||
54 | $source.removeClass('transition'); | ||
55 | $target.removeClass('inmotion transition'); | ||
56 | !callback || callback.apply(this, arguments); | ||
57 | }; | ||
58 | timeout = setTimeout(cleanup, 500); | ||
59 | |||
60 | if (data.shown) { | ||
61 | $(this).data('actionsheet', {}); | ||
62 | $target.one('webkitTransitionEnd', cleanup); | ||
63 | |||
64 | $source.addClass('transition'); | ||
65 | $target.removeClass('current').addClass('inmotion transition'); | ||
66 | $('#jqt').removeClass('actionopened'); | ||
67 | } | ||
68 | return $target; | ||
69 | } | ||
70 | |||
71 | function show(callback) { | ||
72 | var $target = $(this); | ||
73 | var data = $(this).data('actionsheet') || {}; | ||
74 | if (!data.shown) { | ||
75 | var $source = $('#jqt .current:not(.actionsheet)'); | ||
76 | |||
77 | $target.one('webkitTransitionEnd', function() { | ||
78 | $source.removeClass('transition'); | ||
79 | $target.removeClass('inmotion transition'); | ||
80 | !callback || callback.apply(this, arguments); | ||
81 | }); | ||
82 | |||
83 | data.shown = true; | ||
84 | data.source = $source; | ||
85 | $(this).data('actionsheet', data); | ||
86 | |||
87 | $source.addClass('transition'); | ||
88 | $target.addClass('inmotion transition'); | ||
89 | $('#jqt').addClass('actionopened'); | ||
90 | setTimeout(function() { | ||
91 | $target.addClass('current'); | ||
92 | }, 50); | ||
93 | } | ||
94 | return $target; | ||
95 | } | ||
96 | |||
97 | var methods = { | ||
98 | init: function(options) { | ||
99 | $(this).addClass('actionsheet'); | ||
100 | $(this).data({shown: false}); | ||
101 | }, | ||
102 | show: show, | ||
103 | hide: hide | ||
104 | }; | ||
105 | |||
106 | $.fn.actionsheet = function(method) { | ||
107 | if (methods[method]) { | ||
108 | if ($(this).is('.actionsheet')) { | ||
109 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
110 | } else { | ||
111 | var msg = 'Target is not a `actionsheet`. Action `' + method + '` is ignored.'; | ||
112 | console.warn(msg); | ||
113 | } | ||
114 | } else if ( typeof method === 'object' || ! method ) { | ||
115 | return methods.init.apply(this, arguments); | ||
116 | } else { | ||
117 | $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); | ||
118 | } | ||
119 | }; | ||
120 | |||
121 | if ($.jQTouch) { | ||
122 | $.jQTouch.addTapHandler({ | ||
123 | name: 'open-actionsheet', | ||
124 | isSupported: function(e, params) { | ||
125 | return params.$el.is('.action'); | ||
126 | }, | ||
127 | fn: function(e, params) { | ||
128 | params.$el.removeClass('active'); | ||
129 | |||
130 | var $target = $(params.hash); | ||
131 | $target.actionsheet('show'); | ||
132 | |||
133 | return false; | ||
134 | } | ||
135 | }); | ||
136 | $.jQTouch.addTapHandler({ | ||
137 | name: 'follow-actionlink', | ||
138 | isSupported: function(e, params) { | ||
139 | if ($('#jqt').hasClass('actionopened')) { | ||
140 | return params.$el.is('.actionsheet a'); | ||
141 | } | ||
142 | return false; | ||
143 | }, | ||
144 | fn: function(e, params) { | ||
145 | params.$el.removeClass('active'); | ||
146 | |||
147 | var $target = params.$el.closest('.actionsheet'); | ||
148 | $target.actionsheet('hide', function() { | ||
149 | if (!params.$el.is('.dismiss')) { | ||
150 | params.$el.trigger('tap'); | ||
151 | } | ||
152 | }); | ||
153 | return false; | ||
154 | } | ||
155 | }); | ||
156 | } else { | ||
157 | console.error('Extension `jqt.actionsheet` failed to load. jQT not found'); | ||
158 | } | ||
159 | })($); | ||