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