/libs/amazeui/1.0.0-beta2/js/amazeui.basic.js
JavaScript | 10407 lines | 8113 code | 50 blank | 2244 comment | 2053 complexity | ecb0da555092596262222b4070de3604 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- /*! Amaze UI v1.0.0-beta2 ~ basic | by Amaze UI Team | (c) 2014 AllMobilize, Inc. | Licensed under MIT | 2014-09-28T02:09:21 UTC */
- /*! Sea.js 2.2.1 | seajs.org/LICENSE.md */
- !function(a,b){function c(a){return function(b){return{}.toString.call(b)=="[object "+a+"]"}}function d(){return A++}function e(a){return a.match(D)[0]}function f(a){for(a=a.replace(E,"/");a.match(F);)a=a.replace(F,"/");return a=a.replace(G,"$1/")}function g(a){var b=a.length-1,c=a.charAt(b);return"#"===c?a.substring(0,b):".js"===a.substring(b-2)||a.indexOf("?")>0||".css"===a.substring(b-3)||"/"===c?a:a+".js"}function h(a){var b=v.alias;return b&&x(b[a])?b[a]:a}function i(a){var b=v.paths,c;return b&&(c=a.match(H))&&x(b[c[1]])&&(a=b[c[1]]+c[2]),a}function j(a){var b=v.vars;return b&&a.indexOf("{")>-1&&(a=a.replace(I,function(a,c){return x(b[c])?b[c]:a})),a}function k(a){var b=v.map,c=a;if(b)for(var d=0,e=b.length;e>d;d++){var f=b[d];if(c=z(f)?f(a)||a:a.replace(f[0],f[1]),c!==a)break}return c}function l(a,b){var c,d=a.charAt(0);if(J.test(a))c=a;else if("."===d)c=f((b?e(b):v.cwd)+a);else if("/"===d){var g=v.cwd.match(K);c=g?g[0]+a.substring(1):a}else c=v.base+a;return 0===c.indexOf("//")&&(c=location.protocol+c),c}function m(a,b){if(!a)return"";a=h(a),a=i(a),a=j(a),a=g(a);var c=l(a,b);return c=k(c)}function n(a){return a.hasAttribute?a.src:a.getAttribute("src",4)}function o(a,b,c){var d=S.test(a),e=L.createElement(d?"link":"script");if(c){var f=z(c)?c(a):c;f&&(e.charset=f)}p(e,b,d,a),d?(e.rel="stylesheet",e.href=a):(e.async=!0,e.src=a),T=e,R?Q.insertBefore(e,R):Q.appendChild(e),T=null}function p(a,c,d,e){function f(){a.onload=a.onerror=a.onreadystatechange=null,d||v.debug||Q.removeChild(a),a=null,c()}var g="onload"in a;return!d||!V&&g?(g?(a.onload=f,a.onerror=function(){C("error",{uri:e,node:a}),f()}):a.onreadystatechange=function(){/loaded|complete/.test(a.readyState)&&f()},b):(setTimeout(function(){q(a,c)},1),b)}function q(a,b){var c=a.sheet,d;if(V)c&&(d=!0);else if(c)try{c.cssRules&&(d=!0)}catch(e){"NS_ERROR_DOM_SECURITY_ERR"===e.name&&(d=!0)}setTimeout(function(){d?b():q(a,b)},20)}function r(){if(T)return T;if(U&&"interactive"===U.readyState)return U;for(var a=Q.getElementsByTagName("script"),b=a.length-1;b>=0;b--){var c=a[b];if("interactive"===c.readyState)return U=c}}function s(a){var b=[];return a.replace(X,"").replace(W,function(a,c,d){d&&b.push(d)}),b}function t(a,b){this.uri=a,this.dependencies=b||[],this.exports=null,this.status=0,this._waitings={},this._remain=0}if(!a.seajs){var u=a.seajs={version:"2.2.1"},v=u.data={},w=c("Object"),x=c("String"),y=Array.isArray||c("Array"),z=c("Function"),A=0,B=v.events={};u.on=function(a,b){var c=B[a]||(B[a]=[]);return c.push(b),u},u.off=function(a,b){if(!a&&!b)return B=v.events={},u;var c=B[a];if(c)if(b)for(var d=c.length-1;d>=0;d--)c[d]===b&&c.splice(d,1);else delete B[a];return u};var C=u.emit=function(a,b){var c=B[a],d;if(c)for(c=c.slice();d=c.shift();)d(b);return u},D=/[^?#]*\//,E=/\/\.\//g,F=/\/[^/]+\/\.\.\//,G=/([^:/])\/\//g,H=/^([^/:]+)(\/.+)$/,I=/{([^{]+)}/g,J=/^\/\/.|:\//,K=/^.*?\/\/.*?\//,L=document,M=e(L.URL),N=L.scripts,O=L.getElementById("seajsnode")||N[N.length-1],P=e(n(O)||M);u.resolve=m;var Q=L.head||L.getElementsByTagName("head")[0]||L.documentElement,R=Q.getElementsByTagName("base")[0],S=/\.css(?:\?|$)/i,T,U,V=+navigator.userAgent.replace(/.*(?:AppleWebKit|AndroidWebKit)\/(\d+).*/,"$1")<536;u.request=o;var W=/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\/\*[\S\s]*?\*\/|\/(?:\\\/|[^\/\r\n])+\/(?=[^\/])|\/\/.*|\.\s*require|(?:^|[^$])\brequire\s*\(\s*(["'])(.+?)\1\s*\)/g,X=/\\\\/g,Y=u.cache={},Z,$={},_={},ab={},bb=t.STATUS={FETCHING:1,SAVED:2,LOADING:3,LOADED:4,EXECUTING:5,EXECUTED:6};t.prototype.resolve=function(){for(var a=this,b=a.dependencies,c=[],d=0,e=b.length;e>d;d++)c[d]=t.resolve(b[d],a.uri);return c},t.prototype.load=function(){var a=this;if(!(a.status>=bb.LOADING)){a.status=bb.LOADING;var c=a.resolve();C("load",c);for(var d=a._remain=c.length,e,f=0;d>f;f++)e=t.get(c[f]),e.status<bb.LOADED?e._waitings[a.uri]=(e._waitings[a.uri]||0)+1:a._remain--;if(0===a._remain)return a.onload(),b;var g={};for(f=0;d>f;f++)e=Y[c[f]],e.status<bb.FETCHING?e.fetch(g):e.status===bb.SAVED&&e.load();for(var h in g)g.hasOwnProperty(h)&&g[h]()}},t.prototype.onload=function(){var a=this;a.status=bb.LOADED,a.callback&&a.callback();var b=a._waitings,c,d;for(c in b)b.hasOwnProperty(c)&&(d=Y[c],d._remain-=b[c],0===d._remain&&d.onload());delete a._waitings,delete a._remain},t.prototype.fetch=function(a){function c(){u.request(g.requestUri,g.onRequest,g.charset)}function d(){delete $[h],_[h]=!0,Z&&(t.save(f,Z),Z=null);var a,b=ab[h];for(delete ab[h];a=b.shift();)a.load()}var e=this,f=e.uri;e.status=bb.FETCHING;var g={uri:f};C("fetch",g);var h=g.requestUri||f;return!h||_[h]?(e.load(),b):$[h]?(ab[h].push(e),b):($[h]=!0,ab[h]=[e],C("request",g={uri:f,requestUri:h,onRequest:d,charset:v.charset}),g.requested||(a?a[g.requestUri]=c:c()),b)},t.prototype.exec=function(){function a(b){return t.get(a.resolve(b)).exec()}var c=this;if(c.status>=bb.EXECUTING)return c.exports;c.status=bb.EXECUTING;var e=c.uri;a.resolve=function(a){return t.resolve(a,e)},a.async=function(b,c){return t.use(b,c,e+"_async_"+d()),a};var f=c.factory,g=z(f)?f(a,c.exports={},c):f;return g===b&&(g=c.exports),delete c.factory,c.exports=g,c.status=bb.EXECUTED,C("exec",c),g},t.resolve=function(a,b){var c={id:a,refUri:b};return C("resolve",c),c.uri||u.resolve(c.id,b)},t.define=function(a,c,d){var e=arguments.length;1===e?(d=a,a=b):2===e&&(d=c,y(a)?(c=a,a=b):c=b),!y(c)&&z(d)&&(c=s(""+d));var f={id:a,uri:t.resolve(a),deps:c,factory:d};if(!f.uri&&L.attachEvent){var g=r();g&&(f.uri=g.src)}C("define",f),f.uri?t.save(f.uri,f):Z=f},t.save=function(a,b){var c=t.get(a);c.status<bb.SAVED&&(c.id=b.id||a,c.dependencies=b.deps||[],c.factory=b.factory,c.status=bb.SAVED)},t.get=function(a,b){return Y[a]||(Y[a]=new t(a,b))},t.use=function(b,c,d){var e=t.get(d,y(b)?b:[b]);e.callback=function(){for(var b=[],d=e.resolve(),f=0,g=d.length;g>f;f++)b[f]=Y[d[f]].exec();c&&c.apply(a,b),delete e.callback},e.load()},t.preload=function(a){var b=v.preload,c=b.length;c?t.use(b,function(){b.splice(0,c),t.preload(a)},v.cwd+"_preload_"+d()):a()},u.use=function(a,b){return t.preload(function(){t.use(a,b,v.cwd+"_use_"+d())}),u},t.define.cmd={},a.define=t.define,u.Module=t,v.fetchedList=_,v.cid=d,u.require=function(a){var b=t.get(t.resolve(a));return b.status<bb.EXECUTING&&(b.onload(),b.exec()),b.exports};var cb=/^(.+?\/)(\?\?)?(seajs\/)+/;v.base=(P.match(cb)||["",P])[1],v.dir=P,v.cwd=M,v.charset="utf-8",v.preload=function(){var a=[],b=location.search.replace(/(seajs-\w+)(&|$)/g,"$1=1$2");return b+=" "+L.cookie,b.replace(/(seajs-\w+)=1/g,function(b,c){a.push(c)}),a}(),u.config=function(a){for(var b in a){var c=a[b],d=v[b];if(d&&w(d))for(var e in c)d[e]=c[e];else y(d)?c=d.concat(c):"base"===b&&("/"!==c.slice(-1)&&(c+="/"),c=l(c)),v[b]=c}return C("config",a),u}}}(this);
- define("core", [ "zepto.extend.fx", "zepto.extend.data", "zepto.extend.selector" ], function(require, exports, module) {
- // Zepto animate extend
- require("zepto.extend.fx");
- // Zepto data extend
- require("zepto.extend.data");
- // Zepto selector extend
- require("zepto.extend.selector");
- var $ = window.Zepto, UI = $.AMUI || {}, $win = $(window), doc = window.document, $html = $("html");
- UI.support = {};
- UI.support.transition = function() {
- var transitionEnd = function() {
- // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend#Browser_compatibility
- 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
- };
- }();
- UI.support.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || function(callback) {
- window.setTimeout(callback, 1e3 / 60);
- };
- UI.support.touch = "ontouchstart" in window && navigator.userAgent.toLowerCase().match(/mobile|tablet/) || window.DocumentTouch && document instanceof window.DocumentTouch || window.navigator["msPointerEnabled"] && window.navigator["msMaxTouchPoints"] > 0 || //IE 10
- window.navigator["pointerEnabled"] && window.navigator["maxTouchPoints"] > 0 || //IE >=11
- false;
- // https://developer.mozilla.org/zh-CN/docs/DOM/MutationObserver
- UI.support.mutationobserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || null;
- UI.utils = {};
- /**
- * Debounce function
- * @param {function} func Function to be debounced
- * @param {number} wait Function execution threshold in milliseconds
- * @param {bool} immediate Whether the function should be called at
- * the beginning of the delay instead of the
- * end. Default is false.
- * @desc Executes a function when it stops being invoked for n seconds
- * @via _.debounce() http://underscorejs.org
- */
- 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.isInView = function(element, options) {
- var $element = $(element);
- var visible = !!($element.width() || $element.height()) && $element.css("display") !== "none";
- if (!visible) {
- return false;
- }
- var window_left = $win.scrollLeft(), window_top = $win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top;
- options = $.extend({
- topOffset: 0,
- leftOffset: 0
- }, options);
- return top + $element.height() >= window_top && top - options.topOffset <= window_top + $win.height() && left + $element.width() >= window_left && left - options.leftOffset <= window_left + $win.width();
- };
- UI.utils.parseOptions = UI.utils.options = function(string) {
- if ($.isPlainObject(string)) return string;
- var start = string ? string.indexOf("{") : -1, options = {};
- if (start != -1) {
- try {
- options = new Function("", "var json = " + string.substr(start) + "; return JSON.parse(JSON.stringify(json));")();
- } catch (e) {}
- }
- return options;
- };
- UI.utils.generateGUID = function(namespace) {
- var uid = namespace + "-" || "am-";
- do {
- uid += Math.random().toString(36).substring(2, 7);
- } while (document.getElementById(uid));
- return uid;
- };
- $.AMUI = UI;
- // http://blog.alexmaccaw.com/css-transitions
- $.fn.emulateTransitionEnd = function(duration) {
- var called = false, $el = this;
- $(this).one(UI.support.transition.end, function() {
- called = true;
- });
- var callback = function() {
- if (!called) {
- $($el).trigger(UI.support.transition.end);
- }
- };
- setTimeout(callback, duration);
- return this;
- };
- $.fn.redraw = function() {
- $(this).each(function() {
- var redraw = this.offsetHeight;
- });
- return this;
- };
- $.fn.transitionEnd = function(callback) {
- var endEvent = UI.support.transition.end, dom = this;
- function fireCallBack(e) {
- callback.call(this, e);
- endEvent && dom.off(endEvent, fireCallBack);
- }
- if (callback && endEvent) {
- dom.on(endEvent, fireCallBack);
- }
- return this;
- };
- $.fn.removeClassRegEx = function() {
- return this.each(function(regex) {
- var classes = $(this).attr("class");
- if (!classes || !regex) return false;
- var classArray = [];
- classes = classes.split(" ");
- for (var i = 0, len = classes.length; i < len; i++) if (!classes[i].match(regex)) classArray.push(classes[i]);
- $(this).attr("class", classArray.join(" "));
- });
- };
- //
- $.fn.alterClass = function(removals, additions) {
- var self = this;
- if (removals.indexOf("*") === -1) {
- // Use native jQuery methods if there is no wildcard matching
- self.removeClass(removals);
- return !additions ? self : self.addClass(additions);
- }
- var classPattern = new RegExp("\\s" + removals.replace(/\*/g, "[A-Za-z0-9-_]+").split(" ").join("\\s|\\s") + "\\s", "g");
- self.each(function(i, it) {
- var cn = " " + it.className + " ";
- while (classPattern.test(cn)) {
- cn = cn.replace(classPattern, " ");
- }
- it.className = $.trim(cn);
- });
- return !additions ? self : self.addClass(additions);
- };
- $.fn.getHeight = function() {
- var $ele = $(this), height = "auto";
- if ($ele.is(":visible")) {
- height = $ele.height();
- } else {
- var tmp = {
- position: $ele.css("position"),
- visibility: $ele.css("visibility"),
- display: $ele.css("display")
- };
- height = $ele.css({
- position: "absolute",
- visibility: "hidden",
- display: "block"
- }).height();
- $ele.css(tmp);
- }
- return height;
- };
- $.fn.getSize = function() {
- var $el = $(this);
- if ($el.css("display") !== "none") {
- return {
- width: $el.width(),
- height: $el.height()
- };
- }
- var old = {
- position: $el.css("position"),
- visibility: $el.css("visibility"),
- display: $el.css("display")
- }, tmpStyle = {
- display: "block",
- position: "absolute",
- visibility: "hidden"
- };
- $el.css(tmpStyle);
- var width = $el.width(), height = $el.height();
- $el.css(old);
- return {
- width: width,
- height: height
- };
- };
- // adding :visible and :hidden to zepto
- // https://github.com/jquery/jquery/blob/73e120116ce13b992d5229b3e10fcc19f9505a15/src/css/hiddenVisibleSelectors.js
- var _is = $.fn.is, _filter = $.fn.filter;
- function visible(elem) {
- elem = $(elem);
- return !!(elem.width() || elem.height()) && elem.css("display") !== "none";
- }
- $.fn.is = function(sel) {
- if (sel === ":visible") {
- return visible(this);
- }
- if (sel === ":hidden") {
- return !visible(this);
- }
- return _is.call(this, sel);
- };
- $.fn.filter = function(sel) {
- if (sel === ":visible") {
- return $([].filter.call(this, visible));
- }
- if (sel === ":hidden") {
- return $([].filter.call(this, function(elem) {
- return !visible(elem);
- }));
- }
- return _filter.call(this, sel);
- };
- // handle multiple browsers for requestAnimationFrame()
- // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
- // https://github.com/gnarf/jquery-requestAnimationFrame
- UI.utils.rAF = function() {
- return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || //window.oRequestAnimationFrame ||
- // if all else fails, use setTimeout
- function(callback) {
- return window.setTimeout(callback, 1e3 / 60);
- };
- }();
- // handle multiple browsers for cancelAnimationFrame()
- UI.utils.cancelAF = function() {
- return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || //window.oCancelAnimationFrame ||
- function(id) {
- window.clearTimeout(id);
- };
- }();
- // Require fastclick.js on touch devices
- if (UI.support.touch) {
- require.async([ "util.fastclick" ], function(FastClick) {
- $(function() {
- FastClick && FastClick.attach(document.body);
- $html.addClass("am-touch");
- });
- });
- }
- // via http://davidwalsh.name/detect-scrollbar-width
- UI.utils.measureScrollbar = function() {
- if (document.body.clientWidth >= window.innerWidth) return 0;
- // if ($html.width() >= window.innerWidth) return;
- // var scrollbarWidth = window.innerWidth - $html.width();
- var $measure = $('<div style="width: 100px;height: 100px;overflow: scroll;position: absolute;top: -9999px;"></div>');
- $(document.body).append($measure);
- var scrollbarWidth = $measure[0].offsetWidth - $measure[0].clientWidth;
- $measure.remove();
- return scrollbarWidth;
- };
- UI.utils.imageLoader = function($image, callback) {
- function loaded() {
- callback($image[0]);
- }
- function bindLoad() {
- this.one("load", loaded);
- if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
- var src = this.attr("src"), param = src.match(/\?/) ? "&" : "?";
- param += "random=" + new Date().getTime();
- this.attr("src", src + param);
- }
- }
- if (!$image.attr("src")) {
- loaded();
- return;
- }
- if ($image[0].complete || $image[0].readyState === 4) {
- loaded();
- } else {
- bindLoad.call($image);
- }
- };
- $(function() {
- var $body = $("body");
- // trigger domready event
- $(document).trigger("domready:amui");
- $html.removeClass("no-js").addClass("js");
- UI.support.animation && $html.addClass("cssanimations");
- $(".am-topbar-fixed-top").length && $body.addClass("am-with-topbar-fixed-top");
- $(".am-topbar-fixed-bottom").length && $body.addClass("am-with-topbar-fixed-bottom");
- // Remove responsive classes in .am-layout
- var $layout = $(".am-layout");
- $layout.find('[class*="md-block-grid"]').alterClass("md-block-grid-*");
- $layout.find('[class*="lg-block-grid"]').alterClass("lg-block-grid");
- // widgets not in .am-layout
- $("[data-am-widget]").each(function() {
- var $widget = $(this);
- // console.log($widget.parents('.am-layout').length)
- if ($widget.parents(".am-layout").length === 0) {
- $widget.addClass("am-no-layout");
- }
- });
- });
- module.exports = UI;
- });
- define("util.fastclick", [], function(require, exports, module) {
- var $ = window.Zepto;
- /**
- * FastClick: polyfill to remove click delays on browsers with touch UIs.
- *
- * @version 1.0.2
- * @codingstandard ftlabs-jsv2
- * @copyright The Financial Times Limited [All Rights Reserved]
- * @license MIT License (see LICENSE.txt)
- */
- /*jslint browser:true, node:true*/
- /*global define, Event, Node*/
- /**
- * Instantiate fast-clicking listeners on the specified layer.
- *
- * @constructor
- * @param {Element} layer The layer to listen on
- * @param {Object} options The options to override the defaults
- */
- function FastClick(layer, options) {
- "use strict";
- var oldOnClick;
- options = options || {};
- /**
- * Whether a click is currently being tracked.
- *
- * @type boolean
- */
- this.trackingClick = false;
- /**
- * Timestamp for when click tracking started.
- *
- * @type number
- */
- this.trackingClickStart = 0;
- /**
- * The element being tracked for a click.
- *
- * @type EventTarget
- */
- this.targetElement = null;
- /**
- * X-coordinate of touch start event.
- *
- * @type number
- */
- this.touchStartX = 0;
- /**
- * Y-coordinate of touch start event.
- *
- * @type number
- */
- this.touchStartY = 0;
- /**
- * ID of the last touch, retrieved from Touch.identifier.
- *
- * @type number
- */
- this.lastTouchIdentifier = 0;
- /**
- * Touchmove boundary, beyond which a click will be cancelled.
- *
- * @type number
- */
- this.touchBoundary = options.touchBoundary || 10;
- /**
- * The FastClick layer.
- *
- * @type Element
- */
- this.layer = layer;
- /**
- * The minimum time between tap(touchstart and touchend) events
- *
- * @type number
- */
- this.tapDelay = options.tapDelay || 200;
- if (FastClick.notNeeded(layer)) {
- return;
- }
- // Some old versions of Android don't have Function.prototype.bind
- function bind(method, context) {
- return function() {
- return method.apply(context, arguments);
- };
- }
- var methods = [ "onMouse", "onClick", "onTouchStart", "onTouchMove", "onTouchEnd", "onTouchCancel" ];
- var context = this;
- for (var i = 0, l = methods.length; i < l; i++) {
- context[methods[i]] = bind(context[methods[i]], context);
- }
- // Set up event handlers as required
- if (deviceIsAndroid) {
- layer.addEventListener("mouseover", this.onMouse, true);
- layer.addEventListener("mousedown", this.onMouse, true);
- layer.addEventListener("mouseup", this.onMouse, true);
- }
- layer.addEventListener("click", this.onClick, true);
- layer.addEventListener("touchstart", this.onTouchStart, false);
- layer.addEventListener("touchmove", this.onTouchMove, false);
- layer.addEventListener("touchend", this.onTouchEnd, false);
- layer.addEventListener("touchcancel", this.onTouchCancel, false);
- // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
- // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
- // layer when they are cancelled.
- if (!Event.prototype.stopImmediatePropagation) {
- layer.removeEventListener = function(type, callback, capture) {
- var rmv = Node.prototype.removeEventListener;
- if (type === "click") {
- rmv.call(layer, type, callback.hijacked || callback, capture);
- } else {
- rmv.call(layer, type, callback, capture);
- }
- };
- layer.addEventListener = function(type, callback, capture) {
- var adv = Node.prototype.addEventListener;
- if (type === "click") {
- adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
- if (!event.propagationStopped) {
- callback(event);
- }
- }), capture);
- } else {
- adv.call(layer, type, callback, capture);
- }
- };
- }
- // If a handler is already declared in the element's onclick attribute, it will be fired before
- // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
- // adding it as listener.
- if (typeof layer.onclick === "function") {
- // Android browser on at least 3.2 requires a new reference to the function in layer.onclick
- // - the old one won't work if passed to addEventListener directly.
- oldOnClick = layer.onclick;
- layer.addEventListener("click", function(event) {
- oldOnClick(event);
- }, false);
- layer.onclick = null;
- }
- }
- /**
- * Android requires exceptions.
- *
- * @type boolean
- */
- var deviceIsAndroid = navigator.userAgent.indexOf("Android") > 0;
- /**
- * iOS requires exceptions.
- *
- * @type boolean
- */
- var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent);
- /**
- * iOS 4 requires an exception for select elements.
- *
- * @type boolean
- */
- var deviceIsIOS4 = deviceIsIOS && /OS 4_\d(_\d)?/.test(navigator.userAgent);
- /**
- * iOS 6.0(+?) requires the target element to be manually derived
- *
- * @type boolean
- */
- var deviceIsIOSWithBadTarget = deviceIsIOS && /OS ([6-9]|\d{2})_\d/.test(navigator.userAgent);
- /**
- * Determine whether a given element requires a native click.
- *
- * @param {EventTarget|Element} target Target DOM element
- * @returns {boolean} Returns true if the element needs a native click
- */
- FastClick.prototype.needsClick = function(target) {
- "use strict";
- switch (target.nodeName.toLowerCase()) {
- // Don't send a synthetic click to disabled inputs (issue #62)
- case "button":
- case "select":
- case "textarea":
- if (target.disabled) {
- return true;
- }
- break;
- case "input":
- // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
- if (deviceIsIOS && target.type === "file" || target.disabled) {
- return true;
- }
- break;
- case "label":
- case "video":
- return true;
- }
- return /\bneedsclick\b/.test(target.className);
- };
- /**
- * Determine whether a given element requires a call to focus to simulate click into element.
- *
- * @param {EventTarget|Element} target Target DOM element
- * @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
- */
- FastClick.prototype.needsFocus = function(target) {
- "use strict";
- switch (target.nodeName.toLowerCase()) {
- case "textarea":
- return true;
- case "select":
- return !deviceIsAndroid;
- case "input":
- switch (target.type) {
- case "button":
- case "checkbox":
- case "file":
- case "image":
- case "radio":
- case "submit":
- return false;
- }
- // No point in attempting to focus disabled inputs
- return !target.disabled && !target.readOnly;
- default:
- return /\bneedsfocus\b/.test(target.className);
- }
- };
- /**
- * Send a click event to the specified element.
- *
- * @param {EventTarget|Element} targetElement
- * @param {Event} event
- */
- FastClick.prototype.sendClick = function(targetElement, event) {
- "use strict";
- var clickEvent, touch;
- // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
- if (document.activeElement && document.activeElement !== targetElement) {
- document.activeElement.blur();
- }
- touch = event.changedTouches[0];
- // Synthesise a click event, with an extra attribute so it can be tracked
- clickEvent = document.createEvent("MouseEvents");
- clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
- clickEvent.forwardedTouchEvent = true;
- targetElement.dispatchEvent(clickEvent);
- };
- FastClick.prototype.determineEventType = function(targetElement) {
- "use strict";
- //Issue #159: Android Chrome Select Box does not open with a synthetic click event
- if (deviceIsAndroid && targetElement.tagName.toLowerCase() === "select") {
- return "mousedown";
- }
- return "click";
- };
- /**
- * @param {EventTarget|Element} targetElement
- */
- FastClick.prototype.focus = function(targetElement) {
- "use strict";
- var length;
- // Issue #160: on iOS 7, some input elements (e.g. date datetime) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
- if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf("date") !== 0 && targetElement.type !== "time") {
- length = targetElement.value.length;
- targetElement.setSelectionRange(length, length);
- } else {
- targetElement.focus();
- }
- };
- /**
- * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
- *
- * @param {EventTarget|Element} targetElement
- */
- FastClick.prototype.updateScrollParent = function(targetElement) {
- "use strict";
- var scrollParent, parentElement;
- scrollParent = targetElement.fastClickScrollParent;
- // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
- // target element was moved to another parent.
- if (!scrollParent || !scrollParent.contains(targetElement)) {
- parentElement = targetElement;
- do {
- if (parentElement.scrollHeight > parentElement.offsetHeight) {
- scrollParent = parentElement;
- targetElement.fastClickScrollParent = parentElement;
- break;
- }
- parentElement = parentElement.parentElement;
- } while (parentElement);
- }
- // Always update the scroll top tracker if possible.
- if (scrollParent) {
- scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
- }
- };
- /**
- * @param {EventTarget} targetElement
- * @returns {Element|EventTarget}
- */
- FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
- "use strict";
- // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
- if (eventTarget.nodeType === Node.TEXT_NODE) {
- return eventTarget.parentNode;
- }
- return eventTarget;
- };
- /**
- * On touch start, record the position and scroll offset.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.onTouchStart = function(event) {
- "use strict";
- var targetElement, touch, selection;
- // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
- if (event.targetTouches.length > 1) {
- return true;
- }
- targetElement = this.getTargetElementFromEventTarget(event.target);
- touch = event.targetTouches[0];
- if (deviceIsIOS) {
- // Only trusted events will deselect text on iOS (issue #49)
- selection = window.getSelection();
- if (selection.rangeCount && !selection.isCollapsed) {
- return true;
- }
- if (!deviceIsIOS4) {
- // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
- // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
- // with the same identifier as the touch event that previously triggered the click that triggered the alert.
- // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
- // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
- if (touch.identifier === this.lastTouchIdentifier) {
- event.preventDefault();
- return false;
- }
- this.lastTouchIdentifier = touch.identifier;
- // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
- // 1) the user does a fling scroll on the scrollable layer
- // 2) the user stops the fling scroll with another tap
- // then the event.target of the last 'touchend' event will be the element that was under the user's finger
- // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
- // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
- this.updateScrollParent(targetElement);
- }
- }
- this.trackingClick = true;
- this.trackingClickStart = event.timeStamp;
- this.targetElement = targetElement;
- this.touchStartX = touch.pageX;
- this.touchStartY = touch.pageY;
- // Prevent phantom clicks on fast double-tap (issue #36)
- if (event.timeStamp - this.lastClickTime < this.tapDelay) {
- event.preventDefault();
- }
- return true;
- };
- /**
- * Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.touchHasMoved = function(event) {
- "use strict";
- var touch = event.changedTouches[0], boundary = this.touchBoundary;
- if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
- return true;
- }
- return false;
- };
- /**
- * Update the last position.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.onTouchMove = function(event) {
- "use strict";
- if (!this.trackingClick) {
- return true;
- }
- // If the touch has moved, cancel the click tracking
- if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
- this.trackingClick = false;
- this.targetElement = null;
- }
- return true;
- };
- /**
- * Attempt to find the labelled control for the given label element.
- *
- * @param {EventTarget|HTMLLabelElement} labelElement
- * @returns {Element|null}
- */
- FastClick.prototype.findControl = function(labelElement) {
- "use strict";
- // Fast path for newer browsers supporting the HTML5 control attribute
- if (labelElement.control !== undefined) {
- return labelElement.control;
- }
- // All browsers under test that support touch events also support the HTML5 htmlFor attribute
- if (labelElement.htmlFor) {
- return document.getElementById(labelElement.htmlFor);
- }
- // If no for attribute exists, attempt to retrieve the first labellable descendant element
- // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
- return labelElement.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea");
- };
- /**
- * On touch end, determine whether to send a click event at once.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.onTouchEnd = function(event) {
- "use strict";
- var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
- if (!this.trackingClick) {
- return true;
- }
- // Prevent phantom clicks on fast double-tap (issue #36)
- if (event.timeStamp - this.lastClickTime < this.tapDelay) {
- this.cancelNextClick = true;
- return true;
- }
- // Reset to prevent wrong click cancel on input (issue #156).
- this.cancelNextClick = false;
- this.lastClickTime = event.timeStamp;
- trackingClickStart = this.trackingClickStart;
- this.trackingClick = false;
- this.trackingClickStart = 0;
- // On some iOS devices, the targetElement supplied with the event is invalid if the layer
- // is performing a transition or scroll, and has to be re-detected manually. Note that
- // for this to function correctly, it must be called *after* the event target is checked!
- // See issue #57; also filed as rdar://13048589 .
- if (deviceIsIOSWithBadTarget) {
- touch = event.changedTouches[0];
- // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
- targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
- targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
- }
- targetTagName = targetElement.tagName.toLowerCase();
- if (targetTagName === "label") {
- forElement = this.findControl(targetElement);
- if (forElement) {
- this.focus(targetElement);
- if (deviceIsAndroid) {
- return false;
- }
- targetElement = forElement;
- }
- } else if (this.needsFocus(targetElement)) {
- // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
- // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
- if (event.timeStamp - trackingClickStart > 100 || deviceIsIOS && window.top !== window && targetTagName === "input") {
- this.targetElement = null;
- return false;
- }
- this.focus(targetElement);
- this.sendClick(targetElement, event);
- // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
- // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
- if (!deviceIsIOS || targetTagName !== "select") {
- this.targetElement = null;
- event.preventDefault();
- }
- return false;
- }
- if (deviceIsIOS && !deviceIsIOS4) {
- // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
- // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
- scrollParent = targetElement.fastClickScrollParent;
- if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
- return true;
- }
- }
- // Prevent the actual click from going though - unless the target node is marked as requiring
- // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
- if (!this.needsClick(targetElement)) {
- event.preventDefault();
- this.sendClick(targetElement, event);
- }
- return false;
- };
- /**
- * On touch cancel, stop tracking the click.
- *
- * @returns {void}
- */
- FastClick.prototype.onTouchCancel = function() {
- "use strict";
- this.trackingClick = false;
- this.targetElement = null;
- };
- /**
- * Determine mouse events which should be permitted.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.onMouse = function(event) {
- "use strict";
- // If a target element was never set (because a touch event was never fired) allow the event
- if (!this.targetElement) {
- return true;
- }
- if (event.forwardedTouchEvent) {
- return true;
- }
- // Programmatically generated events targeting a specific element should be permitted
- if (!event.cancelable) {
- return true;
- }
- // Derive and check the target element to see whether the mouse event needs to be permitted;
- // unless explicitly enabled, prevent non-touch click events from triggering actions,
- // to prevent ghost/doubleclicks.
- if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
- // Prevent any user-added listeners declared on FastClick element from being fired.
- if (event.stopImmediatePropagation) {
- event.stopImmediatePropagation();
- } else {
- // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
- event.propagationStopped = true;
- }
- // Cancel the event
- event.stopPropagation();
- event.preventDefault();
- return false;
- }
- // If the mouse event is permitted, return true for the action to go through.
- return true;
- };
- /**
- * On actual clicks, determine whether this is a touch-generated click, a click action occurring
- * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
- * an actual click which should be permitted.
- *
- * @param {Event} event
- * @returns {boolean}
- */
- FastClick.prototype.onClick = function(event) {
- "use strict";
- var permitted;
- // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
- if (this.trackingClick) {
- this.targetElement = null;
- this.trackingClick = false;
- return true;
- }
- // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
- if (event.target.type === "submit" && event.detail === 0) {
- return true;
- }
- permitted = this.onMouse(event);
- // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
- if (!permitted) {
- this.targetElement = null;
- }
- // If clicks are permitted, return true for the action to go through.
- return permitted;
- };
- /**
- * Remove all FastClick's event listeners.
- *
- * @returns {void}
- */
- FastClick.prototype.destroy = function() {
- "use strict";
- var layer = this.layer;
- if (deviceIsAndroid) {
- layer.removeEventListener("mouseover", this.onMouse, true);
- layer.removeEventListener("mousedown", this.onMouse, true);
- layer.removeEventListener("mouseup", this.onMouse, true);
- }
- layer.removeEventListener("click", this.onClick, true);
- layer.removeEventListener("touchstart", this.onTouchStart, false);
- layer.removeEventListener("touchmove", this.onTouchMove, false);
- layer.removeEventListener("touchend", this.onTouchEnd, false);
- layer.removeEventListener("touchcancel", this.onTouchCancel, false);
- };
- /**
- * Check whether FastClick is needed.
- *
- * @param {Element} layer The layer to listen on
- */
- FastClick.notNeeded = function(layer) {
- "use strict";
- var metaViewport;
- var chromeVersion;
- // Devices that don't support touch don't need FastClick
- if (typeof window.ontouchstart === "undefined") {
- return true;
- }
- // Chrome version - zero for other browsers
- chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [ , 0 ])[1];
- if (chromeVersion) {
- if (deviceIsAndroid) {
- metaViewport = document.querySelector("meta[name=viewport]");
- if (metaViewport) {
- // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
- if (metaViewport.content.indexOf("user-scalable=no") !== -1) {
- return true;
- }
- // Chrome 32 and above with width=device-width or less don't need FastClick
- if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
- return true;
- }
- }
- } else {
- return true;
- }
- }
- // IE10 with -ms-touch-action: none, which disables double-tap-to-zoom (issue #97)
- if (layer.style.msTouchAction === "none") {
- return true;
- }
- return false;
- };
- /**
- * Factory method for creating a FastClick object
- *
- * @param {Element} layer The layer to listen on
- * @param {Object} options The options to override the defaults
- */
- FastClick.attach = function(layer, options) {
- "use strict";
- return new FastClick(layer, options);
- };
- module.exports = FastClick;
- });
- define("util.hammer", [ "core", "zepto.extend.fx", "zepto.extend.data", "zepto.extend.selector" ], function(require, exports, module) {
- require("core");
- var $ = window.Zepto, UI = $.AMUI;
- /**
- * Hammer.js
- * @via https://github.com/hammerjs/hammer.js
- * @copyright Copyright (C) 2011-2014 by Jorik Tangelder (Eight Media)
- * @license https://github.com/hammerjs/hammer.js/blob/master/LICENSE.md
- */
- var VENDOR_PREFIXES = [ "", "webkit", "moz", "MS", "ms", "o" ];
- var TEST_ELEMENT = document.createElement("div");
- var TYPE_FUNCTION = "function";
- var round = Math.round;
- var abs = Math.abs;
- var now = Date.now;
- /**
- * set a timeout with a given scope
- * @param {Function} fn
- * @param {Number} timeout
- * @param {Object} context
- * @returns {number}
- */
- function setTimeoutContext(fn, timeout, context) {
- return setTimeout(bindFn(fn, context), timeout);
- }
- /**
- * if the argument is an array, we want to execute the fn on each entry
- * if it aint an array we don't want to do a thing.
- * this is used by all the methods that accept a single and array argument.
- * @param {*|Array} arg
- * @param {String} fn
- * @param {Object} [context]
- * @returns {Boolean}
- */
- function invokeArrayArg(arg, fn, context) {
- if (Array.isArray(arg)) {
- each(arg, context[fn], context);
- return true;
- }
- return false;
- }
- /**
- * walk objects and arrays
- * @param {Object} obj
- * @param {Function} iterator
- * @param {Object} context
- */
- function each(obj, iterator, context) {
- var i;
- if (!obj) {
- return;
- }
- if (obj.forEach) {
- obj.forEach(iterator, context);
- } else if (obj.length !== undefined) {
- i = 0;
- while (i < obj.length) {
- iterator.call(context, obj[i], i, obj);
- i++;
- }
- } else {
- for (i in obj) {
- obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
- }
- }
- }
- /**
- * extend object.
- * means that properties in dest will be overwritten by the ones in src.
- * @param {Object} dest
- * @param {Object} src
- * @param {Boolean} [merge]
- * @returns {Object} dest
- */
- function extend(dest, src, merge) {
- var keys = Object.keys(src);
- var i = 0;
- while (i < keys.length) {
- if (!merge || merge && dest[keys[i]] === undefined) {
- dest[keys[i]] = src[keys[i]];
- }
- i++;
- }
- return dest;
- }
- /**
- * merge the values from src in the dest.
- * means that properties that exist in dest will not be overwritten by src
- * @param {Obje…
Large files files are truncated, but you can click here to view the full file