Subversion Repositories Applications.papyrus

Rev

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