Subversion Repositories Applications.papyrus

Rev

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