Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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