summaryrefslogtreecommitdiff
path: root/lib/dojo/_base/lang.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/_base/lang.js')
-rw-r--r--lib/dojo/_base/lang.js393
1 files changed, 2 insertions, 391 deletions
diff --git a/lib/dojo/_base/lang.js b/lib/dojo/_base/lang.js
index 9061de01e..bc88c7cde 100644
--- a/lib/dojo/_base/lang.js
+++ b/lib/dojo/_base/lang.js
@@ -4,394 +4,5 @@
see: http://dojotoolkit.org/license for details
*/
-
-if(!dojo._hasResource["dojo._base.lang"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
-dojo._hasResource["dojo._base.lang"] = true;
-dojo.provide("dojo._base.lang");
-
-
-(function(){
- var d = dojo, opts = Object.prototype.toString;
-
- // Crockford (ish) functions
-
- dojo.isString = function(/*anything*/ it){
- // summary:
- // Return true if it is a String
- return (typeof it == "string" || it instanceof String); // Boolean
- };
-
- dojo.isArray = function(/*anything*/ it){
- // summary:
- // Return true if it is an Array.
- // Does not work on Arrays created in other windows.
- return it && (it instanceof Array || typeof it == "array"); // Boolean
- };
-
- dojo.isFunction = function(/*anything*/ it){
- // summary:
- // Return true if it is a Function
- return opts.call(it) === "[object Function]";
- };
-
- dojo.isObject = function(/*anything*/ it){
- // summary:
- // Returns true if it is a JavaScript object (or an Array, a Function
- // or null)
- return it !== undefined &&
- (it === null || typeof it == "object" || d.isArray(it) || d.isFunction(it)); // Boolean
- };
-
- dojo.isArrayLike = function(/*anything*/ it){
- // summary:
- // similar to dojo.isArray() but more permissive
- // description:
- // Doesn't strongly test for "arrayness". Instead, settles for "isn't
- // a string or number and has a length property". Arguments objects
- // and DOM collections will return true when passed to
- // dojo.isArrayLike(), but will return false when passed to
- // dojo.isArray().
- // returns:
- // If it walks like a duck and quacks like a duck, return `true`
- return it && it !== undefined && // Boolean
- // keep out built-in constructors (Number, String, ...) which have length
- // properties
- !d.isString(it) && !d.isFunction(it) &&
- !(it.tagName && it.tagName.toLowerCase() == 'form') &&
- (d.isArray(it) || isFinite(it.length));
- };
-
- dojo.isAlien = function(/*anything*/ it){
- // summary:
- // Returns true if it is a built-in function or some other kind of
- // oddball that *should* report as a function but doesn't
- return it && !d.isFunction(it) && /\{\s*\[native code\]\s*\}/.test(String(it)); // Boolean
- };
-
- dojo.extend = function(/*Object*/ constructor, /*Object...*/ props){
- // summary:
- // Adds all properties and methods of props to constructor's
- // prototype, making them available to all instances created with
- // constructor.
- for(var i=1, l=arguments.length; i<l; i++){
- d._mixin(constructor.prototype, arguments[i]);
- }
- return constructor; // Object
- };
-
- dojo._hitchArgs = function(scope, method /*,...*/){
- var pre = d._toArray(arguments, 2);
- var named = d.isString(method);
- return function(){
- // arrayify arguments
- var args = d._toArray(arguments);
- // locate our method
- var f = named ? (scope||d.global)[method] : method;
- // invoke with collected args
- return f && f.apply(scope || this, pre.concat(args)); // mixed
- }; // Function
- };
-
- dojo.hitch = function(/*Object*/scope, /*Function|String*/method /*,...*/){
- // summary:
- // Returns a function that will only ever execute in the a given scope.
- // This allows for easy use of object member functions
- // in callbacks and other places in which the "this" keyword may
- // otherwise not reference the expected scope.
- // Any number of default positional arguments may be passed as parameters
- // beyond "method".
- // Each of these values will be used to "placehold" (similar to curry)
- // for the hitched function.
- // scope:
- // The scope to use when method executes. If method is a string,
- // scope is also the object containing method.
- // method:
- // A function to be hitched to scope, or the name of the method in
- // scope to be hitched.
- // example:
- // | dojo.hitch(foo, "bar")();
- // runs foo.bar() in the scope of foo
- // example:
- // | dojo.hitch(foo, myFunction);
- // returns a function that runs myFunction in the scope of foo
- // example:
- // Expansion on the default positional arguments passed along from
- // hitch. Passed args are mixed first, additional args after.
- // | var foo = { bar: function(a, b, c){ console.log(a, b, c); } };
- // | var fn = dojo.hitch(foo, "bar", 1, 2);
- // | fn(3); // logs "1, 2, 3"
- // example:
- // | var foo = { bar: 2 };
- // | dojo.hitch(foo, function(){ this.bar = 10; })();
- // execute an anonymous function in scope of foo
-
- if(arguments.length > 2){
- return d._hitchArgs.apply(d, arguments); // Function
- }
- if(!method){
- method = scope;
- scope = null;
- }
- if(d.isString(method)){
- scope = scope || d.global;
- if(!scope[method]){ throw(['dojo.hitch: scope["', method, '"] is null (scope="', scope, '")'].join('')); }
- return function(){ return scope[method].apply(scope, arguments || []); }; // Function
- }
- return !scope ? method : function(){ return method.apply(scope, arguments || []); }; // Function
- };
-
- /*=====
- dojo.delegate = function(obj, props){
- // summary:
- // Returns a new object which "looks" to obj for properties which it
- // does not have a value for. Optionally takes a bag of properties to
- // seed the returned object with initially.
- // description:
- // This is a small implementaton of the Boodman/Crockford delegation
- // pattern in JavaScript. An intermediate object constructor mediates
- // the prototype chain for the returned object, using it to delegate
- // down to obj for property lookup when object-local lookup fails.
- // This can be thought of similarly to ES4's "wrap", save that it does
- // not act on types but rather on pure objects.
- // obj:
- // The object to delegate to for properties not found directly on the
- // return object or in props.
- // props:
- // an object containing properties to assign to the returned object
- // returns:
- // an Object of anonymous type
- // example:
- // | var foo = { bar: "baz" };
- // | var thinger = dojo.delegate(foo, { thud: "xyzzy"});
- // | thinger.bar == "baz"; // delegated to foo
- // | foo.thud == undefined; // by definition
- // | thinger.thud == "xyzzy"; // mixed in from props
- // | foo.bar = "thonk";
- // | thinger.bar == "thonk"; // still delegated to foo's bar
- }
- =====*/
-
- dojo.delegate = dojo._delegate = (function(){
- // boodman/crockford delegation w/ cornford optimization
- function TMP(){}
- return function(obj, props){
- TMP.prototype = obj;
- var tmp = new TMP();
- TMP.prototype = null;
- if(props){
- d._mixin(tmp, props);
- }
- return tmp; // Object
- };
- })();
-
- /*=====
- dojo._toArray = function(obj, offset, startWith){
- // summary:
- // Converts an array-like object (i.e. arguments, DOMCollection) to an
- // array. Returns a new Array with the elements of obj.
- // obj: Object
- // the object to "arrayify". We expect the object to have, at a
- // minimum, a length property which corresponds to integer-indexed
- // properties.
- // offset: Number?
- // the location in obj to start iterating from. Defaults to 0.
- // Optional.
- // startWith: Array?
- // An array to pack with the properties of obj. If provided,
- // properties in obj are appended at the end of startWith and
- // startWith is the returned array.
- }
- =====*/
-
- var efficient = function(obj, offset, startWith){
- return (startWith||[]).concat(Array.prototype.slice.call(obj, offset||0));
- };
-
- var slow = function(obj, offset, startWith){
- var arr = startWith||[];
- for(var x = offset || 0; x < obj.length; x++){
- arr.push(obj[x]);
- }
- return arr;
- };
-
- dojo._toArray =
- d.isIE ? function(obj){
- return ((obj.item) ? slow : efficient).apply(this, arguments);
- } :
- efficient;
-
- dojo.partial = function(/*Function|String*/method /*, ...*/){
- // summary:
- // similar to hitch() except that the scope object is left to be
- // whatever the execution context eventually becomes.
- // description:
- // Calling dojo.partial is the functional equivalent of calling:
- // | dojo.hitch(null, funcName, ...);
- var arr = [ null ];
- return d.hitch.apply(d, arr.concat(d._toArray(arguments))); // Function
- };
-
- var extraNames = d._extraNames, extraLen = extraNames.length, empty = {};
-
- dojo.clone = function(/*anything*/ o){
- // summary:
- // Clones objects (including DOM nodes) and all children.
- // Warning: do not clone cyclic structures.
- if(!o || typeof o != "object" || d.isFunction(o)){
- // null, undefined, any non-object, or function
- return o; // anything
- }
- if(o.nodeType && "cloneNode" in o){
- // DOM Node
- return o.cloneNode(true); // Node
- }
- if(o instanceof Date){
- // Date
- return new Date(o.getTime()); // Date
- }
- if(o instanceof RegExp){
- // RegExp
- return new RegExp(o); // RegExp
- }
- var r, i, l, s, name;
- if(d.isArray(o)){
- // array
- r = [];
- for(i = 0, l = o.length; i < l; ++i){
- if(i in o){
- r.push(d.clone(o[i]));
- }
- }
-// we don't clone functions for performance reasons
-// }else if(d.isFunction(o)){
-// // function
-// r = function(){ return o.apply(this, arguments); };
- }else{
- // generic objects
- r = o.constructor ? new o.constructor() : {};
- }
- for(name in o){
- // the "tobj" condition avoid copying properties in "source"
- // inherited from Object.prototype. For example, if target has a custom
- // toString() method, don't overwrite it with the toString() method
- // that source inherited from Object.prototype
- s = o[name];
- if(!(name in r) || (r[name] !== s && (!(name in empty) || empty[name] !== s))){
- r[name] = d.clone(s);
- }
- }
- // IE doesn't recognize some custom functions in for..in
- if(extraLen){
- for(i = 0; i < extraLen; ++i){
- name = extraNames[i];
- s = o[name];
- if(!(name in r) || (r[name] !== s && (!(name in empty) || empty[name] !== s))){
- r[name] = s; // functions only, we don't clone them
- }
- }
- }
- return r; // Object
- };
-
- /*=====
- dojo.trim = function(str){
- // summary:
- // Trims whitespace from both sides of the string
- // str: String
- // String to be trimmed
- // returns: String
- // Returns the trimmed string
- // description:
- // This version of trim() was selected for inclusion into the base due
- // to its compact size and relatively good performance
- // (see [Steven Levithan's blog](http://blog.stevenlevithan.com/archives/faster-trim-javascript)
- // Uses String.prototype.trim instead, if available.
- // The fastest but longest version of this function is located at
- // dojo.string.trim()
- return ""; // String
- }
- =====*/
-
- dojo.trim = String.prototype.trim ?
- function(str){ return str.trim(); } :
- function(str){ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };
-
- /*=====
- dojo.replace = function(tmpl, map, pattern){
- // summary:
- // Performs parameterized substitutions on a string. Throws an
- // exception if any parameter is unmatched.
- // tmpl: String
- // String to be used as a template.
- // map: Object|Function
- // If an object, it is used as a dictionary to look up substitutions.
- // If a function, it is called for every substitution with following
- // parameters: a whole match, a name, an offset, and the whole template
- // string (see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/replace
- // for more details).
- // pattern: RegEx?
- // Optional regular expression objects that overrides the default pattern.
- // Must be global and match one item. The default is: /\{([^\}]+)\}/g,
- // which matches patterns like that: "{xxx}", where "xxx" is any sequence
- // of characters, which doesn't include "}".
- // returns: String
- // Returns the substituted string.
- // example:
- // | // uses a dictionary for substitutions:
- // | dojo.replace("Hello, {name.first} {name.last} AKA {nick}!",
- // | {
- // | nick: "Bob",
- // | name: {
- // | first: "Robert",
- // | middle: "X",
- // | last: "Cringely"
- // | }
- // | });
- // | // returns: Hello, Robert Cringely AKA Bob!
- // example:
- // | // uses an array for substitutions:
- // | dojo.replace("Hello, {0} {2}!",
- // | ["Robert", "X", "Cringely"]);
- // | // returns: Hello, Robert Cringely!
- // example:
- // | // uses a function for substitutions:
- // | function sum(a){
- // | var t = 0;
- // | dojo.forEach(a, function(x){ t += x; });
- // | return t;
- // | }
- // | dojo.replace(
- // | "{count} payments averaging {avg} USD per payment.",
- // | dojo.hitch(
- // | { payments: [11, 16, 12] },
- // | function(_, key){
- // | switch(key){
- // | case "count": return this.payments.length;
- // | case "min": return Math.min.apply(Math, this.payments);
- // | case "max": return Math.max.apply(Math, this.payments);
- // | case "sum": return sum(this.payments);
- // | case "avg": return sum(this.payments) / this.payments.length;
- // | }
- // | }
- // | )
- // | );
- // | // prints: 3 payments averaging 13 USD per payment.
- // example:
- // | // uses an alternative PHP-like pattern for substitutions:
- // | dojo.replace("Hello, ${0} ${2}!",
- // | ["Robert", "X", "Cringely"], /\$\{([^\}]+)\}/g);
- // | // returns: Hello, Robert Cringely!
- return ""; // String
- }
- =====*/
-
- var _pattern = /\{([^\}]+)\}/g;
- dojo.replace = function(tmpl, map, pattern){
- return tmpl.replace(pattern || _pattern, d.isFunction(map) ?
- map : function(_, k){ return d.getObject(k, false, map); });
- };
-})();
-
-}
+//>>built
+define("dojo/_base/lang",["./kernel","../has","./sniff"],function(_1,_2){_2.add("bug-for-in-skips-shadowed",function(){for(var i in {toString:1}){return 0;}return 1;});var _3=_2("bug-for-in-skips-shadowed")?"hasOwnProperty.valueOf.isPrototypeOf.propertyIsEnumerable.toLocaleString.toString.constructor".split("."):[],_4=_3.length,_5=function(_6,_7,_8){var _9,s,i,_a={};for(_9 in _7){s=_7[_9];if(!(_9 in _6)||(_6[_9]!==s&&(!(_9 in _a)||_a[_9]!==s))){_6[_9]=_8?_8(s):s;}}if(_2("bug-for-in-skips-shadowed")){if(_7){for(i=0;i<_4;++i){_9=_3[i];s=_7[_9];if(!(_9 in _6)||(_6[_9]!==s&&(!(_9 in _a)||_a[_9]!==s))){_6[_9]=_8?_8(s):s;}}}}return _6;},_b=function(_c,_d){if(!_c){_c={};}for(var i=1,l=arguments.length;i<l;i++){_e._mixin(_c,arguments[i]);}return _c;},_f=function(_10,_11,_12){var p,i=0,_13=_1.global;if(!_12){if(!_10.length){return _13;}else{p=_10[i++];try{_12=_1.scopeMap[p]&&_1.scopeMap[p][1];}catch(e){}_12=_12||(p in _13?_13[p]:(_11?_13[p]={}:undefined));}}while(_12&&(p=_10[i++])){_12=(p in _12?_12[p]:(_11?_12[p]={}:undefined));}return _12;},_14=function(_15,_16,_17){var _18=_15.split("."),p=_18.pop(),obj=_f(_18,true,_17);return obj&&p?(obj[p]=_16):undefined;},_19=function(_1a,_1b,_1c){return _f(_1a.split("."),_1b,_1c);},_1d=function(_1e,obj){return _e.getObject(_1e,false,obj)!==undefined;},_1f=Object.prototype.toString,_20=function(it){return (typeof it=="string"||it instanceof String);},_21=function(it){return it&&(it instanceof Array||typeof it=="array");},_22=function(it){return _1f.call(it)==="[object Function]";},_23=function(it){return it!==undefined&&(it===null||typeof it=="object"||_e.isArray(it)||_e.isFunction(it));},_24=function(it){return it&&it!==undefined&&!_e.isString(it)&&!_e.isFunction(it)&&!(it.tagName&&it.tagName.toLowerCase()=="form")&&(_e.isArray(it)||isFinite(it.length));},_25=function(it){return it&&!_e.isFunction(it)&&/\{\s*\[native code\]\s*\}/.test(String(it));},_26=function(_27,_28){for(var i=1,l=arguments.length;i<l;i++){_e._mixin(_27.prototype,arguments[i]);}return _27;},_29=function(_2a,_2b){var pre=_2c(arguments,2);var _2d=_e.isString(_2b);return function(){var _2e=_2c(arguments);var f=_2d?(_2a||_1.global)[_2b]:_2b;return f&&f.apply(_2a||this,pre.concat(_2e));};},_2f=function(_30,_31){if(arguments.length>2){return _e._hitchArgs.apply(_1,arguments);}if(!_31){_31=_30;_30=null;}if(_e.isString(_31)){_30=_30||_1.global;if(!_30[_31]){throw (["dojo.hitch: scope[\"",_31,"\"] is null (scope=\"",_30,"\")"].join(""));}return function(){return _30[_31].apply(_30,arguments||[]);};}return !_30?_31:function(){return _31.apply(_30,arguments||[]);};},_32=(function(){function TMP(){};return function(obj,_33){TMP.prototype=obj;var tmp=new TMP();TMP.prototype=null;if(_33){_e._mixin(tmp,_33);}return tmp;};})(),_34=function(obj,_35,_36){return (_36||[]).concat(Array.prototype.slice.call(obj,_35||0));},_2c=_2("ie")?(function(){function _37(obj,_38,_39){var arr=_39||[];for(var x=_38||0;x<obj.length;x++){arr.push(obj[x]);}return arr;};return function(obj){return ((obj.item)?_37:_34).apply(this,arguments);};})():_34,_3a=function(_3b){var arr=[null];return _e.hitch.apply(_1,arr.concat(_e._toArray(arguments)));},_3c=function(src){if(!src||typeof src!="object"||_e.isFunction(src)){return src;}if(src.nodeType&&"cloneNode" in src){return src.cloneNode(true);}if(src instanceof Date){return new Date(src.getTime());}if(src instanceof RegExp){return new RegExp(src);}var r,i,l;if(_e.isArray(src)){r=[];for(i=0,l=src.length;i<l;++i){if(i in src){r.push(_3c(src[i]));}}}else{r=src.constructor?new src.constructor():{};}return _e._mixin(r,src,_3c);},_3d=String.prototype.trim?function(str){return str.trim();}:function(str){return str.replace(/^\s\s*/,"").replace(/\s\s*$/,"");},_3e=/\{([^\}]+)\}/g,_3f=function(_40,map,_41){return _40.replace(_41||_3e,_e.isFunction(map)?map:function(_42,k){return _19(k,false,map);});},_e={_extraNames:_3,_mixin:_5,mixin:_b,setObject:_14,getObject:_19,exists:_1d,isString:_20,isArray:_21,isFunction:_22,isObject:_23,isArrayLike:_24,isAlien:_25,extend:_26,_hitchArgs:_29,hitch:_2f,delegate:_32,_toArray:_2c,partial:_3a,clone:_3c,trim:_3d,replace:_3f};1&&_b(_1,_e);return _e;}); \ No newline at end of file