Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.lang.func");
13
dojo.provide("dojo.lang.func");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
dojo.lang.hitch = function (thisObject, method) {
15
dojo.lang.hitch = function (thisObject, method) {
-
 
16
	var args = [];
-
 
17
	for (var x = 2; x < arguments.length; x++) {
-
 
18
		args.push(arguments[x]);
-
 
19
	}
14
	var fcn = (dojo.lang.isString(method) ? thisObject[method] : method) || function () {
20
	var fcn = (dojo.lang.isString(method) ? thisObject[method] : method) || function () {
15
	};
21
	};
16
	return function () {
22
	return function () {
-
 
23
		var ta = args.concat([]);
-
 
24
		for (var x = 0; x < arguments.length; x++) {
-
 
25
			ta.push(arguments[x]);
-
 
26
		}
17
		return fcn.apply(thisObject, arguments);
27
		return fcn.apply(thisObject, ta);
18
	};
28
	};
19
};
29
};
20
dojo.lang.anonCtr = 0;
30
dojo.lang.anonCtr = 0;
21
dojo.lang.anon = {};
31
dojo.lang.anon = {};
22
dojo.lang.nameAnonFunc = function (anonFuncPtr, thisObj, searchForNames) {
32
dojo.lang.nameAnonFunc = function (anonFuncPtr, thisObj, searchForNames) {
23
	var nso = (thisObj || dojo.lang.anon);
33
	var nso = (thisObj || dojo.lang.anon);
24
	if ((searchForNames) || ((dj_global["djConfig"]) && (djConfig["slowAnonFuncLookups"] == true))) {
34
	if ((searchForNames) || ((dj_global["djConfig"]) && (djConfig["slowAnonFuncLookups"] == true))) {
25
		for (var x in nso) {
35
		for (var x in nso) {
26
			try {
36
			try {
27
				if (nso[x] === anonFuncPtr) {
37
				if (nso[x] === anonFuncPtr) {
28
					return x;
38
					return x;
29
				}
39
				}
30
			}
40
			}
31
			catch (e) {
41
			catch (e) {
32
			}
42
			}
33
		}
43
		}
34
	}
44
	}
35
	var ret = "__" + dojo.lang.anonCtr++;
45
	var ret = "__" + dojo.lang.anonCtr++;
36
	while (typeof nso[ret] != "undefined") {
46
	while (typeof nso[ret] != "undefined") {
37
		ret = "__" + dojo.lang.anonCtr++;
47
		ret = "__" + dojo.lang.anonCtr++;
38
	}
48
	}
39
	nso[ret] = anonFuncPtr;
49
	nso[ret] = anonFuncPtr;
40
	return ret;
50
	return ret;
41
};
51
};
42
dojo.lang.forward = function (funcName) {
52
dojo.lang.forward = function (funcName) {
43
	return function () {
53
	return function () {
44
		return this[funcName].apply(this, arguments);
54
		return this[funcName].apply(this, arguments);
45
	};
55
	};
46
};
56
};
47
dojo.lang.curry = function (thisObj, func) {
57
dojo.lang.curry = function (thisObj, func) {
48
	var outerArgs = [];
58
	var outerArgs = [];
49
	thisObj = thisObj || dj_global;
59
	thisObj = thisObj || dj_global;
50
	if (dojo.lang.isString(func)) {
60
	if (dojo.lang.isString(func)) {
51
		func = thisObj[func];
61
		func = thisObj[func];
52
	}
62
	}
53
	for (var x = 2; x < arguments.length; x++) {
63
	for (var x = 2; x < arguments.length; x++) {
54
		outerArgs.push(arguments[x]);
64
		outerArgs.push(arguments[x]);
55
	}
65
	}
56
	var ecount = (func["__preJoinArity"] || func.length) - outerArgs.length;
66
	var ecount = (func["__preJoinArity"] || func.length) - outerArgs.length;
57
	function gather(nextArgs, innerArgs, expected) {
67
	function gather(nextArgs, innerArgs, expected) {
58
		var texpected = expected;
68
		var texpected = expected;
59
		var totalArgs = innerArgs.slice(0);
69
		var totalArgs = innerArgs.slice(0);
60
		for (var x = 0; x < nextArgs.length; x++) {
70
		for (var x = 0; x < nextArgs.length; x++) {
61
			totalArgs.push(nextArgs[x]);
71
			totalArgs.push(nextArgs[x]);
62
		}
72
		}
63
		expected = expected - nextArgs.length;
73
		expected = expected - nextArgs.length;
64
		if (expected <= 0) {
74
		if (expected <= 0) {
65
			var res = func.apply(thisObj, totalArgs);
75
			var res = func.apply(thisObj, totalArgs);
66
			expected = texpected;
76
			expected = texpected;
67
			return res;
77
			return res;
68
		} else {
78
		} else {
69
			return function () {
79
			return function () {
70
				return gather(arguments, totalArgs, expected);
80
				return gather(arguments, totalArgs, expected);
71
			};
81
			};
72
		}
82
		}
73
	}
83
	}
74
	return gather([], outerArgs, ecount);
84
	return gather([], outerArgs, ecount);
75
};
85
};
76
dojo.lang.curryArguments = function (thisObj, func, args, offset) {
86
dojo.lang.curryArguments = function (thisObj, func, args, offset) {
77
	var targs = [];
87
	var targs = [];
78
	var x = offset || 0;
88
	var x = offset || 0;
79
	for (x = offset; x < args.length; x++) {
89
	for (x = offset; x < args.length; x++) {
80
		targs.push(args[x]);
90
		targs.push(args[x]);
81
	}
91
	}
82
	return dojo.lang.curry.apply(dojo.lang, [thisObj, func].concat(targs));
92
	return dojo.lang.curry.apply(dojo.lang, [thisObj, func].concat(targs));
83
};
93
};
84
dojo.lang.tryThese = function () {
94
dojo.lang.tryThese = function () {
85
	for (var x = 0; x < arguments.length; x++) {
95
	for (var x = 0; x < arguments.length; x++) {
86
		try {
96
		try {
87
			if (typeof arguments[x] == "function") {
97
			if (typeof arguments[x] == "function") {
88
				var ret = (arguments[x]());
98
				var ret = (arguments[x]());
89
				if (ret) {
99
				if (ret) {
90
					return ret;
100
					return ret;
91
				}
101
				}
92
			}
102
			}
93
		}
103
		}
94
		catch (e) {
104
		catch (e) {
95
			dojo.debug(e);
105
			dojo.debug(e);
96
		}
106
		}
97
	}
107
	}
98
};
108
};
99
dojo.lang.delayThese = function (farr, cb, delay, onend) {
109
dojo.lang.delayThese = function (farr, cb, delay, onend) {
100
	if (!farr.length) {
110
	if (!farr.length) {
101
		if (typeof onend == "function") {
111
		if (typeof onend == "function") {
102
			onend();
112
			onend();
103
		}
113
		}
104
		return;
114
		return;
105
	}
115
	}
106
	if ((typeof delay == "undefined") && (typeof cb == "number")) {
116
	if ((typeof delay == "undefined") && (typeof cb == "number")) {
107
		delay = cb;
117
		delay = cb;
108
		cb = function () {
118
		cb = function () {
109
		};
119
		};
110
	} else {
120
	} else {
111
		if (!cb) {
121
		if (!cb) {
112
			cb = function () {
122
			cb = function () {
113
			};
123
			};
114
			if (!delay) {
124
			if (!delay) {
115
				delay = 0;
125
				delay = 0;
116
			}
126
			}
117
		}
127
		}
118
	}
128
	}
119
	setTimeout(function () {
129
	setTimeout(function () {
120
		(farr.shift())();
130
		(farr.shift())();
121
		cb();
131
		cb();
122
		dojo.lang.delayThese(farr, cb, delay, onend);
132
		dojo.lang.delayThese(farr, cb, delay, onend);
123
	}, delay);
133
	}, delay);
124
};
134
};
125
 
135