author | Clipperz <info@clipperz.com> | 2013-01-09 09:03:53 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-09 09:03:53 (UTC) |
commit | 644891059e1f37d0748bc34b9ca78c05fa748214 (patch) (unidiff) | |
tree | a746ee125d503088dc53dac823474e4295560947 /frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js | |
parent | a9974c63bdcef65f009420dce095d1e39da7e3b8 (diff) | |
download | clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.zip clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.tar.gz clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.tar.bz2 |
Added JQTouch and Zepto libraries
JQTouch and Zepto are tentatively used for the mobile version of Clipperz.
No final commitment has been made, though.
Diffstat (limited to 'frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js b/frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js new file mode 100644 index 0000000..8d21aca --- a/dev/null +++ b/frontend/gamma/js/JQTouch/extensions/jqt.menusheet.js | |||
@@ -0,0 +1,137 @@ | |||
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 | (function($) { | ||
20 | var src = $("head script").last().attr("src") || ''; | ||
21 | var scriptpath = src.split('?')[0].split('/').slice(0, -1).join('/')+'/'; | ||
22 | var csspath = scriptpath + 'jqt.menusheet.css'; | ||
23 | var link = $('<link href="' + csspath + '" rel="stylesheet">'); | ||
24 | $('head').append($(link)); | ||
25 | |||
26 | function hide(callback) { | ||
27 | var $target = $(this); | ||
28 | var data = $(this).data('menusheet'); | ||
29 | if (data.shown) { | ||
30 | $(this).data('menusheet', {}); | ||
31 | var $source = data.source; | ||
32 | $source.unbind('touchstart mousedown', data.closehandler); | ||
33 | $source.one('webkitTransitionEnd', function() { | ||
34 | $source.removeClass('inmotion transition in'); | ||
35 | $target.removeClass('inmotion out'); | ||
36 | !callback || callback.apply(this, arguments); | ||
37 | }); | ||
38 | |||
39 | $source.addClass('inmotion transition in'); | ||
40 | $target.addClass('inmotion out').removeClass('current'); | ||
41 | $('#jqt').removeClass('menuopened'); | ||
42 | } | ||
43 | return $target; | ||
44 | } | ||
45 | |||
46 | function show(callback) { | ||
47 | var $target = $(this); | ||
48 | var data = $(this).data('menusheet') || {}; | ||
49 | if (!data.shown) { | ||
50 | var $source = $('#jqt .current:not(.menusheet)'); | ||
51 | var closehandler = function() { | ||
52 | $target.menusheet('hide'); | ||
53 | return false; | ||
54 | }; | ||
55 | |||
56 | $source.one('webkitTransitionEnd', function() { | ||
57 | $source.one('touchstart mousedown', closehandler); | ||
58 | $source.removeClass('inmotion transition out'); | ||
59 | $target.removeClass('inmotion in'); | ||
60 | !callback || callback.apply(this, arguments); | ||
61 | }); | ||
62 | |||
63 | data.shown = true; | ||
64 | data.closehandler = closehandler; | ||
65 | data.source = $source; | ||
66 | $(this).data('menusheet', data); | ||
67 | |||
68 | $source.addClass('inmotion transition out'); | ||
69 | $target.addClass('current in'); | ||
70 | $('#jqt').addClass('menuopened'); | ||
71 | } | ||
72 | return $target; | ||
73 | } | ||
74 | |||
75 | var methods = { | ||
76 | init: function(options) { | ||
77 | $(this).addClass('menusheet'); | ||
78 | $(this).data({shown: false}); | ||
79 | }, | ||
80 | show: show, | ||
81 | hide: hide | ||
82 | }; | ||
83 | |||
84 | $.fn.menusheet = function(method) { | ||
85 | if (methods[method]) { | ||
86 | if ($(this).is('.menusheet')) { | ||
87 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
88 | } else { | ||
89 | var msg = 'Target is not a `menusheet`. Action `' + method + '` is ignored.'; | ||
90 | console.warn(msg); | ||
91 | } | ||
92 | } else if ( typeof method === 'object' || ! method ) { | ||
93 | return methods.init.apply(this, arguments); | ||
94 | } else { | ||
95 | $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); | ||
96 | } | ||
97 | }; | ||
98 | |||
99 | if ($.jQTouch) { | ||
100 | $.jQTouch.addTapHandler({ | ||
101 | name: 'open-menusheet', | ||
102 | isSupported: function(e, params) { | ||
103 | return params.$el.is('.menu'); | ||
104 | }, | ||
105 | fn: function(e, params) { | ||
106 | params.$el.removeClass('active'); | ||
107 | |||
108 | var $target = $(params.hash); | ||
109 | $target.menusheet('show'); | ||
110 | |||
111 | return false; | ||
112 | } | ||
113 | }); | ||
114 | $.jQTouch.addTapHandler({ | ||
115 | name: 'follow-menulink', | ||
116 | isSupported: function(e, params) { | ||
117 | if ($('#jqt').hasClass('menuopened')) { | ||
118 | return params.$el.is('.menusheet a'); | ||
119 | } | ||
120 | return false; | ||
121 | }, | ||
122 | fn: function(e, params) { | ||
123 | params.$el.removeClass('active'); | ||
124 | |||
125 | var $target = params.$el.closest('.menusheet'); | ||
126 | $target.menusheet('hide', function() { | ||
127 | if (!params.$el.is('.dismiss')) { | ||
128 | params.$el.trigger('tap'); | ||
129 | } | ||
130 | }); | ||
131 | return false; | ||
132 | } | ||
133 | }); | ||
134 | } else { | ||
135 | console.error('Extension `jqt.menusheet` failed to load. jQT not found'); | ||
136 | } | ||
137 | })($); | ||