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.declare");
13
dojo.provide("dojo.lang.declare");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
dojo.require("dojo.lang.extras");
15
dojo.require("dojo.lang.extras");
14
dojo.lang.declare = function (className, superclass, init, props) {
16
dojo.lang.declare = function (className, superclass, init, props) {
15
	if ((dojo.lang.isFunction(props)) || ((!props) && (!dojo.lang.isFunction(init)))) {
17
	if ((dojo.lang.isFunction(props)) || ((!props) && (!dojo.lang.isFunction(init)))) {
16
		var temp = props;
18
		var temp = props;
17
		props = init;
19
		props = init;
18
		init = temp;
20
		init = temp;
19
	}
21
	}
20
	var mixins = [];
22
	var mixins = [];
21
	if (dojo.lang.isArray(superclass)) {
23
	if (dojo.lang.isArray(superclass)) {
22
		mixins = superclass;
24
		mixins = superclass;
23
		superclass = mixins.shift();
25
		superclass = mixins.shift();
24
	}
26
	}
25
	if (!init) {
27
	if (!init) {
26
		init = dojo.evalObjPath(className, false);
28
		init = dojo.evalObjPath(className, false);
27
		if ((init) && (!dojo.lang.isFunction(init))) {
29
		if ((init) && (!dojo.lang.isFunction(init))) {
28
			init = null;
30
			init = null;
29
		}
31
		}
30
	}
32
	}
31
	var ctor = dojo.lang.declare._makeConstructor();
33
	var ctor = dojo.lang.declare._makeConstructor();
32
	var scp = (superclass ? superclass.prototype : null);
34
	var scp = (superclass ? superclass.prototype : null);
33
	if (scp) {
35
	if (scp) {
34
		scp.prototyping = true;
36
		scp.prototyping = true;
35
		ctor.prototype = new superclass();
37
		ctor.prototype = new superclass();
36
		scp.prototyping = false;
38
		scp.prototyping = false;
37
	}
39
	}
38
	ctor.superclass = scp;
40
	ctor.superclass = scp;
39
	ctor.mixins = mixins;
41
	ctor.mixins = mixins;
40
	for (var i = 0, l = mixins.length; i < l; i++) {
42
	for (var i = 0, l = mixins.length; i < l; i++) {
41
		dojo.lang.extend(ctor, mixins[i].prototype);
43
		dojo.lang.extend(ctor, mixins[i].prototype);
42
	}
44
	}
43
	ctor.prototype.initializer = null;
45
	ctor.prototype.initializer = null;
44
	ctor.prototype.declaredClass = className;
46
	ctor.prototype.declaredClass = className;
45
	if (dojo.lang.isArray(props)) {
47
	if (dojo.lang.isArray(props)) {
46
		dojo.lang.extend.apply(dojo.lang, [ctor].concat(props));
48
		dojo.lang.extend.apply(dojo.lang, [ctor].concat(props));
47
	} else {
49
	} else {
48
		dojo.lang.extend(ctor, (props) || {});
50
		dojo.lang.extend(ctor, (props) || {});
49
	}
51
	}
50
	dojo.lang.extend(ctor, dojo.lang.declare._common);
52
	dojo.lang.extend(ctor, dojo.lang.declare._common);
51
	ctor.prototype.constructor = ctor;
53
	ctor.prototype.constructor = ctor;
52
	ctor.prototype.initializer = (ctor.prototype.initializer) || (init) || (function () {
54
	ctor.prototype.initializer = (ctor.prototype.initializer) || (init) || (function () {
53
	});
55
	});
54
	var created = dojo.parseObjPath(className, null, true);
56
	var created = dojo.parseObjPath(className, null, true);
55
	created.obj[created.prop] = ctor;
57
	created.obj[created.prop] = ctor;
56
	return ctor;
58
	return ctor;
57
};
59
};
58
dojo.lang.declare._makeConstructor = function () {
60
dojo.lang.declare._makeConstructor = function () {
59
	return function () {
61
	return function () {
60
		var self = this._getPropContext();
62
		var self = this._getPropContext();
61
		var s = self.constructor.superclass;
63
		var s = self.constructor.superclass;
62
		if ((s) && (s.constructor)) {
64
		if ((s) && (s.constructor)) {
63
			if (s.constructor == arguments.callee) {
65
			if (s.constructor == arguments.callee) {
64
				this._inherited("constructor", arguments);
66
				this._inherited("constructor", arguments);
65
			} else {
67
			} else {
66
				this._contextMethod(s, "constructor", arguments);
68
				this._contextMethod(s, "constructor", arguments);
67
			}
69
			}
68
		}
70
		}
69
		var ms = (self.constructor.mixins) || ([]);
71
		var ms = (self.constructor.mixins) || ([]);
70
		for (var i = 0, m; (m = ms[i]); i++) {
72
		for (var i = 0, m; (m = ms[i]); i++) {
71
			(((m.prototype) && (m.prototype.initializer)) || (m)).apply(this, arguments);
73
			(((m.prototype) && (m.prototype.initializer)) || (m)).apply(this, arguments);
72
		}
74
		}
73
		if ((!this.prototyping) && (self.initializer)) {
75
		if ((!this.prototyping) && (self.initializer)) {
74
			self.initializer.apply(this, arguments);
76
			self.initializer.apply(this, arguments);
75
		}
77
		}
76
	};
78
	};
77
};
79
};
78
dojo.lang.declare._common = {_getPropContext:function () {
80
dojo.lang.declare._common = {_getPropContext:function () {
79
	return (this.___proto || this);
81
	return (this.___proto || this);
80
}, _contextMethod:function (ptype, method, args) {
82
}, _contextMethod:function (ptype, method, args) {
81
	var result, stack = this.___proto;
83
	var result, stack = this.___proto;
82
	this.___proto = ptype;
84
	this.___proto = ptype;
83
	try {
85
	try {
84
		result = ptype[method].apply(this, (args || []));
86
		result = ptype[method].apply(this, (args || []));
85
	}
87
	}
86
	catch (e) {
88
	catch (e) {
87
		throw e;
89
		throw e;
88
	}
90
	}
89
	finally {
91
	finally {
90
		this.___proto = stack;
92
		this.___proto = stack;
91
	}
93
	}
92
	return result;
94
	return result;
93
}, _inherited:function (prop, args) {
95
}, _inherited:function (prop, args) {
94
	var p = this._getPropContext();
96
	var p = this._getPropContext();
95
	do {
97
	do {
96
		if ((!p.constructor) || (!p.constructor.superclass)) {
98
		if ((!p.constructor) || (!p.constructor.superclass)) {
97
			return;
99
			return;
98
		}
100
		}
99
		p = p.constructor.superclass;
101
		p = p.constructor.superclass;
100
	} while (!(prop in p));
102
	} while (!(prop in p));
101
	return (dojo.lang.isFunction(p[prop]) ? this._contextMethod(p, prop, args) : p[prop]);
103
	return (dojo.lang.isFunction(p[prop]) ? this._contextMethod(p, prop, args) : p[prop]);
102
}, inherited:function (prop, args) {
104
}, inherited:function (prop, args) {
103
	dojo.deprecated("'inherited' method is dangerous, do not up-call! 'inherited' is slated for removal in 0.5; name your super class (or use superclass property) instead.", "0.5");
105
	dojo.deprecated("'inherited' method is dangerous, do not up-call! 'inherited' is slated for removal in 0.5; name your super class (or use superclass property) instead.", "0.5");
104
	this._inherited(prop, args);
106
	this._inherited(prop, args);
105
}};
107
}};
106
dojo.declare = dojo.lang.declare;
108
dojo.declare = dojo.lang.declare;
107
 
109