Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.
This commit is contained in:
commit
4f2e303079
1839 changed files with 235630 additions and 0 deletions
12
webapp/web/src/lang/Lang.js
Normal file
12
webapp/web/src/lang/Lang.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.require("dojo.lang");
|
||||
dojo.deprecated("dojo.lang.Lang", "use dojo.lang instead", "0.4");
|
24
webapp/web/src/lang/__package__.js
Normal file
24
webapp/web/src/lang/__package__.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.kwCompoundRequire({
|
||||
common: [
|
||||
"dojo.lang",
|
||||
"dojo.lang.common",
|
||||
"dojo.lang.assert",
|
||||
"dojo.lang.array",
|
||||
"dojo.lang.type",
|
||||
"dojo.lang.func",
|
||||
"dojo.lang.extras",
|
||||
"dojo.lang.repr",
|
||||
"dojo.lang.declare"
|
||||
]
|
||||
});
|
||||
dojo.provide("dojo.lang.*");
|
172
webapp/web/src/lang/array.js
Normal file
172
webapp/web/src/lang/array.js
Normal file
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.array");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
|
||||
// FIXME: Is this worthless since you can do: if(name in obj)
|
||||
// is this the right place for this?
|
||||
dojo.lang.has = function(obj, name){
|
||||
try{
|
||||
return (typeof obj[name] != "undefined");
|
||||
}catch(e){ return false; }
|
||||
}
|
||||
|
||||
dojo.lang.isEmpty = function(obj) {
|
||||
if(dojo.lang.isObject(obj)) {
|
||||
var tmp = {};
|
||||
var count = 0;
|
||||
for(var x in obj){
|
||||
if(obj[x] && (!tmp[x])){
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (count == 0);
|
||||
} else if(dojo.lang.isArrayLike(obj) || dojo.lang.isString(obj)) {
|
||||
return obj.length == 0;
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang.map = function(arr, obj, unary_func){
|
||||
var isString = dojo.lang.isString(arr);
|
||||
if(isString){
|
||||
arr = arr.split("");
|
||||
}
|
||||
if(dojo.lang.isFunction(obj)&&(!unary_func)){
|
||||
unary_func = obj;
|
||||
obj = dj_global;
|
||||
}else if(dojo.lang.isFunction(obj) && unary_func){
|
||||
// ff 1.5 compat
|
||||
var tmpObj = obj;
|
||||
obj = unary_func;
|
||||
unary_func = tmpObj;
|
||||
}
|
||||
if(Array.map){
|
||||
var outArr = Array.map(arr, unary_func, obj);
|
||||
}else{
|
||||
var outArr = [];
|
||||
for(var i=0;i<arr.length;++i){
|
||||
outArr.push(unary_func.call(obj, arr[i]));
|
||||
}
|
||||
}
|
||||
if(isString) {
|
||||
return outArr.join("");
|
||||
} else {
|
||||
return outArr;
|
||||
}
|
||||
}
|
||||
|
||||
// http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach
|
||||
dojo.lang.forEach = function(anArray /* Array */, callback /* Function */, thisObject /* Object */){
|
||||
if(dojo.lang.isString(anArray)){
|
||||
anArray = anArray.split("");
|
||||
}
|
||||
if(Array.forEach){
|
||||
Array.forEach(anArray, callback, thisObject);
|
||||
}else{
|
||||
// FIXME: there are several ways of handilng thisObject. Is dj_global always the default context?
|
||||
if(!thisObject){
|
||||
thisObject=dj_global;
|
||||
}
|
||||
for(var i=0,l=anArray.length; i<l; i++){
|
||||
callback.call(thisObject, anArray[i], i, anArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang._everyOrSome = function(every, arr, callback, thisObject){
|
||||
if(dojo.lang.isString(arr)){
|
||||
arr = arr.split("");
|
||||
}
|
||||
if(Array.every){
|
||||
return Array[ (every) ? "every" : "some" ](arr, callback, thisObject);
|
||||
}else{
|
||||
if(!thisObject){
|
||||
thisObject = dj_global;
|
||||
}
|
||||
for(var i=0,l=arr.length; i<l; i++){
|
||||
var result = callback.call(thisObject, arr[i], i, arr);
|
||||
if((every)&&(!result)){
|
||||
return false;
|
||||
}else if((!every)&&(result)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return (every) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang.every = function(arr, callback, thisObject){
|
||||
return this._everyOrSome(true, arr, callback, thisObject);
|
||||
}
|
||||
|
||||
dojo.lang.some = function(arr, callback, thisObject){
|
||||
return this._everyOrSome(false, arr, callback, thisObject);
|
||||
}
|
||||
|
||||
dojo.lang.filter = function(arr, callback, thisObject) {
|
||||
var isString = dojo.lang.isString(arr);
|
||||
if(isString) { arr = arr.split(""); }
|
||||
if(Array.filter) {
|
||||
var outArr = Array.filter(arr, callback, thisObject);
|
||||
} else {
|
||||
if(!thisObject) {
|
||||
if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); }
|
||||
thisObject = dj_global;
|
||||
}
|
||||
|
||||
var outArr = [];
|
||||
for(var i = 0; i < arr.length; i++) {
|
||||
if(callback.call(thisObject, arr[i], i, arr)) {
|
||||
outArr.push(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isString) {
|
||||
return outArr.join("");
|
||||
} else {
|
||||
return outArr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 1-D array out of all the arguments passed,
|
||||
* unravelling any array-like objects in the process
|
||||
*
|
||||
* Ex:
|
||||
* unnest(1, 2, 3) ==> [1, 2, 3]
|
||||
* unnest(1, [2, [3], [[[4]]]]) ==> [1, 2, 3, 4]
|
||||
*/
|
||||
dojo.lang.unnest = function(/* ... */) {
|
||||
var out = [];
|
||||
for(var i = 0; i < arguments.length; i++) {
|
||||
if(dojo.lang.isArrayLike(arguments[i])) {
|
||||
var add = dojo.lang.unnest.apply(this, arguments[i]);
|
||||
out = out.concat(add);
|
||||
} else {
|
||||
out.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array-like object (i.e. arguments, DOMCollection)
|
||||
* to an array
|
||||
**/
|
||||
dojo.lang.toArray = function(arrayLike, startOffset) {
|
||||
var array = [];
|
||||
for(var i = startOffset||0; i < arrayLike.length; i++) {
|
||||
array.push(arrayLike[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
121
webapp/web/src/lang/assert.js
Normal file
121
webapp/web/src/lang/assert.js
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.assert");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
dojo.require("dojo.lang.array");
|
||||
dojo.require("dojo.lang.type");
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Assertion methods
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Throws an exception if the assertion fails.
|
||||
*
|
||||
* If the asserted condition is true, this method does nothing. If the
|
||||
* condition is false, we throw an error with a error message.
|
||||
*
|
||||
* @param booleanValue A boolean value, which needs to be true for the assertion to succeed.
|
||||
* @param message Optional. A string describing the assertion.
|
||||
* @throws Throws an Error if 'booleanValue' is false.
|
||||
*/
|
||||
dojo.lang.assert = function(booleanValue, message){
|
||||
if(!booleanValue){
|
||||
var errorMessage = "An assert statement failed.\n" +
|
||||
"The method dojo.lang.assert() was called with a 'false' value.\n";
|
||||
if(message){
|
||||
errorMessage += "Here's the assert message:\n" + message + "\n";
|
||||
}
|
||||
// Use throw instead of dojo.raise, until bug #264 is fixed:
|
||||
// dojo.raise(errorMessage);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a value and a data type, this method checks the type of the value
|
||||
* to make sure it matches the data type, and throws an exception if there
|
||||
* is a mismatch.
|
||||
*
|
||||
* Examples:
|
||||
* <pre>
|
||||
* dojo.lang.assertType("foo", String);
|
||||
* dojo.lang.assertType(12345, Number);
|
||||
* dojo.lang.assertType(false, Boolean);
|
||||
* dojo.lang.assertType([6, 8], Array);
|
||||
* dojo.lang.assertType(dojo.lang.assertType, Function);
|
||||
* dojo.lang.assertType({foo: "bar"}, Object);
|
||||
* dojo.lang.assertType(new Date(), Date);
|
||||
* </pre>
|
||||
*
|
||||
* @scope public function
|
||||
* @param value Any literal value or object instance.
|
||||
* @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.
|
||||
* @param message Optional. A string describing the assertion.
|
||||
* @throws Throws an Error if 'value' is not of type 'type'.
|
||||
*/
|
||||
dojo.lang.assertType = function(value, type, message){
|
||||
if(!dojo.lang.isOfType(value, type)){
|
||||
if(!message){
|
||||
if(!dojo.lang.assertType._errorMessage){
|
||||
dojo.lang.assertType._errorMessage = "Type mismatch: dojo.lang.assertType() failed.";
|
||||
}
|
||||
message = dojo.lang.assertType._errorMessage;
|
||||
}
|
||||
dojo.lang.assert(false, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an anonymous object and a list of expected property names, this
|
||||
* method check to make sure the object does not have any properties
|
||||
* that aren't on the list of expected properties, and throws an Error
|
||||
* if there are unexpected properties. This is useful for doing error
|
||||
* checking on keyword arguments, to make sure there aren't typos.
|
||||
*
|
||||
* Examples:
|
||||
* <pre>
|
||||
* dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b"]);
|
||||
* dojo.lang.assertValidKeywords({a: 1, b: 2}, ["a", "b", "c"]);
|
||||
* dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo"]);
|
||||
* dojo.lang.assertValidKeywords({foo: "iggy"}, ["foo", "bar"]);
|
||||
* dojo.lang.assertValidKeywords({foo: "iggy"}, {foo: null, bar: null});
|
||||
* </pre>
|
||||
*
|
||||
* @scope public function
|
||||
* @param object An anonymous object.
|
||||
* @param expectedProperties An array of strings (or an object with all the expected properties).
|
||||
* @param message Optional. A string describing the assertion.
|
||||
* @throws Throws an Error if 'value' is not of type 'type'.
|
||||
*/
|
||||
dojo.lang.assertValidKeywords = function(object, expectedProperties, message){
|
||||
var key;
|
||||
if(!message){
|
||||
if(!dojo.lang.assertValidKeywords._errorMessage){
|
||||
dojo.lang.assertValidKeywords._errorMessage = "In dojo.lang.assertValidKeywords(), found invalid keyword:";
|
||||
}
|
||||
message = dojo.lang.assertValidKeywords._errorMessage;
|
||||
}
|
||||
if(dojo.lang.isArray(expectedProperties)){
|
||||
for(key in object){
|
||||
if(!dojo.lang.inArray(expectedProperties, key)){
|
||||
dojo.lang.assert(false, message + " " + key);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for(key in object){
|
||||
if(!(key in expectedProperties)){
|
||||
dojo.lang.assert(false, message + " " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
190
webapp/web/src/lang/common.js
Normal file
190
webapp/web/src/lang/common.js
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.common");
|
||||
dojo.require("dojo.lang");
|
||||
|
||||
/*
|
||||
* Adds the given properties/methods to the specified object
|
||||
*/
|
||||
dojo.lang._mixin = function(obj, props){
|
||||
var tobj = {};
|
||||
for(var x in props){
|
||||
// the "tobj" condition avoid copying properties in "props"
|
||||
// inherited from Object.prototype. For example, if obj has a custom
|
||||
// toString() method, don't overwrite it with the toString() method
|
||||
// that props inherited from Object.protoype
|
||||
if(typeof tobj[x] == "undefined" || tobj[x] != props[x]) {
|
||||
obj[x] = props[x];
|
||||
}
|
||||
}
|
||||
// IE doesn't recognize custom toStrings in for..in
|
||||
if(dojo.render.html.ie && dojo.lang.isFunction(props["toString"]) && props["toString"] != obj["toString"]) {
|
||||
obj.toString = props.toString;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the properties/methods of argument Objects to obj
|
||||
*/
|
||||
dojo.lang.mixin = function(obj, props /*, props, ..., props */){
|
||||
for(var i=1, l=arguments.length; i<l; i++){
|
||||
dojo.lang._mixin(obj, arguments[i]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the properties/methods of argument Objects to ctor's prototype
|
||||
*/
|
||||
dojo.lang.extend = function(ctor /*function*/, props /*, props, ..., props */){
|
||||
for(var i=1, l=arguments.length; i<l; i++){
|
||||
dojo.lang._mixin(ctor.prototype, arguments[i]);
|
||||
}
|
||||
return ctor;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if val is in arr. Call signatures:
|
||||
* find(array, value, identity) // recommended
|
||||
* find(value, array, identity)
|
||||
**/
|
||||
dojo.lang.find = function( /*Array*/ arr,
|
||||
/*Object*/ val,
|
||||
/*boolean*/ identity,
|
||||
/*boolean*/ findLast){
|
||||
// support both (arr, val) and (val, arr)
|
||||
if(!dojo.lang.isArrayLike(arr) && dojo.lang.isArrayLike(val)) {
|
||||
var a = arr;
|
||||
arr = val;
|
||||
val = a;
|
||||
}
|
||||
var isString = dojo.lang.isString(arr);
|
||||
if(isString) { arr = arr.split(""); }
|
||||
|
||||
if(findLast) {
|
||||
var step = -1;
|
||||
var i = arr.length - 1;
|
||||
var end = -1;
|
||||
} else {
|
||||
var step = 1;
|
||||
var i = 0;
|
||||
var end = arr.length;
|
||||
}
|
||||
if(identity){
|
||||
while(i != end) {
|
||||
if(arr[i] === val){ return i; }
|
||||
i += step;
|
||||
}
|
||||
}else{
|
||||
while(i != end) {
|
||||
if(arr[i] == val){ return i; }
|
||||
i += step;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
dojo.lang.indexOf = dojo.lang.find;
|
||||
|
||||
dojo.lang.findLast = function(/*Array*/ arr, /*Object*/ val, /*boolean*/ identity){
|
||||
return dojo.lang.find(arr, val, identity, true);
|
||||
}
|
||||
|
||||
dojo.lang.lastIndexOf = dojo.lang.findLast;
|
||||
|
||||
dojo.lang.inArray = function(arr /*Array*/, val /*Object*/){
|
||||
return dojo.lang.find(arr, val) > -1; // return: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial implmentation of is* functions from
|
||||
* http://www.crockford.com/javascript/recommend.html
|
||||
* NOTE: some of these may not be the best thing to use in all situations
|
||||
* as they aren't part of core JS and therefore can't work in every case.
|
||||
* See WARNING messages inline for tips.
|
||||
*
|
||||
* The following is* functions are fairly "safe"
|
||||
*/
|
||||
|
||||
dojo.lang.isObject = function(wh){
|
||||
if(typeof wh == "undefined"){ return false; }
|
||||
return (typeof wh == "object" || wh === null || dojo.lang.isArray(wh) || dojo.lang.isFunction(wh));
|
||||
}
|
||||
|
||||
dojo.lang.isArray = function(wh){
|
||||
return (wh instanceof Array || typeof wh == "array");
|
||||
}
|
||||
|
||||
dojo.lang.isArrayLike = function(wh){
|
||||
if(dojo.lang.isString(wh)){ return false; }
|
||||
if(dojo.lang.isFunction(wh)){ return false; } // keeps out built-in ctors (Number, String, ...) which have length properties
|
||||
if(dojo.lang.isArray(wh)){ return true; }
|
||||
if(typeof wh != "undefined" && wh
|
||||
&& dojo.lang.isNumber(wh.length) && isFinite(wh.length)){ return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
dojo.lang.isFunction = function(wh){
|
||||
if(!wh){ return false; }
|
||||
return (wh instanceof Function || typeof wh == "function");
|
||||
}
|
||||
|
||||
dojo.lang.isString = function(wh){
|
||||
return (wh instanceof String || typeof wh == "string");
|
||||
}
|
||||
|
||||
dojo.lang.isAlien = function(wh){
|
||||
if(!wh){ return false; }
|
||||
return !dojo.lang.isFunction() && /\{\s*\[native code\]\s*\}/.test(String(wh));
|
||||
}
|
||||
|
||||
dojo.lang.isBoolean = function(wh){
|
||||
return (wh instanceof Boolean || typeof wh == "boolean");
|
||||
}
|
||||
|
||||
/**
|
||||
* The following is***() functions are somewhat "unsafe". Fortunately,
|
||||
* there are workarounds the the language provides and are mentioned
|
||||
* in the WARNING messages.
|
||||
*
|
||||
* WARNING: In most cases, isNaN(wh) is sufficient to determine whether or not
|
||||
* something is a number or can be used as such. For example, a number or string
|
||||
* can be used interchangably when accessing array items (arr["1"] is the same as
|
||||
* arr[1]) and isNaN will return false for both values ("1" and 1). Should you
|
||||
* use isNumber("1"), that will return false, which is generally not too useful.
|
||||
* Also, isNumber(NaN) returns true, again, this isn't generally useful, but there
|
||||
* are corner cases (like when you want to make sure that two things are really
|
||||
* the same type of thing). That is really where isNumber "shines".
|
||||
*
|
||||
* RECOMMENDATION: Use isNaN(wh) when possible
|
||||
*/
|
||||
dojo.lang.isNumber = function(wh){
|
||||
return (wh instanceof Number || typeof wh == "number");
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING: In some cases, isUndefined will not behave as you
|
||||
* might expect. If you do isUndefined(foo) and there is no earlier
|
||||
* reference to foo, an error will be thrown before isUndefined is
|
||||
* called. It behaves correctly if you scope yor object first, i.e.
|
||||
* isUndefined(foo.bar) where foo is an object and bar isn't a
|
||||
* property of the object.
|
||||
*
|
||||
* RECOMMENDATION: Use `typeof foo == "undefined"` when possible
|
||||
*
|
||||
* FIXME: Should isUndefined go away since it is error prone?
|
||||
*/
|
||||
dojo.lang.isUndefined = function(wh){
|
||||
return ((wh == undefined)&&(typeof wh == "undefined"));
|
||||
}
|
||||
|
||||
// end Crockford functions
|
156
webapp/web/src/lang/declare.js
Normal file
156
webapp/web/src/lang/declare.js
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.declare");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
dojo.require("dojo.lang.extras");
|
||||
|
||||
/*
|
||||
* Creates a constructor: inherit and extend
|
||||
*
|
||||
* - inherits from "superclass(es)"
|
||||
*
|
||||
* "superclass" argument may be a Function, or an array of
|
||||
* Functions.
|
||||
*
|
||||
* If "superclass" is an array, the first element is used
|
||||
* as the prototypical ancestor and any following Functions
|
||||
* become mixin ancestors.
|
||||
*
|
||||
* All "superclass(es)" must be Functions (not mere Objects).
|
||||
*
|
||||
* Using mixin ancestors provides a type of multiple
|
||||
* inheritance. Mixin ancestors prototypical
|
||||
* properties are copied to the subclass, and any
|
||||
* inializater/constructor is invoked.
|
||||
*
|
||||
* - "props" are copied to the constructor prototype
|
||||
*
|
||||
* - name of the class ("className" argument) is stored in
|
||||
* "declaredClass" property
|
||||
*
|
||||
* - An initializer function can be specified in the "init"
|
||||
* argument, or by including a function called "initializer"
|
||||
* in "props".
|
||||
*
|
||||
* - Superclass methods (inherited methods) can be invoked using "inherited" method:
|
||||
*
|
||||
* this.inherited(<method name>[, <argument array>]);
|
||||
*
|
||||
* - inherited will continue up the prototype chain until it finds an implementation of method
|
||||
* - nested calls to inherited are supported (i.e. inherited method "A" can succesfully call inherited("A"), and so on)
|
||||
*
|
||||
* Aliased as "dojo.declare"
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* dojo.declare("my.classes.bar", my.classes.foo, {
|
||||
* initializer: function() {
|
||||
* this.myComplicatedObject = new ReallyComplicatedObject();
|
||||
* },
|
||||
* someValue: 2,
|
||||
* aMethod: function() { doStuff(); }
|
||||
* });
|
||||
*
|
||||
*/
|
||||
dojo.lang.declare = function(className /*string*/, superclass /*function || array*/, init /*function*/, props /*object*/){
|
||||
// FIXME: parameter juggling for backward compat ... deprecate and remove after 0.3.*
|
||||
// new sig: (className (string)[, superclass (function || array)[, init (function)][, props (object)]])
|
||||
// old sig: (className (string)[, superclass (function || array), props (object), init (function)])
|
||||
if ((dojo.lang.isFunction(props))||((!props)&&(!dojo.lang.isFunction(init)))){
|
||||
var temp = props;
|
||||
props = init;
|
||||
init = temp;
|
||||
}
|
||||
var mixins = [ ];
|
||||
if (dojo.lang.isArray(superclass)) {
|
||||
mixins = superclass;
|
||||
superclass = mixins.shift();
|
||||
}
|
||||
if(!init){
|
||||
init = dojo.evalObjPath(className, false);
|
||||
if ((init)&&(!dojo.lang.isFunction(init))){ init = null };
|
||||
}
|
||||
var ctor = dojo.lang.declare._makeConstructor();
|
||||
var scp = (superclass ? superclass.prototype : null);
|
||||
if(scp){
|
||||
scp.prototyping = true;
|
||||
ctor.prototype = new superclass();
|
||||
scp.prototyping = false;
|
||||
}
|
||||
ctor.superclass = scp;
|
||||
ctor.mixins = mixins;
|
||||
for(var i=0,l=mixins.length; i<l; i++){
|
||||
dojo.lang.extend(ctor, mixins[i].prototype);
|
||||
}
|
||||
ctor.prototype.initializer = null;
|
||||
ctor.prototype.declaredClass = className;
|
||||
if(dojo.lang.isArray(props)){
|
||||
dojo.lang.extend.apply(dojo.lang, [ctor].concat(props));
|
||||
}else{
|
||||
dojo.lang.extend(ctor, (props)||{});
|
||||
}
|
||||
dojo.lang.extend(ctor, dojo.lang.declare.base);
|
||||
ctor.prototype.constructor = ctor;
|
||||
ctor.prototype.initializer=(ctor.prototype.initializer)||(init)||(function(){});
|
||||
dojo.lang.setObjPathValue(className, ctor, null, true);
|
||||
}
|
||||
|
||||
dojo.lang.declare._makeConstructor = function() {
|
||||
return function(){
|
||||
// get the generational context (which object [or prototype] should be constructed)
|
||||
var self = this._getPropContext();
|
||||
var s = self.constructor.superclass;
|
||||
if((s)&&(s.constructor)){
|
||||
if(s.constructor==arguments.callee){
|
||||
// if this constructor is invoked directly (my.ancestor.call(this))
|
||||
this.inherited("constructor", arguments);
|
||||
}else{
|
||||
this._inherited(s, "constructor", arguments);
|
||||
}
|
||||
}
|
||||
var m = (self.constructor.mixins)||([]);
|
||||
for(var i=0,l=m.length; i<l; i++) {
|
||||
(((m[i].prototype)&&(m[i].prototype.initializer))||(m[i])).apply(this, arguments);
|
||||
}
|
||||
if((!this.prototyping)&&(self.initializer)){
|
||||
self.initializer.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang.declare.base = {
|
||||
_getPropContext: function() { return (this.___proto||this); },
|
||||
// caches ptype context and calls method on it
|
||||
_inherited: function(ptype, method, args){
|
||||
var stack = this.___proto;
|
||||
this.___proto = ptype;
|
||||
var result = ptype[method].apply(this,(args||[]));
|
||||
this.___proto = stack;
|
||||
return result;
|
||||
},
|
||||
// invokes ctor.prototype.method, with args, in our context
|
||||
inheritedFrom: function(ctor, prop, args){
|
||||
var p = ((ctor)&&(ctor.prototype)&&(ctor.prototype[prop]));
|
||||
return (dojo.lang.isFunction(p) ? p.apply(this, (args||[])) : p);
|
||||
},
|
||||
// searches backward thru prototype chain to find nearest ancestral instance of prop
|
||||
inherited: function(prop, args){
|
||||
var p = this._getPropContext();
|
||||
do{
|
||||
if((!p.constructor)||(!p.constructor.superclass)){return;}
|
||||
p = p.constructor.superclass;
|
||||
}while(!(prop in p));
|
||||
return (dojo.lang.isFunction(p[prop]) ? this._inherited(p, prop, args) : p[prop]);
|
||||
}
|
||||
}
|
||||
|
||||
dojo.declare = dojo.lang.declare;
|
108
webapp/web/src/lang/extras.js
Normal file
108
webapp/web/src/lang/extras.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.extras");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
|
||||
/**
|
||||
* Sets a timeout in milliseconds to execute a function in a given context
|
||||
* with optional arguments.
|
||||
*
|
||||
* setTimeout (Object context, function func, number delay[, arg1[, ...]]);
|
||||
* setTimeout (function func, number delay[, arg1[, ...]]);
|
||||
*/
|
||||
dojo.lang.setTimeout = function(func, delay){
|
||||
var context = window, argsStart = 2;
|
||||
if(!dojo.lang.isFunction(func)){
|
||||
context = func;
|
||||
func = delay;
|
||||
delay = arguments[2];
|
||||
argsStart++;
|
||||
}
|
||||
|
||||
if(dojo.lang.isString(func)){
|
||||
func = context[func];
|
||||
}
|
||||
|
||||
var args = [];
|
||||
for (var i = argsStart; i < arguments.length; i++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return setTimeout(function () { func.apply(context, args); }, delay);
|
||||
}
|
||||
|
||||
dojo.lang.getNameInObj = function(ns, item){
|
||||
if(!ns){ ns = dj_global; }
|
||||
|
||||
for(var x in ns){
|
||||
if(ns[x] === item){
|
||||
return new String(x);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
dojo.lang.shallowCopy = function(obj) {
|
||||
var ret = {}, key;
|
||||
for(key in obj) {
|
||||
if(dojo.lang.isUndefined(ret[key])) {
|
||||
ret[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first argument that isn't undefined
|
||||
*/
|
||||
dojo.lang.firstValued = function(/* ... */) {
|
||||
for(var i = 0; i < arguments.length; i++) {
|
||||
if(typeof arguments[i] != "undefined") {
|
||||
return arguments[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from a reference specified as a string descriptor,
|
||||
* (e.g. "A.B") in the given context.
|
||||
*
|
||||
* getObjPathValue(String objpath [, Object context, Boolean create])
|
||||
*
|
||||
* If context is not specified, dj_global is used
|
||||
* If create is true, undefined objects in the path are created.
|
||||
*/
|
||||
dojo.lang.getObjPathValue = function(objpath, context, create){
|
||||
with(dojo.parseObjPath(objpath, context, create)){
|
||||
return dojo.evalProp(prop, obj, create);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value on a reference specified as a string descriptor.
|
||||
* (e.g. "A.B") in the given context.
|
||||
*
|
||||
* setObjPathValue(String objpath, value [, Object context, Boolean create])
|
||||
*
|
||||
* If context is not specified, dj_global is used
|
||||
* If create is true, undefined objects in the path are created.
|
||||
*/
|
||||
dojo.lang.setObjPathValue = function(objpath, value, context, create){
|
||||
if(arguments.length < 4){
|
||||
create = true;
|
||||
}
|
||||
with(dojo.parseObjPath(objpath, context, create)){
|
||||
if(obj && (create || (prop in obj))){
|
||||
obj[prop] = value;
|
||||
}
|
||||
}
|
||||
}
|
150
webapp/web/src/lang/func.js
Normal file
150
webapp/web/src/lang/func.js
Normal file
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.func");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
|
||||
/**
|
||||
* Runs a function in a given scope (thisObject), can
|
||||
* also be used to preserve scope.
|
||||
*
|
||||
* hitch(foo, "bar"); // runs foo.bar() in the scope of foo
|
||||
* hitch(foo, myFunction); // runs myFunction in the scope of foo
|
||||
*/
|
||||
dojo.lang.hitch = function(thisObject, method) {
|
||||
if(dojo.lang.isString(method)) {
|
||||
var fcn = thisObject[method];
|
||||
} else {
|
||||
var fcn = method;
|
||||
}
|
||||
|
||||
return function() {
|
||||
return fcn.apply(thisObject, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang.anonCtr = 0;
|
||||
dojo.lang.anon = {};
|
||||
dojo.lang.nameAnonFunc = function(anonFuncPtr, namespaceObj, searchForNames){
|
||||
var nso = (namespaceObj || dojo.lang.anon);
|
||||
if( (searchForNames) ||
|
||||
((dj_global["djConfig"])&&(djConfig["slowAnonFuncLookups"] == true)) ){
|
||||
for(var x in nso){
|
||||
if(nso[x] === anonFuncPtr){
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
var ret = "__"+dojo.lang.anonCtr++;
|
||||
while(typeof nso[ret] != "undefined"){
|
||||
ret = "__"+dojo.lang.anonCtr++;
|
||||
}
|
||||
nso[ret] = anonFuncPtr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
dojo.lang.forward = function(funcName){
|
||||
// Returns a function that forwards a method call to this.func(...)
|
||||
return function(){
|
||||
return this[funcName].apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
dojo.lang.curry = function(ns, func /* args ... */){
|
||||
var outerArgs = [];
|
||||
ns = ns||dj_global;
|
||||
if(dojo.lang.isString(func)){
|
||||
func = ns[func];
|
||||
}
|
||||
for(var x=2; x<arguments.length; x++){
|
||||
outerArgs.push(arguments[x]);
|
||||
}
|
||||
// since the event system replaces the original function with a new
|
||||
// join-point runner with an arity of 0, we check to see if it's left us
|
||||
// any clues about the original arity in lieu of the function's actual
|
||||
// length property
|
||||
var ecount = (func["__preJoinArity"]||func.length) - outerArgs.length;
|
||||
// borrowed from svend tofte
|
||||
function gather(nextArgs, innerArgs, expected){
|
||||
var texpected = expected;
|
||||
var totalArgs = innerArgs.slice(0); // copy
|
||||
for(var x=0; x<nextArgs.length; x++){
|
||||
totalArgs.push(nextArgs[x]);
|
||||
}
|
||||
// check the list of provided nextArgs to see if it, plus the
|
||||
// number of innerArgs already supplied, meets the total
|
||||
// expected.
|
||||
expected = expected-nextArgs.length;
|
||||
if(expected<=0){
|
||||
var res = func.apply(ns, totalArgs);
|
||||
expected = texpected;
|
||||
return res;
|
||||
}else{
|
||||
return function(){
|
||||
return gather(arguments,// check to see if we've been run
|
||||
// with enough args
|
||||
totalArgs, // a copy
|
||||
expected); // how many more do we need to run?;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gather([], outerArgs, ecount);
|
||||
}
|
||||
|
||||
dojo.lang.curryArguments = function(ns, func, args, offset){
|
||||
var targs = [];
|
||||
var x = offset||0;
|
||||
for(x=offset; x<args.length; x++){
|
||||
targs.push(args[x]); // ensure that it's an arr
|
||||
}
|
||||
return dojo.lang.curry.apply(dojo.lang, [ns, func].concat(targs));
|
||||
}
|
||||
|
||||
dojo.lang.tryThese = function(){
|
||||
for(var x=0; x<arguments.length; x++){
|
||||
try{
|
||||
if(typeof arguments[x] == "function"){
|
||||
var ret = (arguments[x]());
|
||||
if(ret){
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
dojo.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dojo.lang.delayThese = function(farr, cb, delay, onend){
|
||||
/**
|
||||
* alternate: (array funcArray, function callback, function onend)
|
||||
* alternate: (array funcArray, function callback)
|
||||
* alternate: (array funcArray)
|
||||
*/
|
||||
if(!farr.length){
|
||||
if(typeof onend == "function"){
|
||||
onend();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if((typeof delay == "undefined")&&(typeof cb == "number")){
|
||||
delay = cb;
|
||||
cb = function(){};
|
||||
}else if(!cb){
|
||||
cb = function(){};
|
||||
if(!delay){ delay = 0; }
|
||||
}
|
||||
setTimeout(function(){
|
||||
(farr.shift())();
|
||||
cb();
|
||||
dojo.lang.delayThese(farr, cb, delay, onend);
|
||||
}, delay);
|
||||
}
|
90
webapp/web/src/lang/repr.js
Normal file
90
webapp/web/src/lang/repr.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.repr");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
dojo.require("dojo.AdapterRegistry");
|
||||
dojo.require("dojo.string.extras");
|
||||
|
||||
dojo.lang.reprRegistry = new dojo.AdapterRegistry();
|
||||
dojo.lang.registerRepr = function(name, check, wrap, /*optional*/ override){
|
||||
/***
|
||||
Register a repr function. repr functions should take
|
||||
one argument and return a string representation of it
|
||||
suitable for developers, primarily used when debugging.
|
||||
|
||||
If override is given, it is used as the highest priority
|
||||
repr, otherwise it will be used as the lowest.
|
||||
***/
|
||||
dojo.lang.reprRegistry.register(name, check, wrap, override);
|
||||
};
|
||||
|
||||
dojo.lang.repr = function(obj){
|
||||
/***
|
||||
Return a "programmer representation" for an object
|
||||
***/
|
||||
if(typeof(obj) == "undefined"){
|
||||
return "undefined";
|
||||
}else if(obj === null){
|
||||
return "null";
|
||||
}
|
||||
|
||||
try{
|
||||
if(typeof(obj["__repr__"]) == 'function'){
|
||||
return obj["__repr__"]();
|
||||
}else if((typeof(obj["repr"]) == 'function')&&(obj.repr != arguments.callee)){
|
||||
return obj["repr"]();
|
||||
}
|
||||
return dojo.lang.reprRegistry.match(obj);
|
||||
}catch(e){
|
||||
if(typeof(obj.NAME) == 'string' && (
|
||||
obj.toString == Function.prototype.toString ||
|
||||
obj.toString == Object.prototype.toString
|
||||
)){
|
||||
return o.NAME;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof(obj) == "function"){
|
||||
obj = (obj + "").replace(/^\s+/, "");
|
||||
var idx = obj.indexOf("{");
|
||||
if(idx != -1){
|
||||
obj = obj.substr(0, idx) + "{...}";
|
||||
}
|
||||
}
|
||||
return obj + "";
|
||||
}
|
||||
|
||||
dojo.lang.reprArrayLike = function(arr){
|
||||
try{
|
||||
var na = dojo.lang.map(arr, dojo.lang.repr);
|
||||
return "[" + na.join(", ") + "]";
|
||||
}catch(e){ }
|
||||
};
|
||||
|
||||
dojo.lang.reprString = function(str){
|
||||
dojo.deprecated("dojo.lang.reprNumber", "use `String(num)` instead", "0.4");
|
||||
return dojo.string.escapeString(str);
|
||||
};
|
||||
|
||||
dojo.lang.reprNumber = function(num){
|
||||
dojo.deprecated("dojo.lang.reprNumber", "use `String(num)` instead", "0.4");
|
||||
return num + "";
|
||||
};
|
||||
|
||||
(function(){
|
||||
var m = dojo.lang;
|
||||
m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
|
||||
m.registerRepr("string", m.isString, m.reprString);
|
||||
m.registerRepr("numbers", m.isNumber, m.reprNumber);
|
||||
m.registerRepr("boolean", m.isBoolean, m.reprNumber);
|
||||
// m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber);
|
||||
})();
|
226
webapp/web/src/lang/type.js
Normal file
226
webapp/web/src/lang/type.js
Normal file
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
Copyright (c) 2004-2006, The Dojo Foundation
|
||||
All Rights Reserved.
|
||||
|
||||
Licensed under the Academic Free License version 2.1 or above OR the
|
||||
modified BSD license. For more information on Dojo licensing, see:
|
||||
|
||||
http://dojotoolkit.org/community/licensing.shtml
|
||||
*/
|
||||
|
||||
dojo.provide("dojo.lang.type");
|
||||
|
||||
dojo.require("dojo.lang.common");
|
||||
|
||||
dojo.lang.whatAmI = function(wh) {
|
||||
try {
|
||||
if(dojo.lang.isArray(wh)) { return "array"; }
|
||||
if(dojo.lang.isFunction(wh)) { return "function"; }
|
||||
if(dojo.lang.isString(wh)) { return "string"; }
|
||||
if(dojo.lang.isNumber(wh)) { return "number"; }
|
||||
if(dojo.lang.isBoolean(wh)) { return "boolean"; }
|
||||
if(dojo.lang.isAlien(wh)) { return "alien"; }
|
||||
if(dojo.lang.isUndefined(wh)) { return "undefined"; }
|
||||
// FIXME: should this go first?
|
||||
for(var name in dojo.lang.whatAmI.custom) {
|
||||
if(dojo.lang.whatAmI.custom[name](wh)) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
if(dojo.lang.isObject(wh)) { return "object"; }
|
||||
} catch(E) {}
|
||||
return "unknown";
|
||||
}
|
||||
/*
|
||||
* dojo.lang.whatAmI.custom[typeName] = someFunction
|
||||
* will return typeName is someFunction(wh) returns true
|
||||
*/
|
||||
dojo.lang.whatAmI.custom = {};
|
||||
|
||||
/**
|
||||
* Returns true for values that commonly represent numbers.
|
||||
*
|
||||
* Examples:
|
||||
* <pre>
|
||||
* dojo.lang.isNumeric(3); // returns true
|
||||
* dojo.lang.isNumeric("3"); // returns true
|
||||
* dojo.lang.isNumeric(new Number(3)); // returns true
|
||||
* dojo.lang.isNumeric(new String("3")); // returns true
|
||||
*
|
||||
* dojo.lang.isNumeric(3/0); // returns false
|
||||
* dojo.lang.isNumeric("foo"); // returns false
|
||||
* dojo.lang.isNumeric(new Number("foo")); // returns false
|
||||
* dojo.lang.isNumeric(false); // returns false
|
||||
* dojo.lang.isNumeric(true); // returns false
|
||||
* </pre>
|
||||
*/
|
||||
dojo.lang.isNumeric = function(wh){
|
||||
return (!isNaN(wh) && isFinite(wh) && (wh != null) &&
|
||||
!dojo.lang.isBoolean(wh) && !dojo.lang.isArray(wh));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true for any literal, and for any object that is an
|
||||
* instance of a built-in type like String, Number, Boolean,
|
||||
* Array, Function, or Error.
|
||||
*/
|
||||
dojo.lang.isBuiltIn = function(wh){
|
||||
return (dojo.lang.isArray(wh) ||
|
||||
dojo.lang.isFunction(wh) ||
|
||||
dojo.lang.isString(wh) ||
|
||||
dojo.lang.isNumber(wh) ||
|
||||
dojo.lang.isBoolean(wh) ||
|
||||
(wh == null) ||
|
||||
(wh instanceof Error) ||
|
||||
(typeof wh == "error") );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true for any object where the value of the
|
||||
* property 'constructor' is 'Object'.
|
||||
*
|
||||
* Examples:
|
||||
* <pre>
|
||||
* dojo.lang.isPureObject(new Object()); // returns true
|
||||
* dojo.lang.isPureObject({a: 1, b: 2}); // returns true
|
||||
*
|
||||
* dojo.lang.isPureObject(new Date()); // returns false
|
||||
* dojo.lang.isPureObject([11, 2, 3]); // returns false
|
||||
* </pre>
|
||||
*/
|
||||
dojo.lang.isPureObject = function(wh){
|
||||
return ((wh != null) && dojo.lang.isObject(wh) && wh.constructor == Object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a value and a datatype, this method returns true if the
|
||||
* type of the value matches the datatype. The datatype parameter
|
||||
* can be an array of datatypes, in which case the method returns
|
||||
* true if the type of the value matches any of the datatypes.
|
||||
*
|
||||
* Examples:
|
||||
* <pre>
|
||||
* dojo.lang.isOfType("foo", String); // returns true
|
||||
* dojo.lang.isOfType(12345, Number); // returns true
|
||||
* dojo.lang.isOfType(false, Boolean); // returns true
|
||||
* dojo.lang.isOfType([6, 8], Array); // returns true
|
||||
* dojo.lang.isOfType(dojo.lang.isOfType, Function); // returns true
|
||||
* dojo.lang.isOfType({foo: "bar"}, Object); // returns true
|
||||
* dojo.lang.isOfType(new Date(), Date); // returns true
|
||||
* dojo.lang.isOfType(xxxxx, Date); // returns true
|
||||
*
|
||||
* dojo.lang.isOfType("foo", "string"); // returns true
|
||||
* dojo.lang.isOfType(12345, "number"); // returns true
|
||||
* dojo.lang.isOfType(false, "boolean"); // returns true
|
||||
* dojo.lang.isOfType([6, 8], "array"); // returns true
|
||||
* dojo.lang.isOfType(dojo.lang.isOfType, "function"); // returns true
|
||||
* dojo.lang.isOfType({foo: "bar"}, "object"); // returns true
|
||||
* dojo.lang.isOfType(xxxxx, "undefined"); // returns true
|
||||
* dojo.lang.isOfType(null, "null"); // returns true
|
||||
|
||||
* dojo.lang.isOfType("foo", [Number, String, Boolean]); // returns true
|
||||
* dojo.lang.isOfType(12345, [Number, String, Boolean]); // returns true
|
||||
* dojo.lang.isOfType(false, [Number, String, Boolean]); // returns true
|
||||
* dojo.lang.isOfType(xxxxx, "undefined"); // returns true
|
||||
* </pre>
|
||||
*
|
||||
* @param value Any literal value or object instance.
|
||||
* @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.
|
||||
* @return Returns a boolean
|
||||
*/
|
||||
dojo.lang.isOfType = function(value, type) {
|
||||
if(dojo.lang.isArray(type)){
|
||||
var arrayOfTypes = type;
|
||||
for(var i in arrayOfTypes){
|
||||
var aType = arrayOfTypes[i];
|
||||
if(dojo.lang.isOfType(value, aType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}else{
|
||||
if(dojo.lang.isString(type)){
|
||||
type = type.toLowerCase();
|
||||
}
|
||||
switch (type) {
|
||||
case Array:
|
||||
case "array":
|
||||
return dojo.lang.isArray(value);
|
||||
break;
|
||||
case Function:
|
||||
case "function":
|
||||
return dojo.lang.isFunction(value);
|
||||
break;
|
||||
case String:
|
||||
case "string":
|
||||
return dojo.lang.isString(value);
|
||||
break;
|
||||
case Number:
|
||||
case "number":
|
||||
return dojo.lang.isNumber(value);
|
||||
break;
|
||||
case "numeric":
|
||||
return dojo.lang.isNumeric(value);
|
||||
break;
|
||||
case Boolean:
|
||||
case "boolean":
|
||||
return dojo.lang.isBoolean(value);
|
||||
break;
|
||||
case Object:
|
||||
case "object":
|
||||
return dojo.lang.isObject(value);
|
||||
break;
|
||||
case "pureobject":
|
||||
return dojo.lang.isPureObject(value);
|
||||
break;
|
||||
case "builtin":
|
||||
return dojo.lang.isBuiltIn(value);
|
||||
break;
|
||||
case "alien":
|
||||
return dojo.lang.isAlien(value);
|
||||
break;
|
||||
case "undefined":
|
||||
return dojo.lang.isUndefined(value);
|
||||
break;
|
||||
case null:
|
||||
case "null":
|
||||
return (value === null);
|
||||
break;
|
||||
case "optional":
|
||||
return ((value === null) || dojo.lang.isUndefined(value));
|
||||
break;
|
||||
default:
|
||||
if (dojo.lang.isFunction(type)) {
|
||||
return (value instanceof type);
|
||||
} else {
|
||||
dojo.raise("dojo.lang.isOfType() was passed an invalid type");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
dojo.raise("If we get here, it means a bug was introduced above.");
|
||||
}
|
||||
|
||||
/*
|
||||
* From reflection code, part of merge.
|
||||
* TRT 2006-02-01
|
||||
*/
|
||||
dojo.lang.getObject=function(/* String */ str){
|
||||
// summary
|
||||
// Will return an object, if it exists, based on the name in the passed string.
|
||||
var parts=str.split("."), i=0, obj=dj_global;
|
||||
do{
|
||||
obj=obj[parts[i++]];
|
||||
}while(i<parts.length&&obj);
|
||||
return (obj!=dj_global)?obj:null; // Object
|
||||
}
|
||||
|
||||
dojo.lang.doesObjectExist=function(/* String */ str){
|
||||
// summary
|
||||
// Check to see if object [str] exists, based on the passed string.
|
||||
var parts=str.split("."), i=0, obj=dj_global;
|
||||
do{
|
||||
obj=obj[parts[i++]];
|
||||
}while(i<parts.length&&obj);
|
||||
return (obj&&obj!=dj_global); // boolean
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue