modulex-util
Version:
common utilities from modulex
1 lines • 11.5 kB
JavaScript
define("util",[],function(n,t,r){var e,i,o,u,a,c,f,l,s,p;e=function(n){var t=0,r="";return n={version:"1.1.8",_debug:"",mix:function(n,t){for(var r in t)n[r]=t[r];return n},guid:function(n){return(n||r)+t++}}}(),i=function(n){function t(){var n=a;for(var t in c){var r=c[t];n+=r+"|"}return n=n.slice(0,-1),i=new RegExp(n,"g")}function r(){var n=a;for(var t in f){var r=f[t];n+=r+"|"}return n+="&#(\\d{1,5});",o=new RegExp(n,"g")}var i,o,u=e,a="",c={"&":"&",">":">","<":"<","`":"`","/":"/",""":'"',"'":"'"},f={},l=/[&<>"'`]/,s=/[\-#$\^*()+\[\]{}|\\,.?\s]/g;return function(){for(var n in c)f[c[n]]=n}(),i=t(),o=r(),u.mix(u,{escapeHtml:function(n){return n||0===n?(n=""+n,l.test(n)?(n+"").replace(i,function(n){return f[n]}):n):""},escapeRegExp:function(n){return n.replace(s,"\\$&")},unEscapeHtml:function(n){return n.replace(o,function(n,t){return c[n]||String.fromCharCode(+t)})}}),u.escapeHTML=u.escapeHtml,u.unEscapeHTML=u.unEscapeHtml,n}(),o=function(n){function t(n,t,r){function e(){}var i=[].slice,o=i.call(arguments,3),u=function(){var u=i.call(arguments);return t.apply(this instanceof e?this:r||this,n?u.concat(o):o.concat(u))};return e.prototype=t.prototype,u.prototype=new e,u}var r=e;return r.mix(r,{noop:function(){},bind:t(0,t,null,0),rbind:t(0,t,null,1),later:function(n,t,e,i,o){t=t||0;var u,a,c=n,f=r.makeArray(o);return"string"==typeof n&&(c=i[n]),u=function(){c.apply(i,f)},a=e?setInterval(u,t):setTimeout(u,t),{id:a,interval:e,cancel:function(){this.interval?clearInterval(a):clearTimeout(a)}}},throttle:function(n,t,e){if(t=t||150,-1===t)return function(){n.apply(e||this,arguments)};var i=r.now();return function(){var o=r.now();o-i>t&&(i=o,n.apply(e||this,arguments))}},buffer:function(n,t,e){function i(){i.stop(),o=r.later(n,t,0,e||this,arguments)}if(t=t||150,-1===t)return function(){n.apply(e||this,arguments)};var o=null;return i.stop=function(){o&&(o.cancel(),o=0)},i}}),n}(),u=function(n){function t(n,t){return null!==n&&n!==p&&n[t]!==p}function r(n,t,r){return delete n[w],delete t[w],r}function i(n,e){if(n[w]===e&&e[w]===n)return!0;n[w]=e,e[w]=n;for(var i in e)if(!t(n,i)&&t(e,i))return r(n,e,!1);for(i in n)if(!t(e,i)&&t(n,i))return r(n,e,!1);for(i in e)if(i!==w&&!v.equals(n[i],e[i]))return r(n,e,!1);return v.isArray(n)&&v.isArray(e)&&n.length!==e.length?r(n,e,!1):r(n,e,!0)}function o(){}function u(n,t){var r;return b?r=b(n):(o.prototype=n,r=new o),r.constructor=t,r}function a(n,t){for(var r in t)n[r]=t[r]}function c(n,t,r,e,i,o,u){if(!t||!n)return n;var a,c,f,s;for(t[y]=n,o.push(t),f=v.keys(t),s=f.length,a=0;s>a;a++)c=f[a],c!==y&&l(c,n,t,r,e,i,o,u);return n}function f(n,t){return"constructor"===n?p:t}function l(n,t,r,e,i,o,u,a){if(e||!(n in t)||o){var f=t[n],l=r[n];if(f===l)return f===p&&(t[n]=f),void 0;if(i&&(l=i.call(r,n,l)),o&&l&&(v.isArray(l)||v.isPlainObject(l)))if(a&&l[y])t[n]=l[y];else{var s=f&&(v.isArray(f)||v.isPlainObject(f))?f:v.isArray(l)?[]:{};t[n]=s,c(s,l,e,i,!0,u,a)}else l===p||!e&&n in t||(t[n]=l)}}function s(n,t,r,e){var i,o,u,a,c=n;if(!n)return c;if(e&&n[d])return r[n[d]].destination;if("object"==typeof n){var f=n.constructor;v.inArray(f,[Boolean,String,Number,Date,RegExp])?c=new f(n.valueOf()):(i=v.isArray(n))?c=t?v.filter(n,t):n.concat():(o=v.isPlainObject(n))&&(c={}),e&&(n[d]=a=v.guid("c"),r[a]={destination:c,input:n})}if(i)for(var l=0;l<c.length;l++)c[l]=s(c[l],t,r,e);else if(o)for(u in n)u===d||t&&t.call(n,n[u],u,n)===!1||(c[u]=s(n[u],t,r,e));return c}var p,v=e,y="__MIX_CIRCULAR",m="__~ks_stamped",g="undefined"==typeof window?global:window,d="__~ks_cloned",h={}.toString,w="__~ks_compared",x=Object,b=x.create,E=!{toString:1}.propertyIsEnumerable("toString"),O=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toString","toLocaleString","valueOf"];return a(v,{equals:function(n,t){return n===t?!0:n===p||null===n||t===p||null===t?null==n&&null==t:n instanceof Date&&t instanceof Date?n.getTime()===t.getTime():"string"==typeof n&&"string"==typeof t?n===t:"number"==typeof n&&"number"==typeof t?n===t:"object"==typeof n&&"object"==typeof t?i(n,t):n===t},keys:Object.keys||function(n){var t,r,e=[];for(t in n)n.hasOwnProperty(t)&&e.push(t);if(E)for(r=O.length-1;r>=0;r--)t=O[r],n.hasOwnProperty(t)&&e.push(t);return e},each:function(n,t,r){if(n){var e,i,o,u=0,a=n&&n.length,c=a===p||"[object Function]"===h.call(n);if(r=r||null,c)for(o=v.keys(n);u<o.length&&(e=o[u],t.call(r,n[e],e,n)!==!1);u++);else for(i=n[0];a>u&&t.call(r,i,u,n)!==!1;i=n[++u]);}return n},now:Date.now||function(){return+new Date},isEmptyObject:function(n){for(var t in n)if(t!==p)return!1;return!0},stamp:function(n,t,r){r=r||m;var e=n[r];if(e)return e;if(!t)try{e=n[r]=v.guid(r)}catch(i){e=p}return e},mix:function(n,t,r,e,i){var o;if("object"==typeof r&&(e=r.whitelist,i=r.deep,o=r.structured,r=r.overwrite),e&&"function"!=typeof e){var u=e;e=function(n,t){return v.inArray(n,u)?t:p}}r===p&&(r=!0),o===p&&(o=!0);var a,f=[],l=0;for(c(n,t,r,e,i,f,o);a=f[l++];)delete a[y];return n},merge:function(n){n=v.makeArray(arguments);var t,r={},e=n.length;for(t=0;e>t;t++)v.mix(r,n[t]);return r},augment:function(n,t){var r,e,i=v.makeArray(arguments),o=i.length-2,u=1,a=i[o],c=i[o+1];for(i[1]=t,v.isArray(c)||(a=c,c=p,o++),"boolean"!=typeof a&&(a=p,o++);o>u;u++)e=i[u],(r=e.prototype)&&(e=v.mix({},r,!0,f)),v.mix(n.prototype,e,a,c);return n},extend:function(n,t,r,e){var i,o=t.prototype;return o.constructor=t,i=u(o,n),n.prototype=v.mix(i,n.prototype),n.superclass=o,r&&v.mix(i,r),e&&v.mix(n,e),n},namespace:function(n,t){var r,e,i;for(i=n.split("."),r=t||g,e=0;e<i.length;++e)r=r[i[e]]=r[i[e]]||{};return r},clone:function(n,t){var r;"object"==typeof t&&(r=t.structured,t=t.filter),r===p&&(r=!0);var e;r&&(e={});var i=s(n,t,e,r);return r&&v.each(e,function(n){if(n=n.input,n[d])try{delete n[d]}catch(t){n[d]=p}}),e=null,i}}),n}(),a=function(n){function t(){return arguments[1].toUpperCase()}var r,i=e,o=/\\?\{([^{}]+)\}/g,u="",a=/^[\s\xa0]+|[\s\xa0]+$/g,c=String.prototype.trim,f=/-([a-z])/gi;return i.mix(i,{startsWith:function(n,t){return 0===n.lastIndexOf(t,0)},endsWith:function(n,t){var r=n.length-t.length;return r>=0&&n.indexOf(t,r)===r},trim:c?function(n){return null==n?u:c.call(n)}:function(n){return null==n?u:(n+"").replace(a,u)},urlEncode:function(n){return encodeURIComponent(String(n))},urlDecode:function(n){return decodeURIComponent(n.replace(/\+/g," "))},camelCase:function(n){return-1===n.indexOf("-")?n:n.replace(f,t)},substitute:function(n,t,e){return"string"==typeof n&&t?n.replace(e||o,function(n,e){return"\\"===n.charAt(0)?n.slice(1):t[e]===r?u:t[e]}):n},ucfirst:function(n){return n+="",n.charAt(0).toUpperCase()+n.substring(1)}}),n}(),c=function(n){function t(n,t){return a.hasOwnProperty.call(n,t)}var r,i=e,o={},u=!1,a=(i.noop,Object.prototype),c=a.toString;i.mix(i,{type:function(n){return null==n?String(n):o[c.call(n)]||"object"},isPlainObject:function(n){if(!n||"object"!==i.type(n)||n.nodeType||n.window==n)return u;var e,o;try{if((o=n.constructor)&&!t(n,"constructor")&&!t(o.prototype,"isPrototypeOf"))return u}catch(a){return u}for(e in n);return e===r||t(n,e)}});for(var f="Boolean Number String Function Date RegExp Object Array".split(" "),l=0;l<f.length;l++)!function(n,t){o["[object "+n+"]"]=t=n.toLowerCase(),i["is"+n]=function(n){return i.type(n)===t}}(f[l],l);return i.isArray=Array.isArray||i.isArray,n}(),f=function(n){var t=e,r=/^[\],:{}\s]*$/,i=/(?:^|:|,)(?:\s*\[)+/g,o=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,u=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g;return t.parseJson=function(n){if(null===n)return n;if("string"==typeof n&&(n=t.trim(n),n&&r.test(n.replace(o,"@").replace(u,"]").replace(i,""))))return new Function("return "+n)();throw new Error("Invalid Json: "+n)},n}(),l=function(n){function t(){if(!f){o&&o.setTimeout&&E(o,w,t),f=1;for(var n=0;n<l.length;n++)try{l[n]()}catch(r){setTimeout(function(){throw r},0)}}}function r(){if(!u||u.readyState===x)return t(),void 0;if(b(o,w,t),m){var n=function(){E(u,d,n),t()};b(u,d,n)}else{var r=function(){u.readyState===x&&(E(u,h,r),t())};b(u,h,r);var e,i=a&&a.doScroll;try{e=null===o.frameElement}catch(c){e=!1}if(i&&e){var f=function(){try{i("left"),t()}catch(n){setTimeout(f,p)}};f()}}}var i=e,o="undefined"!=typeof window?window:{},u=o.document||{},a=u.documentElement,c="",f=0,l=[],s=500,p=40,v=/^#?([\w-]+)$/,y=/\S/,m=u.addEventListener,g=u.attachEvent||m,d="DOMContentLoaded",h="readystatechange",w="load",x="complete",b=m?function(n,t,r){n.addEventListener(t,r,!1)}:function(n,t,r){n.attachEvent("on"+t,r)},E=m?function(n,t,r){n.removeEventListener(t,r,!1)}:function(n,t,r){n.detachEvent("on"+t,r)};i.mix(i,{isWindow:function(n){return null!=n&&n==n.window},parseXml:function(n){if(n.documentElement)return n;var t;if(o.DOMParser?t=(new DOMParser).parseFromString(n,"text/xml"):(t=new ActiveXObject("Microsoft.XMLDOM"),t.async=!1,t.loadXML(n)),!t||!t.documentElement||t.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: "+n);return t},globalEval:function(n){n&&y.test(n)&&(o.execScript?o.execScript(n):!function(n){o.eval.call(o,n)}(n))},ready:function(n){if(f)try{n()}catch(t){setTimeout(function(){throw t},0)}else l.push(n);return this},available:function(n,t){n=(n+c).match(v)[1];var r=1,e=i.later(function(){if(++r>s)return e.cancel(),void 0;var i=u.getElementById(n);i&&(t(i),e.cancel())},p,!0)}}),i.parseXML=i.parseXml,g&&r();try{u.execCommand&&u.execCommand("BackgroundImageCache",!1,!0)}catch(O){}return n}(),s=function(n){var t,r=!0,i=Array.prototype,o=i.indexOf,u=i.lastIndexOf,a=i.filter,c=i.every,f=i.some,l=e,s=i.map,p=!1;return l.mix(l,{indexOf:o?function(n,r,e){return e===t?o.call(r,n):o.call(r,n,e)}:function(n,t,r){for(var e=r||0,i=t.length;i>e;++e)if(t[e]===n)return e;return-1},lastIndexOf:u?function(n,r,e){return e===t?u.call(r,n):u.call(r,n,e)}:function(n,r,e){e===t&&(e=r.length-1);for(var i=e;i>=0&&r[i]!==n;i--);return i},unique:function(n,t){var r=n.slice();t&&r.reverse();for(var e,i,o=0;o<r.length;){for(i=r[o];(e=l.lastIndexOf(i,r))!==o;)r.splice(e,1);o+=1}return t&&r.reverse(),r},inArray:function(n,t){return l.indexOf(n,t)>-1},filter:a?function(n,t,r){return a.call(n,t,r||this)}:function(n,t,r){var e=[];return l.each(n,function(n,i,o){t.call(r||this,n,i,o)&&e.push(n)}),e},map:s?function(n,t,r){return s.call(n,t,r||this)}:function(n,t,r){for(var e=n.length,i=new Array(e),o=0;e>o;o++){var u="string"==typeof n?n.charAt(o):n[o];(u||o in n)&&(i[o]=t.call(r||this,u,o,n))}return i},reduce:function(n,e,i){var o=n.length;if("function"!=typeof e)throw new TypeError("callback is not function!");if(0===o&&2===arguments.length)throw new TypeError("arguments invalid");var u,a=0;if(arguments.length>=3)u=i;else do{if(a in n){u=n[a++];break}if(a+=1,a>=o)throw new TypeError}while(r);for(;o>a;)a in n&&(u=e.call(t,u,n[a],a,n)),a++;return u},every:c?function(n,t,r){return c.call(n,t,r||this)}:function(n,t,e){for(var i=n&&n.length||0,o=0;i>o;o++)if(o in n&&!t.call(e,n[o],o,n))return p;return r},some:f?function(n,t,r){return f.call(n,t,r||this)}:function(n,t,e){for(var i=n&&n.length||0,o=0;i>o;o++)if(o in n&&t.call(e,n[o],o,n))return r;return p},makeArray:function(n){if(null==n)return[];if(l.isArray(n))return n;var t=typeof n.length,r=typeof n;if("number"!==t||"string"==typeof n.nodeName||null!=n&&n==n.window||"string"===r||"function"===r&&!("item"in n&&"number"===t))return[n];for(var e=[],i=0,o=n.length;o>i;i++)e[i]=n[i];return e}}),n}(),p=function(n){return n=e,r.exports.version="1.1.8",n}(),r.exports=p});