blob: 80142637cb33530e6d35b45c119602de62928150 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/**
* base class for creating inheritable classes
* based on resigs 'Simple Javascript Inheritance Class' (based on base2 and prototypejs)
* modified with static super and auto config
* @name Class
* @constructor
*/
(function( $, app ){
var ux = app.ns("ux");
var initializing = false, fnTest = /\b_super\b/;
ux.Class = function(){};
ux.Class.extend = function(prop) {
function Class() {
if(!initializing) {
var args = Array.prototype.slice.call(arguments);
this.config = $.extend( function(t) { // automatically construct a config object based on defaults and last item passed into the constructor
return $.extend(t._proto && t._proto() && arguments.callee(t._proto()) || {}, t.defaults);
} (this) , args.pop() );
this.init && this.init.apply(this, args); // automatically run the init function when class created
}
}
initializing = true;
var prototype = new this();
initializing = false;
var _super = this.prototype;
prototype._proto = function() {
return _super;
};
for(var name in prop) {
prototype[name] = typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() { this._super = _super[name]; return fn.apply(this, arguments); };
})(name, prop[name]) : prop[name];
}
Class.prototype = prototype;
Class.constructor = Class;
Class.extend = arguments.callee; // make class extendable
return Class;
};
})( this.jQuery, this.app );
|