A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2388 lines
69 KiB

  1. /*! UIkit 2.3.1 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
  2. (function($, doc, global) {
  3. "use strict";
  4. var UI = $.UIkit || {}, $html = $("html"), $win = $(window);
  5. if (UI.fn) {
  6. return;
  7. }
  8. UI.version = '2.3.1';
  9. UI.fn = function(command, options) {
  10. var args = arguments, cmd = command.match(/^([a-z\-]+)(?:\.([a-z]+))?/i), component = cmd[1], method = cmd[2];
  11. if (!UI[component]) {
  12. $.error("UIkit component [" + component + "] does not exist.");
  13. return this;
  14. }
  15. return this.each(function() {
  16. var $this = $(this), data = $this.data(component);
  17. if (!data) $this.data(component, (data = new UI[component](this, method ? undefined : options)));
  18. if (method) data[method].apply(data, Array.prototype.slice.call(args, 1));
  19. });
  20. };
  21. UI.support = {};
  22. UI.support.transition = (function() {
  23. var transitionEnd = (function() {
  24. var element = doc.body || doc.documentElement,
  25. transEndEventNames = {
  26. WebkitTransition: 'webkitTransitionEnd',
  27. MozTransition: 'transitionend',
  28. OTransition: 'oTransitionEnd otransitionend',
  29. transition: 'transitionend'
  30. }, name;
  31. for (name in transEndEventNames) {
  32. if (element.style[name] !== undefined) {
  33. return transEndEventNames[name];
  34. }
  35. }
  36. }());
  37. return transitionEnd && { end: transitionEnd };
  38. })();
  39. UI.support.requestAnimationFrame = global.requestAnimationFrame || global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.msRequestAnimationFrame || global.oRequestAnimationFrame || function(callback){ global.setTimeout(callback, 1000/60); };
  40. UI.support.touch = (
  41. ('ontouchstart' in window && navigator.userAgent.toLowerCase().match(/mobile|tablet/)) ||
  42. (global.DocumentTouch && document instanceof global.DocumentTouch) ||
  43. (global.navigator['msPointerEnabled'] && global.navigator['msMaxTouchPoints'] > 0) || //IE 10
  44. (global.navigator['pointerEnabled'] && global.navigator['maxTouchPoints'] > 0) || //IE >=11
  45. false
  46. );
  47. UI.support.mutationobserver = (global.MutationObserver || global.WebKitMutationObserver || global.MozMutationObserver || null);
  48. UI.Utils = {};
  49. UI.Utils.debounce = function(func, wait, immediate) {
  50. var timeout;
  51. return function() {
  52. var context = this, args = arguments;
  53. var later = function() {
  54. timeout = null;
  55. if (!immediate) func.apply(context, args);
  56. };
  57. var callNow = immediate && !timeout;
  58. clearTimeout(timeout);
  59. timeout = setTimeout(later, wait);
  60. if (callNow) func.apply(context, args);
  61. };
  62. };
  63. UI.Utils.removeCssRules = function(selectorRegEx) {
  64. var idx, idxs, stylesheet, _i, _j, _k, _len, _len1, _len2, _ref;
  65. if(!selectorRegEx) return;
  66. setTimeout(function(){
  67. try {
  68. _ref = document.styleSheets;
  69. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  70. stylesheet = _ref[_i];
  71. idxs = [];
  72. stylesheet.cssRules = stylesheet.cssRules;
  73. for (idx = _j = 0, _len1 = stylesheet.cssRules.length; _j < _len1; idx = ++_j) {
  74. if (stylesheet.cssRules[idx].type === CSSRule.STYLE_RULE && selectorRegEx.test(stylesheet.cssRules[idx].selectorText)) {
  75. idxs.unshift(idx);
  76. }
  77. }
  78. for (_k = 0, _len2 = idxs.length; _k < _len2; _k++) {
  79. stylesheet.deleteRule(idxs[_k]);
  80. }
  81. }
  82. } catch (_error) {}
  83. }, 0);
  84. };
  85. UI.Utils.isInView = function(element, options) {
  86. var $element = $(element);
  87. if (!$element.is(':visible')) {
  88. return false;
  89. }
  90. var window_left = $win.scrollLeft(), window_top = $win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top;
  91. options = $.extend({topoffset:0, leftoffset:0}, options);
  92. if (top + $element.height() >= window_top && top - options.topoffset <= window_top + $win.height() &&
  93. left + $element.width() >= window_left && left - options.leftoffset <= window_left + $win.width()) {
  94. return true;
  95. } else {
  96. return false;
  97. }
  98. };
  99. UI.Utils.options = function(string) {
  100. if ($.isPlainObject(string)) return string;
  101. var start = (string ? string.indexOf("{") : -1), options = {};
  102. if (start != -1) {
  103. try {
  104. options = (new Function("", "var json = " + string.substr(start) + "; return JSON.parse(JSON.stringify(json));"))();
  105. } catch (e) {}
  106. }
  107. return options;
  108. };
  109. UI.Utils.events = {};
  110. UI.Utils.events.click = UI.support.touch ? 'tap' : 'click';
  111. $.UIkit = UI;
  112. $.fn.uk = UI.fn;
  113. $.UIkit.langdirection = $html.attr("dir") == "rtl" ? "right" : "left";
  114. $(function(){
  115. $(doc).trigger("uk-domready");
  116. // Check for dom modifications
  117. if(!UI.support.mutationobserver) return;
  118. var observer = new UI.support.mutationobserver(UI.Utils.debounce(function(mutations) {
  119. $(doc).trigger("uk-domready");
  120. }, 300));
  121. // pass in the target node, as well as the observer options
  122. observer.observe(document.body, { childList: true, subtree: true });
  123. // remove css hover rules for touch devices
  124. if (UI.support.touch) {
  125. //UI.Utils.removeCssRules(/\.uk-(?!navbar).*:hover/);
  126. }
  127. });
  128. // add touch identifier class
  129. $html.addClass(UI.support.touch ? "uk-touch" : "uk-notouch");
  130. })(jQuery, document, window);
  131. (function($, UI) {
  132. "use strict";
  133. var win = $(window), event = 'resize orientationchange';
  134. var StackMargin = function(element, options) {
  135. var $this = this, $element = $(element);
  136. if($element.data("stackMargin")) return;
  137. this.element = $element;
  138. this.columns = this.element.children();
  139. this.options = $.extend({}, StackMargin.defaults, options);
  140. if (!this.columns.length) return;
  141. win.on(event, (function() {
  142. var fn = function() {
  143. $this.process();
  144. };
  145. $(function() {
  146. fn();
  147. win.on("load", fn);
  148. });
  149. return UI.Utils.debounce(fn, 150);
  150. })());
  151. $(document).on("uk-domready", function(e) {
  152. $this.columns = $this.element.children();
  153. $this.process();
  154. });
  155. this.element.data("stackMargin", this);
  156. };
  157. $.extend(StackMargin.prototype, {
  158. process: function() {
  159. var $this = this;
  160. this.revert();
  161. var skip = false,
  162. firstvisible = this.columns.filter(":visible:first"),
  163. offset = firstvisible.length ? firstvisible.offset().top : false;
  164. if (offset === false) return;
  165. this.columns.each(function() {
  166. var column = $(this);
  167. if (column.is(":visible")) {
  168. if (skip) {
  169. column.addClass($this.options.cls);
  170. } else {
  171. if (column.offset().top != offset) {
  172. column.addClass($this.options.cls);
  173. skip = true;
  174. }
  175. }
  176. }
  177. });
  178. return this;
  179. },
  180. revert: function() {
  181. this.columns.removeClass(this.options.cls);
  182. return this;
  183. }
  184. });
  185. StackMargin.defaults = {
  186. 'cls': 'uk-margin-small-top'
  187. };
  188. UI["stackMargin"] = StackMargin;
  189. // init code
  190. $(document).on("uk-domready", function(e) {
  191. $("[data-uk-margin]").each(function() {
  192. var ele = $(this), obj;
  193. if (!ele.data("stackMargin")) {
  194. obj = new StackMargin(ele, UI.Utils.options(ele.attr("data-uk-margin")));
  195. }
  196. });
  197. });
  198. })(jQuery, jQuery.UIkit);
  199. // Based on Zeptos touch.js
  200. // https://raw.github.com/madrobby/zepto/master/src/touch.js
  201. // Zepto.js may be freely distributed under the MIT license.
  202. ;(function($){
  203. var touch = {},
  204. touchTimeout, tapTimeout, swipeTimeout, longTapTimeout,
  205. longTapDelay = 750,
  206. gesture;
  207. function swipeDirection(x1, x2, y1, y2) {
  208. return Math.abs(x1 - x2) >= Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down');
  209. }
  210. function longTap() {
  211. longTapTimeout = null;
  212. if (touch.last) {
  213. touch.el.trigger('longTap');
  214. touch = {};
  215. }
  216. }
  217. function cancelLongTap() {
  218. if (longTapTimeout) clearTimeout(longTapTimeout);
  219. longTapTimeout = null;
  220. }
  221. function cancelAll() {
  222. if (touchTimeout) clearTimeout(touchTimeout);
  223. if (tapTimeout) clearTimeout(tapTimeout);
  224. if (swipeTimeout) clearTimeout(swipeTimeout);
  225. if (longTapTimeout) clearTimeout(longTapTimeout);
  226. touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null;
  227. touch = {};
  228. }
  229. function isPrimaryTouch(event){
  230. return event.pointerType == event.MSPOINTER_TYPE_TOUCH && event.isPrimary;
  231. }
  232. $(function(){
  233. var now, delta, deltaX = 0, deltaY = 0, firstTouch;
  234. if ('MSGesture' in window) {
  235. gesture = new MSGesture();
  236. gesture.target = document.body;
  237. }
  238. $(document)
  239. .bind('MSGestureEnd', function(e){
  240. var swipeDirectionFromVelocity = e.originalEvent.velocityX > 1 ? 'Right' : e.originalEvent.velocityX < -1 ? 'Left' : e.originalEvent.velocityY > 1 ? 'Down' : e.originalEvent.velocityY < -1 ? 'Up' : null;
  241. if (swipeDirectionFromVelocity) {
  242. touch.el.trigger('swipe');
  243. touch.el.trigger('swipe'+ swipeDirectionFromVelocity);
  244. }
  245. })
  246. .on('touchstart MSPointerDown', function(e){
  247. if(e.type == 'MSPointerDown' && !isPrimaryTouch(e.originalEvent)) return;
  248. firstTouch = e.type == 'MSPointerDown' ? e : e.originalEvent.touches[0];
  249. now = Date.now();
  250. delta = now - (touch.last || now);
  251. touch.el = $('tagName' in firstTouch.target ? firstTouch.target : firstTouch.target.parentNode);
  252. if(touchTimeout) clearTimeout(touchTimeout);
  253. touch.x1 = firstTouch.pageX;
  254. touch.y1 = firstTouch.pageY;
  255. if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
  256. touch.last = now;
  257. longTapTimeout = setTimeout(longTap, longTapDelay);
  258. // adds the current touch contact for IE gesture recognition
  259. if (gesture && e.type == 'MSPointerDown') gesture.addPointer(e.originalEvent.pointerId);
  260. })
  261. .on('touchmove MSPointerMove', function(e){
  262. if(e.type == 'MSPointerMove' && !isPrimaryTouch(e.originalEvent)) return;
  263. firstTouch = e.type == 'MSPointerMove' ? e : e.originalEvent.touches[0];
  264. cancelLongTap();
  265. touch.x2 = firstTouch.pageX;
  266. touch.y2 = firstTouch.pageY;
  267. deltaX += Math.abs(touch.x1 - touch.x2);
  268. deltaY += Math.abs(touch.y1 - touch.y2);
  269. })
  270. .on('touchend MSPointerUp', function(e){
  271. if(e.type == 'MSPointerUp' && !isPrimaryTouch(e.originalEvent)) return;
  272. cancelLongTap();
  273. // swipe
  274. if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)){
  275. swipeTimeout = setTimeout(function() {
  276. touch.el.trigger('swipe');
  277. touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)));
  278. touch = {};
  279. }, 0);
  280. // normal tap
  281. } else if ('last' in touch) {
  282. // don't fire tap when delta position changed by more than 30 pixels,
  283. // for instance when moving to a point and back to origin
  284. if (isNaN(deltaX) || (deltaX < 30 && deltaY < 30)) {
  285. // delay by one tick so we can cancel the 'tap' event if 'scroll' fires
  286. // ('tap' fires before 'scroll')
  287. tapTimeout = setTimeout(function() {
  288. // trigger universal 'tap' with the option to cancelTouch()
  289. // (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
  290. var event = $.Event('tap');
  291. event.cancelTouch = cancelAll;
  292. touch.el.trigger(event);
  293. // trigger double tap immediately
  294. if (touch.isDoubleTap) {
  295. touch.el.trigger('doubleTap');
  296. touch = {};
  297. }
  298. // trigger single tap after 250ms of inactivity
  299. else {
  300. touchTimeout = setTimeout(function(){
  301. touchTimeout = null;
  302. touch.el.trigger('singleTap');
  303. touch = {};
  304. }, 250);
  305. }
  306. }, 0);
  307. } else {
  308. touch = {};
  309. }
  310. deltaX = deltaY = 0;
  311. }
  312. })
  313. // when the browser window loses focus,
  314. // for example when a modal dialog is shown,
  315. // cancel all ongoing events
  316. .on('touchcancel MSPointerCancel', cancelAll);
  317. // scrolling the window indicates intention of the user
  318. // to scroll, not tap or swipe, so cancel all ongoing events
  319. $(window).on('scroll', cancelAll);
  320. });
  321. ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){
  322. $.fn[eventName] = function(callback){ return $(this).on(eventName, callback); };
  323. });
  324. })(jQuery);
  325. (function($, UI) {
  326. "use strict";
  327. var Alert = function(element, options) {
  328. var $this = this;
  329. this.options = $.extend({}, Alert.defaults, options);
  330. this.element = $(element);
  331. if(this.element.data("alert")) return;
  332. this.element.on("click", this.options.trigger, function(e) {
  333. e.preventDefault();
  334. $this.close();
  335. });
  336. this.element.data("alert", this);
  337. };
  338. $.extend(Alert.prototype, {
  339. close: function() {
  340. var element = this.element.trigger("close");
  341. if (this.options.fade) {
  342. element.css("overflow", "hidden").css("max-height", element.height()).animate({
  343. "height": 0,
  344. "opacity": 0,
  345. "padding-top": 0,
  346. "padding-bottom": 0,
  347. "margin-top": 0,
  348. "margin-bottom": 0
  349. }, this.options.duration, removeElement);
  350. } else {
  351. removeElement();
  352. }
  353. function removeElement() {
  354. element.trigger("closed").remove();
  355. }
  356. }
  357. });
  358. Alert.defaults = {
  359. "fade": true,
  360. "duration": 200,
  361. "trigger": ".uk-alert-close"
  362. };
  363. UI["alert"] = Alert;
  364. // init code
  365. $(document).on("click.alert.uikit", "[data-uk-alert]", function(e) {
  366. var ele = $(this);
  367. if (!ele.data("alert")) {
  368. var alert = new Alert(ele, UI.Utils.options(ele.data("uk-alert")));
  369. if ($(e.target).is(ele.data("alert").options.trigger)) {
  370. e.preventDefault();
  371. alert.close();
  372. }
  373. }
  374. });
  375. })(jQuery, jQuery.UIkit);
  376. (function($, UI) {
  377. "use strict";
  378. var ButtonRadio = function(element, options) {
  379. var $this = this, $element = $(element);
  380. if($element.data("buttonRadio")) return;
  381. this.options = $.extend({}, ButtonRadio.defaults, options);
  382. this.element = $element.on("click", this.options.target, function(e) {
  383. e.preventDefault();
  384. $element.find($this.options.target).not(this).removeClass("uk-active").blur();
  385. $element.trigger("change", [$(this).addClass("uk-active")]);
  386. });
  387. this.element.data("buttonRadio", this);
  388. };
  389. $.extend(ButtonRadio.prototype, {
  390. getSelected: function() {
  391. this.element.find(".uk-active");
  392. }
  393. });
  394. ButtonRadio.defaults = {
  395. "target": ".uk-button"
  396. };
  397. var ButtonCheckbox = function(element, options) {
  398. var $element = $(element);
  399. if($element.data("buttonCheckbox")) return;
  400. this.options = $.extend({}, ButtonCheckbox.defaults, options);
  401. this.element = $element.on("click", this.options.target, function(e) {
  402. e.preventDefault();
  403. $element.trigger("change", [$(this).toggleClass("uk-active").blur()]);
  404. });
  405. this.element.data("buttonCheckbox", this);
  406. };
  407. $.extend(ButtonCheckbox.prototype, {
  408. getSelected: function() {
  409. this.element.find(".uk-active");
  410. }
  411. });
  412. ButtonCheckbox.defaults = {
  413. "target": ".uk-button"
  414. };
  415. var Button = function(element, options) {
  416. var $this = this, $element = $(element);
  417. if($element.data("button")) return;
  418. this.options = $.extend({}, Button.defaults, options);
  419. this.element = $element.on("click", function(e) {
  420. e.preventDefault();
  421. $this.toggle();
  422. $element.trigger("change", [$element.blur().hasClass("uk-active")]);
  423. });
  424. this.element.data("button", this);
  425. };
  426. $.extend(Button.prototype, {
  427. options: {},
  428. toggle: function() {
  429. this.element.toggleClass("uk-active");
  430. }
  431. });
  432. Button.defaults = {};
  433. UI["button"] = Button;
  434. UI["buttonCheckbox"] = ButtonCheckbox;
  435. UI["buttonRadio"] = ButtonRadio;
  436. // init code
  437. $(document).on("click.buttonradio.uikit", "[data-uk-button-radio]", function(e) {
  438. var ele = $(this);
  439. if (!ele.data("buttonRadio")) {
  440. var obj = new ButtonRadio(ele, UI.Utils.options(ele.attr("data-uk-button-radio")));
  441. if ($(e.target).is(obj.options.target)) {
  442. $(e.target).trigger("click");
  443. }
  444. }
  445. });
  446. $(document).on("click.buttoncheckbox.uikit", "[data-uk-button-checkbox]", function(e) {
  447. var ele = $(this);
  448. if (!ele.data("buttonCheckbox")) {
  449. var obj = new ButtonCheckbox(ele, UI.Utils.options(ele.attr("data-uk-button-checkbox")));
  450. if ($(e.target).is(obj.options.target)) {
  451. $(e.target).trigger("click");
  452. }
  453. }
  454. });
  455. $(document).on("click.button.uikit", "[data-uk-button]", function(e) {
  456. var ele = $(this);
  457. if (!ele.data("button")) {
  458. var obj = new Button(ele, ele.attr("data-uk-button"));
  459. ele.trigger("click");
  460. }
  461. });
  462. })(jQuery, jQuery.UIkit);
  463. (function($, UI) {
  464. "use strict";
  465. var active = false,
  466. Dropdown = function(element, options) {
  467. var $this = this, $element = $(element);
  468. if($element.data("dropdown")) return;
  469. this.options = $.extend({}, Dropdown.defaults, options);
  470. this.element = $element;
  471. this.dropdown = this.element.find(".uk-dropdown");
  472. this.centered = this.dropdown.hasClass("uk-dropdown-center");
  473. this.justified = this.options.justify ? $(this.options.justify) : false;
  474. this.boundary = $(this.options.boundary);
  475. if(!this.boundary.length) {
  476. this.boundary = $(window);
  477. }
  478. if (this.options.mode == "click" || UI.support.touch) {
  479. this.element.on("click", function(e) {
  480. var $target = $(e.target);
  481. if (!$target.parents(".uk-dropdown").length) {
  482. if ($target.is("a[href='#']") || $target.parent().is("a[href='#']")){
  483. e.preventDefault();
  484. }
  485. $target.blur();
  486. }
  487. if (!$this.element.hasClass("uk-open")) {
  488. $this.show();
  489. } else {
  490. if ($target.is("a") || !$this.element.find(".uk-dropdown").find(e.target).length) {
  491. $this.element.removeClass("uk-open");
  492. active = false;
  493. }
  494. }
  495. });
  496. } else {
  497. this.element.on("mouseenter", function(e) {
  498. if ($this.remainIdle) {
  499. clearTimeout($this.remainIdle);
  500. }
  501. $this.show();
  502. }).on("mouseleave", function() {
  503. $this.remainIdle = setTimeout(function() {
  504. $this.element.removeClass("uk-open");
  505. $this.remainIdle = false;
  506. if (active && active[0] == $this.element[0]) active = false;
  507. }, $this.options.remaintime);
  508. });
  509. }
  510. this.element.data("dropdown", this);
  511. };
  512. $.extend(Dropdown.prototype, {
  513. remainIdle: false,
  514. show: function(){
  515. if (active && active[0] != this.element[0]) {
  516. active.removeClass("uk-open");
  517. }
  518. this.checkDimensions();
  519. this.element.addClass("uk-open");
  520. active = this.element;
  521. this.registerOuterClick();
  522. },
  523. registerOuterClick: function(){
  524. var $this = this;
  525. $(document).off("click.outer.dropdown");
  526. setTimeout(function() {
  527. $(document).on("click.outer.dropdown", function(e) {
  528. if (active && active[0] == $this.element[0] && ($(e.target).is("a") || !$this.element.find(".uk-dropdown").find(e.target).length)) {
  529. active.removeClass("uk-open");
  530. $(document).off("click.outer.dropdown");
  531. }
  532. });
  533. }, 10);
  534. },
  535. checkDimensions: function() {
  536. if(!this.dropdown.length) return;
  537. var dropdown = this.dropdown.css("margin-" + $.UIkit.langdirection, "").css("min-width", ""),
  538. offset = dropdown.show().offset(),
  539. width = dropdown.outerWidth(),
  540. boundarywidth = this.boundary.width(),
  541. boundaryoffset = this.boundary.offset() ? this.boundary.offset().left:0;
  542. // centered dropdown
  543. if (this.centered) {
  544. dropdown.css("margin-" + $.UIkit.langdirection, (parseFloat(width) / 2 - dropdown.parent().width() / 2) * -1);
  545. offset = dropdown.offset();
  546. // reset dropdown
  547. if ((width + offset.left) > boundarywidth || offset.left < 0) {
  548. dropdown.css("margin-" + $.UIkit.langdirection, "");
  549. offset = dropdown.offset();
  550. }
  551. }
  552. // justify dropdown
  553. if (this.justified && this.justified.length) {
  554. var jwidth = this.justified.outerWidth();
  555. dropdown.css("min-width", jwidth);
  556. if ($.UIkit.langdirection == 'right') {
  557. var right1 = boundarywidth - (this.justified.offset().left + jwidth),
  558. right2 = boundarywidth - (dropdown.offset().left + dropdown.outerWidth());
  559. dropdown.css("margin-right", right1 - right2);
  560. } else {
  561. dropdown.css("margin-left", this.justified.offset().left - offset.left);
  562. }
  563. offset = dropdown.offset();
  564. }
  565. if ((width + (offset.left-boundaryoffset)) > boundarywidth) {
  566. dropdown.addClass("uk-dropdown-flip");
  567. offset = dropdown.offset();
  568. }
  569. if (offset.left < 0) {
  570. dropdown.addClass("uk-dropdown-stack");
  571. }
  572. dropdown.css("display", "");
  573. }
  574. });
  575. Dropdown.defaults = {
  576. "mode": "hover",
  577. "remaintime": 800,
  578. "justify": false,
  579. "boundary": $(window)
  580. };
  581. UI["dropdown"] = Dropdown;
  582. var triggerevent = UI.support.touch ? "click":"mouseenter";
  583. // init code
  584. $(document).on(triggerevent+".dropdown.uikit", "[data-uk-dropdown]", function(e) {
  585. var ele = $(this);
  586. if (!ele.data("dropdown")) {
  587. var dropdown = new Dropdown(ele, UI.Utils.options(ele.data("uk-dropdown")));
  588. if (triggerevent=="click" || (triggerevent=="mouseenter" && dropdown.options.mode=="hover")) {
  589. dropdown.show();
  590. }
  591. if(dropdown.element.find('.uk-dropdown').length) {
  592. e.preventDefault();
  593. }
  594. }
  595. });
  596. })(jQuery, jQuery.UIkit);
  597. (function($, UI) {
  598. "use strict";
  599. var win = $(window), event = 'resize orientationchange';
  600. var GridMatchHeight = function(element, options) {
  601. var $this = this, $element = $(element);
  602. if($element.data("gridMatchHeight")) return;
  603. this.options = $.extend({}, GridMatchHeight.defaults, options);
  604. this.element = $element;
  605. this.columns = this.element.children();
  606. this.elements = this.options.target ? this.element.find(this.options.target) : this.columns;
  607. if (!this.columns.length) return;
  608. win.on(event, (function() {
  609. var fn = function() {
  610. $this.match();
  611. };
  612. $(function() {
  613. fn();
  614. win.on("load", fn);
  615. });
  616. return UI.Utils.debounce(fn, 150);
  617. })());
  618. $(document).on("uk-domready", function(e) {
  619. $this.columns = $this.element.children();
  620. $this.elements = $this.options.target ? $this.element.find($this.options.target) : $this.columns;
  621. $this.match();
  622. });
  623. this.element.data("gridMatchHeight", this);
  624. };
  625. $.extend(GridMatchHeight.prototype, {
  626. match: function() {
  627. this.revert();
  628. var firstvisible = this.columns.filter(":visible:first");
  629. if (!firstvisible.length) return;
  630. var stacked = Math.ceil(100 * parseFloat(firstvisible.css('width')) / parseFloat(firstvisible.parent().css('width'))) >= 100 ? true : false,
  631. max = 0,
  632. $this = this;
  633. if (stacked) return;
  634. this.elements.each(function() {
  635. max = Math.max(max, $(this).outerHeight());
  636. }).each(function(i) {
  637. var element = $(this),
  638. height = max - (element.outerHeight() - element.height());
  639. element.css('min-height', height + 'px');
  640. });
  641. return this;
  642. },
  643. revert: function() {
  644. this.elements.css('min-height', '');
  645. return this;
  646. }
  647. });
  648. GridMatchHeight.defaults = {
  649. "target": false
  650. };
  651. var GridMargin = function(element, options) {
  652. var $element = $(element);
  653. if($element.data("gridMargin")) return;
  654. this.options = $.extend({}, GridMargin.defaults, options);
  655. var stackMargin = new UI.stackMargin($element, this.options);
  656. $element.data("gridMargin", stackMargin);
  657. };
  658. GridMargin.defaults = {
  659. cls: 'uk-grid-margin'
  660. };
  661. UI["gridMatchHeight"] = GridMatchHeight;
  662. UI["gridMargin"] = GridMargin;
  663. // init code
  664. $(document).on("uk-domready", function(e) {
  665. $("[data-uk-grid-match],[data-uk-grid-margin]").each(function() {
  666. var grid = $(this), obj;
  667. if (grid.is("[data-uk-grid-match]") && !grid.data("gridMatchHeight")) {
  668. obj = new GridMatchHeight(grid, UI.Utils.options(grid.attr("data-uk-grid-match")));
  669. }
  670. if (grid.is("[data-uk-grid-margin]") && !grid.data("gridMargin")) {
  671. obj = new GridMargin(grid, UI.Utils.options(grid.attr("data-uk-grid-margin")));
  672. }
  673. });
  674. });
  675. })(jQuery, jQuery.UIkit);
  676. (function($, UI, $win) {
  677. "use strict";
  678. var active = false,
  679. html = $("html"),
  680. tpl = '<div class="uk-modal"><div class="uk-modal-dialog"></div></div>',
  681. Modal = function(element, options) {
  682. var $this = this;
  683. this.element = $(element);
  684. this.options = $.extend({}, Modal.defaults, options);
  685. this.transition = UI.support.transition;
  686. this.dialog = this.element.find(".uk-modal-dialog");
  687. this.element.on("click", ".uk-modal-close", function(e) {
  688. e.preventDefault();
  689. $this.hide();
  690. }).on("click", function(e) {
  691. var target = $(e.target);
  692. if (target[0] == $this.element[0] && $this.options.bgclose) {
  693. $this.hide();
  694. }
  695. });
  696. };
  697. $.extend(Modal.prototype, {
  698. transition: false,
  699. toggle: function() {
  700. this[this.isActive() ? "hide" : "show"]();
  701. return this;
  702. },
  703. show: function() {
  704. var $this = this;
  705. if (this.isActive()) return;
  706. if (active) active.hide(true);
  707. this.resize();
  708. this.element.removeClass("uk-open").show();
  709. active = this;
  710. html.addClass("uk-modal-page").height(); // force browser engine redraw
  711. this.element.addClass("uk-open").trigger("uk.modal.show");
  712. return this;
  713. },
  714. hide: function(force) {
  715. if (!this.isActive()) return;
  716. if (!force && UI.support.transition) {
  717. var $this = this;
  718. this.element.one(UI.support.transition.end, function() {
  719. $this._hide();
  720. }).removeClass("uk-open");
  721. } else {
  722. this._hide();
  723. }
  724. return this;
  725. },
  726. resize: function() {
  727. this.dialog.css("margin-left", "");
  728. var modalwidth = parseInt(this.dialog.css("width"), 10),
  729. inview = (modalwidth + parseInt(this.dialog.css("margin-left"),10) + parseInt(this.dialog.css("margin-right"),10)) < $win.width();
  730. this.dialog.css("margin-left", modalwidth && inview ? -1*Math.ceil(modalwidth/2) : "");
  731. },
  732. _hide: function() {
  733. this.element.hide().removeClass("uk-open");
  734. html.removeClass("uk-modal-page");
  735. if(active===this) active = false;
  736. this.element.trigger("uk.modal.hide");
  737. },
  738. isActive: function() {
  739. return (active == this);
  740. }
  741. });
  742. Modal.defaults = {
  743. keyboard: true,
  744. show: false,
  745. bgclose: true
  746. };
  747. var ModalTrigger = function(element, options) {
  748. var $this = this,
  749. $element = $(element);
  750. if($element.data("modal")) return;
  751. this.options = $.extend({
  752. "target": $element.is("a") ? $element.attr("href") : false
  753. }, options);
  754. this.element = $element;
  755. this.modal = new Modal(this.options.target, options);
  756. $element.on("click", function(e) {
  757. e.preventDefault();
  758. $this.show();
  759. });
  760. //methods
  761. $.each(["show", "hide", "isActive"], function(index, method) {
  762. $this[method] = function() { return $this.modal[method](); };
  763. });
  764. this.element.data("modal", this);
  765. };
  766. ModalTrigger.dialog = function(content, options) {
  767. var modal = new Modal($(tpl).appendTo("body"), options);
  768. modal.element.on("uk.modal.hide", function(){
  769. if (modal.persist) {
  770. modal.persist.appendTo(modal.persist.data("modalPersistParent"));
  771. modal.persist = false;
  772. }
  773. modal.element.remove();
  774. });
  775. setContent(content, modal);
  776. return modal;
  777. };
  778. ModalTrigger.alert = function(content, options) {
  779. ModalTrigger.dialog(([
  780. '<div class="uk-margin">'+String(content)+'</div>',
  781. '<button class="uk-button uk-button-primary uk-modal-close">Ok</button>'
  782. ]).join(""), $.extend({bgclose:false, keyboard:false}, options)).show();
  783. };
  784. ModalTrigger.confirm = function(content, onconfirm, options) {
  785. onconfirm = $.isFunction(onconfirm) ? onconfirm : function(){};
  786. var modal = ModalTrigger.dialog(([
  787. '<div class="uk-margin">'+String(content)+'</div>',
  788. '<button class="uk-button uk-button-primary js-modal-confirm">Ok</button> <button class="uk-button uk-modal-close">Cancel</button>'
  789. ]).join(""), $.extend({bgclose:false, keyboard:false}, options));
  790. modal.element.find(".js-modal-confirm").on("click", function(){
  791. onconfirm();
  792. modal.hide();
  793. });
  794. modal.show();
  795. };
  796. ModalTrigger.Modal = Modal;
  797. UI["modal"] = ModalTrigger;
  798. // init code
  799. $(document).on("click.modal.uikit", "[data-uk-modal]", function(e) {
  800. var ele = $(this);
  801. if (!ele.data("modal")) {
  802. var modal = new ModalTrigger(ele, UI.Utils.options(ele.attr("data-uk-modal")));
  803. modal.show();
  804. }
  805. });
  806. // close modal on esc button
  807. $(document).on('keydown.modal.uikit', function (e) {
  808. if (active && e.keyCode === 27 && active.options.keyboard) { // ESC
  809. e.preventDefault();
  810. active.hide();
  811. }
  812. });
  813. $win.on("resize orientationchange", UI.Utils.debounce(function(){
  814. if(active) active.resize();
  815. }, 150));
  816. // helper functions
  817. function setContent(content, modal){
  818. if(!modal) return;
  819. if (typeof content === 'object') {
  820. // convert DOM object to a jQuery object
  821. content = content instanceof jQuery ? content : $(content);
  822. if(content.parent().length) {
  823. modal.persist = content;
  824. modal.persist.data("modalPersistParent", content.parent());
  825. }
  826. }else if (typeof content === 'string' || typeof content === 'number') {
  827. // just insert the data as innerHTML
  828. content = $('<div></div>').html(content);
  829. }else {
  830. // unsupported data type!
  831. content = $('<div></div>').html('$.UIkitt.modal Error: Unsupported data type: ' + typeof content);
  832. }
  833. content.appendTo(modal.element.find('.uk-modal-dialog'));
  834. return modal;
  835. }
  836. })(jQuery, jQuery.UIkit, jQuery(window));
  837. (function($, UI) {
  838. "use strict";
  839. var $win = $(window),
  840. $doc = $(document),
  841. Offcanvas = {
  842. show: function(element) {
  843. element = $(element);
  844. if (!element.length) return;
  845. var doc = $("html"),
  846. bar = element.find(".uk-offcanvas-bar:first"),
  847. rtl = ($.UIkit.langdirection == "right"),
  848. dir = (bar.hasClass("uk-offcanvas-bar-flip") ? -1 : 1) * (rtl ? -1 : 1),
  849. scrollbar = dir == -1 && $win.width() < window.innerWidth ? (window.innerWidth - $win.width()) : 0;
  850. scrollpos = {x: window.scrollX, y: window.scrollY};
  851. element.addClass("uk-active");
  852. doc.css({"width": window.innerWidth, "height": window.innerHeight}).addClass("uk-offcanvas-page");
  853. doc.css((rtl ? "margin-right" : "margin-left"), (rtl ? -1 : 1) * ((bar.outerWidth() - scrollbar) * dir)).width(); // .width() - force redraw
  854. bar.addClass("uk-offcanvas-bar-show").width();
  855. element.off(".ukoffcanvas").on("click.ukoffcanvas swipeRight.ukoffcanvas swipeLeft.ukoffcanvas", function(e) {
  856. var target = $(e.target);
  857. if (!e.type.match(/swipe/)) {
  858. if (target.hasClass("uk-offcanvas-bar")) return;
  859. if (target.parents(".uk-offcanvas-bar:first").length) return;
  860. }
  861. e.stopImmediatePropagation();
  862. Offcanvas.hide();
  863. });
  864. $doc.on('keydown.offcanvas', function(e) {
  865. if (e.keyCode === 27) { // ESC
  866. Offcanvas.hide();
  867. }
  868. });
  869. },
  870. hide: function(force) {
  871. var doc = $("html"),
  872. panel = $(".uk-offcanvas.uk-active"),
  873. rtl = ($.UIkit.langdirection == "right"),
  874. bar = panel.find(".uk-offcanvas-bar:first");
  875. if (!panel.length) return;
  876. if ($.UIkit.support.transition && !force) {
  877. doc.one($.UIkit.support.transition.end, function() {
  878. doc.removeClass("uk-offcanvas-page").attr("style", "");
  879. panel.removeClass("uk-active");
  880. window.scrollTo(scrollpos.x, scrollpos.y);
  881. }).css((rtl ? "margin-right" : "margin-left"), "");
  882. setTimeout(function(){
  883. bar.removeClass("uk-offcanvas-bar-show");
  884. }, 50);
  885. } else {
  886. doc.removeClass("uk-offcanvas-page").attr("style", "");
  887. panel.removeClass("uk-active");
  888. bar.removeClass("uk-offcanvas-bar-show");
  889. window.scrollTo(scrollpos.x, scrollpos.y);
  890. }
  891. panel.off(".ukoffcanvas");
  892. $doc.off(".ukoffcanvas");
  893. }
  894. }, scrollpos;
  895. var OffcanvasTrigger = function(element, options) {
  896. var $this = this,
  897. $element = $(element);
  898. if($element.data("offcanvas")) return;
  899. this.options = $.extend({
  900. "target": $element.is("a") ? $element.attr("href") : false
  901. }, options);
  902. this.element = $element;
  903. $element.on("click", function(e) {
  904. e.preventDefault();
  905. Offcanvas.show($this.options.target);
  906. });
  907. this.element.data("offcanvas", this);
  908. };
  909. OffcanvasTrigger.offcanvas = Offcanvas;
  910. UI["offcanvas"] = OffcanvasTrigger;
  911. // init code
  912. $doc.on("click.offcanvas.uikit", "[data-uk-offcanvas]", function(e) {
  913. e.preventDefault();
  914. var ele = $(this);
  915. if (!ele.data("offcanvas")) {
  916. var obj = new OffcanvasTrigger(ele, UI.Utils.options(ele.attr("data-uk-offcanvas")));
  917. ele.trigger("click");
  918. }
  919. });
  920. })(jQuery, jQuery.UIkit);
  921. (function($, UI) {
  922. "use strict";
  923. var Nav = function(element, options) {
  924. var $this = this, $element = $(element);
  925. if($element.data("nav")) return;
  926. this.options = $.extend({}, Nav.defaults, options);
  927. this.element = $element.on("click", this.options.toggler, function(e) {
  928. e.preventDefault();
  929. var ele = $(this);
  930. $this.open(ele.parent()[0] == $this.element[0] ? ele : ele.parent("li"));
  931. });
  932. this.element.find(this.options.lists).each(function() {
  933. var $ele = $(this),
  934. parent = $ele.parent(),
  935. active = parent.hasClass("uk-active");
  936. $ele.wrap('<div style="overflow:hidden;height:0;position:relative;"></div>');
  937. parent.data("list-container", $ele.parent());
  938. if (active) $this.open(parent, true);
  939. });
  940. this.element.data("nav", this);
  941. };
  942. $.extend(Nav.prototype, {
  943. open: function(li, noanimation) {
  944. var element = this.element, $li = $(li);
  945. if (!this.options.multiple) {
  946. element.children(".uk-open").not(li).each(function() {
  947. if ($(this).data("list-container")) {
  948. $(this).data("list-container").stop().animate({height: 0}, function() {
  949. $(this).parent().removeClass("uk-open");
  950. });
  951. }
  952. });
  953. }
  954. $li.toggleClass("uk-open");
  955. if ($li.data("list-container")) {
  956. if (noanimation) {
  957. $li.data('list-container').stop().height($li.hasClass("uk-open") ? "auto" : 0);
  958. } else {
  959. $li.data('list-container').stop().animate({
  960. height: ($li.hasClass("uk-open") ? getHeight($li.data('list-container').find('ul:first')) : 0)
  961. });
  962. }
  963. }
  964. }
  965. });
  966. Nav.defaults = {
  967. "toggler": ">li.uk-parent > a[href='#']",
  968. "lists": ">li.uk-parent > ul",
  969. "multiple": false
  970. };
  971. UI["nav"] = Nav;
  972. // helper
  973. function getHeight(ele) {
  974. var $ele = $(ele), height = "auto";
  975. if ($ele.is(":visible")) {
  976. height = $ele.outerHeight();
  977. } else {
  978. var tmp = {
  979. position: $ele.css("position"),
  980. visibility: $ele.css("visibility"),
  981. display: $ele.css("display")
  982. };
  983. height = $ele.css({position: 'absolute', visibility: 'hidden', display: 'block'}).outerHeight();
  984. $ele.css(tmp); // reset element
  985. }
  986. return height;
  987. }
  988. // init code
  989. $(document).on("uk-domready", function(e) {
  990. $("[data-uk-nav]").each(function() {
  991. var nav = $(this);
  992. if (!nav.data("nav")) {
  993. var obj = new Nav(nav, UI.Utils.options(nav.attr("data-uk-nav")));
  994. }
  995. });
  996. });
  997. })(jQuery, jQuery.UIkit);
  998. (function($, UI, $win) {
  999. "use strict";
  1000. var $tooltip, // tooltip container
  1001. tooltipdelay;
  1002. var Tooltip = function(element, options) {
  1003. var $this = this, $element = $(element);
  1004. if($element.data("tooltip")) return;
  1005. this.options = $.extend({}, Tooltip.defaults, options);
  1006. this.element = $element.on({
  1007. "focus" : function(e) { $this.show(); },
  1008. "blur" : function(e) { $this.hide(); },
  1009. "mouseenter": function(e) { $this.show(); },
  1010. "mouseleave": function(e) { $this.hide(); }
  1011. });
  1012. this.tip = typeof(this.options.src) === "function" ? this.options.src.call(this.element) : this.options.src;
  1013. // disable title attribute
  1014. this.element.attr("data-cached-title", this.element.attr("title")).attr("title", "");
  1015. this.element.data("tooltip", this);
  1016. };
  1017. $.extend(Tooltip.prototype, {
  1018. tip: "",
  1019. show: function() {
  1020. if (tooltipdelay) clearTimeout(tooltipdelay);
  1021. if (!this.tip.length) return;
  1022. $tooltip.stop().css({"top": -2000, "visibility": "hidden"}).show();
  1023. $tooltip.html('<div class="uk-tooltip-inner">' + this.tip + '</div>');
  1024. var $this = this,
  1025. pos = $.extend({}, this.element.offset(), {width: this.element[0].offsetWidth, height: this.element[0].offsetHeight}),
  1026. width = $tooltip[0].offsetWidth,
  1027. height = $tooltip[0].offsetHeight,
  1028. offset = typeof(this.options.offset) === "function" ? this.options.offset.call(this.element) : this.options.offset,
  1029. position = typeof(this.options.pos) === "function" ? this.options.pos.call(this.element) : this.options.pos,
  1030. tcss = {
  1031. "display": "none",
  1032. "visibility": "visible",
  1033. "top": (pos.top + pos.height + height),
  1034. "left": pos.left
  1035. },
  1036. tmppos = position.split("-");
  1037. if ((tmppos[0] == "left" || tmppos[0] == "right") && $.UIkit.langdirection == 'right') {
  1038. tmppos[0] = tmppos[0] == "left" ? "right" : "left";
  1039. }
  1040. var variants = {
  1041. "bottom" : {top: pos.top + pos.height + offset, left: pos.left + pos.width / 2 - width / 2},
  1042. "top" : {top: pos.top - height - offset, left: pos.left + pos.width / 2 - width / 2},
  1043. "left" : {top: pos.top + pos.height / 2 - height / 2, left: pos.left - width - offset},
  1044. "right" : {top: pos.top + pos.height / 2 - height / 2, left: pos.left + pos.width + offset}
  1045. };
  1046. $.extend(tcss, variants[tmppos[0]]);
  1047. if (tmppos.length == 2) tcss.left = (tmppos[1] == 'left') ? (pos.left) : ((pos.left + pos.width) - width);
  1048. var boundary = this.checkBoundary(tcss.left, tcss.top, width, height);
  1049. if(boundary) {
  1050. switch(boundary) {
  1051. case "x":
  1052. if (tmppos.length == 2) {
  1053. position = tmppos[0]+"-"+(tcss.left < 0 ? "left": "right");
  1054. } else {
  1055. position = tcss.left < 0 ? "right": "left";
  1056. }
  1057. break;
  1058. case "y":
  1059. if (tmppos.length == 2) {
  1060. position = (tcss.top < 0 ? "bottom": "top")+"-"+tmppos[1];
  1061. } else {
  1062. position = (tcss.top < 0 ? "bottom": "top");
  1063. }
  1064. break;
  1065. case "xy":
  1066. if (tmppos.length == 2) {
  1067. position = (tcss.top < 0 ? "bottom": "top")+"-"+(tcss.left < 0 ? "left": "right");
  1068. } else {
  1069. position = tcss.left < 0 ? "right": "left";
  1070. }
  1071. break;
  1072. }
  1073. tmppos = position.split("-");
  1074. $.extend(tcss, variants[tmppos[0]]);
  1075. if (tmppos.length == 2) tcss.left = (tmppos[1] == 'left') ? (pos.left) : ((pos.left + pos.width) - width);
  1076. }
  1077. tcss.left -= $("body").position().left;
  1078. tooltipdelay = setTimeout(function(){
  1079. $tooltip.css(tcss).attr("class", "uk-tooltip uk-tooltip-" + position);
  1080. if ($this.options.animation) {
  1081. $tooltip.css({opacity: 0, display: 'block'}).animate({opacity: 1}, parseInt($this.options.animation, 10) || 400);
  1082. } else {
  1083. $tooltip.show();
  1084. }
  1085. tooltipdelay = false;
  1086. }, parseInt(this.options.delay, 10) || 0);
  1087. },
  1088. hide: function() {
  1089. if(this.element.is("input") && this.element[0]===document.activeElement) return;
  1090. if(tooltipdelay) clearTimeout(tooltipdelay);
  1091. $tooltip.stop();
  1092. if (this.options.animation) {
  1093. $tooltip.fadeOut(parseInt(this.options.animation, 10) || 400);
  1094. } else {
  1095. $tooltip.hide();
  1096. }
  1097. },
  1098. content: function() {
  1099. return this.tip;
  1100. },
  1101. checkBoundary: function(left, top, width, height) {
  1102. var axis = "";
  1103. if(left < 0 || ((left-$win.scrollLeft())+width) > window.innerWidth) {
  1104. axis += "x";
  1105. }
  1106. if(top < 0 || ((top-$win.scrollTop())+height) > window.innerHeight) {
  1107. axis += "y";
  1108. }
  1109. return axis;
  1110. }
  1111. });
  1112. Tooltip.defaults = {
  1113. "offset": 5,
  1114. "pos": "top",
  1115. "animation": false,
  1116. "delay": 0, // in miliseconds
  1117. "src": function() { return this.attr("title"); }
  1118. };
  1119. UI["tooltip"] = Tooltip;
  1120. $(function() {
  1121. $tooltip = $('<div class="uk-tooltip"></div>').appendTo("body");
  1122. });
  1123. // init code
  1124. $(document).on("mouseenter.tooltip.uikit focus.tooltip.uikit", "[data-uk-tooltip]", function(e) {
  1125. var ele = $(this);
  1126. if (!ele.data("tooltip")) {
  1127. var obj = new Tooltip(ele, UI.Utils.options(ele.attr("data-uk-tooltip")));
  1128. ele.trigger("mouseenter");
  1129. }
  1130. });
  1131. })(jQuery, jQuery.UIkit, jQuery(window));
  1132. (function($, UI) {
  1133. "use strict";
  1134. var Switcher = function(element, options) {
  1135. var $this = this, $element = $(element);
  1136. if($element.data("switcher")) return;
  1137. this.options = $.extend({}, Switcher.defaults, options);
  1138. this.element = $element.on("click", this.options.toggler, function(e) {
  1139. e.preventDefault();
  1140. $this.show(this);
  1141. });
  1142. if (this.options.connect) {
  1143. this.connect = $(this.options.connect).find(".uk-active").removeClass(".uk-active").end();
  1144. var togglers = this.element.find(this.options.toggler),
  1145. active = togglers.filter(".uk-active");
  1146. if (active.length) {
  1147. this.show(active);
  1148. } else {
  1149. active = togglers.eq(0);
  1150. if (active.length) this.show(active);
  1151. }
  1152. }
  1153. this.element.data("switcher", this);
  1154. };
  1155. $.extend(Switcher.prototype, {
  1156. show: function(tab) {
  1157. tab = isNaN(tab) ? $(tab) : this.element.find(this.options.toggler).eq(tab);
  1158. var active = tab;
  1159. if (active.hasClass("uk-disabled")) return;
  1160. this.element.find(this.options.toggler).filter(".uk-active").removeClass("uk-active");
  1161. active.addClass("uk-active");
  1162. if (this.options.connect && this.connect.length) {
  1163. var index = this.element.find(this.options.toggler).index(active);
  1164. this.connect.children().removeClass("uk-active").eq(index).addClass("uk-active");
  1165. }
  1166. this.element.trigger("uk.switcher.show", [active]);
  1167. }
  1168. });
  1169. Switcher.defaults = {
  1170. connect : false,
  1171. toggler : ">*"
  1172. };
  1173. UI["switcher"] = Switcher;
  1174. // init code
  1175. $(document).on("uk-domready", function(e) {
  1176. $("[data-uk-switcher]").each(function() {
  1177. var switcher = $(this);
  1178. if (!switcher.data("switcher")) {
  1179. var obj = new Switcher(switcher, UI.Utils.options(switcher.attr("data-uk-switcher")));
  1180. }
  1181. });
  1182. });
  1183. })(jQuery, jQuery.UIkit);
  1184. (function($, UI) {
  1185. "use strict";
  1186. var Tab = function(element, options) {
  1187. var $this = this, $element = $(element);
  1188. if($element.data("tab")) return;
  1189. this.element = $element;
  1190. this.options = $.extend({}, Tab.defaults, options);
  1191. if (this.options.connect) {
  1192. this.connect = $(this.options.connect);
  1193. }
  1194. if (window.location.hash) {
  1195. var active = this.element.children().filter(window.location.hash);
  1196. if (active.length) {
  1197. this.element.children().removeClass('uk-active').filter(active).addClass("uk-active");
  1198. }
  1199. }
  1200. var mobiletab = $('<li class="uk-tab-responsive uk-active"><a href="javascript:void(0);"></a></li>'),
  1201. caption = mobiletab.find("a:first"),
  1202. dropdown = $('<div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown"></ul><div>'),
  1203. ul = dropdown.find("ul");
  1204. caption.html(this.element.find("li.uk-active:first").find("a").text());
  1205. if (this.element.hasClass("uk-tab-bottom")) dropdown.addClass("uk-dropdown-up");
  1206. if (this.element.hasClass("uk-tab-flip")) dropdown.addClass("uk-dropdown-flip");
  1207. this.element.find("a").each(function(i) {
  1208. var tab = $(this).parent(),
  1209. item = $('<li><a href="javascript:void(0);">' + tab.text() + '</a></li>').on("click", function(e) {
  1210. $this.element.data("switcher").show(i);
  1211. });
  1212. if (!$(this).parents(".uk-disabled:first").length) ul.append(item);
  1213. });
  1214. this.element.uk("switcher", {"toggler": ">li:not(.uk-tab-responsive)", "connect": this.options.connect});
  1215. mobiletab.append(dropdown).uk("dropdown", {"mode": "click"});
  1216. this.element.append(mobiletab).data({
  1217. "dropdown": mobiletab.data("dropdown"),
  1218. "mobilecaption": caption
  1219. }).on("uk.switcher.show", function(e, tab) {
  1220. mobiletab.addClass("uk-active");
  1221. caption.html(tab.find("a").text());
  1222. });
  1223. this.element.data("tab", this);
  1224. };
  1225. Tab.defaults = {
  1226. connect: false
  1227. };
  1228. UI["tab"] = Tab;
  1229. $(document).on("uk-domready", function(e) {
  1230. $("[data-uk-tab]").each(function() {
  1231. var tab = $(this);
  1232. if (!tab.data("tab")) {
  1233. var obj = new Tab(tab, UI.Utils.options(tab.attr("data-uk-tab")));
  1234. }
  1235. });
  1236. });
  1237. })(jQuery, jQuery.UIkit);
  1238. (function($, UI) {
  1239. "use strict";
  1240. var renderers = {},
  1241. Search = function(element, options) {
  1242. var $this = this, $element = $(element);
  1243. if($element.data("search")) return;
  1244. this.options = $.extend({}, Search.defaults, options);
  1245. this.element = $element;
  1246. this.timer = null;
  1247. this.value = null;
  1248. this.input = this.element.find(".uk-search-field");
  1249. this.form = this.input.length ? $(this.input.get(0).form) : $();
  1250. this.input.attr('autocomplete', 'off');
  1251. this.input.on({
  1252. keydown: function(event) {
  1253. $this.form[($this.input.val()) ? 'addClass' : 'removeClass']($this.options.filledClass);
  1254. if (event && event.which && !event.shiftKey) {
  1255. switch (event.which) {
  1256. case 13: // enter
  1257. $this.done($this.selected);
  1258. event.preventDefault();
  1259. break;
  1260. case 38: // up
  1261. $this.pick('prev');
  1262. event.preventDefault();
  1263. break;
  1264. case 40: // down
  1265. $this.pick('next');
  1266. event.preventDefault();
  1267. break;
  1268. case 27:
  1269. case 9: // esc, tab
  1270. $this.hide();
  1271. break;
  1272. default:
  1273. break;
  1274. }
  1275. }
  1276. },
  1277. keyup: function(event) {
  1278. $this.trigger();
  1279. },
  1280. blur: function(event) {
  1281. setTimeout(function() { $this.hide(event); }, 200);
  1282. }
  1283. });
  1284. this.form.find('button[type=reset]').bind("click", function() {
  1285. $this.form.removeClass("uk-open").removeClass("uk-loading").removeClass("uk-active");
  1286. $this.value = null;
  1287. $this.input.focus();
  1288. });
  1289. this.dropdown = $('<div class="uk-dropdown uk-dropdown-search"><ul class="uk-nav uk-nav-search"></ul></div>').appendTo(this.form).find('.uk-nav-search');
  1290. if (this.options.flipDropdown) {
  1291. this.dropdown.parent().addClass('uk-dropdown-flip');
  1292. }
  1293. this.dropdown.on("mouseover", ">li", function(){
  1294. $this.pick($(this));
  1295. });
  1296. this.renderer = new renderers[this.options.renderer](this);
  1297. this.element.data("search", this);
  1298. };
  1299. $.extend(Search.prototype, {
  1300. request: function(options) {
  1301. var $this = this;
  1302. this.form.addClass(this.options.loadingClass);
  1303. if (this.options.source) {
  1304. $.ajax($.extend({
  1305. url: this.options.source,
  1306. type: this.options.method,
  1307. dataType: 'json',
  1308. success: function(data) {
  1309. data = $this.options.onLoadedResults.apply(this, [data]);
  1310. $this.form.removeClass($this.options.loadingClass);
  1311. $this.suggest(data);
  1312. }
  1313. }, options));
  1314. } else {
  1315. this.form.removeClass($this.options.loadingClass);
  1316. }
  1317. },
  1318. pick: function(item) {
  1319. var selected = false;
  1320. if (typeof item !== "string" && !item.hasClass(this.options.skipClass)) {
  1321. selected = item;
  1322. }
  1323. if (item == 'next' || item == 'prev') {
  1324. var items = this.dropdown.children().filter(this.options.match);
  1325. if (this.selected) {
  1326. var index = items.index(this.selected);
  1327. if (item == 'next') {
  1328. selected = items.eq(index + 1 < items.length ? index + 1 : 0);
  1329. } else {
  1330. selected = items.eq(index - 1 < 0 ? items.length - 1 : index - 1);
  1331. }
  1332. } else {
  1333. selected = items[(item == 'next') ? 'first' : 'last']();
  1334. }
  1335. }
  1336. if (selected && selected.length) {
  1337. this.selected = selected;
  1338. this.dropdown.children().removeClass(this.options.hoverClass);
  1339. this.selected.addClass(this.options.hoverClass);
  1340. }
  1341. },
  1342. trigger: function() {
  1343. var $this = this, old = this.value, data = {};
  1344. this.value = this.input.val();
  1345. if (this.value.length < this.options.minLength) {
  1346. return this.hide();
  1347. }
  1348. if (this.value != old) {
  1349. if (this.timer) window.clearTimeout(this.timer);
  1350. this.timer = window.setTimeout(function() {
  1351. data[$this.options.param] = $this.value;
  1352. $this.request({'data': data});
  1353. }, this.options.delay, this);
  1354. }
  1355. return this;
  1356. },
  1357. done: function(selected) {
  1358. this.renderer.done(selected);
  1359. },
  1360. suggest: function(data) {
  1361. if (!data) return;
  1362. if (data === false) {
  1363. this.hide();
  1364. } else {
  1365. this.selected = null;
  1366. this.dropdown.empty();
  1367. this.renderer.suggest(data);
  1368. this.show();
  1369. }
  1370. },
  1371. show: function() {
  1372. if (this.visible) return;
  1373. this.visible = true;
  1374. this.form.addClass("uk-open");
  1375. },
  1376. hide: function() {
  1377. if (!this.visible)
  1378. return;
  1379. this.visible = false;
  1380. this.form.removeClass(this.options.loadingClass).removeClass("uk-open");
  1381. }
  1382. });
  1383. Search.addRenderer = function(name, klass) {
  1384. renderers[name] = klass;
  1385. };
  1386. Search.defaults = {
  1387. source: false,
  1388. param: 'search',
  1389. method: 'post',
  1390. minLength: 3,
  1391. delay: 300,
  1392. flipDropdown: false,
  1393. match: ':not(.uk-skip)',
  1394. skipClass: 'uk-skip',
  1395. loadingClass: 'uk-loading',
  1396. filledClass: 'uk-active',
  1397. listClass: 'results',
  1398. hoverClass: 'uk-active',
  1399. onLoadedResults: function(results) { return results; },
  1400. renderer: "default"
  1401. };
  1402. var DefaultRenderer = function(search) {
  1403. this.search = search;
  1404. this.options = $.extend({}, DefaultRenderer.defaults, search.options);
  1405. };
  1406. $.extend(DefaultRenderer.prototype, {
  1407. done: function(selected) {
  1408. if (!selected) {
  1409. this.search.form.submit();
  1410. return;
  1411. }
  1412. if (selected.hasClass(this.options.moreResultsClass)) {
  1413. this.search.form.submit();
  1414. } else if (selected.data('choice')) {
  1415. window.location = selected.data('choice').url;
  1416. }
  1417. this.search.hide();
  1418. },
  1419. suggest: function(data) {
  1420. var $this = this,
  1421. events = {
  1422. 'click': function(e) {
  1423. e.preventDefault();
  1424. $this.done($(this).parent());
  1425. }
  1426. };
  1427. if (this.options.msgResultsHeader) {
  1428. $('<li>').addClass(this.options.resultsHeaderClass + ' ' + this.options.skipClass).html(this.options.msgResultsHeader).appendTo(this.search.dropdown);
  1429. }
  1430. if (data.results && data.results.length > 0) {
  1431. $(data.results).each(function(i) {
  1432. var item = $('<li><a href="#">' + this.title + '</a></li>').data('choice', this);
  1433. if (this["text"]) {
  1434. item.find("a").append('<div>' + this.text + '</div>');
  1435. }
  1436. $this.search.dropdown.append(item);
  1437. });
  1438. if (this.options.msgMoreResults) {
  1439. $('<li>').addClass('uk-nav-divider ' + $this.options.skipClass).appendTo($this.dropdown);
  1440. $('<li>').addClass($this.options.moreResultsClass).html('<a href="#">' + $this.options.msgMoreResults + '</a>').appendTo($this.search.dropdown).on(events);
  1441. }
  1442. $this.search.dropdown.find("li>a").on(events);
  1443. } else if (this.options.msgNoResults) {
  1444. $('<li>').addClass(this.options.noResultsClass + ' ' + this.options.skipClass).html('<a>' + this.options.msgNoResults + '</a>').appendTo($this.search.dropdown);
  1445. }
  1446. }
  1447. });
  1448. DefaultRenderer.defaults = {
  1449. resultsHeaderClass: 'uk-nav-header',
  1450. moreResultsClass: 'uk-search-moreresults',
  1451. noResultsClass: '',
  1452. msgResultsHeader: 'Search Results',
  1453. msgMoreResults: 'More Results',
  1454. msgNoResults: 'No results found'
  1455. };
  1456. Search.addRenderer("default", DefaultRenderer);
  1457. UI["search"] = Search;
  1458. // init code
  1459. $(document).on("focus.search.uikit", "[data-uk-search]", function(e) {
  1460. var ele = $(this);
  1461. if (!ele.data("search")) {
  1462. var obj = new Search(ele, UI.Utils.options(ele.attr("data-uk-search")));
  1463. }
  1464. });
  1465. })(jQuery, jQuery.UIkit);
  1466. (function($, UI) {
  1467. "use strict";
  1468. var $win = $(window),
  1469. scrollspies = [],
  1470. checkScrollSpy = function() {
  1471. for(var i=0; i < scrollspies.length; i++) {
  1472. UI.support.requestAnimationFrame.apply(window, [scrollspies[i].check]);
  1473. }
  1474. },
  1475. ScrollSpy = function(element, options) {
  1476. var $element = $(element);
  1477. if($element.data("scrollspy")) return;
  1478. this.options = $.extend({}, ScrollSpy.defaults, options);
  1479. this.element = $(element);
  1480. var $this = this, idle, inviewstate, initinview,
  1481. fn = function(){
  1482. var inview = UI.Utils.isInView($this.element, $this.options);
  1483. if(inview && !inviewstate) {
  1484. if(idle) clearTimeout(idle);
  1485. if(!initinview) {
  1486. $this.element.addClass($this.options.initcls);
  1487. $this.offset = $this.element.offset();
  1488. initinview = true;
  1489. $this.element.trigger("uk-scrollspy-init");
  1490. }
  1491. idle = setTimeout(function(){
  1492. if(inview) {
  1493. $this.element.addClass("uk-scrollspy-inview").addClass($this.options.cls).width();
  1494. }
  1495. }, $this.options.delay);
  1496. inviewstate = true;
  1497. $this.element.trigger("uk.scrollspy.inview");
  1498. }
  1499. if (!inview && inviewstate && $this.options.repeat) {
  1500. $this.element.removeClass("uk-scrollspy-inview").removeClass($this.options.cls);
  1501. inviewstate = false;
  1502. $this.element.trigger("uk.scrollspy.outview");
  1503. }
  1504. };
  1505. fn();
  1506. this.element.data("scrollspy", this);
  1507. this.check = fn;
  1508. scrollspies.push(this);
  1509. };
  1510. ScrollSpy.defaults = {
  1511. "cls" : "uk-scrollspy-inview",
  1512. "initcls" : "uk-scrollspy-init-inview",
  1513. "topoffset" : 0,
  1514. "leftoffset" : 0,
  1515. "repeat" : false,
  1516. "delay" : 0
  1517. };
  1518. UI["scrollspy"] = ScrollSpy;
  1519. var scrollspynavs = [],
  1520. checkScrollSpyNavs = function() {
  1521. for(var i=0; i < scrollspynavs.length; i++) {
  1522. UI.support.requestAnimationFrame.apply(window, [scrollspynavs[i].check]);
  1523. }
  1524. },
  1525. ScrollSpyNav = function(element, options) {
  1526. var $element = $(element);
  1527. if($element.data("scrollspynav")) return;
  1528. this.element = $element;
  1529. this.options = $.extend({}, ScrollSpyNav.defaults, options);
  1530. var ids = [],
  1531. links = this.element.find("a[href^='#']").each(function(){ ids.push($(this).attr("href")); }),
  1532. targets = $(ids.join(","));
  1533. var $this = this, inviews, fn = function(){
  1534. inviews = [];
  1535. for(var i=0 ; i < targets.length ; i++) {
  1536. if(UI.Utils.isInView(targets.eq(i), $this.options)) {
  1537. inviews.push(targets.eq(i));
  1538. }
  1539. }
  1540. if(inviews.length) {
  1541. var scrollTop = $win.scrollTop(),
  1542. target = (function(){
  1543. for(var i=0; i< inviews.length;i++){
  1544. if(inviews[i].offset().top >= scrollTop){
  1545. return inviews[i];
  1546. }
  1547. }
  1548. })();
  1549. if(!target) return;
  1550. if($this.options.closest) {
  1551. links.closest($this.options.closest).removeClass($this.options.cls).end().filter("a[href='#"+target.attr("id")+"']").closest($this.options.closest).addClass($this.options.cls);
  1552. } else {
  1553. links.removeClass($this.options.cls).filter("a[href='#"+target.attr("id")+"']").addClass($this.options.cls);
  1554. }
  1555. }
  1556. };
  1557. if(this.options.smoothscroll && UI["smoothScroll"]) {
  1558. links.each(function(){
  1559. new UI["smoothScroll"](this, $this.options.smoothscroll);
  1560. });
  1561. }
  1562. fn();
  1563. this.element.data("scrollspynav", this);
  1564. this.check = fn;
  1565. scrollspynavs.push(this);
  1566. };
  1567. ScrollSpyNav.defaults = {
  1568. "cls" : 'uk-active',
  1569. "closest" : false,
  1570. "topoffset" : 0,
  1571. "leftoffset" : 0,
  1572. "smoothscroll" : false
  1573. };
  1574. UI["scrollspynav"] = ScrollSpyNav;
  1575. var fnCheck = function(){
  1576. checkScrollSpy();
  1577. checkScrollSpyNavs();
  1578. };
  1579. // listen to scroll and resize
  1580. $win.on("scroll", fnCheck).on("resize orientationchange", UI.Utils.debounce(fnCheck, 50));
  1581. // init code
  1582. $(document).on("uk-domready", function(e) {
  1583. $("[data-uk-scrollspy]").each(function() {
  1584. var element = $(this);
  1585. if (!element.data("scrollspy")) {
  1586. var obj = new ScrollSpy(element, UI.Utils.options(element.attr("data-uk-scrollspy")));
  1587. }
  1588. });
  1589. $("[data-uk-scrollspy-nav]").each(function() {
  1590. var element = $(this);
  1591. if (!element.data("scrollspynav")) {
  1592. var obj = new ScrollSpyNav(element, UI.Utils.options(element.attr("data-uk-scrollspy-nav")));
  1593. }
  1594. });
  1595. });
  1596. })(jQuery, jQuery.UIkit);
  1597. (function($, UI) {
  1598. "use strict";
  1599. var SmoothScroll = function(element, options) {
  1600. var $this = this, $element = $(element);
  1601. if($element.data("smoothScroll")) return;
  1602. this.options = $.extend({}, SmoothScroll.defaults, options);
  1603. this.element = $element.on("click", function(e) {
  1604. // get / set parameters
  1605. var ele = ($(this.hash).length ? $(this.hash) : $("body")),
  1606. target = ele.offset().top - $this.options.offset,
  1607. docheight = $(document).height(),
  1608. winheight = $(window).height(),
  1609. eleheight = ele.outerHeight();
  1610. if ((target + winheight) > docheight) {
  1611. target = docheight - winheight;
  1612. }
  1613. // animate to target and set the hash to the window.location after the animation
  1614. $("html,body").stop().animate({scrollTop: target}, $this.options.duration, $this.options.transition);
  1615. // cancel default click action
  1616. return false;
  1617. });
  1618. this.element.data("smoothScroll", this);
  1619. };
  1620. SmoothScroll.defaults = {
  1621. duration: 1000,
  1622. transition: 'easeOutExpo',
  1623. offset: 0
  1624. };
  1625. UI["smoothScroll"] = SmoothScroll;
  1626. if (!$.easing['easeOutExpo']) {
  1627. $.easing['easeOutExpo'] = function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; };
  1628. }
  1629. // init code
  1630. $(document).on("click.smooth-scroll.uikit", "[data-uk-smooth-scroll]", function(e) {
  1631. var ele = $(this);
  1632. if (!ele.data("smoothScroll")) {
  1633. var obj = new SmoothScroll(ele, UI.Utils.options(ele.attr("data-uk-smooth-scroll")));
  1634. ele.trigger("click");
  1635. }
  1636. });
  1637. })(jQuery, jQuery.UIkit);
  1638. (function(global, $, UI){
  1639. var Toggle = function(element, options) {
  1640. var $this = this, $element = $(element);
  1641. if($element.data("toggle")) return;
  1642. this.options = $.extend({}, Toggle.defaults, options);
  1643. this.totoggle = this.options.target ? $(this.options.target):[];
  1644. this.element = $element.on("click", function(e) {
  1645. e.preventDefault();
  1646. $this.toggle();
  1647. });
  1648. this.element.data("toggle", this);
  1649. };
  1650. $.extend(Toggle.prototype, {
  1651. toggle: function() {
  1652. if(!this.totoggle.length) return;
  1653. this.totoggle.toggleClass(this.options.cls);
  1654. }
  1655. });
  1656. Toggle.defaults = {
  1657. target: false,
  1658. cls: 'uk-hidden'
  1659. };
  1660. UI["toggle"] = Toggle;
  1661. $(document).on("click.toggle.uikit", "[data-uk-toggle]", function(e) {
  1662. var ele = $(this);
  1663. if (!ele.data("toggle")) {
  1664. var obj = new Toggle(ele, UI.Utils.options(ele.attr("data-uk-toggle")));
  1665. ele.trigger("click");
  1666. }
  1667. });
  1668. })(this, jQuery, jQuery.UIkit);