UNPKG

v-uikit

Version:

基于 UIKit 和 Vue2 开发的界面套件

1,642 lines (1,158 loc) 796 kB
/*! * VueUi v1.0.2 (https://github.com/DotNetAge/vue-ui) * (c) 2017 Ray Liang * Released under the MIT License. */ module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); __webpack_require__(1); __webpack_require__(2); __webpack_require__(3); var _UkIcon = __webpack_require__(10); var _UkIcon2 = _interopRequireDefault(_UkIcon); var _UkButton = __webpack_require__(11); var _UkButton2 = _interopRequireDefault(_UkButton); var _UkButtonGroup = __webpack_require__(15); var _UkButtonGroup2 = _interopRequireDefault(_UkButtonGroup); var _UkPanel = __webpack_require__(16); var _UkPanel2 = _interopRequireDefault(_UkPanel); var _UkNav = __webpack_require__(19); var _UkNav2 = _interopRequireDefault(_UkNav); var _UkDatepicker = __webpack_require__(20); var _UkDatepicker2 = _interopRequireDefault(_UkDatepicker); var _UkTimepicker = __webpack_require__(26); var _UkTimepicker2 = _interopRequireDefault(_UkTimepicker); var _UkTabs = __webpack_require__(31); var _UkHtmlEditor = __webpack_require__(37); var _UkHtmlEditor2 = _interopRequireDefault(_UkHtmlEditor); var _UkAlert = __webpack_require__(52); var _UkAlert2 = _interopRequireDefault(_UkAlert); var _UkModal = __webpack_require__(55); var _UkModal2 = _interopRequireDefault(_UkModal); var _UkPager = __webpack_require__(58); var _UkPager2 = _interopRequireDefault(_UkPager); var _UkBadge = __webpack_require__(60); var _UkBadge2 = _interopRequireDefault(_UkBadge); var _UkPassword = __webpack_require__(63); var _UkPassword2 = _interopRequireDefault(_UkPassword); var _UkSelect = __webpack_require__(69); var _UkSelect2 = _interopRequireDefault(_UkSelect); var _UkProgress = __webpack_require__(75); var _UkProgress2 = _interopRequireDefault(_UkProgress); var _UkDropdown = __webpack_require__(78); var _UkDropdown2 = _interopRequireDefault(_UkDropdown); var _UkItemPicker = __webpack_require__(81); var _UkItemPicker2 = _interopRequireDefault(_UkItemPicker); var _UkForm = __webpack_require__(84); var _UkForm2 = _interopRequireDefault(_UkForm); var _UkFormRow = __webpack_require__(87); var _UkFormRow2 = _interopRequireDefault(_UkFormRow); var _UkFormIcon = __webpack_require__(90); var _UkFormIcon2 = _interopRequireDefault(_UkFormIcon); var _UkInput = __webpack_require__(93); var _UkInput2 = _interopRequireDefault(_UkInput); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function (Vue, options) { var ui = window.UIkit; Vue.prototype.$ui = { $: ui.$, modal: ui.modal, alert: ui.modal.alert, confirm: ui.modal.confirm, prompt: ui.modal.prompt, block: ui.modal.blockUI }; Vue.prototype.$uikit = window.UIKit; Vue.component('uk-icon', _UkIcon2.default); Vue.component('uk-icon-field', _UkFormIcon2.default); Vue.component('uk-badge', _UkBadge2.default); Vue.component('uk-button', _UkButton2.default); Vue.component('uk-button-group', _UkButtonGroup2.default); Vue.component('uk-panel', _UkPanel2.default); Vue.component('uk-tab', _UkTabs.UkTab); Vue.component('uk-tabs', _UkTabs.UkTabs); Vue.component('uk-nav', _UkNav2.default); Vue.component('uk-datepicker', _UkDatepicker2.default); Vue.component('uk-timepicker', _UkTimepicker2.default); Vue.component('uk-html-editor', _UkHtmlEditor2.default); Vue.component('uk-alert', _UkAlert2.default); Vue.component('uk-modal', _UkModal2.default); Vue.component('uk-pager', _UkPager2.default); Vue.component('uk-password', _UkPassword2.default); Vue.component('uk-select', _UkSelect2.default); Vue.component('uk-progress', _UkProgress2.default); Vue.component('uk-dropdown-list', _UkDropdown2.default); Vue.component('uk-itempicker', _UkItemPicker2.default); Vue.component('uk-input', _UkInput2.default); Vue.component('uk-form', _UkForm2.default); Vue.component('uk-field', _UkFormRow2.default); }; /***/ }, /* 1 */ /***/ function(module, exports) { module.exports = require("jquery"); /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_RESULT__;/*! UIkit 2.27.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ (function(core) { if (true) { // AMD !(__WEBPACK_AMD_DEFINE_RESULT__ = function(){ var uikit = window.UIkit || core(window, window.jQuery, window.document); uikit.load = function(res, req, onload, config) { var resources = res.split(','), load = [], i, base = (config.config && config.config.uikit && config.config.uikit.base ? config.config.uikit.base : '').replace(/\/+$/g, ''); if (!base) { throw new Error('Please define base path to UIkit in the requirejs config.'); } for (i = 0; i < resources.length; i += 1) { var resource = resources[i].replace(/\./g, '/'); load.push(base+'/components/'+resource); } req(load, function() { onload(uikit); }); }; return uikit; }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } if (!window.jQuery) { throw new Error('UIkit requires jQuery'); } if (window && window.jQuery) { core(window, window.jQuery, window.document); } })(function(global, $, doc) { "use strict"; var UI = {}, _UI = global.UIkit ? Object.create(global.UIkit) : undefined; UI.version = '2.27.2'; UI.noConflict = function() { // restore UIkit version if (_UI) { global.UIkit = _UI; $.UIkit = _UI; $.fn.uk = _UI.fn; } return UI; }; UI.prefix = function(str) { return str; }; // cache jQuery UI.$ = $; UI.$doc = UI.$(document); UI.$win = UI.$(window); UI.$html = UI.$('html'); UI.support = {}; UI.support.transition = (function() { var transitionEnd = (function() { var element = doc.body || doc.documentElement, transEndEventNames = { WebkitTransition : 'webkitTransitionEnd', MozTransition : 'transitionend', OTransition : 'oTransitionEnd otransitionend', transition : 'transitionend' }, name; for (name in transEndEventNames) { if (element.style[name] !== undefined) return transEndEventNames[name]; } }()); return transitionEnd && { end: transitionEnd }; })(); UI.support.animation = (function() { var animationEnd = (function() { var element = doc.body || doc.documentElement, animEndEventNames = { WebkitAnimation : 'webkitAnimationEnd', MozAnimation : 'animationend', OAnimation : 'oAnimationEnd oanimationend', animation : 'animationend' }, name; for (name in animEndEventNames) { if (element.style[name] !== undefined) return animEndEventNames[name]; } }()); return animationEnd && { end: animationEnd }; })(); // requestAnimationFrame polyfill //https://github.com/darius/requestAnimationFrame (function() { Date.now = Date.now || function() { return new Date().getTime(); }; var vendors = ['webkit', 'moz']; for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { var vp = vendors[i]; window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] || window[vp+'CancelRequestAnimationFrame']); } if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy || !window.requestAnimationFrame || !window.cancelAnimationFrame) { var lastTime = 0; window.requestAnimationFrame = function(callback) { var now = Date.now(); var nextTime = Math.max(lastTime + 16, now); return setTimeout(function() { callback(lastTime = nextTime); }, nextTime - now); }; window.cancelAnimationFrame = clearTimeout; } }()); UI.support.touch = ( ('ontouchstart' in document) || (global.DocumentTouch && document instanceof global.DocumentTouch) || (global.navigator.msPointerEnabled && global.navigator.msMaxTouchPoints > 0) || //IE 10 (global.navigator.pointerEnabled && global.navigator.maxTouchPoints > 0) || //IE >=11 false ); UI.support.mutationobserver = (global.MutationObserver || global.WebKitMutationObserver || null); UI.Utils = {}; UI.Utils.isFullscreen = function() { return document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || document.fullscreenElement || false; }; UI.Utils.str2json = function(str, notevil) { try { if (notevil) { return JSON.parse(str // wrap keys without quote with valid double quote .replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":';}) // replacing single quote wrapped ones to double quote .replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"';}) ); } else { return (new Function('', 'var json = ' + str + '; return JSON.parse(JSON.stringify(json));'))(); } } catch(e) { return false; } }; UI.Utils.debounce = function(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; UI.Utils.throttle = function (func, limit) { var wait = false; return function () { if (!wait) { func.call(); wait = true; setTimeout(function () { wait = false; }, limit); } } }; UI.Utils.removeCssRules = function(selectorRegEx) { var idx, idxs, stylesheet, _i, _j, _k, _len, _len1, _len2, _ref; if(!selectorRegEx) return; setTimeout(function(){ try { _ref = document.styleSheets; for (_i = 0, _len = _ref.length; _i < _len; _i++) { stylesheet = _ref[_i]; idxs = []; stylesheet.cssRules = stylesheet.cssRules; for (idx = _j = 0, _len1 = stylesheet.cssRules.length; _j < _len1; idx = ++_j) { if (stylesheet.cssRules[idx].type === CSSRule.STYLE_RULE && selectorRegEx.test(stylesheet.cssRules[idx].selectorText)) { idxs.unshift(idx); } } for (_k = 0, _len2 = idxs.length; _k < _len2; _k++) { stylesheet.deleteRule(idxs[_k]); } } } catch (_error) {} }, 0); }; UI.Utils.isInView = function(element, options) { var $element = $(element); if (!$element.is(':visible')) { return false; } var window_left = UI.$win.scrollLeft(), window_top = UI.$win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top; options = $.extend({topoffset:0, leftoffset:0}, options); if (top + $element.height() >= window_top && top - options.topoffset <= window_top + UI.$win.height() && left + $element.width() >= window_left && left - options.leftoffset <= window_left + UI.$win.width()) { return true; } else { return false; } }; UI.Utils.checkDisplay = function(context, initanimation) { var elements = UI.$('[data-uk-margin], [data-uk-grid-match], [data-uk-grid-margin], [data-uk-check-display]', context || document), animated; if (context && !elements.length) { elements = $(context); } elements.trigger('display.uk.check'); // fix firefox / IE animations if (initanimation) { if (typeof(initanimation)!='string') { initanimation = '[class*="uk-animation-"]'; } elements.find(initanimation).each(function(){ var ele = UI.$(this), cls = ele.attr('class'), anim = cls.match(/uk-animation-(.+)/); ele.removeClass(anim[0]).width(); ele.addClass(anim[0]); }); } return elements; }; UI.Utils.options = function(string) { if ($.type(string)!='string') return string; if (string.indexOf(':') != -1 && string.trim().substr(-1) != '}') { string = '{'+string+'}'; } var start = (string ? string.indexOf("{") : -1), options = {}; if (start != -1) { try { options = UI.Utils.str2json(string.substr(start)); } catch (e) {} } return options; }; UI.Utils.animate = function(element, cls) { var d = $.Deferred(); element = UI.$(element); element.css('display', 'none').addClass(cls).one(UI.support.animation.end, function() { element.removeClass(cls); d.resolve(); }); element.css('display', ''); return d.promise(); }; UI.Utils.uid = function(prefix) { return (prefix || 'id') + (new Date().getTime())+"RAND"+(Math.ceil(Math.random() * 100000)); }; UI.Utils.template = function(str, data) { var tokens = str.replace(/\n/g, '\\n').replace(/\{\{\{\s*(.+?)\s*\}\}\}/g, "{{!$1}}").split(/(\{\{\s*(.+?)\s*\}\})/g), i=0, toc, cmd, prop, val, fn, output = [], openblocks = 0; while(i < tokens.length) { toc = tokens[i]; if(toc.match(/\{\{\s*(.+?)\s*\}\}/)) { i = i + 1; toc = tokens[i]; cmd = toc[0]; prop = toc.substring(toc.match(/^(\^|\#|\!|\~|\:)/) ? 1:0); switch(cmd) { case '~': output.push('for(var $i=0;$i<'+prop+'.length;$i++) { var $item = '+prop+'[$i];'); openblocks++; break; case ':': output.push('for(var $key in '+prop+') { var $val = '+prop+'[$key];'); openblocks++; break; case '#': output.push('if('+prop+') {'); openblocks++; break; case '^': output.push('if(!'+prop+') {'); openblocks++; break; case '/': output.push('}'); openblocks--; break; case '!': output.push('__ret.push('+prop+');'); break; default: output.push('__ret.push(escape('+prop+'));'); break; } } else { output.push("__ret.push('"+toc.replace(/\'/g, "\\'")+"');"); } i = i + 1; } fn = new Function('$data', [ 'var __ret = [];', 'try {', 'with($data){', (!openblocks ? output.join('') : '__ret = ["Not all blocks are closed correctly."]'), '};', '}catch(e){__ret = [e.message];}', 'return __ret.join("").replace(/\\n\\n/g, "\\n");', "function escape(html) { return String(html).replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');}" ].join("\n")); return data ? fn(data) : fn; }; UI.Utils.focus = function(element, extra) { element = $(element); if (!element.length) { return element; } var autofocus = element.find('[autofocus]:first'), tabidx; if (autofocus.length) { return autofocus.focus(); } autofocus = element.find(':input'+(extra && (','+extra) || '')).first(); if (autofocus.length) { return autofocus.focus(); } if (!element.attr('tabindex')) { tabidx = 1000; element.attr('tabindex', tabidx); } element[0].focus(); if (tabidx) { element.attr('tabindex', ''); } return element; } UI.Utils.events = {}; UI.Utils.events.click = UI.support.touch ? 'tap' : 'click'; global.UIkit = UI; // deprecated UI.fn = function(command, options) { var args = arguments, cmd = command.match(/^([a-z\-]+)(?:\.([a-z]+))?/i), component = cmd[1], method = cmd[2]; if (!UI[component]) { $.error('UIkit component [' + component + '] does not exist.'); return this; } return this.each(function() { var $this = $(this), data = $this.data(component); if (!data) $this.data(component, (data = UI[component](this, method ? undefined : options))); if (method) data[method].apply(data, Array.prototype.slice.call(args, 1)); }); }; $.UIkit = UI; $.fn.uk = UI.fn; UI.langdirection = UI.$html.attr("dir") == "rtl" ? "right" : "left"; UI.components = {}; UI.component = function(name, def) { var fn = function(element, options) { var $this = this; this.UIkit = UI; this.element = element ? UI.$(element) : null; this.options = $.extend(true, {}, this.defaults, options); this.plugins = {}; if (this.element) { this.element.data(name, this); } this.init(); (this.options.plugins.length ? this.options.plugins : Object.keys(fn.plugins)).forEach(function(plugin) { if (fn.plugins[plugin].init) { fn.plugins[plugin].init($this); $this.plugins[plugin] = true; } }); this.trigger('init.uk.component', [name, this]); return this; }; fn.plugins = {}; $.extend(true, fn.prototype, { defaults : {plugins: []}, boot: function(){}, init: function(){}, on: function(a1,a2,a3){ return UI.$(this.element || this).on(a1,a2,a3); }, one: function(a1,a2,a3){ return UI.$(this.element || this).one(a1,a2,a3); }, off: function(evt){ return UI.$(this.element || this).off(evt); }, trigger: function(evt, params) { return UI.$(this.element || this).trigger(evt, params); }, find: function(selector) { return UI.$(this.element ? this.element: []).find(selector); }, proxy: function(obj, methods) { var $this = this; methods.split(' ').forEach(function(method) { if (!$this[method]) $this[method] = function() { return obj[method].apply(obj, arguments); }; }); }, mixin: function(obj, methods) { var $this = this; methods.split(' ').forEach(function(method) { if (!$this[method]) $this[method] = obj[method].bind($this); }); }, option: function() { if (arguments.length == 1) { return this.options[arguments[0]] || undefined; } else if (arguments.length == 2) { this.options[arguments[0]] = arguments[1]; } } }, def); this.components[name] = fn; this[name] = function() { var element, options; if (arguments.length) { switch(arguments.length) { case 1: if (typeof arguments[0] === 'string' || arguments[0].nodeType || arguments[0] instanceof jQuery) { element = $(arguments[0]); } else { options = arguments[0]; } break; case 2: element = $(arguments[0]); options = arguments[1]; break; } } if (element && element.data(name)) { return element.data(name); } return (new UI.components[name](element, options)); }; if (UI.domready) { UI.component.boot(name); } return fn; }; UI.plugin = function(component, name, def) { this.components[component].plugins[name] = def; }; UI.component.boot = function(name) { if (UI.components[name].prototype && UI.components[name].prototype.boot && !UI.components[name].booted) { UI.components[name].prototype.boot.apply(UI, []); UI.components[name].booted = true; } }; UI.component.bootComponents = function() { for (var component in UI.components) { UI.component.boot(component); } }; // DOM mutation save ready helper function UI.domObservers = []; UI.domready = false; UI.ready = function(fn) { UI.domObservers.push(fn); if (UI.domready) { fn(document); } }; UI.on = function(a1,a2,a3){ if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { a2.apply(UI.$doc); } return UI.$doc.on(a1,a2,a3); }; UI.one = function(a1,a2,a3){ if (a1 && a1.indexOf('ready.uk.dom') > -1 && UI.domready) { a2.apply(UI.$doc); return UI.$doc; } return UI.$doc.one(a1,a2,a3); }; UI.trigger = function(evt, params) { return UI.$doc.trigger(evt, params); }; UI.domObserve = function(selector, fn) { if(!UI.support.mutationobserver) return; fn = fn || function() {}; UI.$(selector).each(function() { var element = this, $element = UI.$(element); if ($element.data('observer')) { return; } try { var observer = new UI.support.mutationobserver(UI.Utils.debounce(function(mutations) { fn.apply(element, [$element]); $element.trigger('changed.uk.dom'); }, 50), {childList: true, subtree: true}); // pass in the target node, as well as the observer options observer.observe(element, { childList: true, subtree: true }); $element.data('observer', observer); } catch(e) {} }); }; UI.init = function(root) { root = root || document; UI.domObservers.forEach(function(fn){ fn(root); }); }; UI.on('domready.uk.dom', function(){ UI.init(); if (UI.domready) UI.Utils.checkDisplay(); }); document.addEventListener('DOMContentLoaded', function(){ var domReady = function() { UI.$body = UI.$('body'); UI.trigger('beforeready.uk.dom'); UI.component.bootComponents(); // custom scroll observer var rafToken = requestAnimationFrame((function(){ var memory = {dir: {x:0, y:0}, x: window.pageXOffset, y:window.pageYOffset}; var fn = function(){ // reading this (window.page[X|Y]Offset) causes a full page recalc of the layout in Chrome, // so we only want to do this once var wpxo = window.pageXOffset; var wpyo = window.pageYOffset; // Did the scroll position change since the last time we were here? if (memory.x != wpxo || memory.y != wpyo) { // Set the direction of the scroll and store the new position if (wpxo != memory.x) {memory.dir.x = wpxo > memory.x ? 1:-1; } else { memory.dir.x = 0; } if (wpyo != memory.y) {memory.dir.y = wpyo > memory.y ? 1:-1; } else { memory.dir.y = 0; } memory.x = wpxo; memory.y = wpyo; // Trigger the scroll event, this could probably be sent using memory.clone() but this is // more explicit and easier to see exactly what is being sent in the event. UI.$doc.trigger('scrolling.uk.document', [{ dir: {x: memory.dir.x, y: memory.dir.y}, x: wpxo, y: wpyo }]); } cancelAnimationFrame(rafToken); rafToken = requestAnimationFrame(fn); }; if (UI.support.touch) { UI.$html.on('touchmove touchend MSPointerMove MSPointerUp pointermove pointerup', fn); } if (memory.x || memory.y) fn(); return fn; })()); // run component init functions on dom UI.trigger('domready.uk.dom'); if (UI.support.touch) { // remove css hover rules for touch devices // UI.Utils.removeCssRules(/\.uk-(?!navbar).*:hover/); // viewport unit fix for uk-height-viewport - should be fixed in iOS 8 if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) { UI.$win.on('load orientationchange resize', UI.Utils.debounce((function(){ var fn = function() { $('.uk-height-viewport').css('height', window.innerHeight); return fn; }; return fn(); })(), 100)); } } UI.trigger('afterready.uk.dom'); // mark that domready is left behind UI.domready = true; // auto init js components if (UI.support.mutationobserver) { var initFn = UI.Utils.debounce(function(){ requestAnimationFrame(function(){ UI.init(document.body);}); }, 10); (new UI.support.mutationobserver(function(mutations) { var init = false; mutations.every(function(mutation){ if (mutation.type != 'childList') return true; for (var i = 0, node; i < mutation.addedNodes.length; ++i) { node = mutation.addedNodes[i]; if (node.outerHTML && node.outerHTML.indexOf('data-uk-') !== -1) { return (init = true) && false; } } return true; }); if (init) initFn(); })).observe(document.body, {childList: true, subtree: true}); } }; if (document.readyState == 'complete' || document.readyState == 'interactive') { setTimeout(domReady); } return domReady; }()); // add touch identifier class UI.$html.addClass(UI.support.touch ? 'uk-touch' : 'uk-notouch'); // add uk-hover class on tap to support overlays on touch devices if (UI.support.touch) { var hoverset = false, exclude, hovercls = 'uk-hover', selector = '.uk-overlay, .uk-overlay-hover, .uk-overlay-toggle, .uk-animation-hover, .uk-has-hover'; UI.$html.on('mouseenter touchstart MSPointerDown pointerdown', selector, function() { if (hoverset) $('.'+hovercls).removeClass(hovercls); hoverset = $(this).addClass(hovercls); }).on('mouseleave touchend MSPointerUp pointerup', function(e) { exclude = $(e.target).parents(selector); if (hoverset) { hoverset.not(exclude).removeClass(hovercls); } }); } return UI; }); // Based on Zeptos touch.js // https://raw.github.com/madrobby/zepto/master/src/touch.js // Zepto.js may be freely distributed under the MIT license. ;(function($){ if ($.fn.swipeLeft) { return; } var touch = {}, touchTimeout, tapTimeout, swipeTimeout, longTapTimeout, longTapDelay = 750, gesture; function swipeDirection(x1, x2, y1, y2) { return Math.abs(x1 - x2) >= Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down'); } function longTap() { longTapTimeout = null; if (touch.last) { if ( touch.el !== undefined ) touch.el.trigger('longTap'); touch = {}; } } function cancelLongTap() { if (longTapTimeout) clearTimeout(longTapTimeout); longTapTimeout = null; } function cancelAll() { if (touchTimeout) clearTimeout(touchTimeout); if (tapTimeout) clearTimeout(tapTimeout); if (swipeTimeout) clearTimeout(swipeTimeout); if (longTapTimeout) clearTimeout(longTapTimeout); touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null; touch = {}; } function isPrimaryTouch(event){ return event.pointerType == event.MSPOINTER_TYPE_TOUCH && event.isPrimary; } $(function(){ var now, delta, deltaX = 0, deltaY = 0, firstTouch; if ('MSGesture' in window) { gesture = new MSGesture(); gesture.target = document.body; } $(document) .on('MSGestureEnd gestureend', function(e){ var swipeDirectionFromVelocity = e.originalEvent.velocityX > 1 ? 'Right' : e.originalEvent.velocityX < -1 ? 'Left' : e.originalEvent.velocityY > 1 ? 'Down' : e.originalEvent.velocityY < -1 ? 'Up' : null; if (swipeDirectionFromVelocity && touch.el !== undefined) { touch.el.trigger('swipe'); touch.el.trigger('swipe'+ swipeDirectionFromVelocity); } }) // MSPointerDown: for IE10 // pointerdown: for IE11 .on('touchstart MSPointerDown pointerdown', function(e){ if(e.type == 'MSPointerDown' && !isPrimaryTouch(e.originalEvent)) return; firstTouch = (e.type == 'MSPointerDown' || e.type == 'pointerdown') ? e : e.originalEvent.touches[0]; now = Date.now(); delta = now - (touch.last || now); touch.el = $('tagName' in firstTouch.target ? firstTouch.target : firstTouch.target.parentNode); if(touchTimeout) clearTimeout(touchTimeout); touch.x1 = firstTouch.pageX; touch.y1 = firstTouch.pageY; if (delta > 0 && delta <= 250) touch.isDoubleTap = true; touch.last = now; longTapTimeout = setTimeout(longTap, longTapDelay); // adds the current touch contact for IE gesture recognition if (e.originalEvent && e.originalEvent.pointerId && gesture && ( e.type == 'MSPointerDown' || e.type == 'pointerdown' || e.type == 'touchstart' ) ) { gesture.addPointer(e.originalEvent.pointerId); } }) // MSPointerMove: for IE10 // pointermove: for IE11 .on('touchmove MSPointerMove pointermove', function(e){ if (e.type == 'MSPointerMove' && !isPrimaryTouch(e.originalEvent)) return; firstTouch = (e.type == 'MSPointerMove' || e.type == 'pointermove') ? e : e.originalEvent.touches[0]; cancelLongTap(); touch.x2 = firstTouch.pageX; touch.y2 = firstTouch.pageY; deltaX += Math.abs(touch.x1 - touch.x2); deltaY += Math.abs(touch.y1 - touch.y2); }) // MSPointerUp: for IE10 // pointerup: for IE11 .on('touchend MSPointerUp pointerup', function(e){ if (e.type == 'MSPointerUp' && !isPrimaryTouch(e.originalEvent)) return; cancelLongTap(); // swipe if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)){ swipeTimeout = setTimeout(function() { if ( touch.el !== undefined ) { touch.el.trigger('swipe'); touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2))); } touch = {}; }, 0); // normal tap } else if ('last' in touch) { // don't fire tap when delta position changed by more than 30 pixels, // for instance when moving to a point and back to origin if (isNaN(deltaX) || (deltaX < 30 && deltaY < 30)) { // delay by one tick so we can cancel the 'tap' event if 'scroll' fires // ('tap' fires before 'scroll') tapTimeout = setTimeout(function() { // trigger universal 'tap' with the option to cancelTouch() // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) var event = $.Event('tap'); event.cancelTouch = cancelAll; if ( touch.el !== undefined ) touch.el.trigger(event); // trigger double tap immediately if (touch.isDoubleTap) { if ( touch.el !== undefined ) touch.el.trigger('doubleTap'); touch = {}; } // trigger single tap after 250ms of inactivity else { touchTimeout = setTimeout(function(){ touchTimeout = null; if ( touch.el !== undefined ) touch.el.trigger('singleTap'); touch = {}; }, 250); } }, 0); } else { touch = {}; } deltaX = deltaY = 0; } }) // when the browser window loses focus, // for example when a modal dialog is shown, // cancel all ongoing events .on('touchcancel MSPointerCancel pointercancel', cancelAll); // scrolling the window indicates intention of the user // to scroll, not tap or swipe, so cancel all ongoing events $(window).on('scroll', cancelAll); }); ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){ $.fn[eventName] = function(callback){ return $(this).on(eventName, callback); }; }); })(jQuery); (function(UI) { "use strict"; var stacks = []; UI.component('stackMargin', { defaults: { cls: 'uk-margin-small-top', rowfirst: false, observe: false }, boot: function() { // init code UI.ready(function(context) { UI.$('[data-uk-margin]', context).each(function() { var ele = UI.$(this); if (!ele.data('stackMargin')) { UI.stackMargin(ele, UI.Utils.options(ele.attr('data-uk-margin'))); } }); }); }, init: function() { var $this = this; UI.$win.on('resize orientationchange', (function() { var fn = function() { $this.process(); }; UI.$(function() { fn(); UI.$win.on('load', fn); }); return UI.Utils.debounce(fn, 20); })()); this.on('display.uk.check', function(e) { if (this.element.is(':visible')) this.process(); }.bind(this)); if (this.options.observe) { UI.domObserve(this.element, function(e) { if ($this.element.is(':visible')) $this.process(); }); } stacks.push(this); }, process: function() { var $this = this, columns = this.element.children(); UI.Utils.stackMargin(columns, this.options); if (!this.options.rowfirst || !columns.length) { return this; } // Mark first column elements var group = {}, minleft = false; columns.removeClass(this.options.rowfirst).each(function(offset, $ele){ $ele = UI.$(this); if (this.style.display != 'none') { offset = $ele.offset().left; ((group[offset] = group[offset] || []) && group[offset]).push(this); minleft = minleft === false ? offset : Math.min(minleft, offset); } }); UI.$(group[minleft]).addClass(this.options.rowfirst); return this; } }); // responsive element e.g. iframes (function(){ var elements = [], check = function(ele) { if (!ele.is(':visible')) return; var width = ele.parent().width(), iwidth = ele.data('width'), ratio = (width / iwidth), height = Math.floor(ratio * ele.data('height')); ele.css({height: (width < iwidth) ? height : ele.data('height')}); }; UI.component('responsiveElement', { defaults: {}, boot: function() { // init code UI.ready(function(context) { UI.$('iframe.uk-responsive-width, [data-uk-responsive]', context).each(function() { var ele = UI.$(this), obj; if (!ele.data('responsiveElement')) { obj = UI.responsiveElement(ele, {}); } }); }); }, init: function() { var ele = this.element; if (ele.attr('width') && ele.attr('height')) { ele.data({ width : ele.attr('width'), height: ele.attr('height') }).on('display.uk.check', function(){ check(ele); }); check(ele); elements.push(ele); } } }); UI.$win.on('resize load', UI.Utils.debounce(function(){ elements.forEach(function(ele){ check(ele); }); }, 15)); })(); // helper UI.Utils.stackMargin = function(elements, options) { options = UI.$.extend({ cls: 'uk-margin-small-top' }, options); elements = UI.$(elements).removeClass(options.cls); var min = false; elements.each(function(offset, height, pos, $ele){ $ele = UI.$(this); if ($ele.css('display') != 'none') { offset = $ele.offset(); height = $ele.outerHeight(); pos = offset.top + height; $ele.data({ ukMarginPos: pos, ukMarginTop: offset.top }); if (min === false || (offset.top < min.top) ) { min = { top : offset.top, left : offset.left, pos : pos }; } } }).each(function($ele) { $ele = UI.$(this); if ($ele.css('display') != 'none' && $ele.data('ukMarginTop') > min.top && $ele.data('ukMarginPos') > min.pos) { $ele.addClass(options.cls); } }); }; UI.Utils.matchHeights = function(elements, options) { elements = UI.$(elements).css('min-height', ''); options = UI.$.extend({ row : true }, options); var matchHeights = function(group){ if (group.length < 2) return; var max = 0; group.each(function() { max = Math.max(max, UI.$(this).outerHeight()); }).each(function() { var element = UI.$(this), height = max - (element.css('box-sizing') == 'border-box' ? 0 : (element.outerHeight() - element.height())); element.css('min-height', height + 'px'); }); }; if (options.row) { elements.first().width(); // force redraw setTimeout(function(){ var lastoffset = false, group = []; elements.each(function() { var ele = UI.$(this), offset = ele.offset().top; if (offset != lastoffset && group.length) { matchHeights(UI.$(group)); group = []; offset = ele.offset().top; } group.push(ele); lastoffset = offset; }); if (group.length) { matchHeights(UI.$(group)); } }, 0); } else { matchHeights(elements); } }; (function(cacheSvgs){ UI.Utils.inlineSvg = function(selector, root) { var images = UI.$(selector || 'img[src$=".svg"]', root || document).each(function(){ var img = UI.$(this), src = img.attr('src'); if (!cacheSvgs[src]) { var d = UI.$.Deferred(); UI.$.get(src, {nc: Math.random()}, function(data){ d.resolve(UI.$(data).find('svg')); }); cacheSvgs[src] = d.promise(); } cacheSvgs[src].then(function(svg) { var $svg = UI.$(svg).clone(); if (img.attr('id')) $svg.attr('id', img.attr('id')); if (img.attr('class')) $svg.attr('class', img.attr('class')); if (img.attr('style')) $svg.attr('style', img.attr('style')); if (img.attr('width')) { $svg.attr('width', img.attr('width')); if (!img.attr('height')) $svg.removeAttr('height'); } if (img.attr('height')){ $svg.attr('height', img.attr('height')); if (!img.attr('width')) $svg.removeAttr('width'); } img.replaceWith($svg); }); }); }; // init code UI.ready(function(context) { UI.Utils.inlineSvg('[data-uk-svg]', context); }); })({}); UI.Utils.getCssVar = function(name) { /* usage in css: .var-name:before { content:"xyz" } */ var val, doc = document.documentElement, element = doc.appendChild(document.createElement('div')); element.classList.add('var-'+name); try { val = JSON.parse(val = getComputedStyle(element, ':before').content.replace(/^["'](.*)["']$/, '$1')); } catch (e) { val = undefined; } doc.removeChild(element); return val; } })(UIkit); (function(UI) { "use strict"; UI.component('smoothScroll', { boot: function() { // init code UI.$html.on('click.smooth-scroll.uikit', '[data-uk-smooth-scroll]', function(e) { var ele = UI.$(this); if (!ele.data('smoothScroll')) { var obj = UI.smoothScroll(ele, UI.Utils.options(ele.attr('data-uk-smooth-scroll'))); ele.trigger('click'); } return false; }); }, init: function() { var $this = this; this.on('click', function(e) { e.preventDefault(); scrollToElement(UI.$(this.hash).length ? UI.$(this.hash) : UI.$('body'), $this.options); }); } }); function scrollToElement(ele, options) { options = UI.$.extend({ duration: 1000, transition: 'easeOutExpo', offset: 0, complete: function(){} }, options); // get / set parameters var target = ele.offset().top - options.offset, docheight = UI.$doc.height(), winheight = window.innerHeight; if ((target + winheight) > docheight) { target = docheight - winheight; } // animate to target, fire callback when done UI.$('html,body').stop().animate({scrollTop: target}, options.duration, options.transition).promise().done(options.complete); } UI.Utils.scrollToElement = scrollToElement; if (!UI.$.easing.easeOutExpo) { UI.$.easing.easeOutExpo = function(x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }; } })(UIkit); (function(UI) { "use strict"; var $win = UI.$win, $doc = UI.$doc, scrollspies = [], checkScrollSpy = function() { for(var i=0; i < scrollspies.length; i++) { window.requestAnimationFrame.apply(window, [scrollspies[i].check]); } }; UI.component('scrollspy', { defaults: { target : false, cls : 'uk-scrollspy-inview', initcls : 'uk-scrollspy-init-inview', topoffset : 0, leftoffset : 0, repeat : false, delay : 0 }, boot: function() { // listen to scroll and resize $doc.on('scrolling.uk.document', checkScrollSpy); $win.on('load resize orientationchange', UI.Utils.debounce(checkScrollSpy, 50)); // init code UI.ready(function(context) { UI.$('[data-uk-scrollspy]', context).each(function() { var element = UI.$(this); if (!element.data('scrollspy')) { var obj = UI.scrollspy(element, UI.Utils.options(element.attr('data-uk-scrollspy'))); } }); }); }, init: function() {