Changeset 2910

Show
Ignore:
Timestamp:
01/20/06 19:07:28 (3 years ago)
Author:
david
Message:

dojo core shake down + reorg
***WARNING*** this may break people!

Location:
trunk
Files:
12 added
32 modified
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/alg/Alg.js

    r1568 r2910  
    11dojo.provide("dojo.alg.Alg"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.array"); 
    33dj_deprecated("dojo.alg.Alg is deprecated, use dojo.lang instead"); 
    44 
    5 dojo.alg.find = function(arr, val){ return dojo.lang.find(arr, val); } 
    6  
    7 dojo.alg.inArray = function(arr, val){ 
    8         return dojo.lang.inArray(arr, val); 
    9 } 
    10 dojo.alg.inArr = dojo.alg.inArray; // for backwards compatibility 
    11  
    12 dojo.alg.getNameInObj = function(ns, item){ 
    13         return dojo.lang.getNameInObj(ns, item); 
    14 } 
    15  
    16 // is this the right place for this? 
    17 dojo.alg.has = function(obj, name){ 
    18         return dojo.lang.has(obj, name); 
    19 } 
    20  
    21 dojo.alg.forEach = function(arr, unary_func, fix_length){ 
    22         return dojo.lang.forEach(arr, unary_func, fix_length); 
    23 } 
     5dojo.alg = dojo.lang; 
    246 
    257dojo.alg.for_each = dojo.alg.forEach; // burst compat 
    268 
    27 dojo.alg.map = function(arr, obj, unary_func){ 
    28         return dojo.lang.map(arr, obj, unary_func); 
    29 } 
    30  
    31 dojo.alg.tryThese = function(){ 
    32         return dojo.lang.tryThese.apply(dojo.lang, arguments); 
    33 } 
    34  
    35 dojo.alg.delayThese = function(farr, cb, delay, onend){ 
    36         return dojo.lang.delayThese.apply(dojo.lang, arguments); 
    37 } 
    38  
    399dojo.alg.for_each_call = dojo.alg.map; // burst compat 
  • trunk/src/animation/Animation.js

    r2800 r2910  
    22dojo.provide("dojo.animation.Animation"); 
    33 
    4 dojo.require("dojo.lang"); 
     4dojo.require("dojo.lang.func"); 
    55dojo.require("dojo.math"); 
    66dojo.require("dojo.math.curves"); 
  • trunk/src/animation/Timer.js

    r2173 r2910  
    11dojo.provide("dojo.animation.Timer"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.func"); 
    33 
    44dojo.animation.Timer = function(intvl){ 
  • trunk/src/dnd/HtmlDragAndDrop.js

    r2883 r2910  
    99dojo.require("dojo.style"); 
    1010dojo.require("dojo.html"); 
    11 dojo.require("dojo.lang"); 
     11dojo.require("dojo.lang.extras"); 
    1212 
    1313dojo.dnd.HtmlDragSource = function(node, type){ 
  • trunk/src/dnd/HtmlDragManager.js

    r2865 r2910  
    11dojo.provide("dojo.dnd.HtmlDragManager"); 
    22dojo.require("dojo.event.*"); 
    3 dojo.require("dojo.lang"); 
     3dojo.require("dojo.lang.array"); 
    44dojo.require("dojo.html"); 
    55dojo.require("dojo.style"); 
  • trunk/src/dnd/TreeDragAndDrop.js

    r2897 r2910  
    1212 
    1313dojo.require("dojo.dnd.HtmlDragAndDrop"); 
     14dojo.require("dojo.lang.func"); 
     15dojo.require("dojo.lang.array"); 
     16dojo.require("dojo.lang.extras"); 
    1417 
    1518dojo.dnd.TreeDragSource = function(node, syncController, type, treeNode){ 
  • trunk/src/dom.js

    r2774 r2910  
    11dojo.provide("dojo.dom"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.array"); 
    33 
    44dojo.dom.ELEMENT_NODE                  = 1; 
     
    4848}; 
    4949 
    50 dojo.dom.isNode = dojo.lang.isDomNode = function(wh){ 
     50dojo.dom.isNode = function(wh){ 
    5151        if(typeof Element == "object") { 
    5252                try { 
     
    5858        } 
    5959} 
    60 dojo.lang.whatAmI.custom["node"] = dojo.dom.isNode; 
    6160 
    6261dojo.dom.getTagName = function(node){ 
  • trunk/src/event.js

    r2881 r2910  
    1 dojo.require("dojo.lang"); 
    21dojo.provide("dojo.event"); 
     2 
     3dojo.require("dojo.lang.array"); 
     4dojo.require("dojo.lang.extras"); 
    35 
    46dojo.event = new function(){ 
  • trunk/src/fx/html.js

    r2893 r2910  
    22 
    33dojo.require("dojo.style"); 
    4 dojo.require("dojo.lang"); 
     4dojo.require("dojo.lang.func"); 
    55dojo.require("dojo.animation.*"); 
    66dojo.require("dojo.event.*"); 
  • trunk/src/fx/svg.js

    r2516 r2910  
    22 
    33dojo.require("dojo.svg"); 
    4 dojo.require("dojo.lang"); 
    54dojo.require("dojo.animation.*"); 
    65dojo.require("dojo.event.*"); 
  • trunk/src/graphics/color.js

    r2893 r2910  
    11dojo.provide("dojo.graphics.color"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.array"); 
    33dojo.require("dojo.math"); 
    44 
  • trunk/src/hostenv_browser.js

    r2903 r2910  
    4848        if(((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&(document && document.getElementsByTagName)){ 
    4949                var scripts = document.getElementsByTagName("script"); 
    50                 var rePkg = /(__package__|dojo)\.js([\?\.]|$)/i; 
     50                var rePkg = /(__package__|dojo|bootstrap1)\.js([\?\.]|$)/i; 
    5151                for(var i = 0; i < scripts.length; i++) { 
    5252                        var src = scripts[i].getAttribute("src"); 
     
    5555                        if(m) { 
    5656                                root = src.substring(0, m.index); 
     57                                if(src.indexOf("bootstrap1") > -1) { root += "../"; } 
    5758                                if(!this["djConfig"]) { djConfig = {}; } 
    5859                                if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; } 
  • trunk/src/html.js

    r2893 r2910  
    11dojo.provide("dojo.html"); 
     2 
     3dojo.require("dojo.lang.func"); 
    24dojo.require("dojo.dom"); 
    35dojo.require("dojo.style"); 
    46dojo.require("dojo.string"); 
     7dojo.require("dojo.string.extras"); // only necessary until we move renderedTextContent 
    58dojo.require("dojo.uri.Uri"); 
    69 
  • trunk/src/io.js

    r2891 r2910  
    11dojo.provide("dojo.io.IO"); 
    22dojo.require("dojo.string"); 
     3dojo.require("dojo.lang.extras"); 
    34 
    45/****************************************************************************** 
  • trunk/src/io/BrowserIO.js

    r2884 r2910  
    22 
    33dojo.require("dojo.io"); 
    4 dojo.require("dojo.lang"); 
     4dojo.require("dojo.lang.array"); 
     5dojo.require("dojo.lang.func"); 
    56dojo.require("dojo.dom"); 
    67 
  • trunk/src/json.js

    r2890 r2910  
    11dojo.provide("dojo.json"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.func"); 
    33 
    44dojo.json = { 
  • trunk/src/lang.js

    r2854 r2910  
    11dojo.provide("dojo.lang"); 
    2 dojo.provide("dojo.AdapterRegistry"); 
    32dojo.provide("dojo.lang.Lang"); 
    43 
    5 dojo.lang.mixin = function(obj, props){ 
    6         var tobj = {}; 
    7         for(var x in props){ 
    8                 if(typeof tobj[x] == "undefined" || tobj[x] != props[x]) { 
    9                         obj[x] = props[x]; 
    10                 } 
    11         } 
    12         // IE doesn't recognize custom toStrings in for..in 
    13         if(dojo.render.html.ie && dojo.lang.isFunction(props["toString"]) && props["toString"] != obj["toString"]) { 
    14                 obj.toString = props.toString; 
    15         } 
    16         return obj; 
    17 } 
    18  
    19 dojo.lang.extend = function(ctor, props){ 
    20         this.mixin(ctor.prototype, props); 
    21 } 
    22  
    23 dojo.lang.extendPrototype = function(obj, props){ 
    24         this.extend(obj.constructor, props); 
    25 } 
    26  
    27 dojo.lang.anonCtr = 0; 
    28 dojo.lang.anon = {}; 
    29 dojo.lang.nameAnonFunc = function(anonFuncPtr, namespaceObj){ 
    30         var nso = (namespaceObj || dojo.lang.anon); 
    31         if((dj_global["djConfig"])&&(djConfig["slowAnonFuncLookups"] == true)){ 
    32                 for(var x in nso){ 
    33                         if(nso[x] === anonFuncPtr){ 
    34                                 return x; 
    35                         } 
    36                 } 
    37         } 
    38         var ret = "__"+dojo.lang.anonCtr++; 
    39         while(typeof nso[ret] != "undefined"){ 
    40                 ret = "__"+dojo.lang.anonCtr++; 
    41         } 
    42         nso[ret] = anonFuncPtr; 
    43         return ret; 
    44 } 
    45  
    46 /** 
    47  * Runs a function in a given scope (thisObject), can 
    48  * also be used to preserve scope. 
    49  * 
    50  * hitch(foo, "bar"); // runs foo.bar() in the scope of foo 
    51  * hitch(foo, myFunction); // runs myFunction in the scope of foo 
    52  */ 
    53 dojo.lang.hitch = function(thisObject, method) { 
    54         if(dojo.lang.isString(method)) { 
    55                 var fcn = thisObject[method]; 
    56         } else { 
    57                 var fcn = method; 
    58         } 
    59  
    60         return function() { 
    61                 return fcn.apply(thisObject, arguments); 
    62         } 
    63 } 
    64  
    65 dojo.lang.forward = function(funcName){ 
    66         // Returns a function that forwards a method call to this.func(...) 
    67         return function(){ 
    68                 return this[funcName].apply(this, arguments); 
    69         }; 
    70 } 
    71  
    72 dojo.lang.curry = function(ns, func /* args ... */){ 
    73         var outerArgs = []; 
    74         ns = ns||dj_global; 
    75         if(dojo.lang.isString(func)){ 
    76                 func = ns[func]; 
    77         } 
    78         for(var x=2; x<arguments.length; x++){ 
    79                 outerArgs.push(arguments[x]); 
    80         } 
    81         var ecount = func.length - outerArgs.length; 
    82         // borrowed from svend tofte 
    83         function gather(nextArgs, innerArgs, expected){ 
    84                 var texpected = expected; 
    85                 var totalArgs = innerArgs.slice(0); // copy 
    86                 for(var x=0; x<nextArgs.length; x++){ 
    87                         totalArgs.push(nextArgs[x]); 
    88                 } 
    89                 // check the list of provided nextArgs to see if it, plus the 
    90                 // number of innerArgs already supplied, meets the total 
    91                 // expected. 
    92                 expected = expected-nextArgs.length; 
    93                 if(expected<=0){ 
    94                         var res = func.apply(ns, totalArgs); 
    95                         expected = texpected; 
    96                         return res; 
    97                 }else{ 
    98                         return function(){ 
    99                                 return gather(arguments,// check to see if we've been run 
    100                                                                                 // with enough args 
    101                                                         totalArgs,      // a copy 
    102                                                         expected);      // how many more do we need to run?; 
    103                         } 
    104                 } 
    105         } 
    106         return gather([], outerArgs, ecount); 
    107 } 
    108  
    109 dojo.lang.curryArguments = function(ns, func, args, offset){ 
    110         var targs = []; 
    111         var x = offset||0; 
    112         for(x=offset; x<args.length; x++){ 
    113                 targs.push(args[x]); // ensure that it's an arr 
    114         } 
    115         return dojo.lang.curry.apply(dojo.lang, [ns, func].concat(targs)); 
    116 } 
    117  
    118 /** 
    119  * Sets a timeout in milliseconds to execute a function in a given context 
    120  * with optional arguments. 
    121  * 
    122  * setTimeout (Object context, function func, number delay[, arg1[, ...]]); 
    123  * setTimeout (function func, number delay[, arg1[, ...]]); 
    124  */ 
    125 dojo.lang.setTimeout = function(func, delay){ 
    126         var context = window, argsStart = 2; 
    127         if(!dojo.lang.isFunction(func)){ 
    128                 context = func; 
    129                 func = delay; 
    130                 delay = arguments[2]; 
    131                 argsStart++; 
    132         } 
    133  
    134         if(dojo.lang.isString(func)){ 
    135                 func = context[func]; 
    136         } 
    137          
    138         var args = []; 
    139         for (var i = argsStart; i < arguments.length; i++) { 
    140                 args.push(arguments[i]); 
    141         } 
    142         return setTimeout(function () { func.apply(context, args); }, delay); 
    143 } 
    144  
    145 /** 
    146  * Partial implmentation of is* functions from 
    147  * http://www.crockford.com/javascript/recommend.html 
    148  * NOTE: some of these may not be the best thing to use in all situations 
    149  * as they aren't part of core JS and therefore can't work in every case. 
    150  * See WARNING messages inline for tips. 
    151  * 
    152  * The following is* functions are fairly "safe" 
    153  */ 
    154  
    155 dojo.lang.isObject = function(wh) { 
    156         return typeof wh == "object" || dojo.lang.isArray(wh) || dojo.lang.isFunction(wh); 
    157 } 
    158  
    159 dojo.lang.isArray = function(wh) { 
    160         return (wh instanceof Array || typeof wh == "array"); 
    161 } 
    162  
    163 dojo.lang.isArrayLike = function(wh) { 
    164         if(dojo.lang.isString(wh)){ return false; } 
    165         if(dojo.lang.isFunction(wh)){ return false; } // keeps out built-in ctors (Number, String, ...) which have length properties 
    166         if(dojo.lang.isArray(wh)){ return true; } 
    167         if(typeof wh != "undefined" && wh 
    168                 && dojo.lang.isNumber(wh.length) && isFinite(wh.length)){ return true; } 
    169         return false; 
    170 } 
    171  
    172 dojo.lang.isFunction = function(wh) { 
    173         return (wh instanceof Function || typeof wh == "function"); 
    174 } 
    175  
    176 dojo.lang.isString = function(wh) { 
    177         return (wh instanceof String || typeof wh == "string"); 
    178 } 
    179  
    180 dojo.lang.isAlien = function(wh) { 
    181         return !dojo.lang.isFunction() && /\{\s*\[native code\]\s*\}/.test(String(wh)); 
    182 } 
    183  
    184 dojo.lang.isBoolean = function(wh) { 
    185         return (wh instanceof Boolean || typeof wh == "boolean"); 
    186 } 
    187  
    188 /** 
    189  * The following is***() functions are somewhat "unsafe". Fortunately, 
    190  * there are workarounds the the language provides and are mentioned 
    191  * in the WARNING messages. 
    192  * 
    193  * WARNING: In most cases, isNaN(wh) is sufficient to determine whether or not 
    194  * something is a number or can be used as such. For example, a number or string 
    195  * can be used interchangably when accessing array items (arr["1"] is the same as 
    196  * arr[1]) and isNaN will return false for both values ("1" and 1). Should you 
    197  * use isNumber("1"), that will return false, which is generally not too useful. 
    198  * Also, isNumber(NaN) returns true, again, this isn't generally useful, but there 
    199  * are corner cases (like when you want to make sure that two things are really 
    200  * the same type of thing). That is really where isNumber "shines". 
    201  * 
    202  * RECOMMENDATION: Use isNaN(wh) when possible 
    203  */ 
    204 dojo.lang.isNumber = function(wh) { 
    205         return (wh instanceof Number || typeof wh == "number"); 
    206 } 
    207  
    208 /** 
    209  * WARNING: In some cases, isUndefined will not behave as you 
    210  * might expect. If you do isUndefined(foo) and there is no earlier 
    211  * reference to foo, an error will be thrown before isUndefined is 
    212  * called. It behaves correctly if you scope yor object first, i.e. 
    213  * isUndefined(foo.bar) where foo is an object and bar isn't a 
    214  * property of the object. 
    215  * 
    216  * RECOMMENDATION: Use `typeof foo == "undefined"` when possible 
    217  * 
    218  * FIXME: Should isUndefined go away since it is error prone? 
    219  */ 
    220 dojo.lang.isUndefined = function(wh) { 
    221         return ((wh == undefined)&&(typeof wh == "undefined")); 
    222 } 
    223  
    224 // end Crockford functions 
    225  
    226 dojo.lang.whatAmI = function(wh) { 
    227         try { 
    228                 if(dojo.lang.isArray(wh)) { return "array"; } 
    229                 if(dojo.lang.isFunction(wh)) { return "function"; } 
    230                 if(dojo.lang.isString(wh)) { return "string"; } 
    231                 if(dojo.lang.isNumber(wh)) { return "number"; } 
    232                 if(dojo.lang.isBoolean(wh)) { return "boolean"; } 
    233                 if(dojo.lang.isAlien(wh)) { return "alien"; } 
    234                 if(dojo.lang.isUndefined(wh)) { return "undefined"; } 
    235                 // FIXME: should this go first? 
    236                 for(var name in dojo.lang.whatAmI.custom) { 
    237                         if(dojo.lang.whatAmI.custom[name](wh)) { 
    238                                 return name; 
    239                         } 
    240                 } 
    241                 if(dojo.lang.isObject(wh)) { return "object"; } 
    242         } catch(E) {} 
    243         return "unknown"; 
    244 } 
    245 /* 
    246  * dojo.lang.whatAmI.custom[typeName] = someFunction 
    247  * will return typeName is someFunction(wh) returns true 
    248  */ 
    249 dojo.lang.whatAmI.custom = {}; 
    250  
    251 /** 
    252  * Returns true for values that commonly represent numbers. 
    253  * 
    254  * Examples: 
    255  * <pre> 
    256  *   dojo.lang.isNumeric(3);                 // returns true 
    257  *   dojo.lang.isNumeric("3");               // returns true 
    258  *   dojo.lang.isNumeric(new Number(3));     // returns true 
    259  *   dojo.lang.isNumeric(new String("3"));   // returns true 
    260  * 
    261  *   dojo.lang.isNumeric(3/0);               // returns false 
    262  *   dojo.lang.isNumeric("foo");             // returns false 
    263  *   dojo.lang.isNumeric(new Number("foo")); // returns false 
    264  *   dojo.lang.isNumeric(false);             // returns false 
    265  *   dojo.lang.isNumeric(true);              // returns false 
    266  * </pre> 
    267  */ 
    268 dojo.lang.isNumeric = function(wh){ 
    269         return (!isNaN(wh) && isFinite(wh) && (wh != null) && 
    270                         !dojo.lang.isBoolean(wh) && !dojo.lang.isArray(wh)); 
    271 } 
    272  
    273 /** 
    274  * Returns true for any literal, and for any object that is an  
    275  * instance of a built-in type like String, Number, Boolean,  
    276  * Array, Function, or Error. 
    277  */ 
    278 dojo.lang.isBuiltIn = function(wh){ 
    279         return (dojo.lang.isArray(wh)           ||  
    280                         dojo.lang.isFunction(wh)        ||  
    281                         dojo.lang.isString(wh)          ||  
    282                         dojo.lang.isNumber(wh)          ||  
    283                         dojo.lang.isBoolean(wh)         ||  
    284                         (wh == null)                            ||  
    285                         (wh instanceof Error)           ||  
    286                         (typeof wh == "error") ); 
    287 } 
    288  
    289 /** 
    290  * Returns true for any object where the value of the  
    291  * property 'constructor' is 'Object'.   
    292  *  
    293  * Examples: 
    294  * <pre> 
    295  *   dojo.lang.isPureObject(new Object()); // returns true 
    296  *   dojo.lang.isPureObject({a: 1, b: 2}); // returns true 
    297  *  
    298  *   dojo.lang.isPureObject(new Date());   // returns false 
    299  *   dojo.lang.isPureObject([11, 2, 3]);   // returns false 
    300  * </pre> 
    301  */ 
    302 dojo.lang.isPureObject = function(wh){ 
    303         return ((wh != null) && dojo.lang.isObject(wh) && wh.constructor == Object); 
    304 } 
    305  
    306 /** 
    307  * Given a value and a datatype, this method returns true if the 
    308  * type of the value matches the datatype. The datatype parameter 
    309  * can be an array of datatypes, in which case the method returns 
    310  * true if the type of the value matches any of the datatypes. 
    311  * 
    312  * Examples: 
    313  * <pre> 
    314  *   dojo.lang.isOfType("foo", String);                // returns true 
    315  *   dojo.lang.isOfType(12345, Number);                // returns true 
    316  *   dojo.lang.isOfType(false, Boolean);               // returns true 
    317  *   dojo.lang.isOfType([6, 8], Array);                // returns true 
    318  *   dojo.lang.isOfType(dojo.lang.isOfType, Function); // returns true 
    319  *   dojo.lang.isOfType({foo: "bar"}, Object);         // returns true 
    320  *   dojo.lang.isOfType(new Date(), Date);             // returns true 
    321  *   dojo.lang.isOfType(xxxxx, Date);                  // returns true 
    322  * 
    323  *   dojo.lang.isOfType("foo", "string");                // returns true 
    324  *   dojo.lang.isOfType(12345, "number");                // returns true 
    325  *   dojo.lang.isOfType(false, "boolean");               // returns true 
    326  *   dojo.lang.isOfType([6, 8], "array");                // returns true 
    327  *   dojo.lang.isOfType(dojo.lang.isOfType, "function"); // returns true 
    328  *   dojo.lang.isOfType({foo: "bar"}, "object");         // returns true 
    329  *   dojo.lang.isOfType(xxxxx, "undefined");             // returns true 
    330  *   dojo.lang.isOfType(null, "null");                   // returns true 
    331  
    332  *   dojo.lang.isOfType("foo", [Number, String, Boolean]); // returns true 
    333  *   dojo.lang.isOfType(12345, [Number, String, Boolean]); // returns true 
    334  *   dojo.lang.isOfType(false, [Number, String, Boolean]); // returns true 
    335  *   dojo.lang.isOfType(xxxxx, "undefined");               // returns true 
    336  * </pre> 
    337  * 
    338  * @param       value   Any literal value or object instance. 
    339  * @param       type    A class of object, or a literal type, or the string name of a type, or an array with a list of types. 
    340  * @return      Returns a boolean 
    341  */ 
    342 dojo.lang.isOfType = function(value, type) { 
    343         if(dojo.lang.isArray(type)){ 
    344                 var arrayOfTypes = type; 
    345                 for(var i in arrayOfTypes){ 
    346                         var aType = arrayOfTypes[i]; 
    347                         if(dojo.lang.isOfType(value, aType)) { 
    348                                 return true; 
    349                         } 
    350                 } 
    351                 return false; 
    352         }else{ 
    353                 if(dojo.lang.isString(type)){ 
    354                         type = type.toLowerCase(); 
    355                 } 
    356                 switch (type) { 
    357                         case Array: 
    358                         case "array": 
    359                                 return dojo.lang.isArray(value); 
    360                                 break; 
    361                         case Function: 
    362                         case "function": 
    363                                 return dojo.lang.isFunction(value); 
    364                                 break; 
    365                         case String: 
    366                         case "string": 
    367                                 return dojo.lang.isString(value); 
    368                                 break; 
    369                         case Number: 
    370                         case "number": 
    371                                 return dojo.lang.isNumber(value); 
    372                                 break; 
    373                         case "numeric": 
    374                                 return dojo.lang.isNumeric(value); 
    375                                 break; 
    376                         case Boolean: 
    377                         case "boolean": 
    378                                 return dojo.lang.isBoolean(value); 
    379                                 break; 
    380                         case Object: 
    381                         case "object": 
    382                                 return dojo.lang.isObject(value); 
    383                                 break; 
    384                         case "pureobject": 
    385                                 return dojo.lang.isPureObject(value); 
    386                                 break; 
    387                         case "builtin": 
    388                                 return dojo.lang.isBuiltIn(value); 
    389                                 break; 
    390                         case "alien": 
    391                                 return dojo.lang.isAlien(value); 
    392                                 break; 
    393                         case "undefined": 
    394                                 return dojo.lang.isUndefined(value); 
    395                                 break; 
    396                         case null: 
    397                         case "null": 
    398                                 return (value === null); 
    399                                 break; 
    400                         case "optional": 
    401                                 return ((value === null) || dojo.lang.isUndefined(value)); 
    402                                 break; 
    403                         default: 
    404                                 if (dojo.lang.isFunction(type)) { 
    405                                         return (value instanceof type); 
    406                                 } else { 
    407                                         dojo.raise("dojo.lang.isOfType() was passed an invalid type"); 
    408                                 } 
    409                                 break; 
    410                 } 
    411         } 
    412         dojo.raise("If we get here, it means a bug was introduced above."); 
    413 } 
    414  
    415 // ------------------------------------------------------------------- 
    416 // Assertion methods 
    417 // ------------------------------------------------------------------- 
    418  
    419 /** 
    420  * Throws an exception if the assertion fails. 
    421  * 
    422  * If the asserted condition is true, this method does nothing. If the 
    423  * condition is false, we throw an error with a error message.   
    424  * 
    425  * @param       booleanValue    A boolean value, which needs to be true for the assertion to succeed. 
    426  * @param       message Optional. A string describing the assertion. 
    427  * @throws      Throws an Error if 'booleanValue' is false. 
    428  */ 
    429 dojo.lang.assert = function(booleanValue, message){ 
    430         if(!booleanValue){ 
    431                 var errorMessage = "An assert statement failed.\n" + 
    432                         "The method dojo.lang.assert() was called with a 'false' value.\n"; 
    433                 if(message){ 
    434                         errorMessage += "Here's the assert message:\n" + message + "\n"; 
    435                 } 
    436                 // Use throw instead of dojo.raise, until bug #264 is fixed: 
    437                 // dojo.raise(errorMessage); 
    438                 throw new Error(errorMessage); 
    439         } 
    440 } 
    441  
    442 /** 
    443  * Given a value and a data type, this method checks the type of the value 
    444  * to make sure it matches the data type, and throws an exception if there 
    445  * is a mismatch. 
    446  * 
    447  * Examples: 
    448  * <pre> 
    449  *   dojo.lang.assertType("foo", String); 
    450  *   dojo.lang.assertType(12345, Number); 
    451  *   dojo.lang.assertType(false, Boolean); 
    452  *   dojo.lang.assertType([6, 8], Array); 
    453  *   dojo.lang.assertType(dojo.lang.assertType, Function); 
    454  *   dojo.lang.assertType({foo: "bar"}, Object); 
    455  *   dojo.lang.assertType(new Date(), Date); 
    456  * </pre> 
    457  * 
    458  * @scope       public function 
    459  * @param       value   Any literal value or object instance. 
    460  * @param       type    A class of object, or a literal type, or the string name of a type, or an array with a list of types. 
    461  * @param       message Optional. A string describing the assertion. 
    462  * @throws      Throws an Error if 'value' is not of type 'type'. 
    463  */ 
    464 dojo.lang.assertType = function(value, type, message){ 
    465         if(!dojo.lang.isOfType(value, type)){ 
    466                 if(!message){ 
    467                         if(!dojo.lang.assertType._errorMessage){ 
    468                                 dojo.lang.assertType._errorMessage = "Type mismatch: dojo.lang.assertType() failed."; 
    469                         } 
    470                         message = dojo.lang.assertType._errorMessage; 
    471                 } 
    472                 dojo.lang.assert(false, message); 
    473         } 
    474 } 
    475  
    476 /** 
    477  * Given an anonymous object and a list of expected property names, this 
    478  * method check to make sure the object does not have any properties 
    479  * that aren't on the list of expected properties, and throws an Error 
    480  * if there are unexpected properties. This is useful for doing error 
    481  * checking on keyword arguments, to make sure there aren't typos. 
    482  * 
    483  * Examples: 
    484  * <pre> 
    485  *   dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b"]); 
    486  *   dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b", "c"]); 
    487  *   dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo"]); 
    488  *   dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo", "bar"]); 
    489  *   dojo.lang.assertValidKeywords({foo: "iggy"}, {foo: null, bar: null}); 
    490  * </pre> 
    491  * 
    492  * @scope       public function 
    493  * @param       object  An anonymous object. 
    494  * @param       expectedProperties      An array of strings (or an object with all the expected properties). 
    495  * @param       message Optional. A string describing the assertion. 
    496  * @throws      Throws an Error if 'value' is not of type 'type'. 
    497  */ 
    498 dojo.lang.assertValidKeywords = function(object, expectedProperties, message){ 
    499         var key; 
    500         if(!message){ 
    501                 if(!dojo.lang.assertValidKeywords._errorMessage){ 
    502                         dojo.lang.assertValidKeywords._errorMessage = "In dojo.lang.assertValidKeywords(), found invalid keyword:"; 
    503                 } 
    504                 message = dojo.lang.assertValidKeywords._errorMessage; 
    505         } 
    506         if(dojo.lang.isArray(expectedProperties)){ 
    507                 for(key in object){ 
    508                         if(!dojo.lang.inArray(expectedProperties, key)){ 
    509                                 dojo.lang.assert(false, message + " " + key); 
    510                         } 
    511                 } 
    512         }else{ 
    513                 for(key in object){ 
    514                         if(!(key in expectedProperties)){ 
    515                                 dojo.lang.assert(false, message + " " + key); 
    516                         } 
    517                 } 
    518         } 
    519 } 
    520  
    521 /** 
    522  * See if val is in arr. Call signatures: 
    523  *  find(array, value, identity) 
    524 *   find(value, array, identity) 
    525 **/ 
    526 dojo.lang.find = function(arr, val, identity){ 
    527         // support both (arr, val) and (val, arr) 
    528         if(!dojo.lang.isArrayLike(arr) && dojo.lang.isArrayLike(val)) { 
    529                 var a = arr; 
    530                 arr = val; 
    531                 val = a; 
    532         } 
    533         var isString = dojo.lang.isString(arr); 
    534         if(isString) { arr = arr.split(""); } 
    535         if(identity){ 
    536                 for(var i=0;i<arr.length;++i){ 
    537                         if(arr[i] === val){ return i; } 
    538                 } 
    539         }else{ 
    540                 for(var i=0;i<arr.length;++i){ 
    541                         if(arr[i] == val){ return i; } 
    542                 } 
    543         } 
    544         return -1; 
    545 } 
    546  
    547 dojo.lang.indexOf = dojo.lang.find; 
    548  
    549 dojo.lang.findLast = function(arr, val, identity) { 
    550         // support both (arr, val) and (val, arr) 
    551         if(!dojo.lang.isArrayLike(arr) && dojo.lang.isArrayLike(val)) { 
    552                 var a = arr; 
    553                 arr = val; 
    554                 val = a; 
    555         } 
    556         var isString = dojo.lang.isString(arr); 
    557         if(isString) { arr = arr.split(""); } 
    558         if(identity){ 
    559                 for(var i = arr.length-1; i >= 0; i--) { 
    560                         if(arr[i] === val){ return i; } 
    561                 } 
    562         }else{ 
    563                 for(var i = arr.length-1; i >= 0; i--) { 
    564                         if(arr[i] == val){ return i; } 
    565                 } 
    566         } 
    567         return -1; 
    568 } 
    569  
    570 dojo.lang.lastIndexOf = dojo.lang.findLast; 
    571  
    572 dojo.lang.inArray = function(arr, val){ 
    573         return dojo.lang.find(arr, val) > -1; 
    574 } 
    575  
    576 dojo.lang.getNameInObj = function(ns, item){ 
    577         if(!ns){ ns = dj_global; } 
    578  
    579         for(var x in ns){ 
    580                 if(ns[x] === item){ 
    581                         return new String(x); 
    582                 } 
    583         } 
    584         return null; 
    585 } 
    586  
    587 // FIXME: Is this worthless since you can do: if(name in obj) 
    588 // is this the right place for this? 
    589 dojo.lang.has = function(obj, name){ 
    590         return (typeof obj[name] !== 'undefined'); 
    591 } 
    592  
    593 dojo.lang.isEmpty = function(obj) { 
    594         if(dojo.lang.isObject(obj)) { 
    595                 var tmp = {}; 
    596                 var count = 0; 
    597                 for(var x in obj){ 
    598                         if(obj[x] && (!tmp[x])){ 
    599                                 count++; 
    600                                 break; 
    601                         }  
    602                 } 
    603                 return (count == 0); 
    604         } else if(dojo.lang.isArrayLike(obj) || dojo.lang.isString(obj)) { 
    605                 return obj.length == 0; 
    606         } 
    607 } 
    608  
    609 dojo.lang.forEach = function(arr, unary_func, fix_length){ 
    610         var isString = dojo.lang.isString(arr); 
    611         if(isString) { arr = arr.split(""); } 
    612         var il = arr.length; 
    613         for(var i=0; i< ((fix_length) ? il : arr.length); i++){ 
    614                 if(unary_func(arr[i], i, arr) == "break"){ 
    615                         break; 
    616                 } 
    617         } 
    618 } 
    619  
    620 dojo.lang.map = function(arr, obj, unary_func){ 
    621         var isString = dojo.lang.isString(arr); 
    622         if(isString){ 
    623                 arr = arr.split(""); 
    624         } 
    625         if(dojo.lang.isFunction(obj)&&(!unary_func)){ 
    626                 unary_func = obj; 
    627                 obj = dj_global; 
    628         }else if(dojo.lang.isFunction(obj) && unary_func){ 
    629                 // ff 1.5 compat 
    630                 var tmpObj = obj; 
    631                 obj = unary_func; 
    632                 unary_func = tmpObj; 
    633         } 
    634  
    635         if(Array.map){ 
    636                 var outArr = Array.map(arr, unary_func, obj); 
    637         }else{ 
    638                 var outArr = []; 
    639                 for(var i=0;i<arr.length;++i){ 
    640                         outArr.push(unary_func.call(obj, arr[i])); 
    641                 } 
    642         } 
    643  
    644         if(isString) { 
    645                 return outArr.join(""); 
    646         } else { 
    647                 return outArr; 
    648         } 
    649 } 
    650  
    651 dojo.lang.tryThese = function(){ 
    652         for(var x=0; x<arguments.length; x++){ 
    653                 try{ 
    654                         if(typeof arguments[x] == "function"){ 
    655                                 var ret = (arguments[x]()); 
    656                                 if(ret){ 
    657                                         return ret; 
    658                                 } 
    659                         } 
    660                 }catch(e){ 
    661                         dojo.debug(e); 
    662                 } 
    663         } 
    664 } 
    665  
    666 dojo.lang.delayThese = function(farr, cb, delay, onend){ 
    667         /** 
    668          * alternate: (array funcArray, function callback, function onend) 
    669          * alternate: (array funcArray, function callback) 
    670          * alternate: (array funcArray) 
    671          */ 
    672         if(!farr.length){  
    673                 if(typeof onend == "function"){ 
    674                         onend(); 
    675                 } 
    676                 return; 
    677         } 
    678         if((typeof delay == "undefined")&&(typeof cb == "number")){ 
    679                 delay = cb; 
    680                 cb = function(){}; 
    681         }else if(!cb){ 
    682                 cb = function(){}; 
    683                 if(!delay){ delay = 0; } 
    684         } 
    685         setTimeout(function(){ 
    686                 (farr.shift())(); 
    687                 cb(); 
    688                 dojo.lang.delayThese(farr, cb, delay, onend); 
    689         }, delay); 
    690 } 
    691  
    692 dojo.lang.shallowCopy = function(obj) { 
    693         var ret = {}, key; 
    694         for(key in obj) { 
    695                 if(dojo.lang.isUndefined(ret[key])) { 
    696                         ret[key] = obj[key]; 
    697                 } 
    698         } 
    699         return ret; 
    700 } 
    701  
    702 dojo.lang.every = function(arr, callback, thisObject) { 
    703         var isString = dojo.lang.isString(arr); 
    704         if(isString) { arr = arr.split(""); } 
    705         if(Array.every) { 
    706                 return Array.every(arr, callback, thisObject); 
    707         } else { 
    708                 if(!thisObject) { 
    709                         if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); } 
    710                         thisObject = dj_global; 
    711                 } 
    712  
    713                 for(var i = 0; i < arr.length; i++) { 
    714                         if(!callback.call(thisObject, arr[i], i, arr)) { 
    715                                 return false; 
    716                         } 
    717                 } 
    718                 return true; 
    719         } 
    720 } 
    721  
    722 dojo.lang.some = function(arr, callback, thisObject) { 
    723         var isString = dojo.lang.isString(arr); 
    724         if(isString) { arr = arr.split(""); } 
    725         if(Array.some) { 
    726                 return Array.some(arr, callback, thisObject); 
    727         } else { 
    728                 if(!thisObject) { 
    729                         if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); } 
    730                         thisObject = dj_global; 
    731                 } 
    732  
    733                 for(var i = 0; i < arr.length; i++) { 
    734                         if(callback.call(thisObject, arr[i], i, arr)) { 
    735                                 return true; 
    736                         } 
    737                 } 
    738                 return false; 
    739         } 
    740 } 
    741  
    742 dojo.lang.filter = function(arr, callback, thisObject) { 
    743         var isString = dojo.lang.isString(arr); 
    744         if(isString) { arr = arr.split(""); } 
    745         if(Array.filter) { 
    746                 var outArr = Array.filter(arr, callback, thisObject); 
    747         } else { 
    748                 if(!thisObject) { 
    749                         if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); } 
    750                         thisObject = dj_global; 
    751                 } 
    752  
    753                 var outArr = []; 
    754                 for(var i = 0; i < arr.length; i++) { 
    755                         if(callback.call(thisObject, arr[i], i, arr)) { 
    756                                 outArr.push(arr[i]); 
    757                         } 
    758                 } 
    759         } 
    760         if(isString) { 
    761                 return outArr.join(""); 
    762         } else { 
    763                 return outArr; 
    764         } 
    765 } 
    766  
    767 dojo.AdapterRegistry = function(){ 
    768     /*** 
    769         A registry to facilitate adaptation. 
    770  
    771         Pairs is an array of [name, check, wrap] triples 
    772          
    773         All check/wrap functions in this registry should be of the same arity. 
    774     ***/ 
    775     this.pairs = []; 
    776 } 
    777  
    778 dojo.lang.extend(dojo.AdapterRegistry, { 
    779     register: function (name, check, wrap, /* optional */ override){ 
    780         /*** 
    781                         The check function should return true if the given arguments are 
    782                         appropriate for the wrap function. 
    783  
    784                         If override is given and true, the check function will be given 
    785                         highest priority.  Otherwise, it will be the lowest priority 
    786                         adapter. 
    787         ***/ 
    788  
    789         if (override) { 
    790             this.pairs.unshift([name, check, wrap]); 
    791         } else { 
    792             this.pairs.push([name, check, wrap]); 
    793         } 
    794     }, 
    795  
    796     match: function (/* ... */) { 
    797         /*** 
    798                         Find an adapter for the given arguments. 
    799  
    800                         If no suitable adapter is found, throws NotFound. 
    801         ***/ 
    802         for(var i = 0; i < this.pairs.length; i++){ 
    803             var pair = this.pairs[i]; 
    804             if(pair[1].apply(this, arguments)){ 
    805                 return pair[2].apply(this, arguments); 
    806             } 
    807         } 
    808                 throw new Error("No match found"); 
    809         // dojo.raise("No match found"); 
    810     }, 
    811  
    812     unregister: function (name) { 
    813         /*** 
    814                         Remove a named adapter from the registry 
    815         ***/ 
    816         for(var i = 0; i < this.pairs.length; i++){ 
    817             var pair = this.pairs[i]; 
    818             if(pair[0] == name){ 
    819                 this.pairs.splice(i, 1); 
    820                 return true; 
    821             } 
    822         } 
    823         return false; 
    824     } 
    825 }); 
    826  
    827 dojo.lang.reprRegistry = new dojo.AdapterRegistry(); 
    828 dojo.lang.registerRepr = function(name, check, wrap, /*optional*/ override){ 
    829         /*** 
    830                         Register a repr function.  repr functions should take 
    831                         one argument and return a string representation of it 
    832                         suitable for developers, primarily used when debugging. 
    833  
    834                         If override is given, it is used as the highest priority 
    835                         repr, otherwise it will be used as the lowest. 
    836         ***/ 
    837         dojo.lang.reprRegistry.register(name, check, wrap, override); 
    838     }; 
    839  
    840 dojo.lang.repr = function(obj){ 
    841         /*** 
    842                 Return a "programmer representation" for an object 
    843         ***/ 
    844         if(typeof(obj) == "undefined"){ 
    845                 return "undefined"; 
    846         }else if(obj === null){ 
    847                 return "null"; 
    848         } 
    849  
    850         try{ 
    851                 if(typeof(obj["__repr__"]) == 'function'){ 
    852                         return obj["__repr__"](); 
    853                 }else if((typeof(obj["repr"]) == 'function')&&(obj.repr != arguments.callee)){ 
    854                         return obj["repr"](); 
    855                 } 
    856                 return dojo.lang.reprRegistry.match(obj); 
    857         }catch(e){ 
    858                 if(typeof(obj.NAME) == 'string' && ( 
    859                                 obj.toString == Function.prototype.toString || 
    860                                 obj.toString == Object.prototype.toString 
    861                         )){ 
    862                         return o.NAME; 
    863                 } 
    864         } 
    865  
    866         if(typeof(obj) == "function"){ 
    867                 obj = (obj + "").replace(/^\s+/, ""); 
    868                 var idx = obj.indexOf("{"); 
    869                 if(idx != -1){ 
    870                         obj = obj.substr(0, idx) + "{...}"; 
    871                 } 
    872         } 
    873         return obj + ""; 
    874 } 
    875  
    876 dojo.lang.reprArrayLike = function(arr){ 
    877         try{ 
    878                 var na = dojo.lang.map(arr, dojo.lang.repr); 
    879                 return "[" + na.join(", ") + "]"; 
    880         }catch(e){ } 
    881 }; 
    882  
    883 dojo.lang.reprString = function(str){  
    884         return ('"' + str.replace(/(["\\])/g, '\\$1') + '"' 
    885                 ).replace(/[\f]/g, "\\f" 
    886                 ).replace(/[\b]/g, "\\b" 
    887                 ).replace(/[\n]/g, "\\n" 
    888                 ).replace(/[\t]/g, "\\t" 
    889                 ).replace(/[\r]/g, "\\r"); 
    890 }; 
    891  
    892 dojo.lang.reprNumber = function(num){ 
    893         return num + ""; 
    894 }; 
    895  
    896 (function(){ 
    897         var m = dojo.lang; 
    898         m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike); 
    899         m.registerRepr("string", m.isString, m.reprString); 
    900         m.registerRepr("numbers", m.isNumber, m.reprNumber); 
    901         m.registerRepr("boolean", m.isBoolean, m.reprNumber); 
    902         // m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber); 
    903 })(); 
    904  
    905 /** 
    906  * Creates a 1-D array out of all the arguments passed, 
    907  * unravelling any array-like objects in the process 
    908  * 
    909  * Ex: 
    910  * unnest(1, 2, 3) ==> [1, 2, 3] 
    911  * unnest(1, [2, [3], [[[4]]]]) ==> [1, 2, 3, 4] 
    912  */ 
    913 dojo.lang.unnest = function(/* ... */) { 
    914         var out = []; 
    915         for(var i = 0; i < arguments.length; i++) { 
    916                 if(dojo.lang.isArrayLike(arguments[i])) { 
    917                         var add = dojo.lang.unnest.apply(this, arguments[i]); 
    918                         out = out.concat(add); 
    919                 } else { 
    920                         out.push(arguments[i]); 
    921                 } 
    922         } 
    923         return out; 
    924 } 
    925  
    926 /** 
    927  * Return the first argument that isn't undefined 
    928  */ 
    929 dojo.lang.firstValued = function(/* ... */) { 
    930         for(var i = 0; i < arguments.length; i++) { 
    931                 if(typeof arguments[i] != "undefined") { 
    932                         return arguments[i]; 
    933                 } 
    934         } 
    935         return undefined; 
    936 } 
    937  
    938 /** 
    939  * Converts an array-like object (i.e. arguments, DOMCollection) 
    940  * to an array 
    941 **/ 
    942 dojo.lang.toArray = function(arrayLike, startOffset) { 
    943         var array = []; 
    944         for(var i = startOffset||0; i < arrayLike.length; i++) { 
    945                 array.push(arrayLike[i]); 
    946         } 
    947         return array; 
    948 } 
     4dojo.require("dojo.lang.common"); 
  • trunk/src/lang/__package__.js

    r1568 r2910  
    11dojo.hostenv.conditionalLoadModule({ 
    2         common: ["dojo.lang"] 
     2        common: [ 
     3                "dojo.lang", 
     4                "dojo.lang.common", 
     5                "dojo.lang.assert", 
     6                "dojo.lang.array", 
     7                "dojo.lang.type", 
     8                "dojo.lang.func", 
     9                "dojo.lang.extras", 
     10                "dojo.lang.repr" 
     11        ] 
    312}); 
    413dojo.hostenv.moduleLoaded("dojo.lang.*"); 
  • trunk/src/rpc/Deferred.js

    r2703 r2910  
    11dojo.provide("dojo.rpc.Deferred"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.func"); 
    33 
    44dojo.rpc.Deferred = function(/* optional */ canceller){ 
  • trunk/src/rpc/RpcService.js

    r2833 r2910  
    22dojo.require("dojo.io.*"); 
    33dojo.require("dojo.json"); 
    4 dojo.require("dojo.lang"); 
     4dojo.require("dojo.lang.func"); 
    55dojo.require("dojo.rpc.Deferred"); 
    66 
  • trunk/src/selection.js

    r2812 r2910  
    11dojo.provide("dojo.selection"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.array"); 
     3dojo.require("dojo.lang.func"); 
    34dojo.require("dojo.math"); 
    45 
  • trunk/src/string/extras.js

    r2908 r2910  
    11dojo.provide("dojo.string.extras"); 
    22 
    3 dojo.require("dojo.string"); 
     3dojo.require("dojo.string.common"); 
    44dojo.require("dojo.lang"); 
    55 
  • trunk/src/widget/Editor.js

    r2845 r2910  
    99dojo.require("dojo.widget.RichText"); 
    1010dojo.require("dojo.widget.ColorPalette"); 
     11dojo.require("dojo.string.extras"); 
    1112 
    1213dojo.widget.tags.addParseTreeHandler("dojo:Editor"); 
  • trunk/src/widget/html/Button2.js

    r2834 r2910  
    11dojo.provide("dojo.widget.html.Button2"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.extras"); 
    33dojo.require("dojo.html"); 
    44dojo.require("dojo.style"); 
  • trunk/src/widget/html/LayoutPane.js

    r2773 r2910  
    11dojo.provide("dojo.widget.LayoutPane"); 
    22dojo.provide("dojo.widget.html.LayoutPane"); 
     3dojo.require("dojo.string.extras"); 
    34 
    45// 
  • trunk/src/widget/HtmlWidget.js

    r2902 r2910  
    22dojo.require("dojo.widget.DomWidget"); 
    33dojo.require("dojo.html"); 
     4dojo.require("dojo.lang.extras"); 
     5dojo.require("dojo.lang.func"); 
    46 
    57dojo.widget.HtmlWidget = function(args){ 
  • trunk/src/widget/Manager.js

    r2888 r2910  
    11dojo.provide("dojo.widget.Manager"); 
    2 dojo.require("dojo.lang"); 
     2dojo.require("dojo.lang.array"); 
    33dojo.require("dojo.event.*"); 
    44 
  • trunk/src/widget/Widget.js

    r2909 r2910  
    22dojo.provide("dojo.widget.tags"); 
    33 
    4 dojo.require("dojo.lang"); 
     4dojo.require("dojo.lang.func"); 
     5dojo.require("dojo.lang.array"); 
    56dojo.require("dojo.widget.Manager"); 
    67dojo.require("dojo.event.*"); 
  • trunk/tests/fx/test_fx.html

    r2841 r2910  
    6464<script type="text/javascript" src="../../src/fx/html.js"></script> 
    6565<script type="text/javascript"> 
    66 dojo.require("dojo.html"); 
    6766dojo.require("dojo.fx.*"); 
    6867 
  • trunk/tests/io/test_BrowserIO.method.html

    r2330 r2910  
    1717 
    1818        dojo.require("dojo.io.*"); 
     19        dojo.require("dojo.io.IframeIO"); 
    1920        dojo.require("dojo.event.*"); 
    2021 
  • trunk/tests/lang/test_lang.html

    r2880 r2910  
    1111                <script type="text/javascript" src="../jsunit_browser.js"></script> 
    1212                <script type="text/javascript" src="test_lang.js"></script> 
     13                <script type="text/javascript" src="test_array.js"></script> 
     14                <script type="text/javascript" src="test_assert.js"></script> 
     15                <script type="text/javascript" src="test_type.js"></script> 
    1316                <script type="text/javascript"> 
    1417                        dojo.require("dojo.lang.*"); 
     
    1720                                test_lang_mixin(); 
    1821                                test_lang_extend(); 
    19                                 test_lang_extendPrototype(); 
    20                                 test_lang_setTimeout(); 
    2122                                test_lang_isObject(); 
    2223                                test_lang_isArray(); 
  • trunk/tests/lang/test_lang.js

    r2880 r2910  
    2626        jum.assertEquals("20", "function", typeof test["foo"]); 
    2727        jum.assertEquals("21", "string", typeof test["bar"]); 
    28 } 
    29  
    30 function test_lang_extendPrototype(){ 
    31         var src = { 
    32                 foo: function(){ 
    33                         jum.debug("foo"); 
    34                 }, 
    35                 bar: "bar" 
    36         }; 
    37         function dest(){}; 
    38         dojo.lang.extendPrototype(dest.prototype, src); 
    39         var test = new dest(); 
    40         jum.assertEquals("30", "function", typeof test["foo"]); 
    41         jum.assertEquals("31", "string", typeof test["bar"]); 
    42 } 
    43  
    44 function test_lang_setTimeout(){ 
    45         jum.debug("cannot test setTimeout in a pure Rhino envionment"); 
    4628} 
    4729 
     
    10486        jum.assertFalse("94", dojo.lang.isUndefined(undef3)); 
    10587} 
    106  
    107 function test_lang_isNumeric() { 
    108         var number365 = new Number(365); 
    109         var numberFoo = new Number("foo"); 
    110         var string365 = new String("365"); 
    111         var stringFoo = new String("foo"); 
    112         var booleanFalse = new Boolean(false); 
    113         var error = new Error(); 
    114         var undef; // undefined 
    115  
    116         jum.assertTrue("100", dojo.lang.isNumeric(12345)); 
    117         jum.assertTrue("101", dojo.lang.isNumeric("12345")); 
    118         jum.assertTrue("102", dojo.lang.isNumeric(number365)); 
    119         jum.assertTrue("103", dojo.lang.isNumeric(string365)); 
    120  
    121         jum.assertFalse("110", dojo.lang.isNumeric(3/0)); 
    122         jum.assertFalse("111", dojo.lang.isNumeric("foo")); 
    123         jum.assertFalse("112", dojo.lang.isNumeric(numberFoo)); 
    124         jum.assertFalse("113", dojo.lang.isNumeric(false)); 
    125         jum.assertFalse("114", dojo.lang.isNumeric(true)); 
    126         jum.assertFalse("115", dojo.lang.isNumeric(stringFoo)); 
    127         jum.assertFalse("116", dojo.lang.isNumeric(null)); 
    128         jum.assertFalse("117", dojo.lang.isNumeric(undef)); 
    129         jum.assertFalse("118", dojo.lang.isNumeric([])); 
    130         jum.assertFalse("119", dojo.lang.isNumeric(error)); 
    131         // dojo.log.debug("leaving test_lang_isNumeric()"); 
    132 } 
    133  
    134 function test_lang_isPureObject() { 
    135         var undef; // undefined 
    136  
    137         jum.assertTrue("120", dojo.lang.isPureObject(new Object())); 
    138         jum.assertTrue("120", dojo.lang.isPureObject({a: 1, b: 2})); 
    139  
    140         jum.assertFalse("121", dojo.lang.isPureObject([1, 2])); 
    141         jum.assertFalse("122", dojo.lang.isPureObject(new Number(365))); 
    142         jum.assertFalse("123", dojo.lang.isPureObject(new String("foo"))); 
    143         jum.assertFalse("124", dojo.lang.isPureObject(test_lang_isPureObject)); 
    144         jum.assertFalse("125", dojo.lang.isPureObject(new Boolean(true))); 
    145         jum.assertFalse("126", dojo.lang.isPureObject(365)); 
    146         jum.assertFalse("127", dojo.lang.isPureObject("foo")); 
    147         jum.assertFalse("128", dojo.lang.isPureObject(true)); 
    148         jum.assertFalse("129", dojo.lang.isPureObject(null)); 
    149         jum.assertFalse("130", dojo.lang.isPureObject(undef)); 
    150         jum.assertFalse("131", dojo.lang.isPureObject(new Error())); 
    151         // dojo.log.debug("leaving test_lang_isPureObject()"); 
    152 } 
    153  
    154 function test_lang_isOfType() { 
    155         var number365 = new Number(365); 
    156         var stringFoo = new String("foo"); 
    157         var booleanFalse = new Boolean(false); 
    158         var undef; // undefined 
    159  
    160         jum.assertTrue("200", dojo.lang.isOfType("foo", String)); 
    161         jum.assertTrue("201", dojo.lang.isOfType(12345, Number)); 
    162         jum.assertTrue("202", dojo.lang.isOfType(false, Boolean)); 
    163         jum.assertTrue("203", dojo.lang.isOfType([6, 8], Array)); 
    164         jum.assertTrue("204", dojo.lang.isOfType(dojo.lang.isOfType, Function)); 
    165         jum.assertTrue("205", dojo.lang.isOfType({foo: "bar"}, Object)); 
    166         jum.assertTrue("206", dojo.lang.isOfType(new Date(), Date)); 
    167         jum.assertTrue("207", dojo.lang.isOfType(number365, Number)); 
    168         jum.assertTrue("208", dojo.lang.isOfType(stringFoo, String)); 
    169         jum.assertTrue("209", dojo.lang.isOfType(booleanFalse, Boolean)); 
    170  
    171         jum.assertTrue("210", dojo.lang.isOfType("foo", "string")); 
    172         jum.assertTrue("211", dojo.lang.isOfType(12345, "number")); 
    173         jum.assertTrue("212", dojo.lang.isOfType(false, "boolean")); 
    174         jum.assertTrue("213", dojo.lang.isOfType([6, 8], "array")); 
    175         jum.assertTrue("214", dojo.lang.isOfType(dojo.lang.isOfType, "function")); 
    176         jum.assertTrue("215", dojo.lang.isOfType({foo: "bar"}, "object")); 
    177         jum.assertTrue("216", dojo.lang.isOfType(undef, "undefined")); 
    178         jum.assertTrue("217", dojo.lang.isOfType(number365, "number")); 
    179         jum.assertTrue("218", dojo.lang.isOfType(stringFoo, "string")); 
    180         jum.assertTrue("219", dojo.lang.isOfType(booleanFalse, "boolean")); 
    181  
    182         jum.assertTrue("220", dojo.lang.isOfType("foo", [Number, String, Boolean])); 
    183         jum.assertTrue("221", dojo.lang.isOfType(12345, [Number, String, Boolean])); 
    184         jum.assertTrue("222", dojo.lang.isOfType(false, [Number, String, Boolean])); 
    185  
    186         jum.assertTrue("223", dojo.lang.isOfType("foo", ["number", String, "boolean"])); 
    187         jum.assertTrue("224", dojo.lang.isOfType(12345, ["number", String, Boolean])); 
    188         jum.assertTrue("225", dojo.lang.isOfType(false, ["number", "string", "boolean"])); 
    189  
    190         jum.assertTrue("226", dojo.lang.isOfType(undef, ["number", "undefined"])); 
    191         jum.assertTrue("227", dojo.lang.isOfType(undef, ["number", "optional"])); 
    192         jum.assertTrue("228", dojo.lang.isOfType(12345, ["number", "optional"])); 
    193  
    194         jum.assertFalse("230", dojo.lang.isOfType(undef, String)); 
    195         jum.assertFalse("231", dojo.lang.isOfType(undef, Number)); 
    196         jum.assertFalse("232", dojo.lang.isOfType(undef, [Boolean])); 
    197         jum.assertFalse("233", dojo.lang.isOfType(undef, Array)); 
    198         jum.assertFalse("234", dojo.lang.isOfType(undef, Function)); 
    199         jum.assertFalse("235", dojo.lang.isOfType(undef, Object)); 
    200         jum.assertFalse("236", dojo.lang.isOfType(undef, Date)); 
    201         jum.assertFalse("237", dojo.lang.isOfType(undef, [String, Number, Boolean])); 
    202         jum.assertFalse("238", dojo.lang.isOfType(undef, "string")); 
    203         jum.assertFalse("239", dojo.lang.isOfType(undef, ["string", "number"])); 
    204  
    205         jum.assertFalse("240", dojo.lang.isOfType(12345, String)); 
    206         jum.assertFalse("241", dojo.lang.isOfType("foo", "numeric")); 
    207         jum.assertFalse("242", dojo.lang.isOfType(12345, Boolean)); 
    208         jum.assertFalse("243", dojo.lang.isOfType(false, [Array])); 
    209         jum.assertFalse("244", dojo.lang.isOfType(new Date(), Function)); 
    210         jum.assertFalse("245", dojo.lang.isOfType("foo", Object)); 
    211         jum.assertFalse("246", dojo.lang.isOfType([6, 8], Date)); 
    212         jum.assertFalse("247", dojo.lang.isOfType([6, 8], [String, Number, Boolean])); 
    213         jum.assertFalse("248", dojo.lang.isOfType(12345, "string")); 
    214         jum.assertFalse("249", dojo.lang.isOfType(true, "string")); 
    215         jum.assertFalse("250", dojo.lang.isOfType({foo: "bar"}, ["string", "number"])); 
    216         jum.assertFalse("251", dojo.lang.isOfType(number365, "pureobject")); 
    217         jum.assertFalse("252", dojo.lang.isOfType(stringFoo, "pureobject")); 
    218         jum.assertFalse("253", dojo.lang.isOfType(booleanFalse, "pureobject")); 
    219         jum.assertFalse("254", dojo.lang.isOfType([], "numeric")); 
    220  
    221         // dojo.log.debug("leaving test_lang_isOfType()"); 
    222 } 
    223  
    224 function test_lang_isOfTypeToo() { 
    225         var allTypes = [ 
    226                 String, Number, Boolean, Array, Function, Object, null, 
    227                 "string", "number", "boolean", "array", "function", "object", "null", 
    228                 "numeric", "pureobject", "undefined", "optional", Date, Error]; 
    229         var number365 = new Number(365); 
    230         var string365 = new String("365"); 
    231         var numberFoo = new Number("foo"); 
    232         var stringFoo = new String("foo"); 
    233         var booleanTrue = new Boolean(true); 
    234         var booleanFalse = new Boolean(false); 
    235         var error = new Error(); 
    236         var IggyClass = function() {}; 
    237         IggyClass.prototype.valueOf = function() { return 3; }; 
    238         var obj = {a: 1, b: 2}; // obj.undef is undefined 
    239         var iggyInstace = new IggyClass(); 
    240  
    241         var examples = [ 
    242                 {value: "foo",             types: [String, "string"]}, 
    243                 {value: stringFoo,         types: [String, "string", Object, "object"]}, 
    244                 {value: numberFoo,         types: [Number, "number", Object, "object"]}, 
    245                 {value: number365,         types: [Number, "number", "numeric", Object, "object"]}, 
    246                 {value: 365,               types: [Number, "number", "numeric"]}, 
    247                 {value: "365",             types: [String, "string", "numeric"]}, 
    248                 {value: string365,         types: [String, "string", "numeric", Object, "object"]}, 
    249                 {value: true,              types: [Boolean, "boolean"]}, 
    250                 {value: false,             types: [Boolean, "boolean"]}, 
    251                 {value: booleanTrue,       types: [Boolean, "boolean", Object, "object"]}, 
    252                 {value: booleanFalse,      types: [Boolean, "boolean", Object, "object"]}, 
    253                 {value: [],                types: [Array, "array", Object, "object"]}, 
    254                 {value: [1, 2, obj],       types: [Array, "array", Object, "object"]}, 
    255                 {value: dojo.lang.indexOf, types: [Function, "function", Object, "object"]}, 
    256                 {value: parseInt,          types: [Function, "function", Object, "object"]}, 
    257                 {value: Math.sin,          types: [Function, "function", Object, "object"]}, 
    258                 {value: obj,               types: [Object, "object", "pureobject"]}, 
    259                 {value: dojo.lang,         types: [Object, "object", "pureobject"]}, 
    260                 {value: Math,              types: [Object, "object", "pureobject"]}, 
    261                 {value: null,              types: [null, "null", Object, "object", "optional"]}, 
    262                 {value: error,             types: [Error, Object, "object"]}, 
    263                 {value: obj.undef,         types: ["undefined", "optional"]}, 
    264                 {value: iggyInstace,       types: [Object, "object", "numeric"]} 
    265         ]; 
    266          
    267         for (var i in examples) { 
    268                 var example = examples[i]; 
    269                 var value = example.value; 
    270                 var matchingTypes = example.types; 
    271                  
    272                 var whatAmIResult = dojo.lang.whatAmI(value); 
    273                 jum.assertTrue("300: " + i, dojo.lang.isOfType(value, whatAmIResult)); 
    274                  
    275                 for (var j in matchingTypes) { 
    276                         var matchingType = matchingTypes[j]; 
    277                         jum.assertTrue("301", dojo.lang.isOfType(value, matchingType)); 
    278                         jum.assertTrue("302", dojo.lang.isOfType(value, [Number, matchingType, String])); 
    279                         jum.assertTrue("303", dojo.lang.isOfType(value, [matchingType, "optional"])); 
    280                 } 
    281                 for (var k in allTypes) { 
    282                         var possibleType = allTypes[k]; 
    283                         if (!dojo.lang.inArray(matchingTypes, possibleType)) { 
    284                                 var nonMatchingType = possibleType; 
    285                                 jum.assertFalse("310:" + i + " " + k, dojo.lang.isOfType(value, nonMatchingType)); 
    286                         } 
    287                 } 
    288         } 
    289          
    290          
    291         // dojo.log.debug("leaving test_lang_isOfTypeToo()"); 
    292 } 
    293  
    294 function test_lang_assert() { 
    295         dojo.lang.assert(true); 
    296         dojo.lang.assert(true, "400"); 
    297         dojo.lang.assert((1 == 1), "401"); 
    298         dojo.lang.assert("not a boolean value", "402"); 
    299         dojo.lang.assert(28, "403"); 
    300  
    301         var caught404 = false; 
    302         try { 
    303                 dojo.lang.assert(false, "404"); 
    304         } catch (e) { 
    305                 caught404 = true; 
    306         } 
    307         jum.assertTrue("404", caught404); 
    308         // dojo.log.debug("leaving test_lang_assert()"); 
    309 } 
    310  
    311 function test_lang_assertType() { 
    312         dojo.lang.assertType("foo", String, "410"); 
    313         dojo.lang.assertType(12345, Number, "411"); 
    314         dojo.lang.assertType(false, Boolean, "412"); 
    315         dojo.lang.assertType([6, 8], Array, "413"); 
    316         dojo.lang.assertType(dojo.lang.assertType, Function, "414"); 
    317         dojo.lang.assertType({foo: "bar"}, Object, "415"); 
    318         dojo.lang.assertType(new Date(), Date, "416"); 
    319         dojo.lang.assertType(new Error(), Error, "417"); 
    320         dojo.lang.assertType([6, 8], ["array", "optional"], "418"); 
    321         dojo.lang.assertType(null, ["array", "optional"], "419"); 
    322  
    323         var caught430 = false; 
    324         try { 
    325                 dojo.lang.assertType(12345, Boolean, "430"); 
    326         } catch (e) { 
    327                 caught430 = true; 
    328         } 
    329         jum.assertTrue("430", caught430); 
    330  
    331         var caught431 = false; 
    332         try { 
    333                 dojo.lang.assertType("foo", [Number, Boolean, Object], "431"); 
    334         } catch (e) { 
    335                 caught431 = true; 
    336         } 
    337         jum.assertTrue("431", caught431); 
    338         // dojo.log.debug("leaving test_lang_assertType()"); 
    339 } 
    340  
    341 function test_lang_assertValidKeywords() { 
    342         dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b"], "440"); 
    343         dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b", "c"], "441"); 
    344         dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo"], "442"); 
    345         dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo", "bar"], "443"); 
    346         dojo.lang.assertValidKeywords({foo: "iggy"}, {foo: null, bar: null}, "444"); 
    347  
    348         var caught450 = false; 
    349         try { 
    350                 dojo.lang.assertValidKeywords({a: 1, b: 2, c: 3}, ["a", "b"], "450"); 
    351         } catch (e) { 
    352                 caught450 = true; 
    353         } 
    354         jum.assertTrue("450", caught450); 
    355  
    356         // dojo.log.debug("leaving test_lang_assertValidKeywords()"); 
    357 } 
    358  
    359 function test_lang_find() { 
    360         var foo = new Array(128, 256, 512); 
    361         var bar = new Array("aaa", "bbb", "ccc"); 
    362          
    363         jum.assertTrue("500", dojo.lang.find(56, [45, 56, 85]) == 1); 
    364         jum.assertTrue("501", dojo.lang.find([Number, String, Date], String) == 1); 
    365         jum.assertTrue("502", dojo.lang.find(String, [Number, String, Date]) == 1); // bug #348 -- http://trac.dojotoolkit.org/ticket/348 
    366         jum.assertTrue("503", dojo.lang.find(foo[2], foo) == 2); 
    367         jum.assertTrue("504", dojo.lang.find(foo, foo[2]) == 2); 
    368         jum.assertTrue("505", dojo.lang.find(bar[2], bar) == 2); 
    369         jum.assertTrue("506", dojo.lang.find(bar, bar[2]) == 2); 
    370          
    371         foo.push(bar); 
    372         jum.assertTrue("510", dojo.lang.find(foo, bar) == 3); 
    373         // jum.assertTrue("511", dojo.lang.find(bar, foo) == 3); // bug #359 -- http://trac.dojotoolkit.org/ticket/359 
    374 } 
  • trunk/tests/string/test_common.js

    r2808 r2910  
    88        jum.assertEquals("test10", trimmed, dojo.string.trim(ws)); 
    99} 
    10  
    11 function test_string_paramString(){ 
    12         var ps = "This %{string} has %{parameters} %{toReplace}"; 
    13         var ps1 = dojo.string.paramString(ps, { string: "area", parameters: "foo"}); 
    14         jum.assertEquals("test20", "This area has foo %{toReplace}", ps1); 
    15  
    16         var ps2 = dojo.string.paramString(ps, { string: "area", parameters: "foo"}, true); 
    17         jum.assertEquals("test30", "This area has foo ", ps2); 
    18 } 
    19  
    20 function test_string_isBlank(){ 
    21         jum.assertTrue("test40", dojo.string.isBlank('   ')); 
    22         jum.assertFalse("test50", dojo.string.isBlank('            x')); 
    23         jum.assertFalse("test60", dojo.string.isBlank('x             ')); 
    24         jum.assertTrue("test70", dojo.string.isBlank('')); 
    25         jum.assertTrue("test80", dojo.string.isBlank(null)); 
    26         jum.assertTrue("test90", dojo.string.isBlank(new Array())); 
    27 } 
    28  
    29 function test_string_capitalize(){ 
    30         jum.assertEquals("test100", 'This Is A Bunch Of Words', dojo.string.capitalize('this is a bunch of words')); 
    31         jum.assertEquals("test110", 'Word', dojo.string.capitalize('word')); 
    32         jum.assertEquals("test120", '   ', dojo.string.capitalize('   ')); 
    33         jum.assertEquals("test130", '', dojo.string.capitalize('')); 
    34         jum.assertEquals("test140", '', dojo.string.capitalize(null)); 
    35         jum.assertEquals("test150", '', dojo.string.capitalize(new Array())); 
    36         jum.assertEquals("test160", "This One Has  Extra   Space", dojo.string.capitalize("this one has  extra   space")); 
    37 } 
    38  
    39 function test_string_escape() { 
    40         // TODO: vary the tests a bit more :) 
    41         // xml | html 
    42         jum.assertEquals("test200", '&lt;body bgcolor=&quot;#ffcc00&quot;&gt;&amp; becomes &amp;amp; y&#39;all!', 
    43                 dojo.string.escape("xml", '<body bgcolor="#ffcc00">& becomes &amp; y\'all!')); 
    44         jum.assertEquals("test201", '&lt;body bgcolor=&quot;#ffcc00&quot;&gt;&amp; becomes &amp;amp; y&#39;all!', 
    45                 dojo.string.escape("html", '<body bgcolor="#ffcc00">& becomes &amp; y\'all!')); 
    46         jum.assertEquals("test202", '&lt;body bgcolor=&quot;#ffcc00&quot;&gt;&amp; becomes &amp;amp; y&#39;all!', 
    47                 dojo.string.escapeXml('<body bgcolor="#ffcc00">& becomes &amp; y\'all!')); 
    48         // sql 
    49         jum.assertEquals("test210", "Hey y''all! How is it ''''going''''?", 
    50                 dojo.string.escape("sql", "Hey y'all! How is it ''going''?")); 
    51         jum.assertEquals("test210", "Hey y''all! How is it ''''going''''?", 
    52                 dojo.string.escapeSql("Hey y'all! How is it ''going''?")); 
    53         // regexp 
    54         jum.assertEquals("test220", "wrong \\\\ divide", 
    55                 dojo.string.escape("regexp", "wrong \\ divide")); 
    56         jum.assertEquals("test221", "wrong \\\\ divide", 
    57                 dojo.string.escape("regex", "wrong \\ divide")); 
    58         jum.assertEquals("test222", "wrong \\\\ divide", 
    59                 dojo.string.escapeRegExp("wrong \\ divide")); 
    60         // js 
    61         jum.assertEquals("test230", "I have \\\"quotes\\\" of various \\'types\\'", 
    62                 dojo.string.escape("javascript", "I have \"quotes\" of various 'types'")); 
    63         jum.assertEquals("test231", "I have \\\"quotes\\\" of various \\'types\\'", 
    64                 dojo.string.escape("js", "I have \"quotes\" of various 'types'")); 
    65         jum.assertEquals("test232", "I have \\\"quotes\\\" of various \\'types\\'", 
    66                 dojo.string.escapeJavaScript("I have \"quotes\" of various 'types'")); 
    67 } 
    68  
    69 function test_string_summary() { 
    70         jum.assertEquals("test300", "Every good boy do...", 
    71                 dojo.string.summary("Every good boy does fine", 17)); 
    72         jum.assertEquals("test300", "Hey Mr...", 
    73                 dojo.string.summary("Hey Mr. Jones", 6)); 
    74         jum.assertEquals("test300", "I like candy", 
    75                 dojo.string.summary("I like candy", 30)); 
    76 } 
    77  
    78 function test_normalizeNewlines() { 
    79         var t1 = "blahblahblah\r\nblahblahblah\rblahblhablhablhablh\nblahbalhablhablhab"; 
    80         var r1 = "blahblahblah\nblahblahblah\nblahblhablhablhablh\nblahbalhablhablhab"; 
    81         var r2 = "blahblahblah\rblahblahblah\rblahblhablhablhablh\rblahbalhablhablhab"; 
    82         var r3 = "blahblahblah\r\nblahblahblah\r\nblahblhablhablhablh\r\nblahbalhablhablhab"; 
    83  
    84         jum.assertEquals("test401", r1, dojo.string.normalizeNewlines(t1,'\n')); 
    85         jum.assertEquals("test402", r2, dojo.string.normalizeNewlines(t1,'\r')); 
    86         jum.assertEquals("test403", r3, dojo.string.normalizeNewlines(t1)); 
    87 }