@@ 38-825 (lines=788) @@ | ||
35 | }); |
|
36 | } |
|
37 | ||
38 | })(function($) { |
|
39 | ||
40 | "use strict"; |
|
41 | ||
42 | if (window.UIkit2) { |
|
43 | return window.UIkit2; |
|
44 | } |
|
45 | ||
46 | var UI = {}, _UI = window.UIkit || undefined; |
|
47 | ||
48 | UI.version = '2.27.4'; |
|
49 | ||
50 | UI.noConflict = function() { |
|
51 | // restore UIkit version |
|
52 | if (_UI) { |
|
53 | window.UIkit = _UI; |
|
54 | $.UIkit = _UI; |
|
55 | $.fn.uk = _UI.fn; |
|
56 | } |
|
57 | ||
58 | return UI; |
|
59 | }; |
|
60 | ||
61 | window.UIkit2 = UI; |
|
62 | ||
63 | if (!_UI) { |
|
64 | window.UIkit = UI; |
|
65 | } |
|
66 | ||
67 | // cache jQuery |
|
68 | UI.$ = $; |
|
69 | ||
70 | UI.$doc = UI.$(document); |
|
71 | UI.$win = UI.$(window); |
|
72 | UI.$html = UI.$('html'); |
|
73 | ||
74 | UI.support = {}; |
|
75 | UI.support.transition = (function() { |
|
76 | ||
77 | var transitionEnd = (function() { |
|
78 | ||
79 | var element = document.body || document.documentElement, |
|
80 | transEndEventNames = { |
|
81 | WebkitTransition : 'webkitTransitionEnd', |
|
82 | MozTransition : 'transitionend', |
|
83 | OTransition : 'oTransitionEnd otransitionend', |
|
84 | transition : 'transitionend' |
|
85 | }, name; |
|
86 | ||
87 | for (name in transEndEventNames) { |
|
88 | if (element.style[name] !== undefined) return transEndEventNames[name]; |
|
89 | } |
|
90 | }()); |
|
91 | ||
92 | return transitionEnd && { end: transitionEnd }; |
|
93 | })(); |
|
94 | ||
95 | UI.support.animation = (function() { |
|
96 | ||
97 | var animationEnd = (function() { |
|
98 | ||
99 | var element = document.body || document.documentElement, |
|
100 | animEndEventNames = { |
|
101 | WebkitAnimation : 'webkitAnimationEnd', |
|
102 | MozAnimation : 'animationend', |
|
103 | OAnimation : 'oAnimationEnd oanimationend', |
|
104 | animation : 'animationend' |
|
105 | }, name; |
|
106 | ||
107 | for (name in animEndEventNames) { |
|
108 | if (element.style[name] !== undefined) return animEndEventNames[name]; |
|
109 | } |
|
110 | }()); |
|
111 | ||
112 | return animationEnd && { end: animationEnd }; |
|
113 | })(); |
|
114 | ||
115 | // requestAnimationFrame polyfill |
|
116 | //https://github.com/darius/requestAnimationFrame |
|
117 | (function() { |
|
118 | ||
119 | Date.now = Date.now || function() { return new Date().getTime(); }; |
|
120 | ||
121 | var vendors = ['webkit', 'moz']; |
|
122 | for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { |
|
123 | var vp = vendors[i]; |
|
124 | window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; |
|
125 | window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] |
|
126 | || window[vp+'CancelRequestAnimationFrame']); |
|
127 | } |
|
128 | if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy |
|
129 | || !window.requestAnimationFrame || !window.cancelAnimationFrame) { |
|
130 | var lastTime = 0; |
|
131 | window.requestAnimationFrame = function(callback) { |
|
132 | var now = Date.now(); |
|
133 | var nextTime = Math.max(lastTime + 16, now); |
|
134 | return setTimeout(function() { callback(lastTime = nextTime); }, |
|
135 | nextTime - now); |
|
136 | }; |
|
137 | window.cancelAnimationFrame = clearTimeout; |
|
138 | } |
|
139 | }()); |
|
140 | ||
141 | UI.support.touch = ( |
|
142 | ('ontouchstart' in document) || |
|
143 | (window.DocumentTouch && document instanceof window.DocumentTouch) || |
|
144 | (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 0) || //IE 10 |
|
145 | (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 0) || //IE >=11 |
|
146 | false |
|
147 | ); |
|
148 | ||
149 | UI.support.mutationobserver = (window.MutationObserver || window.WebKitMutationObserver || null); |
|
150 | ||
151 | UI.Utils = {}; |
|
152 | ||
153 | UI.Utils.isFullscreen = function() { |
|
154 | return document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || document.fullscreenElement || false; |
|
155 | }; |
|
156 | ||
157 | UI.Utils.str2json = function(str, notevil) { |
|
158 | try { |
|
159 | if (notevil) { |
|
160 | return JSON.parse(str |
|
161 | // wrap keys without quote with valid double quote |
|
162 | .replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":';}) |
|
163 | // replacing single quote wrapped ones to double quote |
|
164 | .replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"';}) |
|
165 | ); |
|
166 | } else { |
|
167 | return (new Function('', 'var json = ' + str + '; return JSON.parse(JSON.stringify(json));'))(); |
|
168 | } |
|
169 | } catch(e) { return false; } |
|
170 | }; |
|
171 | ||
172 | UI.Utils.debounce = function(func, wait, immediate) { |
|
173 | var timeout; |
|
174 | return function() { |
|
175 | var context = this, args = arguments; |
|
176 | var later = function() { |
|
177 | timeout = null; |
|
178 | if (!immediate) func.apply(context, args); |
|
179 | }; |
|
180 | var callNow = immediate && !timeout; |
|
181 | clearTimeout(timeout); |
|
182 | timeout = setTimeout(later, wait); |
|
183 | if (callNow) func.apply(context, args); |
|
184 | }; |
|
185 | }; |
|
186 | ||
187 | UI.Utils.throttle = function (func, limit) { |
|
188 | var wait = false; |
|
189 | return function () { |
|
190 | if (!wait) { |
|
191 | func.call(); |
|
192 | wait = true; |
|
193 | setTimeout(function () { |
|
194 | wait = false; |
|
195 | }, limit); |
|
196 | } |
|
197 | } |
|
198 | }; |
|
199 | ||
200 | UI.Utils.removeCssRules = function(selectorRegEx) { |
|
201 | var idx, idxs, stylesheet, _i, _j, _k, _len, _len1, _len2, _ref; |
|
202 | ||
203 | if(!selectorRegEx) return; |
|
204 | ||
205 | setTimeout(function(){ |
|
206 | try { |
|
207 | _ref = document.styleSheets; |
|
208 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|
209 | stylesheet = _ref[_i]; |
|
210 | idxs = []; |
|
211 | stylesheet.cssRules = stylesheet.cssRules; |
|
212 | for (idx = _j = 0, _len1 = stylesheet.cssRules.length; _j < _len1; idx = ++_j) { |
|
213 | if (stylesheet.cssRules[idx].type === CSSRule.STYLE_RULE && selectorRegEx.test(stylesheet.cssRules[idx].selectorText)) { |
|
214 | idxs.unshift(idx); |
|
215 | } |
|
216 | } |
|
217 | for (_k = 0, _len2 = idxs.length; _k < _len2; _k++) { |
|
218 | stylesheet.deleteRule(idxs[_k]); |
|
219 | } |
|
220 | } |
|
221 | } catch (_error) {} |
|
222 | }, 0); |
|
223 | }; |
|
224 | ||
225 | UI.Utils.isInView = function(element, options) { |
|
226 | ||
227 | var $element = $(element); |
|
228 | ||
229 | if (!$element.is(':visible')) { |
|
230 | return false; |
|
231 | } |
|
232 | ||
233 | var window_left = UI.$win.scrollLeft(), window_top = UI.$win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top; |
|
234 | ||
235 | options = $.extend({topoffset:0, leftoffset:0}, options); |
|
236 | ||
237 | if (top + $element.height() >= window_top && top - options.topoffset <= window_top + UI.$win.height() && |
|
238 | left + $element.width() >= window_left && left - options.leftoffset <= window_left + UI.$win.width()) { |
|
239 | return true; |
|
240 | } else { |
|
241 | return false; |
|
242 | } |
|
243 | }; |
|
244 | ||
245 | UI.Utils.checkDisplay = function(context, initanimation) { |
|
246 | ||
247 | var elements = UI.$('[data-uk-margin], [data-uk-grid-match], [data-uk-grid-margin], [data-uk-check-display]', context || document), animated; |
|
248 | ||
249 | if (context && !elements.length) { |
|
250 | elements = $(context); |
|
251 | } |
|
252 | ||
253 | elements.trigger('display.uk.check'); |
|
254 | ||
255 | // fix firefox / IE animations |
|
256 | if (initanimation) { |
|
257 | ||
258 | if (typeof(initanimation)!='string') { |
|
259 | initanimation = '[class*="uk-animation-"]'; |
|
260 | } |
|
261 | ||
262 | elements.find(initanimation).each(function(){ |
|
263 | ||
264 | var ele = UI.$(this), |
|
265 | cls = ele.attr('class'), |
|
266 | anim = cls.match(/uk-animation-(.+)/); |
|
267 | ||
268 | ele.removeClass(anim[0]).width(); |
|
269 | ||
270 | ele.addClass(anim[0]); |
|
271 | }); |
|
272 | } |
|
273 | ||
274 | return elements; |
|
275 | }; |
|
276 | ||
277 | UI.Utils.options = function(string) { |
|
278 | ||
279 | if ($.type(string)!='string') return string; |
|
280 | ||
281 | if (string.indexOf(':') != -1 && string.trim().substr(-1) != '}') { |
|
282 | string = '{'+string+'}'; |
|
283 | } |
|
284 | ||
285 | var start = (string ? string.indexOf("{") : -1), options = {}; |
|
286 | ||
287 | if (start != -1) { |
|
288 | try { |
|
289 | options = UI.Utils.str2json(string.substr(start)); |
|
290 | } catch (e) {} |
|
291 | } |
|
292 | ||
293 | return options; |
|
294 | }; |
|
295 | ||
296 | UI.Utils.animate = function(element, cls) { |
|
297 | ||
298 | var d = $.Deferred(); |
|
299 | ||
300 | element = UI.$(element); |
|
301 | ||
302 | element.css('display', 'none').addClass(cls).one(UI.support.animation.end, function() { |
|
303 | element.removeClass(cls); |
|
304 | d.resolve(); |
|
305 | }); |
|
306 | ||
307 | element.css('display', ''); |
|
308 | ||
309 | return d.promise(); |
|
310 | }; |
|
311 | ||
312 | UI.Utils.uid = function(prefix) { |
|
313 | return (prefix || 'id') + (new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000)); |
|
314 | }; |
|
315 | ||
316 | UI.Utils.template = function(str, data) { |
|
317 | ||
318 | var tokens = str.replace(/\n/g, '\\n').replace(/\{\{\{\s*(.+?)\s*\}\}\}/g, "{{!$1}}").split(/(\{\{\s*(.+?)\s*\}\})/g), |
|
319 | i=0, toc, cmd, prop, val, fn, output = [], openblocks = 0; |
|
320 | ||
321 | while(i < tokens.length) { |
|
322 | ||
323 | toc = tokens[i]; |
|
324 | ||
325 | if(toc.match(/\{\{\s*(.+?)\s*\}\}/)) { |
|
326 | i = i + 1; |
|
327 | toc = tokens[i]; |
|
328 | cmd = toc[0]; |
|
329 | prop = toc.substring(toc.match(/^(\^|\#|\!|\~|\:)/) ? 1:0); |
|
330 | ||
331 | switch(cmd) { |
|
332 | case '~': |
|
333 | output.push('for(var $i=0;$i<'+prop+'.length;$i++) { var $item = '+prop+'[$i];'); |
|
334 | openblocks++; |
|
335 | break; |
|
336 | case ':': |
|
337 | output.push('for(var $key in '+prop+') { var $val = '+prop+'[$key];'); |
|
338 | openblocks++; |
|
339 | break; |
|
340 | case '#': |
|
341 | output.push('if('+prop+') {'); |
|
342 | openblocks++; |
|
343 | break; |
|
344 | case '^': |
|
345 | output.push('if(!'+prop+') {'); |
|
346 | openblocks++; |
|
347 | break; |
|
348 | case '/': |
|
349 | output.push('}'); |
|
350 | openblocks--; |
|
351 | break; |
|
352 | case '!': |
|
353 | output.push('__ret.push('+prop+');'); |
|
354 | break; |
|
355 | default: |
|
356 | output.push('__ret.push(escape('+prop+'));'); |
|
357 | break; |
|
358 | } |
|
359 | } else { |
|
360 | output.push("__ret.push('"+toc.replace(/\'/g, "\\'")+"');"); |
|
361 | } |
|
362 | i = i + 1; |
|
363 | } |
|
364 | ||
365 | fn = new Function('$data', [ |
|
366 | 'var __ret = [];', |
|
367 | 'try {', |
|
368 | 'with($data){', (!openblocks ? output.join('') : '__ret = ["Not all blocks are closed correctly."]'), '};', |
|
369 | '}catch(e){__ret = [e.message];}', |
|
370 | 'return __ret.join("").replace(/\\n\\n/g, "\\n");', |
|
371 | "function escape(html) { return String(html).replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');}" |
|
372 | ].join("\n")); |
|
373 | ||
374 | return data ? fn(data) : fn; |
|
375 | }; |
|
376 | ||
377 | UI.Utils.focus = function(element, extra) { |
|
378 | ||
379 | element = $(element); |
|
380 | ||
381 | if (!element.length) { |
|
382 | return element; |
|
383 | } |
|
384 | ||
385 | var autofocus = element.find('[autofocus]:first'), tabidx; |
|
386 | ||
387 | if (autofocus.length) { |
|
388 | return autofocus.focus(); |
|
389 | } |
|
390 | ||
391 | autofocus = element.find(':input'+(extra && (','+extra) || '')).first(); |
|
392 | ||
393 | if (autofocus.length) { |
|
394 | return autofocus.focus(); |
|
395 | } |
|
396 | ||
397 | if (!element.attr('tabindex')) { |
|
398 | tabidx = 1000; |
|
399 | element.attr('tabindex', tabidx); |
|
400 | } |
|
401 | ||
402 | element[0].focus(); |
|
403 | ||
404 | if (tabidx) { |
|
405 | element.attr('tabindex', ''); |
|
406 | } |
|
407 | ||
408 | return element; |
|
409 | } |
|
410 | ||
411 | UI.Utils.events = {}; |
|
412 | UI.Utils.events.click = UI.support.touch ? 'tap' : 'click'; |
|
413 | ||
414 | // deprecated |
|
415 | ||
416 | UI.fn = function(command, options) { |
|
417 | ||
418 | var args = arguments, cmd = command.match(/^([a-z\-]+)(?:\.([a-z]+))?/i), component = cmd[1], method = cmd[2]; |
|
419 | ||
420 | if (!UI[component]) { |
|
421 | $.error('UIkit component [' + component + '] does not exist.'); |
|
422 | return this; |
|
423 | } |
|
424 | ||
425 | return this.each(function() { |
|
426 | var $this = $(this), data = $this.data(component); |
|
427 | if (!data) $this.data(component, (data = UI[component](this, method ? undefined : options))); |
|
428 | if (method) data[method].apply(data, Array.prototype.slice.call(args, 1)); |
|
429 | }); |
|
430 | }; |
|
431 | ||
432 | $.UIkit = UI; |
|
433 | $.fn.uk = UI.fn; |
|
434 | ||
435 | UI.langdirection = UI.$html.attr("dir") == "rtl" ? "right" : "left"; |
|
436 | ||
437 | UI.components = {}; |
|
438 | ||
439 | UI.component = function(name, def, override) { |
|
440 | ||
441 | if (UI.components[name] && !override) { |
|
442 | return UI.components[name]; |
|
443 | } |
|
444 | ||
445 | var fn = function(element, options) { |
|
446 | ||
447 | var $this = this; |
|
448 | ||
449 | this.UIkit = UI; |
|
450 | this.element = element ? UI.$(element) : null; |
|
451 | this.options = $.extend(true, {}, this.defaults, options); |
|
452 | this.plugins = {}; |
|
453 | ||
454 | if (this.element) { |
|
455 | this.element.data(name, this); |
|
456 | } |
|
457 | ||
458 | this.init(); |
|
459 | ||
460 | (this.options.plugins.length ? this.options.plugins : Object.keys(fn.plugins)).forEach(function(plugin) { |
|
461 | ||
462 | if (fn.plugins[plugin].init) { |
|
463 | fn.plugins[plugin].init($this); |
|
464 | $this.plugins[plugin] = true; |
|
465 | } |
|
466 | ||
467 | }); |
|
468 | ||
469 | this.trigger('init.uk.component', [name, this]); |
|
470 | ||
471 | return this; |
|
472 | }; |
|
473 | ||
474 | fn.plugins = {}; |
|
475 | ||
476 | $.extend(true, fn.prototype, { |
|
477 | ||
478 | defaults : {plugins: []}, |
|
479 | ||
480 | boot: function(){}, |
|
481 | init: function(){}, |
|
482 | ||
483 | on: function(a1,a2,a3){ |
|
484 | return UI.$(this.element || this).on(a1,a2,a3); |
|
485 | }, |
|
486 | ||
487 | one: function(a1,a2,a3){ |
|
488 | return UI.$(this.element || this).one(a1,a2,a3); |
|
489 | }, |
|
490 | ||
491 | off: function(evt){ |
|
492 | return UI.$(this.element || this).off(evt); |
|
493 | }, |
|
494 | ||
495 | trigger: function(evt, params) { |
|
496 | return UI.$(this.element || this).trigger(evt, params); |
|
497 | }, |
|
498 | ||
499 | find: function(selector) { |
|
500 | return UI.$(this.element ? this.element: []).find(selector); |
|
501 | }, |
|
502 | ||
503 | proxy: function(obj, methods) { |
|
504 | ||
505 | var $this = this; |
|
506 | ||
507 | methods.split(' ').forEach(function(method) { |
|
508 | if (!$this[method]) $this[method] = function() { return obj[method].apply(obj, arguments); }; |
|
509 | }); |
|
510 | }, |
|
511 | ||
512 | mixin: function(obj, methods) { |
|
513 | ||
514 | var $this = this; |
|
515 | ||
516 | methods.split(' ').forEach(function(method) { |
|
517 | if (!$this[method]) $this[method] = obj[method].bind($this); |
|
518 | }); |
|
519 | }, |
|
520 | ||
521 | option: function() { |
|
522 | ||
523 | if (arguments.length == 1) { |
|
524 | return this.options[arguments[0]] || undefined; |
|
525 | } else if (arguments.length == 2) { |
|
526 | this.options[arguments[0]] = arguments[1]; |
|
527 | } |
|
528 | } |
|
529 | ||
530 | }, def); |
|
531 | ||
532 | this.components[name] = fn; |
|
533 | ||
534 | this[name] = function() { |
|
535 | ||
536 | var element, options; |
|
537 | ||
538 | if (arguments.length) { |
|
539 | ||
540 | switch(arguments.length) { |
|
541 | case 1: |
|
542 | ||
543 | if (typeof arguments[0] === 'string' || arguments[0].nodeType || arguments[0] instanceof jQuery) { |
|
544 | element = $(arguments[0]); |
|
545 | } else { |
|
546 | options = arguments[0]; |
|
547 | } |
|
548 | ||
549 | break; |
|
550 | case 2: |
|
551 | ||
552 | element = $(arguments[0]); |
|
553 | options = arguments[1]; |
|
554 | break; |
|
555 | } |
|
556 | } |
|
557 | ||
558 | if (element && element.data(name)) { |
|
559 | return element.data(name); |
|
560 | } |
|
561 | ||
562 | return (new UI.components[name](element, options)); |
|
563 | }; |
|
564 | ||
565 | if (UI.domready) { |
|
566 | UI.component.boot(name); |
|
567 | } |
|
568 | ||
569 | return fn; |
|
570 | }; |
|
571 | ||
572 | UI.plugin = function(component, name, def) { |
|
573 | this.components[component].plugins[name] = def; |
|
574 | }; |
|
575 | ||
576 | UI.component.boot = function(name) { |
|
577 | ||
578 | if (UI.components[name].prototype && UI.components[name].prototype.boot && !UI.components[name].booted) { |
|
579 | UI.components[name].prototype.boot.apply(UI, []); |
|
580 | UI.components[name].booted = true; |
|
581 | } |
|
582 | }; |
|
583 | ||
584 | UI.component.bootComponents = function() { |
|
585 | ||
586 | for (var component in UI.components) { |
|
587 | UI.component.boot(component); |
|
588 | } |
|
589 | }; |
|
590 | ||
591 | ||
592 | // DOM mutation save ready helper function |
|
593 | ||
594 | UI.domObservers = []; |
|
595 | UI.domready = false; |
|
596 | ||
597 | UI.ready = function(fn) { |
|
598 | ||
599 | UI.domObservers.push(fn); |
|
600 | ||
601 | if (UI.domready) { |
|
602 | fn(document); |
|
603 | } |
|
604 | }; |
|
605 | ||
606 | UI.on = function(a1,a2,a3){ |
|
607 | ||
608 | if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
|
609 | a2.apply(UI.$doc); |
|
610 | } |
|
611 | ||
612 | return UI.$doc.on(a1,a2,a3); |
|
613 | }; |
|
614 | ||
615 | UI.one = function(a1,a2,a3){ |
|
616 | ||
617 | if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
|
618 | a2.apply(UI.$doc); |
|
619 | return UI.$doc; |
|
620 | } |
|
621 | ||
622 | return UI.$doc.one(a1,a2,a3); |
|
623 | }; |
|
624 | ||
625 | UI.trigger = function(evt, params) { |
|
626 | return UI.$doc.trigger(evt, params); |
|
627 | }; |
|
628 | ||
629 | UI.domObserve = function(selector, fn) { |
|
630 | ||
631 | if(!UI.support.mutationobserver) return; |
|
632 | ||
633 | fn = fn || function() {}; |
|
634 | ||
635 | UI.$(selector).each(function() { |
|
636 | ||
637 | var element = this, |
|
638 | $element = UI.$(element); |
|
639 | ||
640 | if ($element.data('observer')) { |
|
641 | return; |
|
642 | } |
|
643 | ||
644 | try { |
|
645 | ||
646 | var observer = new UI.support.mutationobserver(UI.Utils.debounce(function(mutations) { |
|
647 | fn.apply(element, [$element]); |
|
648 | $element.trigger('changed.uk.dom'); |
|
649 | }, 50), {childList: true, subtree: true}); |
|
650 | ||
651 | // pass in the target node, as well as the observer options |
|
652 | observer.observe(element, { childList: true, subtree: true }); |
|
653 | ||
654 | $element.data('observer', observer); |
|
655 | ||
656 | } catch(e) {} |
|
657 | }); |
|
658 | }; |
|
659 | ||
660 | UI.init = function(root) { |
|
661 | ||
662 | root = root || document; |
|
663 | ||
664 | UI.domObservers.forEach(function(fn){ |
|
665 | fn(root); |
|
666 | }); |
|
667 | }; |
|
668 | ||
669 | UI.on('domready.uk.dom', function(){ |
|
670 | ||
671 | UI.init(); |
|
672 | ||
673 | if (UI.domready) UI.Utils.checkDisplay(); |
|
674 | }); |
|
675 | ||
676 | document.addEventListener('DOMContentLoaded', function(){ |
|
677 | ||
678 | var domReady = function() { |
|
679 | ||
680 | UI.$body = UI.$('body'); |
|
681 | ||
682 | UI.trigger('beforeready.uk.dom'); |
|
683 | ||
684 | UI.component.bootComponents(); |
|
685 | ||
686 | // custom scroll observer |
|
687 | var rafToken = requestAnimationFrame((function(){ |
|
688 | ||
689 | var memory = {dir: {x:0, y:0}, x: window.pageXOffset, y:window.pageYOffset}; |
|
690 | ||
691 | var fn = function(){ |
|
692 | // reading this (window.page[X|Y]Offset) causes a full page recalc of the layout in Chrome, |
|
693 | // so we only want to do this once |
|
694 | var wpxo = window.pageXOffset; |
|
695 | var wpyo = window.pageYOffset; |
|
696 | ||
697 | // Did the scroll position change since the last time we were here? |
|
698 | if (memory.x != wpxo || memory.y != wpyo) { |
|
699 | ||
700 | // Set the direction of the scroll and store the new position |
|
701 | if (wpxo != memory.x) {memory.dir.x = wpxo > memory.x ? 1:-1; } else { memory.dir.x = 0; } |
|
702 | if (wpyo != memory.y) {memory.dir.y = wpyo > memory.y ? 1:-1; } else { memory.dir.y = 0; } |
|
703 | ||
704 | memory.x = wpxo; |
|
705 | memory.y = wpyo; |
|
706 | ||
707 | // Trigger the scroll event, this could probably be sent using memory.clone() but this is |
|
708 | // more explicit and easier to see exactly what is being sent in the event. |
|
709 | UI.$doc.trigger('scrolling.uk.document', [{ |
|
710 | dir: {x: memory.dir.x, y: memory.dir.y}, x: wpxo, y: wpyo |
|
711 | }]); |
|
712 | } |
|
713 | ||
714 | cancelAnimationFrame(rafToken); |
|
715 | rafToken = requestAnimationFrame(fn); |
|
716 | }; |
|
717 | ||
718 | if (UI.support.touch) { |
|
719 | UI.$html.on('touchmove touchend MSPointerMove MSPointerUp pointermove pointerup', fn); |
|
720 | } |
|
721 | ||
722 | if (memory.x || memory.y) fn(); |
|
723 | ||
724 | return fn; |
|
725 | ||
726 | })()); |
|
727 | ||
728 | // run component init functions on dom |
|
729 | UI.trigger('domready.uk.dom'); |
|
730 | ||
731 | if (UI.support.touch) { |
|
732 | ||
733 | // remove css hover rules for touch devices |
|
734 | // UI.Utils.removeCssRules(/\.uk-(?!navbar).*:hover/); |
|
735 | ||
736 | // viewport unit fix for uk-height-viewport - should be fixed in iOS 8 |
|
737 | if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) { |
|
738 | ||
739 | UI.$win.on('load orientationchange resize', UI.Utils.debounce((function(){ |
|
740 | ||
741 | var fn = function() { |
|
742 | $('.uk-height-viewport').css('height', window.innerHeight); |
|
743 | return fn; |
|
744 | }; |
|
745 | ||
746 | return fn(); |
|
747 | ||
748 | })(), 100)); |
|
749 | } |
|
750 | } |
|
751 | ||
752 | UI.trigger('afterready.uk.dom'); |
|
753 | ||
754 | // mark that domready is left behind |
|
755 | UI.domready = true; |
|
756 | ||
757 | // auto init js components |
|
758 | if (UI.support.mutationobserver) { |
|
759 | ||
760 | var initFn = UI.Utils.debounce(function(){ |
|
761 | requestAnimationFrame(function(){ UI.init(document.body);}); |
|
762 | }, 10); |
|
763 | ||
764 | (new UI.support.mutationobserver(function(mutations) { |
|
765 | ||
766 | var init = false; |
|
767 | ||
768 | mutations.every(function(mutation){ |
|
769 | ||
770 | if (mutation.type != 'childList') return true; |
|
771 | ||
772 | for (var i = 0, node; i < mutation.addedNodes.length; ++i) { |
|
773 | ||
774 | node = mutation.addedNodes[i]; |
|
775 | ||
776 | if (node.outerHTML && node.outerHTML.indexOf('data-uk-') !== -1) { |
|
777 | return (init = true) && false; |
|
778 | } |
|
779 | } |
|
780 | return true; |
|
781 | }); |
|
782 | ||
783 | if (init) initFn(); |
|
784 | ||
785 | })).observe(document.body, {childList: true, subtree: true}); |
|
786 | } |
|
787 | }; |
|
788 | ||
789 | if (document.readyState == 'complete' || document.readyState == 'interactive') { |
|
790 | setTimeout(domReady); |
|
791 | } |
|
792 | ||
793 | return domReady; |
|
794 | ||
795 | }()); |
|
796 | ||
797 | // add touch identifier class |
|
798 | UI.$html.addClass(UI.support.touch ? 'uk-touch' : 'uk-notouch'); |
|
799 | ||
800 | // add uk-hover class on tap to support overlays on touch devices |
|
801 | if (UI.support.touch) { |
|
802 | ||
803 | var hoverset = false, |
|
804 | exclude, |
|
805 | hovercls = 'uk-hover', |
|
806 | selector = '.uk-overlay, .uk-overlay-hover, .uk-overlay-toggle, .uk-animation-hover, .uk-has-hover'; |
|
807 | ||
808 | UI.$html.on('mouseenter touchstart MSPointerDown pointerdown', selector, function() { |
|
809 | ||
810 | if (hoverset) $('.'+hovercls).removeClass(hovercls); |
|
811 | ||
812 | hoverset = $(this).addClass(hovercls); |
|
813 | ||
814 | }).on('mouseleave touchend MSPointerUp pointerup', function(e) { |
|
815 | ||
816 | exclude = $(e.target).parents(selector); |
|
817 | ||
818 | if (hoverset) { |
|
819 | hoverset.not(exclude).removeClass(hovercls); |
|
820 | } |
|
821 | }); |
|
822 | } |
|
823 | ||
824 | return UI; |
|
825 | }); |
|
826 | ||
827 | // Based on Zeptos touch.js |
|
828 | // https://raw.github.com/madrobby/zepto/master/src/touch.js |
@@ 38-825 (lines=788) @@ | ||
35 | }); |
|
36 | } |
|
37 | ||
38 | })(function($) { |
|
39 | ||
40 | "use strict"; |
|
41 | ||
42 | if (window.UIkit2) { |
|
43 | return window.UIkit2; |
|
44 | } |
|
45 | ||
46 | var UI = {}, _UI = window.UIkit || undefined; |
|
47 | ||
48 | UI.version = '2.27.4'; |
|
49 | ||
50 | UI.noConflict = function() { |
|
51 | // restore UIkit version |
|
52 | if (_UI) { |
|
53 | window.UIkit = _UI; |
|
54 | $.UIkit = _UI; |
|
55 | $.fn.uk = _UI.fn; |
|
56 | } |
|
57 | ||
58 | return UI; |
|
59 | }; |
|
60 | ||
61 | window.UIkit2 = UI; |
|
62 | ||
63 | if (!_UI) { |
|
64 | window.UIkit = UI; |
|
65 | } |
|
66 | ||
67 | // cache jQuery |
|
68 | UI.$ = $; |
|
69 | ||
70 | UI.$doc = UI.$(document); |
|
71 | UI.$win = UI.$(window); |
|
72 | UI.$html = UI.$('html'); |
|
73 | ||
74 | UI.support = {}; |
|
75 | UI.support.transition = (function() { |
|
76 | ||
77 | var transitionEnd = (function() { |
|
78 | ||
79 | var element = document.body || document.documentElement, |
|
80 | transEndEventNames = { |
|
81 | WebkitTransition : 'webkitTransitionEnd', |
|
82 | MozTransition : 'transitionend', |
|
83 | OTransition : 'oTransitionEnd otransitionend', |
|
84 | transition : 'transitionend' |
|
85 | }, name; |
|
86 | ||
87 | for (name in transEndEventNames) { |
|
88 | if (element.style[name] !== undefined) return transEndEventNames[name]; |
|
89 | } |
|
90 | }()); |
|
91 | ||
92 | return transitionEnd && { end: transitionEnd }; |
|
93 | })(); |
|
94 | ||
95 | UI.support.animation = (function() { |
|
96 | ||
97 | var animationEnd = (function() { |
|
98 | ||
99 | var element = document.body || document.documentElement, |
|
100 | animEndEventNames = { |
|
101 | WebkitAnimation : 'webkitAnimationEnd', |
|
102 | MozAnimation : 'animationend', |
|
103 | OAnimation : 'oAnimationEnd oanimationend', |
|
104 | animation : 'animationend' |
|
105 | }, name; |
|
106 | ||
107 | for (name in animEndEventNames) { |
|
108 | if (element.style[name] !== undefined) return animEndEventNames[name]; |
|
109 | } |
|
110 | }()); |
|
111 | ||
112 | return animationEnd && { end: animationEnd }; |
|
113 | })(); |
|
114 | ||
115 | // requestAnimationFrame polyfill |
|
116 | //https://github.com/darius/requestAnimationFrame |
|
117 | (function() { |
|
118 | ||
119 | Date.now = Date.now || function() { return new Date().getTime(); }; |
|
120 | ||
121 | var vendors = ['webkit', 'moz']; |
|
122 | for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { |
|
123 | var vp = vendors[i]; |
|
124 | window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; |
|
125 | window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] |
|
126 | || window[vp+'CancelRequestAnimationFrame']); |
|
127 | } |
|
128 | if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy |
|
129 | || !window.requestAnimationFrame || !window.cancelAnimationFrame) { |
|
130 | var lastTime = 0; |
|
131 | window.requestAnimationFrame = function(callback) { |
|
132 | var now = Date.now(); |
|
133 | var nextTime = Math.max(lastTime + 16, now); |
|
134 | return setTimeout(function() { callback(lastTime = nextTime); }, |
|
135 | nextTime - now); |
|
136 | }; |
|
137 | window.cancelAnimationFrame = clearTimeout; |
|
138 | } |
|
139 | }()); |
|
140 | ||
141 | UI.support.touch = ( |
|
142 | ('ontouchstart' in document) || |
|
143 | (window.DocumentTouch && document instanceof window.DocumentTouch) || |
|
144 | (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 0) || //IE 10 |
|
145 | (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 0) || //IE >=11 |
|
146 | false |
|
147 | ); |
|
148 | ||
149 | UI.support.mutationobserver = (window.MutationObserver || window.WebKitMutationObserver || null); |
|
150 | ||
151 | UI.Utils = {}; |
|
152 | ||
153 | UI.Utils.isFullscreen = function() { |
|
154 | return document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || document.fullscreenElement || false; |
|
155 | }; |
|
156 | ||
157 | UI.Utils.str2json = function(str, notevil) { |
|
158 | try { |
|
159 | if (notevil) { |
|
160 | return JSON.parse(str |
|
161 | // wrap keys without quote with valid double quote |
|
162 | .replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":';}) |
|
163 | // replacing single quote wrapped ones to double quote |
|
164 | .replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"';}) |
|
165 | ); |
|
166 | } else { |
|
167 | return (new Function('', 'var json = ' + str + '; return JSON.parse(JSON.stringify(json));'))(); |
|
168 | } |
|
169 | } catch(e) { return false; } |
|
170 | }; |
|
171 | ||
172 | UI.Utils.debounce = function(func, wait, immediate) { |
|
173 | var timeout; |
|
174 | return function() { |
|
175 | var context = this, args = arguments; |
|
176 | var later = function() { |
|
177 | timeout = null; |
|
178 | if (!immediate) func.apply(context, args); |
|
179 | }; |
|
180 | var callNow = immediate && !timeout; |
|
181 | clearTimeout(timeout); |
|
182 | timeout = setTimeout(later, wait); |
|
183 | if (callNow) func.apply(context, args); |
|
184 | }; |
|
185 | }; |
|
186 | ||
187 | UI.Utils.throttle = function (func, limit) { |
|
188 | var wait = false; |
|
189 | return function () { |
|
190 | if (!wait) { |
|
191 | func.call(); |
|
192 | wait = true; |
|
193 | setTimeout(function () { |
|
194 | wait = false; |
|
195 | }, limit); |
|
196 | } |
|
197 | } |
|
198 | }; |
|
199 | ||
200 | UI.Utils.removeCssRules = function(selectorRegEx) { |
|
201 | var idx, idxs, stylesheet, _i, _j, _k, _len, _len1, _len2, _ref; |
|
202 | ||
203 | if(!selectorRegEx) return; |
|
204 | ||
205 | setTimeout(function(){ |
|
206 | try { |
|
207 | _ref = document.styleSheets; |
|
208 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
|
209 | stylesheet = _ref[_i]; |
|
210 | idxs = []; |
|
211 | stylesheet.cssRules = stylesheet.cssRules; |
|
212 | for (idx = _j = 0, _len1 = stylesheet.cssRules.length; _j < _len1; idx = ++_j) { |
|
213 | if (stylesheet.cssRules[idx].type === CSSRule.STYLE_RULE && selectorRegEx.test(stylesheet.cssRules[idx].selectorText)) { |
|
214 | idxs.unshift(idx); |
|
215 | } |
|
216 | } |
|
217 | for (_k = 0, _len2 = idxs.length; _k < _len2; _k++) { |
|
218 | stylesheet.deleteRule(idxs[_k]); |
|
219 | } |
|
220 | } |
|
221 | } catch (_error) {} |
|
222 | }, 0); |
|
223 | }; |
|
224 | ||
225 | UI.Utils.isInView = function(element, options) { |
|
226 | ||
227 | var $element = $(element); |
|
228 | ||
229 | if (!$element.is(':visible')) { |
|
230 | return false; |
|
231 | } |
|
232 | ||
233 | var window_left = UI.$win.scrollLeft(), window_top = UI.$win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top; |
|
234 | ||
235 | options = $.extend({topoffset:0, leftoffset:0}, options); |
|
236 | ||
237 | if (top + $element.height() >= window_top && top - options.topoffset <= window_top + UI.$win.height() && |
|
238 | left + $element.width() >= window_left && left - options.leftoffset <= window_left + UI.$win.width()) { |
|
239 | return true; |
|
240 | } else { |
|
241 | return false; |
|
242 | } |
|
243 | }; |
|
244 | ||
245 | UI.Utils.checkDisplay = function(context, initanimation) { |
|
246 | ||
247 | var elements = UI.$('[data-uk-margin], [data-uk-grid-match], [data-uk-grid-margin], [data-uk-check-display]', context || document), animated; |
|
248 | ||
249 | if (context && !elements.length) { |
|
250 | elements = $(context); |
|
251 | } |
|
252 | ||
253 | elements.trigger('display.uk.check'); |
|
254 | ||
255 | // fix firefox / IE animations |
|
256 | if (initanimation) { |
|
257 | ||
258 | if (typeof(initanimation)!='string') { |
|
259 | initanimation = '[class*="uk-animation-"]'; |
|
260 | } |
|
261 | ||
262 | elements.find(initanimation).each(function(){ |
|
263 | ||
264 | var ele = UI.$(this), |
|
265 | cls = ele.attr('class'), |
|
266 | anim = cls.match(/uk-animation-(.+)/); |
|
267 | ||
268 | ele.removeClass(anim[0]).width(); |
|
269 | ||
270 | ele.addClass(anim[0]); |
|
271 | }); |
|
272 | } |
|
273 | ||
274 | return elements; |
|
275 | }; |
|
276 | ||
277 | UI.Utils.options = function(string) { |
|
278 | ||
279 | if ($.type(string)!='string') return string; |
|
280 | ||
281 | if (string.indexOf(':') != -1 && string.trim().substr(-1) != '}') { |
|
282 | string = '{'+string+'}'; |
|
283 | } |
|
284 | ||
285 | var start = (string ? string.indexOf("{") : -1), options = {}; |
|
286 | ||
287 | if (start != -1) { |
|
288 | try { |
|
289 | options = UI.Utils.str2json(string.substr(start)); |
|
290 | } catch (e) {} |
|
291 | } |
|
292 | ||
293 | return options; |
|
294 | }; |
|
295 | ||
296 | UI.Utils.animate = function(element, cls) { |
|
297 | ||
298 | var d = $.Deferred(); |
|
299 | ||
300 | element = UI.$(element); |
|
301 | ||
302 | element.css('display', 'none').addClass(cls).one(UI.support.animation.end, function() { |
|
303 | element.removeClass(cls); |
|
304 | d.resolve(); |
|
305 | }); |
|
306 | ||
307 | element.css('display', ''); |
|
308 | ||
309 | return d.promise(); |
|
310 | }; |
|
311 | ||
312 | UI.Utils.uid = function(prefix) { |
|
313 | return (prefix || 'id') + (new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000)); |
|
314 | }; |
|
315 | ||
316 | UI.Utils.template = function(str, data) { |
|
317 | ||
318 | var tokens = str.replace(/\n/g, '\\n').replace(/\{\{\{\s*(.+?)\s*\}\}\}/g, "{{!$1}}").split(/(\{\{\s*(.+?)\s*\}\})/g), |
|
319 | i=0, toc, cmd, prop, val, fn, output = [], openblocks = 0; |
|
320 | ||
321 | while(i < tokens.length) { |
|
322 | ||
323 | toc = tokens[i]; |
|
324 | ||
325 | if(toc.match(/\{\{\s*(.+?)\s*\}\}/)) { |
|
326 | i = i + 1; |
|
327 | toc = tokens[i]; |
|
328 | cmd = toc[0]; |
|
329 | prop = toc.substring(toc.match(/^(\^|\#|\!|\~|\:)/) ? 1:0); |
|
330 | ||
331 | switch(cmd) { |
|
332 | case '~': |
|
333 | output.push('for(var $i=0;$i<'+prop+'.length;$i++) { var $item = '+prop+'[$i];'); |
|
334 | openblocks++; |
|
335 | break; |
|
336 | case ':': |
|
337 | output.push('for(var $key in '+prop+') { var $val = '+prop+'[$key];'); |
|
338 | openblocks++; |
|
339 | break; |
|
340 | case '#': |
|
341 | output.push('if('+prop+') {'); |
|
342 | openblocks++; |
|
343 | break; |
|
344 | case '^': |
|
345 | output.push('if(!'+prop+') {'); |
|
346 | openblocks++; |
|
347 | break; |
|
348 | case '/': |
|
349 | output.push('}'); |
|
350 | openblocks--; |
|
351 | break; |
|
352 | case '!': |
|
353 | output.push('__ret.push('+prop+');'); |
|
354 | break; |
|
355 | default: |
|
356 | output.push('__ret.push(escape('+prop+'));'); |
|
357 | break; |
|
358 | } |
|
359 | } else { |
|
360 | output.push("__ret.push('"+toc.replace(/\'/g, "\\'")+"');"); |
|
361 | } |
|
362 | i = i + 1; |
|
363 | } |
|
364 | ||
365 | fn = new Function('$data', [ |
|
366 | 'var __ret = [];', |
|
367 | 'try {', |
|
368 | 'with($data){', (!openblocks ? output.join('') : '__ret = ["Not all blocks are closed correctly."]'), '};', |
|
369 | '}catch(e){__ret = [e.message];}', |
|
370 | 'return __ret.join("").replace(/\\n\\n/g, "\\n");', |
|
371 | "function escape(html) { return String(html).replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');}" |
|
372 | ].join("\n")); |
|
373 | ||
374 | return data ? fn(data) : fn; |
|
375 | }; |
|
376 | ||
377 | UI.Utils.focus = function(element, extra) { |
|
378 | ||
379 | element = $(element); |
|
380 | ||
381 | if (!element.length) { |
|
382 | return element; |
|
383 | } |
|
384 | ||
385 | var autofocus = element.find('[autofocus]:first'), tabidx; |
|
386 | ||
387 | if (autofocus.length) { |
|
388 | return autofocus.focus(); |
|
389 | } |
|
390 | ||
391 | autofocus = element.find(':input'+(extra && (','+extra) || '')).first(); |
|
392 | ||
393 | if (autofocus.length) { |
|
394 | return autofocus.focus(); |
|
395 | } |
|
396 | ||
397 | if (!element.attr('tabindex')) { |
|
398 | tabidx = 1000; |
|
399 | element.attr('tabindex', tabidx); |
|
400 | } |
|
401 | ||
402 | element[0].focus(); |
|
403 | ||
404 | if (tabidx) { |
|
405 | element.attr('tabindex', ''); |
|
406 | } |
|
407 | ||
408 | return element; |
|
409 | } |
|
410 | ||
411 | UI.Utils.events = {}; |
|
412 | UI.Utils.events.click = UI.support.touch ? 'tap' : 'click'; |
|
413 | ||
414 | // deprecated |
|
415 | ||
416 | UI.fn = function(command, options) { |
|
417 | ||
418 | var args = arguments, cmd = command.match(/^([a-z\-]+)(?:\.([a-z]+))?/i), component = cmd[1], method = cmd[2]; |
|
419 | ||
420 | if (!UI[component]) { |
|
421 | $.error('UIkit component [' + component + '] does not exist.'); |
|
422 | return this; |
|
423 | } |
|
424 | ||
425 | return this.each(function() { |
|
426 | var $this = $(this), data = $this.data(component); |
|
427 | if (!data) $this.data(component, (data = UI[component](this, method ? undefined : options))); |
|
428 | if (method) data[method].apply(data, Array.prototype.slice.call(args, 1)); |
|
429 | }); |
|
430 | }; |
|
431 | ||
432 | $.UIkit = UI; |
|
433 | $.fn.uk = UI.fn; |
|
434 | ||
435 | UI.langdirection = UI.$html.attr("dir") == "rtl" ? "right" : "left"; |
|
436 | ||
437 | UI.components = {}; |
|
438 | ||
439 | UI.component = function(name, def, override) { |
|
440 | ||
441 | if (UI.components[name] && !override) { |
|
442 | return UI.components[name]; |
|
443 | } |
|
444 | ||
445 | var fn = function(element, options) { |
|
446 | ||
447 | var $this = this; |
|
448 | ||
449 | this.UIkit = UI; |
|
450 | this.element = element ? UI.$(element) : null; |
|
451 | this.options = $.extend(true, {}, this.defaults, options); |
|
452 | this.plugins = {}; |
|
453 | ||
454 | if (this.element) { |
|
455 | this.element.data(name, this); |
|
456 | } |
|
457 | ||
458 | this.init(); |
|
459 | ||
460 | (this.options.plugins.length ? this.options.plugins : Object.keys(fn.plugins)).forEach(function(plugin) { |
|
461 | ||
462 | if (fn.plugins[plugin].init) { |
|
463 | fn.plugins[plugin].init($this); |
|
464 | $this.plugins[plugin] = true; |
|
465 | } |
|
466 | ||
467 | }); |
|
468 | ||
469 | this.trigger('init.uk.component', [name, this]); |
|
470 | ||
471 | return this; |
|
472 | }; |
|
473 | ||
474 | fn.plugins = {}; |
|
475 | ||
476 | $.extend(true, fn.prototype, { |
|
477 | ||
478 | defaults : {plugins: []}, |
|
479 | ||
480 | boot: function(){}, |
|
481 | init: function(){}, |
|
482 | ||
483 | on: function(a1,a2,a3){ |
|
484 | return UI.$(this.element || this).on(a1,a2,a3); |
|
485 | }, |
|
486 | ||
487 | one: function(a1,a2,a3){ |
|
488 | return UI.$(this.element || this).one(a1,a2,a3); |
|
489 | }, |
|
490 | ||
491 | off: function(evt){ |
|
492 | return UI.$(this.element || this).off(evt); |
|
493 | }, |
|
494 | ||
495 | trigger: function(evt, params) { |
|
496 | return UI.$(this.element || this).trigger(evt, params); |
|
497 | }, |
|
498 | ||
499 | find: function(selector) { |
|
500 | return UI.$(this.element ? this.element: []).find(selector); |
|
501 | }, |
|
502 | ||
503 | proxy: function(obj, methods) { |
|
504 | ||
505 | var $this = this; |
|
506 | ||
507 | methods.split(' ').forEach(function(method) { |
|
508 | if (!$this[method]) $this[method] = function() { return obj[method].apply(obj, arguments); }; |
|
509 | }); |
|
510 | }, |
|
511 | ||
512 | mixin: function(obj, methods) { |
|
513 | ||
514 | var $this = this; |
|
515 | ||
516 | methods.split(' ').forEach(function(method) { |
|
517 | if (!$this[method]) $this[method] = obj[method].bind($this); |
|
518 | }); |
|
519 | }, |
|
520 | ||
521 | option: function() { |
|
522 | ||
523 | if (arguments.length == 1) { |
|
524 | return this.options[arguments[0]] || undefined; |
|
525 | } else if (arguments.length == 2) { |
|
526 | this.options[arguments[0]] = arguments[1]; |
|
527 | } |
|
528 | } |
|
529 | ||
530 | }, def); |
|
531 | ||
532 | this.components[name] = fn; |
|
533 | ||
534 | this[name] = function() { |
|
535 | ||
536 | var element, options; |
|
537 | ||
538 | if (arguments.length) { |
|
539 | ||
540 | switch(arguments.length) { |
|
541 | case 1: |
|
542 | ||
543 | if (typeof arguments[0] === 'string' || arguments[0].nodeType || arguments[0] instanceof jQuery) { |
|
544 | element = $(arguments[0]); |
|
545 | } else { |
|
546 | options = arguments[0]; |
|
547 | } |
|
548 | ||
549 | break; |
|
550 | case 2: |
|
551 | ||
552 | element = $(arguments[0]); |
|
553 | options = arguments[1]; |
|
554 | break; |
|
555 | } |
|
556 | } |
|
557 | ||
558 | if (element && element.data(name)) { |
|
559 | return element.data(name); |
|
560 | } |
|
561 | ||
562 | return (new UI.components[name](element, options)); |
|
563 | }; |
|
564 | ||
565 | if (UI.domready) { |
|
566 | UI.component.boot(name); |
|
567 | } |
|
568 | ||
569 | return fn; |
|
570 | }; |
|
571 | ||
572 | UI.plugin = function(component, name, def) { |
|
573 | this.components[component].plugins[name] = def; |
|
574 | }; |
|
575 | ||
576 | UI.component.boot = function(name) { |
|
577 | ||
578 | if (UI.components[name].prototype && UI.components[name].prototype.boot && !UI.components[name].booted) { |
|
579 | UI.components[name].prototype.boot.apply(UI, []); |
|
580 | UI.components[name].booted = true; |
|
581 | } |
|
582 | }; |
|
583 | ||
584 | UI.component.bootComponents = function() { |
|
585 | ||
586 | for (var component in UI.components) { |
|
587 | UI.component.boot(component); |
|
588 | } |
|
589 | }; |
|
590 | ||
591 | ||
592 | // DOM mutation save ready helper function |
|
593 | ||
594 | UI.domObservers = []; |
|
595 | UI.domready = false; |
|
596 | ||
597 | UI.ready = function(fn) { |
|
598 | ||
599 | UI.domObservers.push(fn); |
|
600 | ||
601 | if (UI.domready) { |
|
602 | fn(document); |
|
603 | } |
|
604 | }; |
|
605 | ||
606 | UI.on = function(a1,a2,a3){ |
|
607 | ||
608 | if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
|
609 | a2.apply(UI.$doc); |
|
610 | } |
|
611 | ||
612 | return UI.$doc.on(a1,a2,a3); |
|
613 | }; |
|
614 | ||
615 | UI.one = function(a1,a2,a3){ |
|
616 | ||
617 | if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { |
|
618 | a2.apply(UI.$doc); |
|
619 | return UI.$doc; |
|
620 | } |
|
621 | ||
622 | return UI.$doc.one(a1,a2,a3); |
|
623 | }; |
|
624 | ||
625 | UI.trigger = function(evt, params) { |
|
626 | return UI.$doc.trigger(evt, params); |
|
627 | }; |
|
628 | ||
629 | UI.domObserve = function(selector, fn) { |
|
630 | ||
631 | if(!UI.support.mutationobserver) return; |
|
632 | ||
633 | fn = fn || function() {}; |
|
634 | ||
635 | UI.$(selector).each(function() { |
|
636 | ||
637 | var element = this, |
|
638 | $element = UI.$(element); |
|
639 | ||
640 | if ($element.data('observer')) { |
|
641 | return; |
|
642 | } |
|
643 | ||
644 | try { |
|
645 | ||
646 | var observer = new UI.support.mutationobserver(UI.Utils.debounce(function(mutations) { |
|
647 | fn.apply(element, [$element]); |
|
648 | $element.trigger('changed.uk.dom'); |
|
649 | }, 50), {childList: true, subtree: true}); |
|
650 | ||
651 | // pass in the target node, as well as the observer options |
|
652 | observer.observe(element, { childList: true, subtree: true }); |
|
653 | ||
654 | $element.data('observer', observer); |
|
655 | ||
656 | } catch(e) {} |
|
657 | }); |
|
658 | }; |
|
659 | ||
660 | UI.init = function(root) { |
|
661 | ||
662 | root = root || document; |
|
663 | ||
664 | UI.domObservers.forEach(function(fn){ |
|
665 | fn(root); |
|
666 | }); |
|
667 | }; |
|
668 | ||
669 | UI.on('domready.uk.dom', function(){ |
|
670 | ||
671 | UI.init(); |
|
672 | ||
673 | if (UI.domready) UI.Utils.checkDisplay(); |
|
674 | }); |
|
675 | ||
676 | document.addEventListener('DOMContentLoaded', function(){ |
|
677 | ||
678 | var domReady = function() { |
|
679 | ||
680 | UI.$body = UI.$('body'); |
|
681 | ||
682 | UI.trigger('beforeready.uk.dom'); |
|
683 | ||
684 | UI.component.bootComponents(); |
|
685 | ||
686 | // custom scroll observer |
|
687 | var rafToken = requestAnimationFrame((function(){ |
|
688 | ||
689 | var memory = {dir: {x:0, y:0}, x: window.pageXOffset, y:window.pageYOffset}; |
|
690 | ||
691 | var fn = function(){ |
|
692 | // reading this (window.page[X|Y]Offset) causes a full page recalc of the layout in Chrome, |
|
693 | // so we only want to do this once |
|
694 | var wpxo = window.pageXOffset; |
|
695 | var wpyo = window.pageYOffset; |
|
696 | ||
697 | // Did the scroll position change since the last time we were here? |
|
698 | if (memory.x != wpxo || memory.y != wpyo) { |
|
699 | ||
700 | // Set the direction of the scroll and store the new position |
|
701 | if (wpxo != memory.x) {memory.dir.x = wpxo > memory.x ? 1:-1; } else { memory.dir.x = 0; } |
|
702 | if (wpyo != memory.y) {memory.dir.y = wpyo > memory.y ? 1:-1; } else { memory.dir.y = 0; } |
|
703 | ||
704 | memory.x = wpxo; |
|
705 | memory.y = wpyo; |
|
706 | ||
707 | // Trigger the scroll event, this could probably be sent using memory.clone() but this is |
|
708 | // more explicit and easier to see exactly what is being sent in the event. |
|
709 | UI.$doc.trigger('scrolling.uk.document', [{ |
|
710 | dir: {x: memory.dir.x, y: memory.dir.y}, x: wpxo, y: wpyo |
|
711 | }]); |
|
712 | } |
|
713 | ||
714 | cancelAnimationFrame(rafToken); |
|
715 | rafToken = requestAnimationFrame(fn); |
|
716 | }; |
|
717 | ||
718 | if (UI.support.touch) { |
|
719 | UI.$html.on('touchmove touchend MSPointerMove MSPointerUp pointermove pointerup', fn); |
|
720 | } |
|
721 | ||
722 | if (memory.x || memory.y) fn(); |
|
723 | ||
724 | return fn; |
|
725 | ||
726 | })()); |
|
727 | ||
728 | // run component init functions on dom |
|
729 | UI.trigger('domready.uk.dom'); |
|
730 | ||
731 | if (UI.support.touch) { |
|
732 | ||
733 | // remove css hover rules for touch devices |
|
734 | // UI.Utils.removeCssRules(/\.uk-(?!navbar).*:hover/); |
|
735 | ||
736 | // viewport unit fix for uk-height-viewport - should be fixed in iOS 8 |
|
737 | if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) { |
|
738 | ||
739 | UI.$win.on('load orientationchange resize', UI.Utils.debounce((function(){ |
|
740 | ||
741 | var fn = function() { |
|
742 | $('.uk-height-viewport').css('height', window.innerHeight); |
|
743 | return fn; |
|
744 | }; |
|
745 | ||
746 | return fn(); |
|
747 | ||
748 | })(), 100)); |
|
749 | } |
|
750 | } |
|
751 | ||
752 | UI.trigger('afterready.uk.dom'); |
|
753 | ||
754 | // mark that domready is left behind |
|
755 | UI.domready = true; |
|
756 | ||
757 | // auto init js components |
|
758 | if (UI.support.mutationobserver) { |
|
759 | ||
760 | var initFn = UI.Utils.debounce(function(){ |
|
761 | requestAnimationFrame(function(){ UI.init(document.body);}); |
|
762 | }, 10); |
|
763 | ||
764 | (new UI.support.mutationobserver(function(mutations) { |
|
765 | ||
766 | var init = false; |
|
767 | ||
768 | mutations.every(function(mutation){ |
|
769 | ||
770 | if (mutation.type != 'childList') return true; |
|
771 | ||
772 | for (var i = 0, node; i < mutation.addedNodes.length; ++i) { |
|
773 | ||
774 | node = mutation.addedNodes[i]; |
|
775 | ||
776 | if (node.outerHTML && node.outerHTML.indexOf('data-uk-') !== -1) { |
|
777 | return (init = true) && false; |
|
778 | } |
|
779 | } |
|
780 | return true; |
|
781 | }); |
|
782 | ||
783 | if (init) initFn(); |
|
784 | ||
785 | })).observe(document.body, {childList: true, subtree: true}); |
|
786 | } |
|
787 | }; |
|
788 | ||
789 | if (document.readyState == 'complete' || document.readyState == 'interactive') { |
|
790 | setTimeout(domReady); |
|
791 | } |
|
792 | ||
793 | return domReady; |
|
794 | ||
795 | }()); |
|
796 | ||
797 | // add touch identifier class |
|
798 | UI.$html.addClass(UI.support.touch ? 'uk-touch' : 'uk-notouch'); |
|
799 | ||
800 | // add uk-hover class on tap to support overlays on touch devices |
|
801 | if (UI.support.touch) { |
|
802 | ||
803 | var hoverset = false, |
|
804 | exclude, |
|
805 | hovercls = 'uk-hover', |
|
806 | selector = '.uk-overlay, .uk-overlay-hover, .uk-overlay-toggle, .uk-animation-hover, .uk-has-hover'; |
|
807 | ||
808 | UI.$html.on('mouseenter touchstart MSPointerDown pointerdown', selector, function() { |
|
809 | ||
810 | if (hoverset) $('.'+hovercls).removeClass(hovercls); |
|
811 | ||
812 | hoverset = $(this).addClass(hovercls); |
|
813 | ||
814 | }).on('mouseleave touchend MSPointerUp pointerup', function(e) { |
|
815 | ||
816 | exclude = $(e.target).parents(selector); |
|
817 | ||
818 | if (hoverset) { |
|
819 | hoverset.not(exclude).removeClass(hovercls); |
|
820 | } |
|
821 | }); |
|
822 | } |
|
823 | ||
824 | return UI; |
|
825 | }); |
|
826 |