PageRenderTime 83ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 4ms

/libs/amazeui/1.0.0-beta2/js/amazeui.js

https://gitlab.com/mba811/static
JavaScript | 10987 lines | 8640 code | 50 blank | 2297 comment | 2113 complexity | 17456fbc241fbc8714d7d7bbbbf956aa 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

  1. /*! Amaze UI v1.0.0-beta2 | by Amaze UI Team | (c) 2014 AllMobilize, Inc. | Licensed under MIT | 2014-09-28T02:09:21 UTC */
  2. /*! Sea.js 2.2.1 | seajs.org/LICENSE.md */
  3. !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);
  4. define("core", [ "zepto.extend.fx", "zepto.extend.data", "zepto.extend.selector" ], function(require, exports, module) {
  5. // Zepto animate extend
  6. require("zepto.extend.fx");
  7. // Zepto data extend
  8. require("zepto.extend.data");
  9. // Zepto selector extend
  10. require("zepto.extend.selector");
  11. var $ = window.Zepto, UI = $.AMUI || {}, $win = $(window), doc = window.document, $html = $("html");
  12. UI.support = {};
  13. UI.support.transition = function() {
  14. var transitionEnd = function() {
  15. // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend#Browser_compatibility
  16. var element = doc.body || doc.documentElement, transEndEventNames = {
  17. WebkitTransition: "webkitTransitionEnd",
  18. MozTransition: "transitionend",
  19. OTransition: "oTransitionEnd otransitionend",
  20. transition: "transitionend"
  21. }, name;
  22. for (name in transEndEventNames) {
  23. if (element.style[name] !== undefined) return transEndEventNames[name];
  24. }
  25. }();
  26. return transitionEnd && {
  27. end: transitionEnd
  28. };
  29. }();
  30. UI.support.animation = function() {
  31. var animationEnd = function() {
  32. var element = doc.body || doc.documentElement, animEndEventNames = {
  33. WebkitAnimation: "webkitAnimationEnd",
  34. MozAnimation: "animationend",
  35. OAnimation: "oAnimationEnd oanimationend",
  36. animation: "animationend"
  37. }, name;
  38. for (name in animEndEventNames) {
  39. if (element.style[name] !== undefined) return animEndEventNames[name];
  40. }
  41. }();
  42. return animationEnd && {
  43. end: animationEnd
  44. };
  45. }();
  46. UI.support.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || function(callback) {
  47. window.setTimeout(callback, 1e3 / 60);
  48. };
  49. 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
  50. window.navigator["pointerEnabled"] && window.navigator["maxTouchPoints"] > 0 || //IE >=11
  51. false;
  52. // https://developer.mozilla.org/zh-CN/docs/DOM/MutationObserver
  53. UI.support.mutationobserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || null;
  54. UI.utils = {};
  55. /**
  56. * Debounce function
  57. * @param {function} func Function to be debounced
  58. * @param {number} wait Function execution threshold in milliseconds
  59. * @param {bool} immediate Whether the function should be called at
  60. * the beginning of the delay instead of the
  61. * end. Default is false.
  62. * @desc Executes a function when it stops being invoked for n seconds
  63. * @via _.debounce() http://underscorejs.org
  64. */
  65. UI.utils.debounce = function(func, wait, immediate) {
  66. var timeout;
  67. return function() {
  68. var context = this, args = arguments;
  69. var later = function() {
  70. timeout = null;
  71. if (!immediate) func.apply(context, args);
  72. };
  73. var callNow = immediate && !timeout;
  74. clearTimeout(timeout);
  75. timeout = setTimeout(later, wait);
  76. if (callNow) func.apply(context, args);
  77. };
  78. };
  79. UI.utils.isInView = function(element, options) {
  80. var $element = $(element);
  81. var visible = !!($element.width() || $element.height()) && $element.css("display") !== "none";
  82. if (!visible) {
  83. return false;
  84. }
  85. var window_left = $win.scrollLeft(), window_top = $win.scrollTop(), offset = $element.offset(), left = offset.left, top = offset.top;
  86. options = $.extend({
  87. topOffset: 0,
  88. leftOffset: 0
  89. }, options);
  90. 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();
  91. };
  92. UI.utils.parseOptions = UI.utils.options = function(string) {
  93. if ($.isPlainObject(string)) return string;
  94. var start = string ? string.indexOf("{") : -1, options = {};
  95. if (start != -1) {
  96. try {
  97. options = new Function("", "var json = " + string.substr(start) + "; return JSON.parse(JSON.stringify(json));")();
  98. } catch (e) {}
  99. }
  100. return options;
  101. };
  102. UI.utils.generateGUID = function(namespace) {
  103. var uid = namespace + "-" || "am-";
  104. do {
  105. uid += Math.random().toString(36).substring(2, 7);
  106. } while (document.getElementById(uid));
  107. return uid;
  108. };
  109. $.AMUI = UI;
  110. // http://blog.alexmaccaw.com/css-transitions
  111. $.fn.emulateTransitionEnd = function(duration) {
  112. var called = false, $el = this;
  113. $(this).one(UI.support.transition.end, function() {
  114. called = true;
  115. });
  116. var callback = function() {
  117. if (!called) {
  118. $($el).trigger(UI.support.transition.end);
  119. }
  120. };
  121. setTimeout(callback, duration);
  122. return this;
  123. };
  124. $.fn.redraw = function() {
  125. $(this).each(function() {
  126. var redraw = this.offsetHeight;
  127. });
  128. return this;
  129. };
  130. $.fn.transitionEnd = function(callback) {
  131. var endEvent = UI.support.transition.end, dom = this;
  132. function fireCallBack(e) {
  133. callback.call(this, e);
  134. endEvent && dom.off(endEvent, fireCallBack);
  135. }
  136. if (callback && endEvent) {
  137. dom.on(endEvent, fireCallBack);
  138. }
  139. return this;
  140. };
  141. $.fn.removeClassRegEx = function() {
  142. return this.each(function(regex) {
  143. var classes = $(this).attr("class");
  144. if (!classes || !regex) return false;
  145. var classArray = [];
  146. classes = classes.split(" ");
  147. for (var i = 0, len = classes.length; i < len; i++) if (!classes[i].match(regex)) classArray.push(classes[i]);
  148. $(this).attr("class", classArray.join(" "));
  149. });
  150. };
  151. //
  152. $.fn.alterClass = function(removals, additions) {
  153. var self = this;
  154. if (removals.indexOf("*") === -1) {
  155. // Use native jQuery methods if there is no wildcard matching
  156. self.removeClass(removals);
  157. return !additions ? self : self.addClass(additions);
  158. }
  159. var classPattern = new RegExp("\\s" + removals.replace(/\*/g, "[A-Za-z0-9-_]+").split(" ").join("\\s|\\s") + "\\s", "g");
  160. self.each(function(i, it) {
  161. var cn = " " + it.className + " ";
  162. while (classPattern.test(cn)) {
  163. cn = cn.replace(classPattern, " ");
  164. }
  165. it.className = $.trim(cn);
  166. });
  167. return !additions ? self : self.addClass(additions);
  168. };
  169. $.fn.getHeight = function() {
  170. var $ele = $(this), height = "auto";
  171. if ($ele.is(":visible")) {
  172. height = $ele.height();
  173. } else {
  174. var tmp = {
  175. position: $ele.css("position"),
  176. visibility: $ele.css("visibility"),
  177. display: $ele.css("display")
  178. };
  179. height = $ele.css({
  180. position: "absolute",
  181. visibility: "hidden",
  182. display: "block"
  183. }).height();
  184. $ele.css(tmp);
  185. }
  186. return height;
  187. };
  188. $.fn.getSize = function() {
  189. var $el = $(this);
  190. if ($el.css("display") !== "none") {
  191. return {
  192. width: $el.width(),
  193. height: $el.height()
  194. };
  195. }
  196. var old = {
  197. position: $el.css("position"),
  198. visibility: $el.css("visibility"),
  199. display: $el.css("display")
  200. }, tmpStyle = {
  201. display: "block",
  202. position: "absolute",
  203. visibility: "hidden"
  204. };
  205. $el.css(tmpStyle);
  206. var width = $el.width(), height = $el.height();
  207. $el.css(old);
  208. return {
  209. width: width,
  210. height: height
  211. };
  212. };
  213. // adding :visible and :hidden to zepto
  214. // https://github.com/jquery/jquery/blob/73e120116ce13b992d5229b3e10fcc19f9505a15/src/css/hiddenVisibleSelectors.js
  215. var _is = $.fn.is, _filter = $.fn.filter;
  216. function visible(elem) {
  217. elem = $(elem);
  218. return !!(elem.width() || elem.height()) && elem.css("display") !== "none";
  219. }
  220. $.fn.is = function(sel) {
  221. if (sel === ":visible") {
  222. return visible(this);
  223. }
  224. if (sel === ":hidden") {
  225. return !visible(this);
  226. }
  227. return _is.call(this, sel);
  228. };
  229. $.fn.filter = function(sel) {
  230. if (sel === ":visible") {
  231. return $([].filter.call(this, visible));
  232. }
  233. if (sel === ":hidden") {
  234. return $([].filter.call(this, function(elem) {
  235. return !visible(elem);
  236. }));
  237. }
  238. return _filter.call(this, sel);
  239. };
  240. // handle multiple browsers for requestAnimationFrame()
  241. // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  242. // https://github.com/gnarf/jquery-requestAnimationFrame
  243. UI.utils.rAF = function() {
  244. return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || //window.oRequestAnimationFrame ||
  245. // if all else fails, use setTimeout
  246. function(callback) {
  247. return window.setTimeout(callback, 1e3 / 60);
  248. };
  249. }();
  250. // handle multiple browsers for cancelAnimationFrame()
  251. UI.utils.cancelAF = function() {
  252. return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || //window.oCancelAnimationFrame ||
  253. function(id) {
  254. window.clearTimeout(id);
  255. };
  256. }();
  257. // Require fastclick.js on touch devices
  258. if (UI.support.touch) {
  259. require.async([ "util.fastclick" ], function(FastClick) {
  260. $(function() {
  261. FastClick && FastClick.attach(document.body);
  262. $html.addClass("am-touch");
  263. });
  264. });
  265. }
  266. // via http://davidwalsh.name/detect-scrollbar-width
  267. UI.utils.measureScrollbar = function() {
  268. if (document.body.clientWidth >= window.innerWidth) return 0;
  269. // if ($html.width() >= window.innerWidth) return;
  270. // var scrollbarWidth = window.innerWidth - $html.width();
  271. var $measure = $('<div style="width: 100px;height: 100px;overflow: scroll;position: absolute;top: -9999px;"></div>');
  272. $(document.body).append($measure);
  273. var scrollbarWidth = $measure[0].offsetWidth - $measure[0].clientWidth;
  274. $measure.remove();
  275. return scrollbarWidth;
  276. };
  277. UI.utils.imageLoader = function($image, callback) {
  278. function loaded() {
  279. callback($image[0]);
  280. }
  281. function bindLoad() {
  282. this.one("load", loaded);
  283. if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
  284. var src = this.attr("src"), param = src.match(/\?/) ? "&" : "?";
  285. param += "random=" + new Date().getTime();
  286. this.attr("src", src + param);
  287. }
  288. }
  289. if (!$image.attr("src")) {
  290. loaded();
  291. return;
  292. }
  293. if ($image[0].complete || $image[0].readyState === 4) {
  294. loaded();
  295. } else {
  296. bindLoad.call($image);
  297. }
  298. };
  299. $(function() {
  300. var $body = $("body");
  301. // trigger domready event
  302. $(document).trigger("domready:amui");
  303. $html.removeClass("no-js").addClass("js");
  304. UI.support.animation && $html.addClass("cssanimations");
  305. $(".am-topbar-fixed-top").length && $body.addClass("am-with-topbar-fixed-top");
  306. $(".am-topbar-fixed-bottom").length && $body.addClass("am-with-topbar-fixed-bottom");
  307. // Remove responsive classes in .am-layout
  308. var $layout = $(".am-layout");
  309. $layout.find('[class*="md-block-grid"]').alterClass("md-block-grid-*");
  310. $layout.find('[class*="lg-block-grid"]').alterClass("lg-block-grid");
  311. // widgets not in .am-layout
  312. $("[data-am-widget]").each(function() {
  313. var $widget = $(this);
  314. // console.log($widget.parents('.am-layout').length)
  315. if ($widget.parents(".am-layout").length === 0) {
  316. $widget.addClass("am-no-layout");
  317. }
  318. });
  319. });
  320. module.exports = UI;
  321. });
  322. define("util.fastclick", [], function(require, exports, module) {
  323. var $ = window.Zepto;
  324. /**
  325. * FastClick: polyfill to remove click delays on browsers with touch UIs.
  326. *
  327. * @version 1.0.2
  328. * @codingstandard ftlabs-jsv2
  329. * @copyright The Financial Times Limited [All Rights Reserved]
  330. * @license MIT License (see LICENSE.txt)
  331. */
  332. /*jslint browser:true, node:true*/
  333. /*global define, Event, Node*/
  334. /**
  335. * Instantiate fast-clicking listeners on the specified layer.
  336. *
  337. * @constructor
  338. * @param {Element} layer The layer to listen on
  339. * @param {Object} options The options to override the defaults
  340. */
  341. function FastClick(layer, options) {
  342. "use strict";
  343. var oldOnClick;
  344. options = options || {};
  345. /**
  346. * Whether a click is currently being tracked.
  347. *
  348. * @type boolean
  349. */
  350. this.trackingClick = false;
  351. /**
  352. * Timestamp for when click tracking started.
  353. *
  354. * @type number
  355. */
  356. this.trackingClickStart = 0;
  357. /**
  358. * The element being tracked for a click.
  359. *
  360. * @type EventTarget
  361. */
  362. this.targetElement = null;
  363. /**
  364. * X-coordinate of touch start event.
  365. *
  366. * @type number
  367. */
  368. this.touchStartX = 0;
  369. /**
  370. * Y-coordinate of touch start event.
  371. *
  372. * @type number
  373. */
  374. this.touchStartY = 0;
  375. /**
  376. * ID of the last touch, retrieved from Touch.identifier.
  377. *
  378. * @type number
  379. */
  380. this.lastTouchIdentifier = 0;
  381. /**
  382. * Touchmove boundary, beyond which a click will be cancelled.
  383. *
  384. * @type number
  385. */
  386. this.touchBoundary = options.touchBoundary || 10;
  387. /**
  388. * The FastClick layer.
  389. *
  390. * @type Element
  391. */
  392. this.layer = layer;
  393. /**
  394. * The minimum time between tap(touchstart and touchend) events
  395. *
  396. * @type number
  397. */
  398. this.tapDelay = options.tapDelay || 200;
  399. if (FastClick.notNeeded(layer)) {
  400. return;
  401. }
  402. // Some old versions of Android don't have Function.prototype.bind
  403. function bind(method, context) {
  404. return function() {
  405. return method.apply(context, arguments);
  406. };
  407. }
  408. var methods = [ "onMouse", "onClick", "onTouchStart", "onTouchMove", "onTouchEnd", "onTouchCancel" ];
  409. var context = this;
  410. for (var i = 0, l = methods.length; i < l; i++) {
  411. context[methods[i]] = bind(context[methods[i]], context);
  412. }
  413. // Set up event handlers as required
  414. if (deviceIsAndroid) {
  415. layer.addEventListener("mouseover", this.onMouse, true);
  416. layer.addEventListener("mousedown", this.onMouse, true);
  417. layer.addEventListener("mouseup", this.onMouse, true);
  418. }
  419. layer.addEventListener("click", this.onClick, true);
  420. layer.addEventListener("touchstart", this.onTouchStart, false);
  421. layer.addEventListener("touchmove", this.onTouchMove, false);
  422. layer.addEventListener("touchend", this.onTouchEnd, false);
  423. layer.addEventListener("touchcancel", this.onTouchCancel, false);
  424. // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
  425. // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
  426. // layer when they are cancelled.
  427. if (!Event.prototype.stopImmediatePropagation) {
  428. layer.removeEventListener = function(type, callback, capture) {
  429. var rmv = Node.prototype.removeEventListener;
  430. if (type === "click") {
  431. rmv.call(layer, type, callback.hijacked || callback, capture);
  432. } else {
  433. rmv.call(layer, type, callback, capture);
  434. }
  435. };
  436. layer.addEventListener = function(type, callback, capture) {
  437. var adv = Node.prototype.addEventListener;
  438. if (type === "click") {
  439. adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
  440. if (!event.propagationStopped) {
  441. callback(event);
  442. }
  443. }), capture);
  444. } else {
  445. adv.call(layer, type, callback, capture);
  446. }
  447. };
  448. }
  449. // If a handler is already declared in the element's onclick attribute, it will be fired before
  450. // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
  451. // adding it as listener.
  452. if (typeof layer.onclick === "function") {
  453. // Android browser on at least 3.2 requires a new reference to the function in layer.onclick
  454. // - the old one won't work if passed to addEventListener directly.
  455. oldOnClick = layer.onclick;
  456. layer.addEventListener("click", function(event) {
  457. oldOnClick(event);
  458. }, false);
  459. layer.onclick = null;
  460. }
  461. }
  462. /**
  463. * Android requires exceptions.
  464. *
  465. * @type boolean
  466. */
  467. var deviceIsAndroid = navigator.userAgent.indexOf("Android") > 0;
  468. /**
  469. * iOS requires exceptions.
  470. *
  471. * @type boolean
  472. */
  473. var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent);
  474. /**
  475. * iOS 4 requires an exception for select elements.
  476. *
  477. * @type boolean
  478. */
  479. var deviceIsIOS4 = deviceIsIOS && /OS 4_\d(_\d)?/.test(navigator.userAgent);
  480. /**
  481. * iOS 6.0(+?) requires the target element to be manually derived
  482. *
  483. * @type boolean
  484. */
  485. var deviceIsIOSWithBadTarget = deviceIsIOS && /OS ([6-9]|\d{2})_\d/.test(navigator.userAgent);
  486. /**
  487. * Determine whether a given element requires a native click.
  488. *
  489. * @param {EventTarget|Element} target Target DOM element
  490. * @returns {boolean} Returns true if the element needs a native click
  491. */
  492. FastClick.prototype.needsClick = function(target) {
  493. "use strict";
  494. switch (target.nodeName.toLowerCase()) {
  495. // Don't send a synthetic click to disabled inputs (issue #62)
  496. case "button":
  497. case "select":
  498. case "textarea":
  499. if (target.disabled) {
  500. return true;
  501. }
  502. break;
  503. case "input":
  504. // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
  505. if (deviceIsIOS && target.type === "file" || target.disabled) {
  506. return true;
  507. }
  508. break;
  509. case "label":
  510. case "video":
  511. return true;
  512. }
  513. return /\bneedsclick\b/.test(target.className);
  514. };
  515. /**
  516. * Determine whether a given element requires a call to focus to simulate click into element.
  517. *
  518. * @param {EventTarget|Element} target Target DOM element
  519. * @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
  520. */
  521. FastClick.prototype.needsFocus = function(target) {
  522. "use strict";
  523. switch (target.nodeName.toLowerCase()) {
  524. case "textarea":
  525. return true;
  526. case "select":
  527. return !deviceIsAndroid;
  528. case "input":
  529. switch (target.type) {
  530. case "button":
  531. case "checkbox":
  532. case "file":
  533. case "image":
  534. case "radio":
  535. case "submit":
  536. return false;
  537. }
  538. // No point in attempting to focus disabled inputs
  539. return !target.disabled && !target.readOnly;
  540. default:
  541. return /\bneedsfocus\b/.test(target.className);
  542. }
  543. };
  544. /**
  545. * Send a click event to the specified element.
  546. *
  547. * @param {EventTarget|Element} targetElement
  548. * @param {Event} event
  549. */
  550. FastClick.prototype.sendClick = function(targetElement, event) {
  551. "use strict";
  552. var clickEvent, touch;
  553. // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
  554. if (document.activeElement && document.activeElement !== targetElement) {
  555. document.activeElement.blur();
  556. }
  557. touch = event.changedTouches[0];
  558. // Synthesise a click event, with an extra attribute so it can be tracked
  559. clickEvent = document.createEvent("MouseEvents");
  560. clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
  561. clickEvent.forwardedTouchEvent = true;
  562. targetElement.dispatchEvent(clickEvent);
  563. };
  564. FastClick.prototype.determineEventType = function(targetElement) {
  565. "use strict";
  566. //Issue #159: Android Chrome Select Box does not open with a synthetic click event
  567. if (deviceIsAndroid && targetElement.tagName.toLowerCase() === "select") {
  568. return "mousedown";
  569. }
  570. return "click";
  571. };
  572. /**
  573. * @param {EventTarget|Element} targetElement
  574. */
  575. FastClick.prototype.focus = function(targetElement) {
  576. "use strict";
  577. var length;
  578. // 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.
  579. if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf("date") !== 0 && targetElement.type !== "time") {
  580. length = targetElement.value.length;
  581. targetElement.setSelectionRange(length, length);
  582. } else {
  583. targetElement.focus();
  584. }
  585. };
  586. /**
  587. * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
  588. *
  589. * @param {EventTarget|Element} targetElement
  590. */
  591. FastClick.prototype.updateScrollParent = function(targetElement) {
  592. "use strict";
  593. var scrollParent, parentElement;
  594. scrollParent = targetElement.fastClickScrollParent;
  595. // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
  596. // target element was moved to another parent.
  597. if (!scrollParent || !scrollParent.contains(targetElement)) {
  598. parentElement = targetElement;
  599. do {
  600. if (parentElement.scrollHeight > parentElement.offsetHeight) {
  601. scrollParent = parentElement;
  602. targetElement.fastClickScrollParent = parentElement;
  603. break;
  604. }
  605. parentElement = parentElement.parentElement;
  606. } while (parentElement);
  607. }
  608. // Always update the scroll top tracker if possible.
  609. if (scrollParent) {
  610. scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
  611. }
  612. };
  613. /**
  614. * @param {EventTarget} targetElement
  615. * @returns {Element|EventTarget}
  616. */
  617. FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
  618. "use strict";
  619. // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
  620. if (eventTarget.nodeType === Node.TEXT_NODE) {
  621. return eventTarget.parentNode;
  622. }
  623. return eventTarget;
  624. };
  625. /**
  626. * On touch start, record the position and scroll offset.
  627. *
  628. * @param {Event} event
  629. * @returns {boolean}
  630. */
  631. FastClick.prototype.onTouchStart = function(event) {
  632. "use strict";
  633. var targetElement, touch, selection;
  634. // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
  635. if (event.targetTouches.length > 1) {
  636. return true;
  637. }
  638. targetElement = this.getTargetElementFromEventTarget(event.target);
  639. touch = event.targetTouches[0];
  640. if (deviceIsIOS) {
  641. // Only trusted events will deselect text on iOS (issue #49)
  642. selection = window.getSelection();
  643. if (selection.rangeCount && !selection.isCollapsed) {
  644. return true;
  645. }
  646. if (!deviceIsIOS4) {
  647. // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
  648. // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
  649. // with the same identifier as the touch event that previously triggered the click that triggered the alert.
  650. // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
  651. // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
  652. if (touch.identifier === this.lastTouchIdentifier) {
  653. event.preventDefault();
  654. return false;
  655. }
  656. this.lastTouchIdentifier = touch.identifier;
  657. // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
  658. // 1) the user does a fling scroll on the scrollable layer
  659. // 2) the user stops the fling scroll with another tap
  660. // then the event.target of the last 'touchend' event will be the element that was under the user's finger
  661. // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
  662. // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
  663. this.updateScrollParent(targetElement);
  664. }
  665. }
  666. this.trackingClick = true;
  667. this.trackingClickStart = event.timeStamp;
  668. this.targetElement = targetElement;
  669. this.touchStartX = touch.pageX;
  670. this.touchStartY = touch.pageY;
  671. // Prevent phantom clicks on fast double-tap (issue #36)
  672. if (event.timeStamp - this.lastClickTime < this.tapDelay) {
  673. event.preventDefault();
  674. }
  675. return true;
  676. };
  677. /**
  678. * Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
  679. *
  680. * @param {Event} event
  681. * @returns {boolean}
  682. */
  683. FastClick.prototype.touchHasMoved = function(event) {
  684. "use strict";
  685. var touch = event.changedTouches[0], boundary = this.touchBoundary;
  686. if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
  687. return true;
  688. }
  689. return false;
  690. };
  691. /**
  692. * Update the last position.
  693. *
  694. * @param {Event} event
  695. * @returns {boolean}
  696. */
  697. FastClick.prototype.onTouchMove = function(event) {
  698. "use strict";
  699. if (!this.trackingClick) {
  700. return true;
  701. }
  702. // If the touch has moved, cancel the click tracking
  703. if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
  704. this.trackingClick = false;
  705. this.targetElement = null;
  706. }
  707. return true;
  708. };
  709. /**
  710. * Attempt to find the labelled control for the given label element.
  711. *
  712. * @param {EventTarget|HTMLLabelElement} labelElement
  713. * @returns {Element|null}
  714. */
  715. FastClick.prototype.findControl = function(labelElement) {
  716. "use strict";
  717. // Fast path for newer browsers supporting the HTML5 control attribute
  718. if (labelElement.control !== undefined) {
  719. return labelElement.control;
  720. }
  721. // All browsers under test that support touch events also support the HTML5 htmlFor attribute
  722. if (labelElement.htmlFor) {
  723. return document.getElementById(labelElement.htmlFor);
  724. }
  725. // If no for attribute exists, attempt to retrieve the first labellable descendant element
  726. // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
  727. return labelElement.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea");
  728. };
  729. /**
  730. * On touch end, determine whether to send a click event at once.
  731. *
  732. * @param {Event} event
  733. * @returns {boolean}
  734. */
  735. FastClick.prototype.onTouchEnd = function(event) {
  736. "use strict";
  737. var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
  738. if (!this.trackingClick) {
  739. return true;
  740. }
  741. // Prevent phantom clicks on fast double-tap (issue #36)
  742. if (event.timeStamp - this.lastClickTime < this.tapDelay) {
  743. this.cancelNextClick = true;
  744. return true;
  745. }
  746. // Reset to prevent wrong click cancel on input (issue #156).
  747. this.cancelNextClick = false;
  748. this.lastClickTime = event.timeStamp;
  749. trackingClickStart = this.trackingClickStart;
  750. this.trackingClick = false;
  751. this.trackingClickStart = 0;
  752. // On some iOS devices, the targetElement supplied with the event is invalid if the layer
  753. // is performing a transition or scroll, and has to be re-detected manually. Note that
  754. // for this to function correctly, it must be called *after* the event target is checked!
  755. // See issue #57; also filed as rdar://13048589 .
  756. if (deviceIsIOSWithBadTarget) {
  757. touch = event.changedTouches[0];
  758. // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
  759. targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
  760. targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
  761. }
  762. targetTagName = targetElement.tagName.toLowerCase();
  763. if (targetTagName === "label") {
  764. forElement = this.findControl(targetElement);
  765. if (forElement) {
  766. this.focus(targetElement);
  767. if (deviceIsAndroid) {
  768. return false;
  769. }
  770. targetElement = forElement;
  771. }
  772. } else if (this.needsFocus(targetElement)) {
  773. // 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.
  774. // 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).
  775. if (event.timeStamp - trackingClickStart > 100 || deviceIsIOS && window.top !== window && targetTagName === "input") {
  776. this.targetElement = null;
  777. return false;
  778. }
  779. this.focus(targetElement);
  780. this.sendClick(targetElement, event);
  781. // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
  782. // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
  783. if (!deviceIsIOS || targetTagName !== "select") {
  784. this.targetElement = null;
  785. event.preventDefault();
  786. }
  787. return false;
  788. }
  789. if (deviceIsIOS && !deviceIsIOS4) {
  790. // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
  791. // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
  792. scrollParent = targetElement.fastClickScrollParent;
  793. if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
  794. return true;
  795. }
  796. }
  797. // Prevent the actual click from going though - unless the target node is marked as requiring
  798. // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
  799. if (!this.needsClick(targetElement)) {
  800. event.preventDefault();
  801. this.sendClick(targetElement, event);
  802. }
  803. return false;
  804. };
  805. /**
  806. * On touch cancel, stop tracking the click.
  807. *
  808. * @returns {void}
  809. */
  810. FastClick.prototype.onTouchCancel = function() {
  811. "use strict";
  812. this.trackingClick = false;
  813. this.targetElement = null;
  814. };
  815. /**
  816. * Determine mouse events which should be permitted.
  817. *
  818. * @param {Event} event
  819. * @returns {boolean}
  820. */
  821. FastClick.prototype.onMouse = function(event) {
  822. "use strict";
  823. // If a target element was never set (because a touch event was never fired) allow the event
  824. if (!this.targetElement) {
  825. return true;
  826. }
  827. if (event.forwardedTouchEvent) {
  828. return true;
  829. }
  830. // Programmatically generated events targeting a specific element should be permitted
  831. if (!event.cancelable) {
  832. return true;
  833. }
  834. // Derive and check the target element to see whether the mouse event needs to be permitted;
  835. // unless explicitly enabled, prevent non-touch click events from triggering actions,
  836. // to prevent ghost/doubleclicks.
  837. if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
  838. // Prevent any user-added listeners declared on FastClick element from being fired.
  839. if (event.stopImmediatePropagation) {
  840. event.stopImmediatePropagation();
  841. } else {
  842. // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
  843. event.propagationStopped = true;
  844. }
  845. // Cancel the event
  846. event.stopPropagation();
  847. event.preventDefault();
  848. return false;
  849. }
  850. // If the mouse event is permitted, return true for the action to go through.
  851. return true;
  852. };
  853. /**
  854. * On actual clicks, determine whether this is a touch-generated click, a click action occurring
  855. * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
  856. * an actual click which should be permitted.
  857. *
  858. * @param {Event} event
  859. * @returns {boolean}
  860. */
  861. FastClick.prototype.onClick = function(event) {
  862. "use strict";
  863. var permitted;
  864. // 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.
  865. if (this.trackingClick) {
  866. this.targetElement = null;
  867. this.trackingClick = false;
  868. return true;
  869. }
  870. // 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.
  871. if (event.target.type === "submit" && event.detail === 0) {
  872. return true;
  873. }
  874. permitted = this.onMouse(event);
  875. // 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.
  876. if (!permitted) {
  877. this.targetElement = null;
  878. }
  879. // If clicks are permitted, return true for the action to go through.
  880. return permitted;
  881. };
  882. /**
  883. * Remove all FastClick's event listeners.
  884. *
  885. * @returns {void}
  886. */
  887. FastClick.prototype.destroy = function() {
  888. "use strict";
  889. var layer = this.layer;
  890. if (deviceIsAndroid) {
  891. layer.removeEventListener("mouseover", this.onMouse, true);
  892. layer.removeEventListener("mousedown", this.onMouse, true);
  893. layer.removeEventListener("mouseup", this.onMouse, true);
  894. }
  895. layer.removeEventListener("click", this.onClick, true);
  896. layer.removeEventListener("touchstart", this.onTouchStart, false);
  897. layer.removeEventListener("touchmove", this.onTouchMove, false);
  898. layer.removeEventListener("touchend", this.onTouchEnd, false);
  899. layer.removeEventListener("touchcancel", this.onTouchCancel, false);
  900. };
  901. /**
  902. * Check whether FastClick is needed.
  903. *
  904. * @param {Element} layer The layer to listen on
  905. */
  906. FastClick.notNeeded = function(layer) {
  907. "use strict";
  908. var metaViewport;
  909. var chromeVersion;
  910. // Devices that don't support touch don't need FastClick
  911. if (typeof window.ontouchstart === "undefined") {
  912. return true;
  913. }
  914. // Chrome version - zero for other browsers
  915. chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [ , 0 ])[1];
  916. if (chromeVersion) {
  917. if (deviceIsAndroid) {
  918. metaViewport = document.querySelector("meta[name=viewport]");
  919. if (metaViewport) {
  920. // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
  921. if (metaViewport.content.indexOf("user-scalable=no") !== -1) {
  922. return true;
  923. }
  924. // Chrome 32 and above with width=device-width or less don't need FastClick
  925. if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
  926. return true;
  927. }
  928. }
  929. } else {
  930. return true;
  931. }
  932. }
  933. // IE10 with -ms-touch-action: none, which disables double-tap-to-zoom (issue #97)
  934. if (layer.style.msTouchAction === "none") {
  935. return true;
  936. }
  937. return false;
  938. };
  939. /**
  940. * Factory method for creating a FastClick object
  941. *
  942. * @param {Element} layer The layer to listen on
  943. * @param {Object} options The options to override the defaults
  944. */
  945. FastClick.attach = function(layer, options) {
  946. "use strict";
  947. return new FastClick(layer, options);
  948. };
  949. module.exports = FastClick;
  950. });
  951. define("util.hammer", [ "core", "zepto.extend.fx", "zepto.extend.data", "zepto.extend.selector" ], function(require, exports, module) {
  952. require("core");
  953. var $ = window.Zepto, UI = $.AMUI;
  954. /**
  955. * Hammer.js
  956. * @via https://github.com/hammerjs/hammer.js
  957. * @copyright Copyright (C) 2011-2014 by Jorik Tangelder (Eight Media)
  958. * @license https://github.com/hammerjs/hammer.js/blob/master/LICENSE.md
  959. */
  960. var VENDOR_PREFIXES = [ "", "webkit", "moz", "MS", "ms", "o" ];
  961. var TEST_ELEMENT = document.createElement("div");
  962. var TYPE_FUNCTION = "function";
  963. var round = Math.round;
  964. var abs = Math.abs;
  965. var now = Date.now;
  966. /**
  967. * set a timeout with a given scope
  968. * @param {Function} fn
  969. * @param {Number} timeout
  970. * @param {Object} context
  971. * @returns {number}
  972. */
  973. function setTimeoutContext(fn, timeout, context) {
  974. return setTimeout(bindFn(fn, context), timeout);
  975. }
  976. /**
  977. * if the argument is an array, we want to execute the fn on each entry
  978. * if it aint an array we don't want to do a thing.
  979. * this is used by all the methods that accept a single and array argument.
  980. * @param {*|Array} arg
  981. * @param {String} fn
  982. * @param {Object} [context]
  983. * @returns {Boolean}
  984. */
  985. function invokeArrayArg(arg, fn, context) {
  986. if (Array.isArray(arg)) {
  987. each(arg, context[fn], context);
  988. return true;
  989. }
  990. return false;
  991. }
  992. /**
  993. * walk objects and arrays
  994. * @param {Object} obj
  995. * @param {Function} iterator
  996. * @param {Object} context
  997. */
  998. function each(obj, iterator, context) {
  999. var i;
  1000. if (!obj) {
  1001. return;
  1002. }
  1003. if (obj.forEach) {
  1004. obj.forEach(iterator, context);
  1005. } else if (obj.length !== undefined) {
  1006. i = 0;
  1007. while (i < obj.length) {
  1008. iterator.call(context, obj[i], i, obj);
  1009. i++;
  1010. }
  1011. } else {
  1012. for (i in obj) {
  1013. obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
  1014. }
  1015. }
  1016. }
  1017. /**
  1018. * extend object.
  1019. * means that properties in dest will be overwritten by the ones in src.
  1020. * @param {Object} dest
  1021. * @param {Object} src
  1022. * @param {Boolean} [merge]
  1023. * @returns {Object} dest
  1024. */
  1025. function extend(dest, src, merge) {
  1026. var keys = Object.keys(src);
  1027. var i = 0;
  1028. while (i < keys.length) {
  1029. if (!merge || merge && dest[keys[i]] === undefined) {
  1030. dest[keys[i]] = src[keys[i]];
  1031. }
  1032. i++;
  1033. }
  1034. return dest;
  1035. }
  1036. /**
  1037. * merge the values from src in the dest.
  1038. * means that properties that exist in dest will not be overwritten by src
  1039. * @param {Object} dest…

Large files files are truncated, but you can click here to view the full file