Mercurial > evolve
annotate docs/tutorial/uikit.js @ 5691:6eb9f82b43ba stable
evolve: remove spurious "working directory is now at ..." messages
The `startnode` variable was sometimes a context, which made the
comparison with `repo[b'.'].node()` in `_cleanup()` fail. This patch
fixes that by making sure that `startnode` is always a (binary)
nodeid.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 24 Nov 2020 18:04:40 -0800 |
parents | aad37ffd7d58 |
children |
rev | line source |
---|---|
3376
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1 /*! UIkit 2.25.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2 (function(core) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
4 if (typeof define == "function" && define.amd) { // AMD |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
5 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
6 define("uikit", function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
7 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
8 var uikit = window.UIkit || core(window, window.jQuery, window.document); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
9 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
10 uikit.load = function(res, req, onload, config) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
11 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
12 var resources = res.split(','), load = [], i, base = (config.config && config.config.uikit && config.config.uikit.base ? config.config.uikit.base : "").replace(/\/+$/g, ""); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
13 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
14 if (!base) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
15 throw new Error( "Please define base path to UIkit in the requirejs config." ); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
16 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
17 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
18 for (i = 0; i < resources.length; i += 1) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
19 var resource = resources[i].replace(/\./g, '/'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
20 load.push(base+'/components/'+resource); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
21 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
22 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
23 req(load, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
24 onload(uikit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
25 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
26 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
27 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
28 return uikit; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
29 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
30 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
31 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
32 if (!window.jQuery) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
33 throw new Error( "UIkit requires jQuery" ); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
34 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
35 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
36 if (window && window.jQuery) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
37 core(window, window.jQuery, window.document); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
38 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
39 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
40 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
41 })(function(global, $, doc) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
42 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
43 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
44 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
45 var UI = {}, _UI = global.UIkit ? Object.create(global.UIkit) : undefined; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
46 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
47 UI.version = '2.25.0'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
48 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
49 UI.noConflict = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
50 // restore UIkit version |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
51 if (_UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
52 global.UIkit = _UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
53 $.UIkit = _UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
54 $.fn.uk = _UI.fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
55 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
56 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
57 return UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
58 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
59 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
60 UI.prefix = function(str) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
61 return str; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
62 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
63 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
64 // cache jQuery |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
65 UI.$ = $; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
66 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
67 UI.$doc = UI.$(document); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
68 UI.$win = UI.$(window); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
69 UI.$html = UI.$('html'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
70 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
71 UI.support = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
72 UI.support.transition = (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
73 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
74 var transitionEnd = (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
75 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
76 var element = doc.body || doc.documentElement, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
77 transEndEventNames = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
78 WebkitTransition : 'webkitTransitionEnd', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
79 MozTransition : 'transitionend', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
80 OTransition : 'oTransitionEnd otransitionend', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
81 transition : 'transitionend' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
82 }, name; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
83 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
84 for (name in transEndEventNames) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
85 if (element.style[name] !== undefined) return transEndEventNames[name]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
86 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
87 }()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
88 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
89 return transitionEnd && { end: transitionEnd }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
90 })(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
91 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
92 UI.support.animation = (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
93 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
94 var animationEnd = (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
95 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
96 var element = doc.body || doc.documentElement, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
97 animEndEventNames = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
98 WebkitAnimation : 'webkitAnimationEnd', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
99 MozAnimation : 'animationend', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
100 OAnimation : 'oAnimationEnd oanimationend', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
101 animation : 'animationend' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
102 }, name; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
103 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
104 for (name in animEndEventNames) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
105 if (element.style[name] !== undefined) return animEndEventNames[name]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
106 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
107 }()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
108 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
109 return animationEnd && { end: animationEnd }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
110 })(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
111 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
112 // requestAnimationFrame polyfill |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
113 //https://github.com/darius/requestAnimationFrame |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
114 (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
115 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
116 Date.now = Date.now || function() { return new Date().getTime(); }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
117 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
118 var vendors = ['webkit', 'moz']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
119 for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
120 var vp = vendors[i]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
121 window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
122 window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
123 || window[vp+'CancelRequestAnimationFrame']); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
124 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
125 if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
126 || !window.requestAnimationFrame || !window.cancelAnimationFrame) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
127 var lastTime = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
128 window.requestAnimationFrame = function(callback) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
129 var now = Date.now(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
130 var nextTime = Math.max(lastTime + 16, now); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
131 return setTimeout(function() { callback(lastTime = nextTime); }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
132 nextTime - now); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
133 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
134 window.cancelAnimationFrame = clearTimeout; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
135 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
136 }()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
137 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
138 UI.support.touch = ( |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
139 ('ontouchstart' in document) || |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
140 (global.DocumentTouch && document instanceof global.DocumentTouch) || |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
141 (global.navigator.msPointerEnabled && global.navigator.msMaxTouchPoints > 0) || //IE 10 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
142 (global.navigator.pointerEnabled && global.navigator.maxTouchPoints > 0) || //IE >=11 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
143 false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
144 ); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
145 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
146 UI.support.mutationobserver = (global.MutationObserver || global.WebKitMutationObserver || null); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
147 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
148 UI.Utils = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
149 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
150 UI.Utils.isFullscreen = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
151 return document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || document.fullscreenElement || false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
152 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
153 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
154 UI.Utils.str2json = function(str, notevil) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
155 try { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
156 if (notevil) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
157 return JSON.parse(str |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
158 // wrap keys without quote with valid double quote |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
159 .replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":';}) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
160 // replacing single quote wrapped ones to double quote |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
161 .replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"';}) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
162 ); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
163 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
164 return (new Function("", "var json = " + str + "; return JSON.parse(JSON.stringify(json));"))(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
165 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
166 } catch(e) { return false; } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
167 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
168 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
169 UI.Utils.debounce = function(func, wait, immediate) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
170 var timeout; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
171 return function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
172 var context = this, args = arguments; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
173 var later = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
174 timeout = null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
175 if (!immediate) func.apply(context, args); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
176 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
177 var callNow = immediate && !timeout; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
178 clearTimeout(timeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
179 timeout = setTimeout(later, wait); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
180 if (callNow) func.apply(context, args); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
181 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
182 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
183 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
184 UI.Utils.removeCssRules = function(selectorRegEx) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
185 var idx, idxs, stylesheet, _i, _j, _k, _len, _len1, _len2, _ref; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
186 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
187 if(!selectorRegEx) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
188 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
189 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
190 try { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
191 _ref = document.styleSheets; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
192 for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
193 stylesheet = _ref[_i]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
194 idxs = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
195 stylesheet.cssRules = stylesheet.cssRules; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
196 for (idx = _j = 0, _len1 = stylesheet.cssRules.length; _j < _len1; idx = ++_j) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
197 if (stylesheet.cssRules[idx].type === CSSRule.STYLE_RULE && selectorRegEx.test(stylesheet.cssRules[idx].selectorText)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
198 idxs.unshift(idx); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
199 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
200 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
201 for (_k = 0, _len2 = idxs.length; _k < _len2; _k++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
202 stylesheet.deleteRule(idxs[_k]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
203 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
204 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
205 } catch (_error) {} |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
206 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
207 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
208 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
209 UI.Utils.isInView = function(element, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
210 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
211 var $element = $(element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
212 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
213 if (!$element.is(':visible')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
214 return false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
215 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
216 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
217 var window_left = UI.$win.scrollLeft(), window_top = UI.$win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
218 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
219 options = $.extend({topoffset:0, leftoffset:0}, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
220 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
221 if (top + $element.height() >= window_top && top - options.topoffset <= window_top + UI.$win.height() && |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
222 left + $element.width() >= window_left && left - options.leftoffset <= window_left + UI.$win.width()) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
223 return true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
224 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
225 return false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
226 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
227 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
228 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
229 UI.Utils.checkDisplay = function(context, initanimation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
230 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
231 var elements = UI.$('[data-uk-margin], [data-uk-grid-match], [data-uk-grid-margin], [data-uk-check-display]', context || document), animated; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
232 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
233 if (context && !elements.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
234 elements = $(context); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
235 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
236 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
237 elements.trigger('display.uk.check'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
238 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
239 // fix firefox / IE animations |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
240 if (initanimation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
241 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
242 if (typeof(initanimation)!='string') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
243 initanimation = '[class*="uk-animation-"]'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
244 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
245 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
246 elements.find(initanimation).each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
247 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
248 var ele = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
249 cls = ele.attr('class'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
250 anim = cls.match(/uk\-animation\-(.+)/); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
251 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
252 ele.removeClass(anim[0]).width(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
253 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
254 ele.addClass(anim[0]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
255 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
256 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
257 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
258 return elements; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
259 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
260 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
261 UI.Utils.options = function(string) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
262 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
263 if ($.type(string)!='string') return string; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
264 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
265 if (string.indexOf(':') != -1 && string.trim().substr(-1) != '}') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
266 string = '{'+string+'}'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
267 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
268 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
269 var start = (string ? string.indexOf("{") : -1), options = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
270 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
271 if (start != -1) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
272 try { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
273 options = UI.Utils.str2json(string.substr(start)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
274 } catch (e) {} |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
275 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
276 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
277 return options; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
278 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
279 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
280 UI.Utils.animate = function(element, cls) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
281 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
282 var d = $.Deferred(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
283 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
284 element = UI.$(element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
285 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
286 element.css('display', 'none').addClass(cls).one(UI.support.animation.end, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
287 element.removeClass(cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
288 d.resolve(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
289 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
290 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
291 element.css('display', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
292 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
293 return d.promise(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
294 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
295 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
296 UI.Utils.uid = function(prefix) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
297 return (prefix || 'id') + (new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
298 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
299 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
300 UI.Utils.template = function(str, data) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
301 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
302 var tokens = str.replace(/\n/g, '\\n').replace(/\{\{\{\s*(.+?)\s*\}\}\}/g, "{{!$1}}").split(/(\{\{\s*(.+?)\s*\}\})/g), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
303 i=0, toc, cmd, prop, val, fn, output = [], openblocks = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
304 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
305 while(i < tokens.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
306 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
307 toc = tokens[i]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
308 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
309 if(toc.match(/\{\{\s*(.+?)\s*\}\}/)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
310 i = i + 1; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
311 toc = tokens[i]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
312 cmd = toc[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
313 prop = toc.substring(toc.match(/^(\^|\#|\!|\~|\:)/) ? 1:0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
314 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
315 switch(cmd) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
316 case '~': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
317 output.push("for(var $i=0;$i<"+prop+".length;$i++) { var $item = "+prop+"[$i];"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
318 openblocks++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
319 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
320 case ':': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
321 output.push("for(var $key in "+prop+") { var $val = "+prop+"[$key];"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
322 openblocks++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
323 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
324 case '#': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
325 output.push("if("+prop+") {"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
326 openblocks++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
327 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
328 case '^': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
329 output.push("if(!"+prop+") {"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
330 openblocks++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
331 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
332 case '/': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
333 output.push("}"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
334 openblocks--; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
335 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
336 case '!': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
337 output.push("__ret.push("+prop+");"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
338 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
339 default: |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
340 output.push("__ret.push(escape("+prop+"));"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
341 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
342 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
343 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
344 output.push("__ret.push('"+toc.replace(/\'/g, "\\'")+"');"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
345 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
346 i = i + 1; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
347 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
348 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
349 fn = new Function('$data', [ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
350 'var __ret = [];', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
351 'try {', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
352 'with($data){', (!openblocks ? output.join('') : '__ret = ["Not all blocks are closed correctly."]'), '};', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
353 '}catch(e){__ret = [e.message];}', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
354 'return __ret.join("").replace(/\\n\\n/g, "\\n");', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
355 "function escape(html) { return String(html).replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');}" |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
356 ].join("\n")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
357 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
358 return data ? fn(data) : fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
359 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
360 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
361 UI.Utils.events = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
362 UI.Utils.events.click = UI.support.touch ? 'tap' : 'click'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
363 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
364 global.UIkit = UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
365 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
366 // deprecated |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
367 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
368 UI.fn = function(command, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
369 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
370 var args = arguments, cmd = command.match(/^([a-z\-]+)(?:\.([a-z]+))?/i), component = cmd[1], method = cmd[2]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
371 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
372 if (!UI[component]) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
373 $.error("UIkit component [" + component + "] does not exist."); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
374 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
375 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
376 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
377 return this.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
378 var $this = $(this), data = $this.data(component); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
379 if (!data) $this.data(component, (data = UI[component](this, method ? undefined : options))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
380 if (method) data[method].apply(data, Array.prototype.slice.call(args, 1)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
381 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
382 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
383 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
384 $.UIkit = UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
385 $.fn.uk = UI.fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
386 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
387 UI.langdirection = UI.$html.attr("dir") == "rtl" ? "right" : "left"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
388 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
389 UI.components = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
390 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
391 UI.component = function(name, def) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
392 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
393 var fn = function(element, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
394 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
395 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
396 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
397 this.UIkit = UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
398 this.element = element ? UI.$(element) : null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
399 this.options = $.extend(true, {}, this.defaults, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
400 this.plugins = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
401 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
402 if (this.element) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
403 this.element.data(name, this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
404 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
405 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
406 this.init(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
407 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
408 (this.options.plugins.length ? this.options.plugins : Object.keys(fn.plugins)).forEach(function(plugin) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
409 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
410 if (fn.plugins[plugin].init) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
411 fn.plugins[plugin].init($this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
412 $this.plugins[plugin] = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
413 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
414 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
415 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
416 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
417 this.trigger('init.uk.component', [name, this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
418 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
419 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
420 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
421 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
422 fn.plugins = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
423 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
424 $.extend(true, fn.prototype, { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
425 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
426 defaults : {plugins: []}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
427 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
428 boot: function(){}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
429 init: function(){}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
430 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
431 on: function(a1,a2,a3){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
432 return UI.$(this.element || this).on(a1,a2,a3); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
433 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
434 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
435 one: function(a1,a2,a3){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
436 return UI.$(this.element || this).one(a1,a2,a3); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
437 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
438 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
439 off: function(evt){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
440 return UI.$(this.element || this).off(evt); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
441 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
442 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
443 trigger: function(evt, params) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
444 return UI.$(this.element || this).trigger(evt, params); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
445 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
446 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
447 find: function(selector) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
448 return UI.$(this.element ? this.element: []).find(selector); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
449 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
450 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
451 proxy: function(obj, methods) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
452 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
453 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
454 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
455 methods.split(' ').forEach(function(method) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
456 if (!$this[method]) $this[method] = function() { return obj[method].apply(obj, arguments); }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
457 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
458 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
459 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
460 mixin: function(obj, methods) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
461 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
462 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
463 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
464 methods.split(' ').forEach(function(method) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
465 if (!$this[method]) $this[method] = obj[method].bind($this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
466 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
467 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
468 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
469 option: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
470 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
471 if (arguments.length == 1) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
472 return this.options[arguments[0]] || undefined; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
473 } else if (arguments.length == 2) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
474 this.options[arguments[0]] = arguments[1]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
475 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
476 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
477 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
478 }, def); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
479 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
480 this.components[name] = fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
481 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
482 this[name] = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
483 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
484 var element, options; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
485 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
486 if (arguments.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
487 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
488 switch(arguments.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
489 case 1: |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
490 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
491 if (typeof arguments[0] === "string" || arguments[0].nodeType || arguments[0] instanceof jQuery) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
492 element = $(arguments[0]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
493 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
494 options = arguments[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
495 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
496 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
497 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
498 case 2: |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
499 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
500 element = $(arguments[0]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
501 options = arguments[1]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
502 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
503 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
504 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
505 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
506 if (element && element.data(name)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
507 return element.data(name); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
508 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
509 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
510 return (new UI.components[name](element, options)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
511 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
512 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
513 if (UI.domready) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
514 UI.component.boot(name); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
515 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
516 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
517 return fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
518 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
519 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
520 UI.plugin = function(component, name, def) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
521 this.components[component].plugins[name] = def; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
522 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
523 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
524 UI.component.boot = function(name) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
525 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
526 if (UI.components[name].prototype && UI.components[name].prototype.boot && !UI.components[name].booted) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
527 UI.components[name].prototype.boot.apply(UI, []); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
528 UI.components[name].booted = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
529 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
530 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
531 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
532 UI.component.bootComponents = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
533 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
534 for (var component in UI.components) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
535 UI.component.boot(component); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
536 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
537 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
538 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
539 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
540 // DOM mutation save ready helper function |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
541 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
542 UI.domObservers = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
543 UI.domready = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
544 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
545 UI.ready = function(fn) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
546 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
547 UI.domObservers.push(fn); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
548 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
549 if (UI.domready) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
550 fn(document); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
551 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
552 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
553 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
554 UI.on = function(a1,a2,a3){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
555 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
556 if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
557 a2.apply(UI.$doc); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
558 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
559 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
560 return UI.$doc.on(a1,a2,a3); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
561 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
562 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
563 UI.one = function(a1,a2,a3){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
564 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
565 if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
566 a2.apply(UI.$doc); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
567 return UI.$doc; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
568 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
569 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
570 return UI.$doc.one(a1,a2,a3); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
571 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
572 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
573 UI.trigger = function(evt, params) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
574 return UI.$doc.trigger(evt, params); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
575 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
576 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
577 UI.domObserve = function(selector, fn) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
578 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
579 if(!UI.support.mutationobserver) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
580 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
581 fn = fn || function() {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
582 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
583 UI.$(selector).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
584 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
585 var element = this, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
586 $element = UI.$(element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
587 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
588 if ($element.data('observer')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
589 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
590 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
591 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
592 try { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
593 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
594 var observer = new UI.support.mutationobserver(UI.Utils.debounce(function(mutations) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
595 fn.apply(element, []); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
596 $element.trigger('changed.uk.dom'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
597 }, 50)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
598 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
599 // pass in the target node, as well as the observer options |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
600 observer.observe(element, { childList: true, subtree: true }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
601 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
602 $element.data('observer', observer); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
603 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
604 } catch(e) {} |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
605 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
606 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
607 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
608 UI.init = function(root) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
609 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
610 root = root || document; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
611 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
612 UI.domObservers.forEach(function(fn){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
613 fn(root); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
614 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
615 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
616 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
617 UI.on('domready.uk.dom', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
618 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
619 UI.init(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
620 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
621 if (UI.domready) UI.Utils.checkDisplay(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
622 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
623 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
624 document.addEventListener('DOMContentLoaded', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
625 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
626 var domReady = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
627 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
628 UI.$body = UI.$('body'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
629 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
630 UI.ready(function(context){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
631 UI.domObserve('[data-uk-observe]'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
632 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
633 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
634 UI.on('changed.uk.dom', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
635 UI.init(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
636 UI.Utils.checkDisplay(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
637 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
638 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
639 UI.trigger('beforeready.uk.dom'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
640 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
641 UI.component.bootComponents(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
642 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
643 // custom scroll observer |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
644 requestAnimationFrame((function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
645 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
646 var memory = {dir: {x:0, y:0}, x: window.pageXOffset, y:window.pageYOffset}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
647 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
648 var fn = function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
649 // reading this (window.page[X|Y]Offset) causes a full page recalc of the layout in Chrome, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
650 // so we only want to do this once |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
651 var wpxo = window.pageXOffset; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
652 var wpyo = window.pageYOffset; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
653 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
654 // Did the scroll position change since the last time we were here? |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
655 if (memory.x != wpxo || memory.y != wpyo) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
656 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
657 // Set the direction of the scroll and store the new position |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
658 if (wpxo != memory.x) {memory.dir.x = wpxo > memory.x ? 1:-1; } else { memory.dir.x = 0; } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
659 if (wpyo != memory.y) {memory.dir.y = wpyo > memory.y ? 1:-1; } else { memory.dir.y = 0; } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
660 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
661 memory.x = wpxo; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
662 memory.y = wpyo; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
663 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
664 // Trigger the scroll event, this could probably be sent using memory.clone() but this is |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
665 // more explicit and easier to see exactly what is being sent in the event. |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
666 UI.$doc.trigger('scrolling.uk.document', [{ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
667 "dir": {"x": memory.dir.x, "y": memory.dir.y}, "x": wpxo, "y": wpyo |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
668 }]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
669 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
670 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
671 requestAnimationFrame(fn); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
672 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
673 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
674 if (UI.support.touch) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
675 UI.$html.on('touchmove touchend MSPointerMove MSPointerUp pointermove pointerup', fn); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
676 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
677 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
678 if (memory.x || memory.y) fn(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
679 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
680 return fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
681 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
682 })()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
683 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
684 // run component init functions on dom |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
685 UI.trigger('domready.uk.dom'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
686 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
687 if (UI.support.touch) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
688 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
689 // remove css hover rules for touch devices |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
690 // UI.Utils.removeCssRules(/\.uk-(?!navbar).*:hover/); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
691 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
692 // viewport unit fix for uk-height-viewport - should be fixed in iOS 8 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
693 if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
694 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
695 UI.$win.on('load orientationchange resize', UI.Utils.debounce((function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
696 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
697 var fn = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
698 $('.uk-height-viewport').css('height', window.innerHeight); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
699 return fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
700 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
701 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
702 return fn(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
703 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
704 })(), 100)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
705 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
706 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
707 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
708 UI.trigger('afterready.uk.dom'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
709 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
710 // mark that domready is left behind |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
711 UI.domready = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
712 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
713 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
714 if (document.readyState == 'complete' || document.readyState == 'interactive') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
715 setTimeout(domReady); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
716 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
717 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
718 return domReady; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
719 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
720 }()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
721 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
722 // add touch identifier class |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
723 UI.$html.addClass(UI.support.touch ? "uk-touch" : "uk-notouch"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
724 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
725 // add uk-hover class on tap to support overlays on touch devices |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
726 if (UI.support.touch) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
727 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
728 var hoverset = false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
729 exclude, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
730 hovercls = 'uk-hover', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
731 selector = '.uk-overlay, .uk-overlay-hover, .uk-overlay-toggle, .uk-animation-hover, .uk-has-hover'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
732 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
733 UI.$html.on('mouseenter touchstart MSPointerDown pointerdown', selector, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
734 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
735 if (hoverset) $('.'+hovercls).removeClass(hovercls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
736 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
737 hoverset = $(this).addClass(hovercls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
738 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
739 }).on('mouseleave touchend MSPointerUp pointerup', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
740 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
741 exclude = $(e.target).parents(selector); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
742 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
743 if (hoverset) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
744 hoverset.not(exclude).removeClass(hovercls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
745 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
746 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
747 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
748 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
749 return UI; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
750 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
751 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
752 // Based on Zeptos touch.js |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
753 // https://raw.github.com/madrobby/zepto/master/src/touch.js |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
754 // Zepto.js may be freely distributed under the MIT license. |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
755 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
756 ;(function($){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
757 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
758 if ($.fn.swipeLeft) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
759 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
760 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
761 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
762 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
763 var touch = {}, touchTimeout, tapTimeout, swipeTimeout, longTapTimeout, longTapDelay = 750, gesture; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
764 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
765 function swipeDirection(x1, x2, y1, y2) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
766 return Math.abs(x1 - x2) >= Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
767 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
768 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
769 function longTap() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
770 longTapTimeout = null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
771 if (touch.last) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
772 if ( touch.el !== undefined ) touch.el.trigger('longTap'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
773 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
774 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
775 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
776 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
777 function cancelLongTap() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
778 if (longTapTimeout) clearTimeout(longTapTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
779 longTapTimeout = null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
780 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
781 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
782 function cancelAll() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
783 if (touchTimeout) clearTimeout(touchTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
784 if (tapTimeout) clearTimeout(tapTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
785 if (swipeTimeout) clearTimeout(swipeTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
786 if (longTapTimeout) clearTimeout(longTapTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
787 touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
788 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
789 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
790 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
791 function isPrimaryTouch(event){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
792 return event.pointerType == event.MSPOINTER_TYPE_TOUCH && event.isPrimary; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
793 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
794 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
795 $(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
796 var now, delta, deltaX = 0, deltaY = 0, firstTouch; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
797 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
798 if ('MSGesture' in window) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
799 gesture = new MSGesture(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
800 gesture.target = document.body; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
801 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
802 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
803 $(document) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
804 .on('MSGestureEnd gestureend', function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
805 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
806 var swipeDirectionFromVelocity = e.originalEvent.velocityX > 1 ? 'Right' : e.originalEvent.velocityX < -1 ? 'Left' : e.originalEvent.velocityY > 1 ? 'Down' : e.originalEvent.velocityY < -1 ? 'Up' : null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
807 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
808 if (swipeDirectionFromVelocity && touch.el !== undefined) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
809 touch.el.trigger('swipe'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
810 touch.el.trigger('swipe'+ swipeDirectionFromVelocity); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
811 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
812 }) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
813 // MSPointerDown: for IE10 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
814 // pointerdown: for IE11 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
815 .on('touchstart MSPointerDown pointerdown', function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
816 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
817 if(e.type == 'MSPointerDown' && !isPrimaryTouch(e.originalEvent)) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
818 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
819 firstTouch = (e.type == 'MSPointerDown' || e.type == 'pointerdown') ? e : e.originalEvent.touches[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
820 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
821 now = Date.now(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
822 delta = now - (touch.last || now); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
823 touch.el = $('tagName' in firstTouch.target ? firstTouch.target : firstTouch.target.parentNode); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
824 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
825 if(touchTimeout) clearTimeout(touchTimeout); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
826 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
827 touch.x1 = firstTouch.pageX; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
828 touch.y1 = firstTouch.pageY; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
829 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
830 if (delta > 0 && delta <= 250) touch.isDoubleTap = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
831 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
832 touch.last = now; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
833 longTapTimeout = setTimeout(longTap, longTapDelay); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
834 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
835 // adds the current touch contact for IE gesture recognition |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
836 if (gesture && ( e.type == 'MSPointerDown' || e.type == 'pointerdown' || e.type == 'touchstart' ) ) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
837 gesture.addPointer(e.originalEvent.pointerId); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
838 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
839 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
840 }) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
841 // MSPointerMove: for IE10 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
842 // pointermove: for IE11 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
843 .on('touchmove MSPointerMove pointermove', function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
844 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
845 if (e.type == 'MSPointerMove' && !isPrimaryTouch(e.originalEvent)) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
846 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
847 firstTouch = (e.type == 'MSPointerMove' || e.type == 'pointermove') ? e : e.originalEvent.touches[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
848 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
849 cancelLongTap(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
850 touch.x2 = firstTouch.pageX; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
851 touch.y2 = firstTouch.pageY; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
852 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
853 deltaX += Math.abs(touch.x1 - touch.x2); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
854 deltaY += Math.abs(touch.y1 - touch.y2); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
855 }) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
856 // MSPointerUp: for IE10 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
857 // pointerup: for IE11 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
858 .on('touchend MSPointerUp pointerup', function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
859 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
860 if (e.type == 'MSPointerUp' && !isPrimaryTouch(e.originalEvent)) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
861 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
862 cancelLongTap(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
863 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
864 // swipe |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
865 if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
866 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
867 swipeTimeout = setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
868 if ( touch.el !== undefined ) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
869 touch.el.trigger('swipe'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
870 touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
871 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
872 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
873 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
874 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
875 // normal tap |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
876 } else if ('last' in touch) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
877 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
878 // don't fire tap when delta position changed by more than 30 pixels, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
879 // for instance when moving to a point and back to origin |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
880 if (isNaN(deltaX) || (deltaX < 30 && deltaY < 30)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
881 // delay by one tick so we can cancel the 'tap' event if 'scroll' fires |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
882 // ('tap' fires before 'scroll') |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
883 tapTimeout = setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
884 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
885 // trigger universal 'tap' with the option to cancelTouch() |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
886 // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
887 var event = $.Event('tap'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
888 event.cancelTouch = cancelAll; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
889 if ( touch.el !== undefined ) touch.el.trigger(event); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
890 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
891 // trigger double tap immediately |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
892 if (touch.isDoubleTap) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
893 if ( touch.el !== undefined ) touch.el.trigger('doubleTap'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
894 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
895 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
896 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
897 // trigger single tap after 250ms of inactivity |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
898 else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
899 touchTimeout = setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
900 touchTimeout = null; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
901 if ( touch.el !== undefined ) touch.el.trigger('singleTap'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
902 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
903 }, 250); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
904 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
905 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
906 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
907 touch = {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
908 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
909 deltaX = deltaY = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
910 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
911 }) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
912 // when the browser window loses focus, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
913 // for example when a modal dialog is shown, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
914 // cancel all ongoing events |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
915 .on('touchcancel MSPointerCancel', cancelAll); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
916 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
917 // scrolling the window indicates intention of the user |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
918 // to scroll, not tap or swipe, so cancel all ongoing events |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
919 $(window).on('scroll', cancelAll); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
920 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
921 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
922 ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
923 $.fn[eventName] = function(callback){ return $(this).on(eventName, callback); }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
924 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
925 })(jQuery); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
926 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
927 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
928 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
929 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
930 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
931 var stacks = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
932 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
933 UI.component('stackMargin', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
934 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
935 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
936 cls: 'uk-margin-small-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
937 rowfirst: false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
938 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
939 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
940 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
941 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
942 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
943 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
944 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
945 UI.$("[data-uk-margin]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
946 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
947 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
948 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
949 if (!ele.data("stackMargin")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
950 UI.stackMargin(ele, UI.Utils.options(ele.attr("data-uk-margin"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
951 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
952 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
953 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
954 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
955 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
956 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
957 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
958 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
959 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
960 UI.$win.on('resize orientationchange', (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
961 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
962 var fn = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
963 $this.process(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
964 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
965 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
966 UI.$(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
967 fn(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
968 UI.$win.on("load", fn); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
969 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
970 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
971 return UI.Utils.debounce(fn, 20); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
972 })()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
973 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
974 UI.$html.on("changed.uk.dom", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
975 $this.process(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
976 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
977 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
978 this.on("display.uk.check", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
979 if (this.element.is(":visible")) this.process(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
980 }.bind(this)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
981 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
982 stacks.push(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
983 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
984 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
985 process: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
986 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
987 var $this = this, columns = this.element.children(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
988 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
989 UI.Utils.stackMargin(columns, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
990 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
991 if (!this.options.rowfirst) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
992 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
993 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
994 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
995 // Mark first column elements |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
996 var pos_cache = columns.removeClass(this.options.rowfirst).filter(':visible').first().position(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
997 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
998 if (pos_cache) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
999 columns.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1000 UI.$(this)[UI.$(this).position().left == pos_cache.left ? 'addClass':'removeClass']($this.options.rowfirst); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1001 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1002 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1003 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1004 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1005 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1006 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1007 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1008 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1009 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1010 // responsive element e.g. iframes |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1011 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1012 (function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1013 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1014 var elements = [], check = function(ele) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1015 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1016 if (!ele.is(':visible')) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1017 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1018 var width = ele.parent().width(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1019 iwidth = ele.data('width'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1020 ratio = (width / iwidth), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1021 height = Math.floor(ratio * ele.data('height')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1022 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1023 ele.css({'height': (width < iwidth) ? height : ele.data('height')}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1024 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1025 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1026 UI.component('responsiveElement', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1027 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1028 defaults: {}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1029 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1030 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1031 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1032 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1033 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1034 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1035 UI.$("iframe.uk-responsive-width, [data-uk-responsive]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1036 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1037 var ele = UI.$(this), obj; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1038 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1039 if (!ele.data("responsiveElement")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1040 obj = UI.responsiveElement(ele, {}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1041 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1042 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1043 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1044 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1045 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1046 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1047 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1048 var ele = this.element; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1049 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1050 if (ele.attr('width') && ele.attr('height')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1051 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1052 ele.data({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1053 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1054 'width' : ele.attr('width'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1055 'height': ele.attr('height') |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1056 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1057 }).on('display.uk.check', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1058 check(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1059 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1060 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1061 check(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1062 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1063 elements.push(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1064 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1065 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1066 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1067 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1068 UI.$win.on('resize load', UI.Utils.debounce(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1069 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1070 elements.forEach(function(ele){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1071 check(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1072 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1073 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1074 }, 15)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1075 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1076 })(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1077 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1078 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1079 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1080 // helper |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1081 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1082 UI.Utils.stackMargin = function(elements, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1083 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1084 options = UI.$.extend({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1085 'cls': 'uk-margin-small-top' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1086 }, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1087 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1088 options.cls = options.cls; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1089 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1090 elements = UI.$(elements).removeClass(options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1091 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1092 var skip = false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1093 firstvisible = elements.filter(":visible:first"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1094 offset = firstvisible.length ? (firstvisible.position().top + firstvisible.outerHeight()) - 1 : false; // (-1): weird firefox bug when parent container is display:flex |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1095 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1096 if (offset === false || elements.length == 1) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1097 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1098 elements.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1099 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1100 var column = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1101 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1102 if (column.is(":visible")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1103 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1104 if (skip) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1105 column.addClass(options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1106 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1107 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1108 if (column.position().top >= offset) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1109 skip = column.addClass(options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1110 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1111 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1112 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1113 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1114 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1115 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1116 UI.Utils.matchHeights = function(elements, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1117 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1118 elements = UI.$(elements).css('min-height', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1119 options = UI.$.extend({ row : true }, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1120 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1121 var matchHeights = function(group){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1122 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1123 if (group.length < 2) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1124 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1125 var max = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1126 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1127 group.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1128 max = Math.max(max, UI.$(this).outerHeight()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1129 }).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1130 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1131 var element = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1132 height = max - (element.css('box-sizing') == 'border-box' ? 0 : (element.outerHeight() - element.height())); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1133 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1134 element.css('min-height', height + 'px'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1135 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1136 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1137 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1138 if (options.row) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1139 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1140 elements.first().width(); // force redraw |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1141 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1142 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1143 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1144 var lastoffset = false, group = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1145 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1146 elements.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1147 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1148 var ele = UI.$(this), offset = ele.offset().top; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1149 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1150 if (offset != lastoffset && group.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1151 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1152 matchHeights(UI.$(group)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1153 group = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1154 offset = ele.offset().top; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1155 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1156 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1157 group.push(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1158 lastoffset = offset; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1159 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1160 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1161 if (group.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1162 matchHeights(UI.$(group)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1163 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1164 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1165 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1166 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1167 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1168 matchHeights(elements); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1169 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1170 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1171 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1172 (function(cacheSvgs){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1173 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1174 UI.Utils.inlineSvg = function(selector, root) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1175 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1176 var images = UI.$(selector || 'img[src$=".svg"]', root || document).each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1177 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1178 var img = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1179 src = img.attr('src'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1180 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1181 if (!cacheSvgs[src]) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1182 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1183 var d = UI.$.Deferred(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1184 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1185 UI.$.get(src, {nc: Math.random()}, function(data){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1186 d.resolve(UI.$(data).find('svg')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1187 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1188 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1189 cacheSvgs[src] = d.promise(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1190 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1191 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1192 cacheSvgs[src].then(function(svg) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1193 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1194 var $svg = UI.$(svg).clone(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1195 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1196 if (img.attr('id')) $svg.attr('id', img.attr('id')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1197 if (img.attr('class')) $svg.attr('class', img.attr('class')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1198 if (img.attr('style')) $svg.attr('style', img.attr('style')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1199 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1200 if (img.attr('width')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1201 $svg.attr('width', img.attr('width')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1202 if (!img.attr('height')) $svg.removeAttr('height'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1203 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1204 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1205 if (img.attr('height')){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1206 $svg.attr('height', img.attr('height')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1207 if (!img.attr('width')) $svg.removeAttr('width'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1208 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1209 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1210 img.replaceWith($svg); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1211 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1212 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1213 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1214 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1215 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1216 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1217 UI.Utils.inlineSvg('[data-uk-svg]', context); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1218 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1219 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1220 })({}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1221 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1222 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1223 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1224 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1225 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1226 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1227 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1228 UI.component('smoothScroll', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1229 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1230 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1231 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1232 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1233 UI.$html.on("click.smooth-scroll.uikit", "[data-uk-smooth-scroll]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1234 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1235 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1236 if (!ele.data("smoothScroll")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1237 var obj = UI.smoothScroll(ele, UI.Utils.options(ele.attr("data-uk-smooth-scroll"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1238 ele.trigger("click"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1239 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1240 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1241 return false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1242 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1243 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1244 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1245 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1246 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1247 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1248 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1249 this.on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1250 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1251 scrollToElement(UI.$(this.hash).length ? UI.$(this.hash) : UI.$("body"), $this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1252 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1253 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1254 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1255 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1256 function scrollToElement(ele, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1257 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1258 options = UI.$.extend({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1259 duration: 1000, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1260 transition: 'easeOutExpo', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1261 offset: 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1262 complete: function(){} |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1263 }, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1264 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1265 // get / set parameters |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1266 var target = ele.offset().top - options.offset, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1267 docheight = UI.$doc.height(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1268 winheight = window.innerHeight; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1269 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1270 if ((target + winheight) > docheight) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1271 target = docheight - winheight; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1272 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1273 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1274 // animate to target, fire callback when done |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1275 UI.$("html,body").stop().animate({scrollTop: target}, options.duration, options.transition).promise().done(options.complete); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1276 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1277 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1278 UI.Utils.scrollToElement = scrollToElement; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1279 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1280 if (!UI.$.easing.easeOutExpo) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1281 UI.$.easing.easeOutExpo = function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1282 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1283 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1284 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1285 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1286 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1287 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1288 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1289 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1290 var $win = UI.$win, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1291 $doc = UI.$doc, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1292 scrollspies = [], |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1293 checkScrollSpy = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1294 for(var i=0; i < scrollspies.length; i++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1295 window.requestAnimationFrame.apply(window, [scrollspies[i].check]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1296 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1297 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1298 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1299 UI.component('scrollspy', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1300 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1301 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1302 "target" : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1303 "cls" : "uk-scrollspy-inview", |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1304 "initcls" : "uk-scrollspy-init-inview", |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1305 "topoffset" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1306 "leftoffset" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1307 "repeat" : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1308 "delay" : 0 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1309 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1310 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1311 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1312 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1313 // listen to scroll and resize |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1314 $doc.on("scrolling.uk.document", checkScrollSpy); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1315 $win.on("load resize orientationchange", UI.Utils.debounce(checkScrollSpy, 50)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1316 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1317 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1318 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1319 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1320 UI.$("[data-uk-scrollspy]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1321 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1322 var element = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1323 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1324 if (!element.data("scrollspy")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1325 var obj = UI.scrollspy(element, UI.Utils.options(element.attr("data-uk-scrollspy"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1326 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1327 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1328 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1329 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1330 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1331 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1332 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1333 var $this = this, inviewstate, initinview, togglecls = this.options.cls.split(/,/), fn = function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1334 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1335 var elements = $this.options.target ? $this.element.find($this.options.target) : $this.element, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1336 delayIdx = elements.length === 1 ? 1 : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1337 toggleclsIdx = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1338 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1339 elements.each(function(idx){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1340 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1341 var element = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1342 inviewstate = element.data('inviewstate'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1343 inview = UI.Utils.isInView(element, $this.options), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1344 toggle = element.data('ukScrollspyCls') || togglecls[toggleclsIdx].trim(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1345 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1346 if (inview && !inviewstate && !element.data('scrollspy-idle')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1347 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1348 if (!initinview) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1349 element.addClass($this.options.initcls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1350 $this.offset = element.offset(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1351 initinview = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1352 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1353 element.trigger("init.uk.scrollspy"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1354 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1355 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1356 element.data('scrollspy-idle', setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1357 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1358 element.addClass("uk-scrollspy-inview").toggleClass(toggle).width(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1359 element.trigger("inview.uk.scrollspy"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1360 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1361 element.data('scrollspy-idle', false); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1362 element.data('inviewstate', true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1363 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1364 }, $this.options.delay * delayIdx)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1365 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1366 delayIdx++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1367 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1368 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1369 if (!inview && inviewstate && $this.options.repeat) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1370 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1371 if (element.data('scrollspy-idle')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1372 clearTimeout(element.data('scrollspy-idle')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1373 element.data('scrollspy-idle', false); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1374 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1375 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1376 element.removeClass("uk-scrollspy-inview").toggleClass(toggle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1377 element.data('inviewstate', false); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1378 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1379 element.trigger("outview.uk.scrollspy"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1380 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1381 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1382 toggleclsIdx = togglecls[toggleclsIdx + 1] ? (toggleclsIdx + 1) : 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1383 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1384 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1385 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1386 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1387 fn(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1388 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1389 this.check = fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1390 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1391 scrollspies.push(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1392 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1393 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1394 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1395 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1396 var scrollspynavs = [], |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1397 checkScrollSpyNavs = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1398 for(var i=0; i < scrollspynavs.length; i++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1399 window.requestAnimationFrame.apply(window, [scrollspynavs[i].check]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1400 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1401 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1402 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1403 UI.component('scrollspynav', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1404 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1405 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1406 "cls" : 'uk-active', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1407 "closest" : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1408 "topoffset" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1409 "leftoffset" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1410 "smoothscroll" : false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1411 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1412 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1413 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1414 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1415 // listen to scroll and resize |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1416 $doc.on("scrolling.uk.document", checkScrollSpyNavs); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1417 $win.on("resize orientationchange", UI.Utils.debounce(checkScrollSpyNavs, 50)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1418 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1419 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1420 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1421 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1422 UI.$("[data-uk-scrollspy-nav]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1423 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1424 var element = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1425 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1426 if (!element.data("scrollspynav")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1427 var obj = UI.scrollspynav(element, UI.Utils.options(element.attr("data-uk-scrollspy-nav"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1428 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1429 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1430 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1431 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1432 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1433 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1434 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1435 var ids = [], |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1436 links = this.find("a[href^='#']").each(function(){ if(this.getAttribute("href").trim()!=='#') ids.push(this.getAttribute("href")); }), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1437 targets = UI.$(ids.join(",")), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1438 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1439 clsActive = this.options.cls, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1440 clsClosest = this.options.closest || this.options.closest; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1441 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1442 var $this = this, inviews, fn = function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1443 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1444 inviews = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1445 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1446 for (var i=0 ; i < targets.length ; i++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1447 if (UI.Utils.isInView(targets.eq(i), $this.options)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1448 inviews.push(targets.eq(i)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1449 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1450 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1451 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1452 if (inviews.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1453 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1454 var navitems, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1455 scrollTop = $win.scrollTop(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1456 target = (function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1457 for(var i=0; i< inviews.length;i++){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1458 if(inviews[i].offset().top >= scrollTop){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1459 return inviews[i]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1460 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1461 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1462 })(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1463 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1464 if (!target) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1465 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1466 if ($this.options.closest) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1467 links.blur().closest(clsClosest).removeClass(clsActive); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1468 navitems = links.filter("a[href='#"+target.attr("id")+"']").closest(clsClosest).addClass(clsActive); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1469 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1470 navitems = links.removeClass(clsActive).filter("a[href='#"+target.attr("id")+"']").addClass(clsActive); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1471 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1472 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1473 $this.element.trigger("inview.uk.scrollspynav", [target, navitems]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1474 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1475 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1476 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1477 if (this.options.smoothscroll && UI.smoothScroll) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1478 links.each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1479 UI.smoothScroll(this, $this.options.smoothscroll); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1480 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1481 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1482 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1483 fn(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1484 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1485 this.element.data("scrollspynav", this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1486 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1487 this.check = fn; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1488 scrollspynavs.push(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1489 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1490 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1491 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1492 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1493 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1494 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1495 (function(UI){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1496 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1497 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1498 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1499 var toggles = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1500 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1501 UI.component('toggle', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1502 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1503 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1504 target : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1505 cls : 'uk-hidden', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1506 animation : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1507 duration : 200 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1508 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1509 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1510 boot: function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1511 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1512 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1513 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1514 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1515 UI.$("[data-uk-toggle]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1516 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1517 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1518 if (!ele.data("toggle")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1519 var obj = UI.toggle(ele, UI.Utils.options(ele.attr("data-uk-toggle"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1520 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1521 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1522 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1523 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1524 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1525 toggles.forEach(function(toggle){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1526 toggle.getToggles(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1527 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1528 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1529 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1530 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1531 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1532 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1533 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1534 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1535 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1536 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1537 this.aria = (this.options.cls.indexOf('uk-hidden') !== -1); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1538 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1539 this.getToggles(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1540 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1541 this.on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1542 if ($this.element.is('a[href="#"]')) e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1543 $this.toggle(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1544 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1545 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1546 toggles.push(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1547 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1548 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1549 toggle: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1550 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1551 if(!this.totoggle.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1552 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1553 if (this.options.animation && UI.support.animation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1554 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1555 var $this = this, animations = this.options.animation.split(','); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1556 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1557 if (animations.length == 1) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1558 animations[1] = animations[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1559 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1560 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1561 animations[0] = animations[0].trim(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1562 animations[1] = animations[1].trim(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1563 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1564 this.totoggle.css('animation-duration', this.options.duration+'ms'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1565 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1566 this.totoggle.each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1567 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1568 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1569 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1570 if (ele.hasClass($this.options.cls)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1571 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1572 ele.toggleClass($this.options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1573 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1574 UI.Utils.animate(ele, animations[0]).then(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1575 ele.css('animation-duration', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1576 UI.Utils.checkDisplay(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1577 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1578 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1579 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1580 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1581 UI.Utils.animate(this, animations[1]+' uk-animation-reverse').then(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1582 ele.toggleClass($this.options.cls).css('animation-duration', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1583 UI.Utils.checkDisplay(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1584 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1585 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1586 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1587 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1588 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1589 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1590 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1591 this.totoggle.toggleClass(this.options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1592 UI.Utils.checkDisplay(this.totoggle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1593 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1594 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1595 this.updateAria(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1596 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1597 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1598 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1599 getToggles: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1600 this.totoggle = this.options.target ? UI.$(this.options.target):[]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1601 this.updateAria(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1602 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1603 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1604 updateAria: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1605 if (this.aria && this.totoggle.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1606 this.totoggle.each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1607 UI.$(this).attr('aria-hidden', UI.$(this).hasClass('uk-hidden')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1608 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1609 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1610 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1611 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1612 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1613 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1614 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1615 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1616 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1617 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1618 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1619 UI.component('alert', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1620 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1621 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1622 "fade": true, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1623 "duration": 200, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1624 "trigger": ".uk-alert-close" |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1625 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1626 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1627 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1628 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1629 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1630 UI.$html.on("click.alert.uikit", "[data-uk-alert]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1631 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1632 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1633 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1634 if (!ele.data("alert")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1635 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1636 var alert = UI.alert(ele, UI.Utils.options(ele.attr("data-uk-alert"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1637 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1638 if (UI.$(e.target).is(alert.options.trigger)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1639 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1640 alert.close(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1641 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1642 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1643 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1644 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1645 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1646 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1647 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1648 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1649 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1650 this.on("click", this.options.trigger, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1651 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1652 $this.close(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1653 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1654 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1655 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1656 close: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1657 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1658 var element = this.trigger("close.uk.alert"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1659 removeElement = function () { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1660 this.trigger("closed.uk.alert").remove(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1661 }.bind(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1662 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1663 if (this.options.fade) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1664 element.css("overflow", "hidden").css("max-height", element.height()).animate({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1665 "height" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1666 "opacity" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1667 "padding-top" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1668 "padding-bottom" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1669 "margin-top" : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1670 "margin-bottom" : 0 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1671 }, this.options.duration, removeElement); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1672 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1673 removeElement(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1674 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1675 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1676 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1677 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1678 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1679 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1680 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1681 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1682 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1683 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1684 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1685 UI.component('buttonRadio', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1686 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1687 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1688 "activeClass": 'uk-active', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1689 "target": ".uk-button" |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1690 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1691 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1692 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1693 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1694 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1695 UI.$html.on("click.buttonradio.uikit", "[data-uk-button-radio]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1696 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1697 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1698 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1699 if (!ele.data("buttonRadio")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1700 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1701 var obj = UI.buttonRadio(ele, UI.Utils.options(ele.attr("data-uk-button-radio"))), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1702 target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1703 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1704 if (target.is(obj.options.target)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1705 target.trigger("click"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1706 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1707 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1708 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1709 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1710 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1711 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1712 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1713 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1714 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1715 // Init ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1716 this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1717 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1718 this.on("click", this.options.target, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1719 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1720 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1721 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1722 if (ele.is('a[href="#"]')) e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1723 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1724 $this.find($this.options.target).not(ele).removeClass($this.options.activeClass).blur(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1725 ele.addClass($this.options.activeClass); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1726 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1727 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1728 $this.find($this.options.target).not(ele).attr('aria-checked', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1729 ele.attr('aria-checked', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1730 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1731 $this.trigger("change.uk.button", [ele]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1732 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1733 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1734 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1735 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1736 getSelected: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1737 return this.find('.' + this.options.activeClass); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1738 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1739 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1740 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1741 UI.component('buttonCheckbox', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1742 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1743 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1744 "activeClass": 'uk-active', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1745 "target": ".uk-button" |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1746 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1747 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1748 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1749 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1750 UI.$html.on("click.buttoncheckbox.uikit", "[data-uk-button-checkbox]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1751 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1752 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1753 if (!ele.data("buttonCheckbox")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1754 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1755 var obj = UI.buttonCheckbox(ele, UI.Utils.options(ele.attr("data-uk-button-checkbox"))), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1756 target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1757 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1758 if (target.is(obj.options.target)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1759 target.trigger("click"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1760 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1761 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1762 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1763 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1764 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1765 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1766 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1767 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1768 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1769 // Init ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1770 this.find($this.options.target).attr('aria-checked', 'false').filter('.' + $this.options.activeClass).attr('aria-checked', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1771 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1772 this.on("click", this.options.target, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1773 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1774 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1775 if (ele.is('a[href="#"]')) e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1776 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1777 ele.toggleClass($this.options.activeClass).blur(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1778 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1779 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1780 ele.attr('aria-checked', ele.hasClass($this.options.activeClass)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1781 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1782 $this.trigger("change.uk.button", [ele]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1783 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1784 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1785 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1786 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1787 getSelected: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1788 return this.find('.' + this.options.activeClass); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1789 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1790 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1791 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1792 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1793 UI.component('button', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1794 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1795 defaults: {}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1796 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1797 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1798 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1799 UI.$html.on("click.button.uikit", "[data-uk-button]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1800 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1801 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1802 if (!ele.data("button")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1803 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1804 var obj = UI.button(ele, UI.Utils.options(ele.attr("data-uk-button"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1805 ele.trigger("click"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1806 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1807 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1808 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1809 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1810 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1811 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1812 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1813 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1814 // Init ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1815 this.element.attr('aria-pressed', this.element.hasClass("uk-active")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1816 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1817 this.on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1818 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1819 if ($this.element.is('a[href="#"]')) e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1820 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1821 $this.toggle(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1822 $this.trigger("change.uk.button", [$this.element.blur().hasClass("uk-active")]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1823 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1824 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1825 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1826 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1827 toggle: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1828 this.element.toggleClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1829 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1830 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1831 this.element.attr('aria-pressed', this.element.hasClass("uk-active")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1832 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1833 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1834 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1835 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1836 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1837 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1838 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1839 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1840 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1841 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1842 var active = false, hoverIdle, flips = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1843 'x': { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1844 "bottom-left" : 'bottom-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1845 "bottom-right" : 'bottom-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1846 "bottom-center" : 'bottom-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1847 "top-left" : 'top-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1848 "top-right" : 'top-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1849 "top-center" : 'top-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1850 "left-top" : 'right-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1851 "left-bottom" : 'right-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1852 "left-center" : 'right-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1853 "right-top" : 'left-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1854 "right-bottom" : 'left-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1855 "right-center" : 'left-center' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1856 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1857 'y': { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1858 "bottom-left" : 'top-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1859 "bottom-right" : 'top-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1860 "bottom-center" : 'top-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1861 "top-left" : 'bottom-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1862 "top-right" : 'bottom-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1863 "top-center" : 'bottom-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1864 "left-top" : 'left-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1865 "left-bottom" : 'left-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1866 "left-center" : 'left-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1867 "right-top" : 'right-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1868 "right-bottom" : 'right-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1869 "right-center" : 'right-center' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1870 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1871 'xy': { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1872 "bottom-left" : 'top-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1873 "bottom-right" : 'top-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1874 "bottom-center" : 'top-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1875 "top-left" : 'bottom-right', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1876 "top-right" : 'bottom-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1877 "top-center" : 'bottom-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1878 "left-top" : 'right-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1879 "left-bottom" : 'right-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1880 "left-center" : 'right-center', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1881 "right-top" : 'left-bottom', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1882 "right-bottom" : 'left-top', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1883 "right-center" : 'left-center' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1884 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1885 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1886 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1887 UI.component('dropdown', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1888 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1889 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1890 'mode' : 'hover', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1891 'pos' : 'bottom-left', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1892 'offset' : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1893 'remaintime' : 800, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1894 'justify' : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1895 'boundary' : UI.$win, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1896 'delay' : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1897 'dropdownSelector': '.uk-dropdown,.uk-dropdown-blank', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1898 'hoverDelayIdle' : 250, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1899 'preventflip' : false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1900 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1901 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1902 remainIdle: false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1903 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1904 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1905 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1906 var triggerevent = UI.support.touch ? "click" : "mouseenter"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1907 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1908 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1909 UI.$html.on(triggerevent+".dropdown.uikit", "[data-uk-dropdown]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1910 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1911 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1912 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1913 if (!ele.data("dropdown")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1914 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1915 var dropdown = UI.dropdown(ele, UI.Utils.options(ele.attr("data-uk-dropdown"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1916 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1917 if (triggerevent=="click" || (triggerevent=="mouseenter" && dropdown.options.mode=="hover")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1918 dropdown.element.trigger(triggerevent); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1919 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1920 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1921 if (dropdown.element.find(dropdown.options.dropdownSelector).length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1922 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1923 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1924 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1925 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1926 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1927 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1928 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1929 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1930 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1931 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1932 this.dropdown = this.find(this.options.dropdownSelector); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1933 this.offsetParent = this.dropdown.parents().filter(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1934 return UI.$.inArray(UI.$(this).css('position'), ['relative', 'fixed', 'absolute']) !== -1; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1935 }).slice(0,1); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1936 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1937 this.centered = this.dropdown.hasClass('uk-dropdown-center'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1938 this.justified = this.options.justify ? UI.$(this.options.justify) : false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1939 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1940 this.boundary = UI.$(this.options.boundary); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1941 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1942 if (!this.boundary.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1943 this.boundary = UI.$win; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1944 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1945 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1946 // legacy DEPRECATED! |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1947 if (this.dropdown.hasClass('uk-dropdown-up')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1948 this.options.pos = 'top-left'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1949 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1950 if (this.dropdown.hasClass('uk-dropdown-flip')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1951 this.options.pos = this.options.pos.replace('left','right'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1952 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1953 if (this.dropdown.hasClass('uk-dropdown-center')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1954 this.options.pos = this.options.pos.replace(/(left|right)/,'center'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1955 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1956 //-- end legacy |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1957 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1958 // Init ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1959 this.element.attr('aria-haspopup', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1960 this.element.attr('aria-expanded', this.element.hasClass("uk-open")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1961 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1962 if (this.options.mode == "click" || UI.support.touch) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1963 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1964 this.on("click.uk.dropdown", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1965 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1966 var $target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1967 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1968 if (!$target.parents($this.options.dropdownSelector).length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1969 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1970 if ($target.is("a[href='#']") || $target.parent().is("a[href='#']") || ($this.dropdown.length && !$this.dropdown.is(":visible")) ){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1971 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1972 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1973 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1974 $target.blur(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1975 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1976 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1977 if (!$this.element.hasClass('uk-open')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1978 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1979 $this.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1980 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1981 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1982 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1983 if (!$this.dropdown.find(e.target).length || $target.is(".uk-dropdown-close") || $target.parents(".uk-dropdown-close").length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1984 $this.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1985 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1986 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1987 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1988 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1989 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1990 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1991 this.on("mouseenter", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1992 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1993 $this.trigger('pointerenter.uk.dropdown', [$this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1994 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1995 if ($this.remainIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1996 clearTimeout($this.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1997 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1998 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1999 if (hoverIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2000 clearTimeout(hoverIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2001 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2002 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2003 if (active && active == $this) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2004 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2005 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2006 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2007 // pseudo manuAim |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2008 if (active && active != $this) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2009 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2010 hoverIdle = setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2011 hoverIdle = setTimeout($this.show.bind($this), $this.options.delay); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2012 }, $this.options.hoverDelayIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2013 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2014 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2015 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2016 hoverIdle = setTimeout($this.show.bind($this), $this.options.delay); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2017 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2018 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2019 }).on("mouseleave", function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2020 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2021 if (hoverIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2022 clearTimeout(hoverIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2023 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2024 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2025 $this.remainIdle = setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2026 if (active && active == $this) $this.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2027 }, $this.options.remaintime); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2028 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2029 $this.trigger('pointerleave.uk.dropdown', [$this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2030 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2031 }).on("click", function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2032 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2033 var $target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2034 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2035 if ($this.remainIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2036 clearTimeout($this.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2037 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2038 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2039 if (active && active == $this) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2040 if (!$this.dropdown.find(e.target).length || $target.is(".uk-dropdown-close") || $target.parents(".uk-dropdown-close").length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2041 $this.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2042 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2043 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2044 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2045 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2046 if ($target.is("a[href='#']") || $target.parent().is("a[href='#']")){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2047 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2048 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2049 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2050 $this.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2051 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2052 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2053 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2054 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2055 show: function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2056 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2057 UI.$html.off("click.outer.dropdown"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2058 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2059 if (active && active != this) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2060 active.hide(true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2061 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2062 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2063 if (hoverIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2064 clearTimeout(hoverIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2065 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2066 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2067 this.trigger('beforeshow.uk.dropdown', [this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2068 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2069 this.checkDimensions(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2070 this.element.addClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2071 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2072 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2073 this.element.attr('aria-expanded', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2074 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2075 this.trigger('show.uk.dropdown', [this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2076 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2077 UI.Utils.checkDisplay(this.dropdown, true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2078 active = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2079 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2080 this.registerOuterClick(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2081 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2082 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2083 hide: function(force) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2084 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2085 this.trigger('beforehide.uk.dropdown', [this, force]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2086 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2087 this.element.removeClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2088 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2089 if (this.remainIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2090 clearTimeout(this.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2091 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2092 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2093 this.remainIdle = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2094 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2095 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2096 this.element.attr('aria-expanded', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2097 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2098 this.trigger('hide.uk.dropdown', [this, force]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2099 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2100 if (active == this) active = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2101 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2102 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2103 registerOuterClick: function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2104 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2105 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2106 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2107 UI.$html.off("click.outer.dropdown"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2108 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2109 setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2110 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2111 UI.$html.on("click.outer.dropdown", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2112 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2113 if (hoverIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2114 clearTimeout(hoverIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2115 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2116 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2117 var $target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2118 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2119 if (active == $this && !$this.element.find(e.target).length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2120 $this.hide(true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2121 UI.$html.off("click.outer.dropdown"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2122 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2123 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2124 }, 10); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2125 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2126 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2127 checkDimensions: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2128 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2129 if (!this.dropdown.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2130 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2131 // reset |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2132 this.dropdown.removeClass('uk-dropdown-top uk-dropdown-bottom uk-dropdown-left uk-dropdown-right uk-dropdown-stack').css({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2133 'top-left':'', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2134 'left':'', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2135 'margin-left' :'', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2136 'margin-right':'' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2137 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2138 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2139 if (this.justified && this.justified.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2140 this.dropdown.css("min-width", ""); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2141 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2142 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2143 var $this = this, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2144 pos = UI.$.extend({}, this.offsetParent.offset(), {width: this.offsetParent[0].offsetWidth, height: this.offsetParent[0].offsetHeight}), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2145 posoffset = this.options.offset, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2146 dropdown = this.dropdown, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2147 offset = dropdown.show().offset() || {left: 0, top: 0}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2148 width = dropdown.outerWidth(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2149 height = dropdown.outerHeight(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2150 boundarywidth = this.boundary.width(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2151 boundaryoffset = this.boundary[0] !== window && this.boundary.offset() ? this.boundary.offset(): {top:0, left:0}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2152 dpos = this.options.pos; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2153 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2154 var variants = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2155 "bottom-left" : {top: 0 + pos.height + posoffset, left: 0}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2156 "bottom-right" : {top: 0 + pos.height + posoffset, left: 0 + pos.width - width}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2157 "bottom-center" : {top: 0 + pos.height + posoffset, left: 0 + pos.width / 2 - width / 2}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2158 "top-left" : {top: 0 - height - posoffset, left: 0}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2159 "top-right" : {top: 0 - height - posoffset, left: 0 + pos.width - width}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2160 "top-center" : {top: 0 - height - posoffset, left: 0 + pos.width / 2 - width / 2}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2161 "left-top" : {top: 0, left: 0 - width - posoffset}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2162 "left-bottom" : {top: 0 + pos.height - height, left: 0 - width - posoffset}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2163 "left-center" : {top: 0 + pos.height / 2 - height / 2, left: 0 - width - posoffset}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2164 "right-top" : {top: 0, left: 0 + pos.width + posoffset}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2165 "right-bottom" : {top: 0 + pos.height - height, left: 0 + pos.width + posoffset}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2166 "right-center" : {top: 0 + pos.height / 2 - height / 2, left: 0 + pos.width + posoffset} |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2167 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2168 css = {}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2169 pp; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2170 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2171 pp = dpos.split('-'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2172 css = variants[dpos] ? variants[dpos] : variants['bottom-left']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2173 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2174 // justify dropdown |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2175 if (this.justified && this.justified.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2176 justify(dropdown.css({left:0}), this.justified, boundarywidth); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2177 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2178 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2179 if (this.options.preventflip !== true) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2180 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2181 var fdpos; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2182 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2183 switch(this.checkBoundary(pos.left + css.left, pos.top + css.top, width, height, boundarywidth)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2184 case "x": |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2185 if(this.options.preventflip !=='x') fdpos = flips['x'][dpos] || 'right-top'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2186 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2187 case "y": |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2188 if(this.options.preventflip !=='y') fdpos = flips['y'][dpos] || 'top-left'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2189 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2190 case "xy": |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2191 if(!this.options.preventflip) fdpos = flips['xy'][dpos] || 'right-bottom'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2192 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2193 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2194 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2195 if (fdpos) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2196 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2197 pp = fdpos.split('-'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2198 css = variants[fdpos] ? variants[fdpos] : variants['bottom-left']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2199 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2200 // check flipped |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2201 if (this.checkBoundary(pos.left + css.left, pos.top + css.top, width, height, boundarywidth)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2202 pp = dpos.split('-'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2203 css = variants[dpos] ? variants[dpos] : variants['bottom-left']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2204 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2205 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2206 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2207 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2208 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2209 if (width > boundarywidth) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2210 dropdown.addClass("uk-dropdown-stack"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2211 this.trigger('stack.uk.dropdown', [this]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2212 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2213 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2214 dropdown.css(css).css("display", "").addClass('uk-dropdown-'+pp[0]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2215 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2216 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2217 checkBoundary: function(left, top, width, height, boundarywidth) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2218 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2219 var axis = ""; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2220 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2221 if (left < 0 || ((left - UI.$win.scrollLeft())+width) > boundarywidth) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2222 axis += "x"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2223 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2224 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2225 if ((top - UI.$win.scrollTop()) < 0 || ((top - UI.$win.scrollTop())+height) > window.innerHeight) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2226 axis += "y"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2227 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2228 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2229 return axis; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2230 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2231 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2232 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2233 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2234 UI.component('dropdownOverlay', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2235 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2236 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2237 'justify' : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2238 'cls' : '', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2239 'duration': 200 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2240 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2241 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2242 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2243 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2244 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2245 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2246 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2247 UI.$("[data-uk-dropdown-overlay]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2248 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2249 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2250 if (!ele.data("dropdownOverlay")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2251 UI.dropdownOverlay(ele, UI.Utils.options(ele.attr("data-uk-dropdown-overlay"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2252 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2253 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2254 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2255 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2256 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2257 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2258 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2259 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2260 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2261 this.justified = this.options.justify ? UI.$(this.options.justify) : false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2262 this.overlay = this.element.find('uk-dropdown-overlay'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2263 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2264 if (!this.overlay.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2265 this.overlay = UI.$('<div class="uk-dropdown-overlay"></div>').appendTo(this.element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2266 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2267 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2268 this.overlay.addClass(this.options.cls); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2269 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2270 this.on({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2271 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2272 'beforeshow.uk.dropdown': function(e, dropdown) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2273 $this.dropdown = dropdown; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2274 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2275 if ($this.justified && $this.justified.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2276 justify($this.overlay.css({'display':'block', 'margin-left':'','margin-right':''}), $this.justified, $this.justified.outerWidth()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2277 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2278 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2279 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2280 'show.uk.dropdown': function(e, dropdown) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2281 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2282 var h = $this.dropdown.dropdown.outerHeight(true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2283 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2284 $this.dropdown.element.removeClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2285 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2286 $this.overlay.stop().css('display', 'block').animate({height: h}, $this.options.duration, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2287 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2288 $this.dropdown.dropdown.css('visibility', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2289 $this.dropdown.element.addClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2290 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2291 UI.Utils.checkDisplay($this.dropdown.dropdown, true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2292 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2293 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2294 $this.pointerleave = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2295 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2296 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2297 'hide.uk.dropdown': function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2298 $this.overlay.stop().animate({height: 0}, $this.options.duration); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2299 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2300 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2301 'pointerenter.uk.dropdown': function(e, dropdown) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2302 clearTimeout($this.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2303 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2304 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2305 'pointerleave.uk.dropdown': function(e, dropdown) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2306 $this.pointerleave = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2307 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2308 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2309 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2310 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2311 this.overlay.on({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2312 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2313 'mouseenter': function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2314 if ($this.remainIdle) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2315 clearTimeout($this.dropdown.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2316 clearTimeout($this.remainIdle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2317 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2318 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2319 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2320 'mouseleave': function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2321 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2322 if ($this.pointerleave && active) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2323 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2324 $this.remainIdle = setTimeout(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2325 if(active) active.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2326 }, active.options.remaintime); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2327 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2328 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2329 }) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2330 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2331 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2332 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2333 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2334 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2335 function justify(ele, justifyTo, boundarywidth, offset) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2336 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2337 ele = UI.$(ele); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2338 justifyTo = UI.$(justifyTo); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2339 boundarywidth = boundarywidth || window.innerWidth; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2340 offset = offset || ele.offset(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2341 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2342 if (justifyTo.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2343 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2344 var jwidth = justifyTo.outerWidth(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2345 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2346 ele.css("min-width", jwidth); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2347 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2348 if (UI.langdirection == 'right') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2349 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2350 var right1 = boundarywidth - (justifyTo.offset().left + jwidth), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2351 right2 = boundarywidth - (ele.offset().left + ele.outerWidth()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2352 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2353 ele.css("margin-right", right1 - right2); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2354 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2355 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2356 ele.css("margin-left", justifyTo.offset().left - offset.left); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2357 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2358 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2359 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2360 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2361 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2362 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2363 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2364 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2365 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2366 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2367 var grids = []; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2368 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2369 UI.component('gridMatchHeight', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2370 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2371 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2372 "target" : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2373 "row" : true, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2374 "ignorestacked" : false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2375 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2376 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2377 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2378 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2379 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2380 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2381 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2382 UI.$("[data-uk-grid-match]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2383 var grid = UI.$(this), obj; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2384 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2385 if (!grid.data("gridMatchHeight")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2386 obj = UI.gridMatchHeight(grid, UI.Utils.options(grid.attr("data-uk-grid-match"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2387 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2388 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2389 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2390 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2391 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2392 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2393 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2394 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2395 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2396 this.columns = this.element.children(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2397 this.elements = this.options.target ? this.find(this.options.target) : this.columns; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2398 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2399 if (!this.columns.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2400 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2401 UI.$win.on('load resize orientationchange', (function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2402 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2403 var fn = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2404 $this.match(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2405 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2406 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2407 UI.$(function() { fn(); }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2408 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2409 return UI.Utils.debounce(fn, 50); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2410 })()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2411 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2412 UI.$html.on("changed.uk.dom", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2413 $this.columns = $this.element.children(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2414 $this.elements = $this.options.target ? $this.find($this.options.target) : $this.columns; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2415 $this.match(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2416 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2417 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2418 this.on("display.uk.check", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2419 if(this.element.is(":visible")) this.match(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2420 }.bind(this)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2421 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2422 grids.push(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2423 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2424 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2425 match: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2426 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2427 var firstvisible = this.columns.filter(":visible:first"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2428 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2429 if (!firstvisible.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2430 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2431 var stacked = Math.ceil(100 * parseFloat(firstvisible.css('width')) / parseFloat(firstvisible.parent().css('width'))) >= 100; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2432 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2433 if (stacked && !this.options.ignorestacked) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2434 this.revert(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2435 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2436 UI.Utils.matchHeights(this.elements, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2437 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2438 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2439 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2440 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2441 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2442 revert: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2443 this.elements.css('min-height', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2444 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2445 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2446 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2447 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2448 UI.component('gridMargin', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2449 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2450 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2451 cls : 'uk-grid-margin', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2452 rowfirst : 'uk-row-first' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2453 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2454 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2455 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2456 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2457 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2458 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2459 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2460 UI.$("[data-uk-grid-margin]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2461 var grid = UI.$(this), obj; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2462 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2463 if (!grid.data("gridMargin")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2464 obj = UI.gridMargin(grid, UI.Utils.options(grid.attr("data-uk-grid-margin"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2465 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2466 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2467 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2468 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2469 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2470 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2471 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2472 var stackMargin = UI.stackMargin(this.element, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2473 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2474 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2475 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2476 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2477 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2478 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2479 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2480 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2481 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2482 var active = false, activeCount = 0, $html = UI.$html, body; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2483 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2484 UI.component('modal', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2485 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2486 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2487 keyboard: true, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2488 bgclose: true, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2489 minScrollHeight: 150, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2490 center: false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2491 modal: true |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2492 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2493 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2494 scrollable: false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2495 transition: false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2496 hasTransitioned: true, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2497 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2498 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2499 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2500 if (!body) body = UI.$('body'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2501 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2502 if (!this.element.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2503 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2504 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2505 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2506 this.paddingdir = "padding-" + (UI.langdirection == 'left' ? "right":"left"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2507 this.dialog = this.find(".uk-modal-dialog"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2508 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2509 this.active = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2510 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2511 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2512 this.element.attr('aria-hidden', this.element.hasClass("uk-open")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2513 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2514 this.on("click", ".uk-modal-close", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2515 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2516 $this.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2517 }).on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2518 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2519 var target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2520 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2521 if (target[0] == $this.element[0] && $this.options.bgclose) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2522 $this.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2523 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2524 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2525 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2526 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2527 toggle: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2528 return this[this.isActive() ? "hide" : "show"](); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2529 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2530 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2531 show: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2532 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2533 if (!this.element.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2534 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2535 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2536 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2537 if (this.isActive()) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2538 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2539 if (this.options.modal && active) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2540 active.hide(true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2541 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2542 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2543 this.element.removeClass("uk-open").show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2544 this.resize(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2545 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2546 if (this.options.modal) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2547 active = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2548 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2549 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2550 this.active = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2551 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2552 activeCount++; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2553 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2554 if (UI.support.transition) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2555 this.hasTransitioned = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2556 this.element.one(UI.support.transition.end, function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2557 $this.hasTransitioned = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2558 }).addClass("uk-open"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2559 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2560 this.element.addClass("uk-open"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2561 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2562 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2563 $html.addClass("uk-modal-page").height(); // force browser engine redraw |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2564 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2565 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2566 this.element.attr('aria-hidden', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2567 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2568 this.element.trigger("show.uk.modal"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2569 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2570 UI.Utils.checkDisplay(this.dialog, true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2571 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2572 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2573 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2574 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2575 hide: function(force) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2576 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2577 if (!force && UI.support.transition && this.hasTransitioned) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2578 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2579 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2580 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2581 this.one(UI.support.transition.end, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2582 $this._hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2583 }).removeClass("uk-open"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2584 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2585 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2586 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2587 this._hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2588 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2589 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2590 return this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2591 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2592 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2593 resize: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2594 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2595 var bodywidth = body.width(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2596 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2597 this.scrollbarwidth = window.innerWidth - bodywidth; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2598 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2599 body.css(this.paddingdir, this.scrollbarwidth); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2600 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2601 this.element.css('overflow-y', this.scrollbarwidth ? 'scroll' : 'auto'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2602 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2603 if (!this.updateScrollable() && this.options.center) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2604 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2605 var dh = this.dialog.outerHeight(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2606 pad = parseInt(this.dialog.css('margin-top'), 10) + parseInt(this.dialog.css('margin-bottom'), 10); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2607 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2608 if ((dh + pad) < window.innerHeight) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2609 this.dialog.css({'top': (window.innerHeight/2 - dh/2) - pad }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2610 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2611 this.dialog.css({'top': ''}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2612 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2613 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2614 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2615 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2616 updateScrollable: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2617 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2618 // has scrollable? |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2619 var scrollable = this.dialog.find('.uk-overflow-container:visible:first'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2620 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2621 if (scrollable.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2622 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2623 scrollable.css('height', 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2624 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2625 var offset = Math.abs(parseInt(this.dialog.css('margin-top'), 10)), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2626 dh = this.dialog.outerHeight(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2627 wh = window.innerHeight, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2628 h = wh - 2*(offset < 20 ? 20:offset) - dh; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2629 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2630 scrollable.css({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2631 'max-height': (h < this.options.minScrollHeight ? '':h), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2632 'height':'' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2633 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2634 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2635 return true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2636 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2637 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2638 return false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2639 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2640 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2641 _hide: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2642 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2643 this.active = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2644 if (activeCount > 0) activeCount--; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2645 else activeCount = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2646 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2647 this.element.hide().removeClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2648 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2649 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2650 this.element.attr('aria-hidden', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2651 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2652 if (!activeCount) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2653 $html.removeClass('uk-modal-page'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2654 body.css(this.paddingdir, ""); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2655 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2656 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2657 if(active===this) active = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2658 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2659 this.trigger('hide.uk.modal'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2660 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2661 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2662 isActive: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2663 return this.active; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2664 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2665 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2666 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2667 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2668 UI.component('modalTrigger', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2669 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2670 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2671 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2672 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2673 UI.$html.on("click.modal.uikit", "[data-uk-modal]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2674 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2675 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2676 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2677 if (ele.is("a")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2678 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2679 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2680 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2681 if (!ele.data("modalTrigger")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2682 var modal = UI.modalTrigger(ele, UI.Utils.options(ele.attr("data-uk-modal"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2683 modal.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2684 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2685 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2686 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2687 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2688 // close modal on esc button |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2689 UI.$html.on('keydown.modal.uikit', function (e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2690 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2691 if (active && e.keyCode === 27 && active.options.keyboard) { // ESC |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2692 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2693 active.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2694 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2695 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2696 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2697 UI.$win.on("resize orientationchange", UI.Utils.debounce(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2698 if (active) active.resize(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2699 }, 150)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2700 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2701 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2702 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2703 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2704 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2705 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2706 this.options = UI.$.extend({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2707 "target": $this.element.is("a") ? $this.element.attr("href") : false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2708 }, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2709 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2710 this.modal = UI.modal(this.options.target, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2711 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2712 this.on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2713 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2714 $this.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2715 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2716 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2717 //methods |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2718 this.proxy(this.modal, "show hide isActive"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2719 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2720 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2721 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2722 UI.modal.dialog = function(content, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2723 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2724 var modal = UI.modal(UI.$(UI.modal.dialog.template).appendTo("body"), options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2725 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2726 modal.on("hide.uk.modal", function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2727 if (modal.persist) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2728 modal.persist.appendTo(modal.persist.data("modalPersistParent")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2729 modal.persist = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2730 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2731 modal.element.remove(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2732 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2733 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2734 setContent(content, modal); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2735 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2736 return modal; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2737 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2738 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2739 UI.modal.dialog.template = '<div class="uk-modal"><div class="uk-modal-dialog" style="min-height:0;"></div></div>'; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2740 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2741 UI.modal.alert = function(content, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2742 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2743 options = UI.$.extend(true, {bgclose:false, keyboard:false, modal:false, labels:UI.modal.labels}, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2744 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2745 var modal = UI.modal.dialog(([ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2746 '<div class="uk-margin uk-modal-content">'+String(content)+'</div>', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2747 '<div class="uk-modal-footer uk-text-right"><button class="uk-button uk-button-primary uk-modal-close">'+options.labels.Ok+'</button></div>' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2748 ]).join(""), options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2749 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2750 modal.on('show.uk.modal', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2751 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2752 modal.element.find('button:first').focus(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2753 }, 50); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2754 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2755 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2756 return modal.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2757 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2758 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2759 UI.modal.confirm = function(content, onconfirm, oncancel) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2760 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2761 var options = arguments.length > 1 && arguments[arguments.length-1] ? arguments[arguments.length-1] : {}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2762 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2763 onconfirm = UI.$.isFunction(onconfirm) ? onconfirm : function(){}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2764 oncancel = UI.$.isFunction(oncancel) ? oncancel : function(){}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2765 options = UI.$.extend(true, {bgclose:false, keyboard:false, modal:false, labels:UI.modal.labels}, UI.$.isFunction(options) ? {}:options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2766 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2767 var modal = UI.modal.dialog(([ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2768 '<div class="uk-margin uk-modal-content">'+String(content)+'</div>', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2769 '<div class="uk-modal-footer uk-text-right"><button class="uk-button js-modal-confirm-cancel">'+options.labels.Cancel+'</button> <button class="uk-button uk-button-primary js-modal-confirm">'+options.labels.Ok+'</button></div>' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2770 ]).join(""), options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2771 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2772 modal.element.find(".js-modal-confirm, .js-modal-confirm-cancel").on("click", function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2773 UI.$(this).is('.js-modal-confirm') ? onconfirm() : oncancel(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2774 modal.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2775 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2776 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2777 modal.on('show.uk.modal', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2778 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2779 modal.element.find('.js-modal-confirm').focus(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2780 }, 50); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2781 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2782 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2783 return modal.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2784 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2785 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2786 UI.modal.prompt = function(text, value, onsubmit, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2787 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2788 onsubmit = UI.$.isFunction(onsubmit) ? onsubmit : function(value){}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2789 options = UI.$.extend(true, {bgclose:false, keyboard:false, modal:false, labels:UI.modal.labels}, options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2790 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2791 var modal = UI.modal.dialog(([ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2792 text ? '<div class="uk-modal-content uk-form">'+String(text)+'</div>':'', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2793 '<div class="uk-margin-small-top uk-modal-content uk-form"><p><input type="text" class="uk-width-1-1"></p></div>', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2794 '<div class="uk-modal-footer uk-text-right"><button class="uk-button uk-modal-close">'+options.labels.Cancel+'</button> <button class="uk-button uk-button-primary js-modal-ok">'+options.labels.Ok+'</button></div>' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2795 ]).join(""), options), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2796 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2797 input = modal.element.find("input[type='text']").val(value || '').on('keyup', function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2798 if (e.keyCode == 13) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2799 modal.element.find(".js-modal-ok").trigger('click'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2800 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2801 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2802 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2803 modal.element.find(".js-modal-ok").on("click", function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2804 if (onsubmit(input.val())!==false){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2805 modal.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2806 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2807 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2808 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2809 modal.on('show.uk.modal', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2810 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2811 input.focus(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2812 }, 50); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2813 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2814 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2815 return modal.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2816 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2817 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2818 UI.modal.blockUI = function(content, options) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2819 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2820 var modal = UI.modal.dialog(([ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2821 '<div class="uk-margin uk-modal-content">'+String(content || '<div class="uk-text-center">...</div>')+'</div>' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2822 ]).join(""), UI.$.extend({bgclose:false, keyboard:false, modal:false}, options)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2823 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2824 modal.content = modal.element.find('.uk-modal-content:first'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2825 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2826 return modal.show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2827 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2828 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2829 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2830 UI.modal.labels = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2831 'Ok': 'Ok', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2832 'Cancel': 'Cancel' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2833 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2834 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2835 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2836 // helper functions |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2837 function setContent(content, modal){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2838 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2839 if(!modal) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2840 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2841 if (typeof content === 'object') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2842 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2843 // convert DOM object to a jQuery object |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2844 content = content instanceof jQuery ? content : UI.$(content); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2845 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2846 if(content.parent().length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2847 modal.persist = content; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2848 modal.persist.data("modalPersistParent", content.parent()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2849 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2850 }else if (typeof content === 'string' || typeof content === 'number') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2851 // just insert the data as innerHTML |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2852 content = UI.$('<div></div>').html(content); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2853 }else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2854 // unsupported data type! |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2855 content = UI.$('<div></div>').html('UIkit.modal Error: Unsupported data type: ' + typeof content); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2856 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2857 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2858 content.appendTo(modal.element.find('.uk-modal-dialog')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2859 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2860 return modal; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2861 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2862 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2863 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2864 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2865 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2866 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2867 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2868 // navigation |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2869 UI.component('nav', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2870 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2871 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2872 "toggle": ">li.uk-parent > a[href*='#']", |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2873 "lists": ">li.uk-parent > ul", |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2874 "multiple": true |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2875 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2876 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2877 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2878 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2879 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2880 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2881 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2882 UI.$("[data-uk-nav]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2883 var nav = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2884 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2885 if (!nav.data("nav")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2886 var obj = UI.nav(nav, UI.Utils.options(nav.attr("data-uk-nav"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2887 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2888 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2889 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2890 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2891 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2892 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2893 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2894 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2895 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2896 this.on("click.uk.nav", this.options.toggle, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2897 // e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2898 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2899 $this.open(ele.parent()[0] == $this.element[0] ? ele : ele.parent("li")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2900 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2901 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2902 this.find(this.options.lists).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2903 var $ele = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2904 parent = $ele.parent(), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2905 active = parent.hasClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2906 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2907 $ele.wrap('<div style="overflow:hidden;height:0;position:relative;"></div>'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2908 parent.data("list-container", $ele.parent()[active ? 'removeClass':'addClass']('uk-hidden')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2909 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2910 // Init ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2911 parent.attr('aria-expanded', parent.hasClass("uk-open")); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2912 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2913 if (active) $this.open(parent, true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2914 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2915 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2916 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2917 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2918 open: function(li, noanimation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2919 noanimation = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2920 var $this = this, element = this.element, $li = UI.$(li), $container = $li.data('list-container'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2921 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2922 if (!this.options.multiple) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2923 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2924 element.children('.uk-open').not(li).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2925 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2926 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2927 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2928 if (ele.data('list-container')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2929 ele.data('list-container').stop().animate({height: 0}, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2930 UI.$(this).parent().removeClass('uk-open').end().addClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2931 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2932 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2933 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2934 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2935 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2936 $li.toggleClass('uk-open'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2937 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2938 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2939 $li.attr('aria-expanded', $li.hasClass('uk-open')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2940 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2941 if ($container) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2942 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2943 if ($li.hasClass('uk-open')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2944 $container.removeClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2945 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2946 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2947 if (noanimation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2948 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2949 $container.stop().height($li.hasClass('uk-open') ? 'auto' : 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2950 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2951 if (!$li.hasClass('uk-open')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2952 $container.addClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2953 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2954 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2955 this.trigger('display.uk.check'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2956 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2957 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2958 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2959 $container.stop().animate({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2960 height: ($li.hasClass('uk-open') ? getHeight($container.find('ul:first')) : 0) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2961 }, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2962 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2963 if (!$li.hasClass('uk-open')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2964 $container.addClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2965 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2966 $container.css('height', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2967 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2968 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2969 $this.trigger('display.uk.check'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2970 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2971 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2972 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2973 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2974 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2975 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2976 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2977 // helper |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2978 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2979 function getHeight(ele) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2980 var $ele = UI.$(ele), height = "auto"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2981 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2982 if ($ele.is(":visible")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2983 height = $ele.outerHeight(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2984 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2985 var tmp = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2986 position: $ele.css("position"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2987 visibility: $ele.css("visibility"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2988 display: $ele.css("display") |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2989 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2990 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2991 height = $ele.css({position: 'absolute', visibility: 'hidden', display: 'block'}).outerHeight(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2992 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2993 $ele.css(tmp); // reset element |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2994 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2995 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2996 return height; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2997 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2998 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2999 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3000 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3001 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3002 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3003 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3004 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3005 var scrollpos = {x: window.scrollX, y: window.scrollY}, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3006 $win = UI.$win, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3007 $doc = UI.$doc, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3008 $html = UI.$html, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3009 Offcanvas = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3010 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3011 show: function(element) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3012 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3013 element = UI.$(element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3014 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3015 if (!element.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3016 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3017 var $body = UI.$('body'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3018 bar = element.find(".uk-offcanvas-bar:first"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3019 rtl = (UI.langdirection == "right"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3020 flip = bar.hasClass("uk-offcanvas-bar-flip") ? -1:1, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3021 dir = flip * (rtl ? -1 : 1), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3022 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3023 scrollbarwidth = window.innerWidth - $body.width(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3024 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3025 scrollpos = {x: window.pageXOffset, y: window.pageYOffset}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3026 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3027 element.addClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3028 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3029 $body.css({"width": window.innerWidth - scrollbarwidth, "height": window.innerHeight}).addClass("uk-offcanvas-page"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3030 $body.css((rtl ? "margin-right" : "margin-left"), (rtl ? -1 : 1) * (bar.outerWidth() * dir)).width(); // .width() - force redraw |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3031 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3032 $html.css('margin-top', scrollpos.y * -1); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3033 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3034 bar.addClass("uk-offcanvas-bar-show"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3035 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3036 this._initElement(element); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3037 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3038 bar.trigger('show.uk.offcanvas', [element, bar]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3039 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3040 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3041 element.attr('aria-hidden', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3042 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3043 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3044 hide: function(force) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3045 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3046 var $body = UI.$('body'), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3047 panel = UI.$(".uk-offcanvas.uk-active"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3048 rtl = (UI.langdirection == "right"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3049 bar = panel.find(".uk-offcanvas-bar:first"), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3050 finalize = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3051 $body.removeClass("uk-offcanvas-page").css({"width": "", "height": "", "margin-left": "", "margin-right": ""}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3052 panel.removeClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3053 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3054 bar.removeClass("uk-offcanvas-bar-show"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3055 $html.css('margin-top', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3056 window.scrollTo(scrollpos.x, scrollpos.y); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3057 bar.trigger('hide.uk.offcanvas', [panel, bar]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3058 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3059 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3060 panel.attr('aria-hidden', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3061 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3062 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3063 if (!panel.length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3064 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3065 if (UI.support.transition && !force) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3066 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3067 $body.one(UI.support.transition.end, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3068 finalize(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3069 }).css((rtl ? "margin-right" : "margin-left"), ""); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3070 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3071 setTimeout(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3072 bar.removeClass("uk-offcanvas-bar-show"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3073 }, 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3074 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3075 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3076 finalize(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3077 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3078 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3079 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3080 _initElement: function(element) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3081 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3082 if (element.data("OffcanvasInit")) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3083 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3084 element.on("click.uk.offcanvas swipeRight.uk.offcanvas swipeLeft.uk.offcanvas", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3085 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3086 var target = UI.$(e.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3087 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3088 if (!e.type.match(/swipe/)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3089 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3090 if (!target.hasClass("uk-offcanvas-close")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3091 if (target.hasClass("uk-offcanvas-bar")) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3092 if (target.parents(".uk-offcanvas-bar:first").length) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3093 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3094 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3095 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3096 e.stopImmediatePropagation(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3097 Offcanvas.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3098 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3099 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3100 element.on("click", "a[href*='#']", function(e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3101 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3102 var link = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3103 href = link.attr("href"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3104 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3105 if (href == "#") { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3106 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3107 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3108 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3109 UI.$doc.one('hide.uk.offcanvas', function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3110 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3111 var target; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3112 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3113 try { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3114 target = UI.$(link[0].hash); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3115 } catch (e){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3116 target = ''; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3117 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3118 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3119 if (!target.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3120 target = UI.$('[name="'+link[0].hash.replace('#','')+'"]'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3121 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3122 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3123 if (target.length && UI.Utils.scrollToElement) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3124 UI.Utils.scrollToElement(target, UI.Utils.options(link.attr('data-uk-smooth-scroll') || '{}')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3125 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3126 window.location.href = href; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3127 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3128 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3129 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3130 Offcanvas.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3131 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3132 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3133 element.data("OffcanvasInit", true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3134 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3135 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3136 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3137 UI.component('offcanvasTrigger', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3138 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3139 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3140 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3141 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3142 $html.on("click.offcanvas.uikit", "[data-uk-offcanvas]", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3143 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3144 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3145 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3146 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3147 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3148 if (!ele.data("offcanvasTrigger")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3149 var obj = UI.offcanvasTrigger(ele, UI.Utils.options(ele.attr("data-uk-offcanvas"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3150 ele.trigger("click"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3151 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3152 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3153 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3154 $html.on('keydown.uk.offcanvas', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3155 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3156 if (e.keyCode === 27) { // ESC |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3157 Offcanvas.hide(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3158 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3159 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3160 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3161 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3162 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3163 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3164 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3165 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3166 this.options = UI.$.extend({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3167 "target": $this.element.is("a") ? $this.element.attr("href") : false |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3168 }, this.options); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3169 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3170 this.on("click", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3171 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3172 Offcanvas.show($this.options.target); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3173 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3174 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3175 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3176 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3177 UI.offcanvas = Offcanvas; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3178 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3179 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3180 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3181 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3182 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3183 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3184 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3185 var Animations; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3186 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3187 UI.component('switcher', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3188 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3189 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3190 connect : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3191 toggle : ">*", |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3192 active : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3193 animation : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3194 duration : 200, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3195 swiping : true |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3196 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3197 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3198 animating: false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3199 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3200 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3201 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3202 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3203 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3204 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3205 UI.$("[data-uk-switcher]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3206 var switcher = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3207 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3208 if (!switcher.data("switcher")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3209 var obj = UI.switcher(switcher, UI.Utils.options(switcher.attr("data-uk-switcher"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3210 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3211 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3212 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3213 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3214 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3215 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3216 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3217 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3218 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3219 this.on("click.uk.switcher", this.options.toggle, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3220 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3221 $this.show(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3222 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3223 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3224 if (this.options.connect) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3225 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3226 this.connect = UI.$(this.options.connect); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3227 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3228 this.connect.find(".uk-active").removeClass(".uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3229 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3230 // delegate switch commands within container content |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3231 if (this.connect.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3232 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3233 // Init ARIA for connect |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3234 this.connect.children().attr('aria-hidden', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3235 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3236 this.connect.on("click", '[data-uk-switcher-item]', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3237 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3238 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3239 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3240 var item = UI.$(this).attr('data-uk-switcher-item'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3241 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3242 if ($this.index == item) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3243 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3244 switch(item) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3245 case 'next': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3246 case 'previous': |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3247 $this.show($this.index + (item=='next' ? 1:-1)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3248 break; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3249 default: |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3250 $this.show(parseInt(item, 10)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3251 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3252 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3253 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3254 if (this.options.swiping) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3255 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3256 this.connect.on('swipeRight swipeLeft', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3257 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3258 if(!window.getSelection().toString()) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3259 $this.show($this.index + (e.type == 'swipeLeft' ? 1 : -1)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3260 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3261 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3262 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3263 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3264 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3265 var toggles = this.find(this.options.toggle), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3266 active = toggles.filter(".uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3267 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3268 if (active.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3269 this.show(active, false); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3270 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3271 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3272 if (this.options.active===false) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3273 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3274 active = toggles.eq(this.options.active); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3275 this.show(active.length ? active : toggles.eq(0), false); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3276 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3277 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3278 // Init ARIA for toggles |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3279 toggles.not(active).attr('aria-expanded', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3280 active.attr('aria-expanded', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3281 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3282 this.on('changed.uk.dom', function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3283 $this.connect = UI.$($this.options.connect); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3284 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3285 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3286 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3287 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3288 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3289 show: function(tab, animate) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3290 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3291 if (this.animating) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3292 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3293 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3294 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3295 if (isNaN(tab)) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3296 tab = UI.$(tab); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3297 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3298 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3299 var toggles = this.find(this.options.toggle); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3300 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3301 tab = tab < 0 ? toggles.length-1 : tab; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3302 tab = toggles.eq(toggles[tab] ? tab : 0); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3303 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3304 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3305 var $this = this, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3306 toggles = this.find(this.options.toggle), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3307 active = UI.$(tab), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3308 animation = Animations[this.options.animation] || function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3309 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3310 if (!$this.options.animation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3311 return Animations.none.apply($this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3312 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3313 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3314 var anim = $this.options.animation.split(','); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3315 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3316 if (anim.length == 1) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3317 anim[1] = anim[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3318 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3319 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3320 anim[0] = anim[0].trim(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3321 anim[1] = anim[1].trim(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3322 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3323 return coreAnimation.apply($this, [anim, current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3324 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3325 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3326 if (animate===false || !UI.support.animation) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3327 animation = Animations.none; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3328 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3329 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3330 if (active.hasClass("uk-disabled")) return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3331 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3332 // Update ARIA for Toggles |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3333 toggles.attr('aria-expanded', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3334 active.attr('aria-expanded', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3335 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3336 toggles.filter(".uk-active").removeClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3337 active.addClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3338 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3339 if (this.options.connect && this.connect.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3340 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3341 this.index = this.find(this.options.toggle).index(active); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3342 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3343 if (this.index == -1 ) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3344 this.index = 0; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3345 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3346 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3347 this.connect.each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3348 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3349 var container = UI.$(this), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3350 children = UI.$(container.children()), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3351 current = UI.$(children.filter('.uk-active')), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3352 next = UI.$(children.eq($this.index)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3353 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3354 $this.animating = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3355 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3356 animation.apply($this, [current, next]).then(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3357 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3358 current.removeClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3359 next.addClass("uk-active"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3360 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3361 // Update ARIA for connect |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3362 current.attr('aria-hidden', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3363 next.attr('aria-hidden', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3364 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3365 UI.Utils.checkDisplay(next, true); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3366 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3367 $this.animating = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3368 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3369 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3370 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3371 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3372 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3373 this.trigger("show.uk.switcher", [active]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3374 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3375 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3376 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3377 Animations = { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3378 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3379 'none': function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3380 var d = UI.$.Deferred(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3381 d.resolve(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3382 return d.promise(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3383 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3384 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3385 'fade': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3386 return coreAnimation.apply(this, ['uk-animation-fade', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3387 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3388 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3389 'slide-bottom': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3390 return coreAnimation.apply(this, ['uk-animation-slide-bottom', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3391 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3392 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3393 'slide-top': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3394 return coreAnimation.apply(this, ['uk-animation-slide-top', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3395 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3396 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3397 'slide-vertical': function(current, next, dir) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3398 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3399 var anim = ['uk-animation-slide-top', 'uk-animation-slide-bottom']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3400 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3401 if (current && current.index() > next.index()) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3402 anim.reverse(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3403 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3404 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3405 return coreAnimation.apply(this, [anim, current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3406 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3407 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3408 'slide-left': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3409 return coreAnimation.apply(this, ['uk-animation-slide-left', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3410 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3411 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3412 'slide-right': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3413 return coreAnimation.apply(this, ['uk-animation-slide-right', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3414 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3415 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3416 'slide-horizontal': function(current, next, dir) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3417 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3418 var anim = ['uk-animation-slide-right', 'uk-animation-slide-left']; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3419 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3420 if (current && current.index() > next.index()) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3421 anim.reverse(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3422 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3423 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3424 return coreAnimation.apply(this, [anim, current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3425 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3426 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3427 'scale': function(current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3428 return coreAnimation.apply(this, ['uk-animation-scale-up', current, next]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3429 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3430 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3431 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3432 UI.switcher.animations = Animations; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3433 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3434 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3435 // helpers |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3436 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3437 function coreAnimation(cls, current, next) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3438 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3439 var d = UI.$.Deferred(), clsIn = cls, clsOut = cls, release; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3440 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3441 if (next[0]===current[0]) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3442 d.resolve(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3443 return d.promise(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3444 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3445 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3446 if (typeof(cls) == 'object') { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3447 clsIn = cls[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3448 clsOut = cls[1] || cls[0]; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3449 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3450 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3451 UI.$body.css('overflow-x', 'hidden'); // fix scroll jumping in iOS |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3452 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3453 release = function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3454 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3455 if (current) current.hide().removeClass('uk-active '+clsOut+' uk-animation-reverse'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3456 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3457 next.addClass(clsIn).one(UI.support.animation.end, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3458 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3459 next.removeClass(''+clsIn+'').css({opacity:'', display:''}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3460 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3461 d.resolve(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3462 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3463 UI.$body.css('overflow-x', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3464 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3465 if (current) current.css({opacity:'', display:''}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3466 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3467 }.bind(this)).show(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3468 }; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3469 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3470 next.css('animation-duration', this.options.duration+'ms'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3471 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3472 if (current && current.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3473 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3474 current.css('animation-duration', this.options.duration+'ms'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3475 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3476 current.css('display', 'none').addClass(clsOut+' uk-animation-reverse').one(UI.support.animation.end, function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3477 release(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3478 }.bind(this)).css('display', ''); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3479 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3480 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3481 next.addClass('uk-active'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3482 release(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3483 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3484 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3485 return d.promise(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3486 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3487 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3488 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3489 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3490 (function(UI) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3491 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3492 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3493 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3494 UI.component('tab', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3495 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3496 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3497 'target' : '>li:not(.uk-tab-responsive, .uk-disabled)', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3498 'connect' : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3499 'active' : 0, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3500 'animation' : false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3501 'duration' : 200, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3502 'swiping' : true |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3503 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3504 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3505 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3506 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3507 // init code |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3508 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3509 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3510 UI.$("[data-uk-tab]", context).each(function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3511 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3512 var tab = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3513 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3514 if (!tab.data("tab")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3515 var obj = UI.tab(tab, UI.Utils.options(tab.attr("data-uk-tab"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3516 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3517 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3518 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3519 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3520 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3521 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3522 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3523 var $this = this; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3524 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3525 this.current = false; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3526 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3527 this.on("click.uk.tab", this.options.target, function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3528 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3529 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3530 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3531 if ($this.switcher && $this.switcher.animating) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3532 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3533 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3534 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3535 var current = $this.find($this.options.target).not(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3536 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3537 current.removeClass("uk-active").blur(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3538 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3539 $this.trigger("change.uk.tab", [UI.$(this).addClass("uk-active"), $this.current]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3540 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3541 $this.current = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3542 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3543 // Update ARIA |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3544 if (!$this.options.connect) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3545 current.attr('aria-expanded', 'false'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3546 UI.$(this).attr('aria-expanded', 'true'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3547 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3548 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3549 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3550 if (this.options.connect) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3551 this.connect = UI.$(this.options.connect); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3552 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3553 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3554 // init responsive tab |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3555 this.responsivetab = UI.$('<li class="uk-tab-responsive uk-active"><a></a></li>').append('<div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown"></ul><div>'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3556 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3557 this.responsivetab.dropdown = this.responsivetab.find('.uk-dropdown'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3558 this.responsivetab.lst = this.responsivetab.dropdown.find('ul'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3559 this.responsivetab.caption = this.responsivetab.find('a:first'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3560 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3561 if (this.element.hasClass("uk-tab-bottom")) this.responsivetab.dropdown.addClass("uk-dropdown-up"); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3562 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3563 // handle click |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3564 this.responsivetab.lst.on('click.uk.tab', 'a', function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3565 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3566 e.preventDefault(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3567 e.stopPropagation(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3568 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3569 var link = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3570 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3571 $this.element.children('li:not(.uk-tab-responsive)').eq(link.data('index')).trigger('click'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3572 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3573 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3574 this.on('show.uk.switcher change.uk.tab', function(e, tab) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3575 $this.responsivetab.caption.html(tab.text()); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3576 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3577 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3578 this.element.append(this.responsivetab); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3579 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3580 // init UIkit components |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3581 if (this.options.connect) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3582 this.switcher = UI.switcher(this.element, { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3583 'toggle' : '>li:not(.uk-tab-responsive)', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3584 'connect' : this.options.connect, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3585 'active' : this.options.active, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3586 'animation' : this.options.animation, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3587 'duration' : this.options.duration, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3588 'swiping' : this.options.swiping |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3589 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3590 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3591 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3592 UI.dropdown(this.responsivetab, {"mode": "click", "preventflip": "y"}); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3593 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3594 // init |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3595 $this.trigger("change.uk.tab", [this.element.find(this.options.target).not('.uk-tab-responsive').filter('.uk-active')]); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3596 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3597 this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3598 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3599 UI.$win.on('resize orientationchange', UI.Utils.debounce(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3600 if ($this.element.is(":visible")) $this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3601 }, 100)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3602 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3603 this.on('display.uk.check', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3604 if ($this.element.is(":visible")) $this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3605 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3606 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3607 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3608 check: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3609 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3610 var children = this.element.children('li:not(.uk-tab-responsive)').removeClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3611 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3612 if (!children.length) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3613 this.responsivetab.addClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3614 return; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3615 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3616 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3617 var top = (children.eq(0).offset().top + Math.ceil(children.eq(0).height()/2)), |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3618 doresponsive = false, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3619 item, link, clone; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3620 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3621 this.responsivetab.lst.empty(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3622 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3623 children.each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3624 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3625 if (UI.$(this).offset().top > top) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3626 doresponsive = true; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3627 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3628 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3629 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3630 if (doresponsive) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3631 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3632 for (var i = 0; i < children.length; i++) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3633 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3634 item = UI.$(children.eq(i)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3635 link = item.find('a'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3636 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3637 if (item.css('float') != 'none' && !item.attr('uk-dropdown')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3638 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3639 if (!item.hasClass('uk-disabled')) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3640 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3641 clone = item[0].outerHTML.replace('<a ', '<a data-index="'+i+'" '); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3642 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3643 this.responsivetab.lst.append(clone); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3644 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3645 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3646 item.addClass('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3647 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3648 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3649 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3650 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3651 this.responsivetab[this.responsivetab.lst.children('li').length ? 'removeClass':'addClass']('uk-hidden'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3652 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3653 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3654 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3655 })(UIkit); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3656 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3657 (function(UI){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3658 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3659 "use strict"; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3660 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3661 UI.component('cover', { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3662 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3663 defaults: { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3664 automute : true |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3665 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3666 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3667 boot: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3668 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3669 // auto init |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3670 UI.ready(function(context) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3671 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3672 UI.$("[data-uk-cover]", context).each(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3673 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3674 var ele = UI.$(this); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3675 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3676 if(!ele.data("cover")) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3677 var plugin = UI.cover(ele, UI.Utils.options(ele.attr("data-uk-cover"))); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3678 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3679 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3680 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3681 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3682 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3683 init: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3684 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3685 this.parent = this.element.parent(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3686 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3687 UI.$win.on('load resize orientationchange', UI.Utils.debounce(function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3688 this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3689 }.bind(this), 100)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3690 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3691 this.on("display.uk.check", function(e) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3692 if(this.element.is(":visible")) this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3693 }.bind(this)); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3694 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3695 this.check(); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3696 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3697 if (this.element.is('iframe') && this.options.automute) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3698 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3699 var src = this.element.attr('src'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3700 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3701 this.element.attr('src', '').on('load', function(){ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3702 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3703 this.contentWindow.postMessage('{ "event": "command", "func": "mute", "method":"setVolume", "value":0}', '*'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3704 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3705 }).attr('src', [src, (src.indexOf('?') > -1 ? '&':'?'), 'enablejsapi=1&api=1'].join('')); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3706 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3707 }, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3708 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3709 check: function() { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3710 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3711 this.element.css({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3712 'width' : '', |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3713 'height' : '' |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3714 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3715 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3716 this.dimension = {w: this.element.width(), h: this.element.height()}; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3717 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3718 if (this.element.attr('width') && !isNaN(this.element.attr('width'))) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3719 this.dimension.w = this.element.attr('width'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3720 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3721 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3722 if (this.element.attr('height') && !isNaN(this.element.attr('height'))) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3723 this.dimension.h = this.element.attr('height'); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3724 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3725 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3726 this.ratio = this.dimension.w / this.dimension.h; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3727 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3728 var w = this.parent.width(), h = this.parent.height(), width, height; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3729 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3730 // if element height < parent height (gap underneath) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3731 if ((w / this.ratio) < h) { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3732 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3733 width = Math.ceil(h * this.ratio); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3734 height = h; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3735 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3736 // element width < parent width (gap to right) |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3737 } else { |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3738 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3739 width = w; |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3740 height = Math.ceil(w / this.ratio); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3741 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3742 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3743 this.element.css({ |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3744 'width' : width, |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3745 'height' : height |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3746 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3747 } |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3748 }); |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3749 |
aad37ffd7d58
doc: import the training support
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3750 })(UIkit); |