]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/util/Class.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / util / Class.js
1 /**
2  * Class.js
3  *
4  * Copyright 2003-2012, Moxiecode Systems AB, All rights reserved.
5  */
6
7 /**
8  * This utilitiy class is used for easier inheritage.
9  *
10  * Features:
11  * * Exposed super functions: this._super();
12  * * Mixins
13  * * Dummy functions
14  * * Property functions: var value = object.value(); and object.value(newValue);
15  * * Static functions
16  * * Defaults settings
17  */
18 define("tinymce/util/Class", [
19         "tinymce/util/Tools"
20 ], function(Tools) {
21         var each = Tools.each, extend = Tools.extend;
22
23         var extendClass, initializing;
24
25         function Class() {
26         }
27
28         // Provides classical inheritance, based on code made by John Resig
29         Class.extend = extendClass = function(prop) {
30                 var Self = this, _super = Self.prototype, prototype, name, member;
31
32                 // The dummy class constructor
33                 function Class() {
34                         var i, mixins, mixin, self;
35
36                         // All construction is actually done in the init method
37                         if (!initializing) {
38                                 self = this;
39
40                                 // Run class constuctor
41                                 if (self.init) {
42                                         self.init.apply(self, arguments);
43                                 }
44
45                                 // Run mixin constructors
46                                 mixins = self.Mixins;
47                                 if (mixins) {
48                                         i = mixins.length;
49                                         while (i--) {
50                                                 mixin = mixins[i];
51                                                 if (mixin.init) {
52                                                         mixin.init.apply(self, arguments);
53                                                 }
54                                         }
55                                 }
56                         }
57                 }
58
59                 // Dummy function, needs to be extended in order to provide functionality
60                 function dummy() {
61                         return this;
62                 }
63
64                 // Creates a overloaded method for the class
65                 // this enables you to use this._super(); to call the super function
66                 function createMethod(name, fn) {
67                         return function(){
68                                 var self = this, tmp = self._super, ret;
69
70                                 self._super = _super[name];
71                                 ret = fn.apply(self, arguments);
72                                 self._super = tmp;
73
74                                 return ret;
75                         };
76                 }
77
78                 // Instantiate a base class (but only create the instance,
79                 // don't run the init constructor)
80                 initializing = true;
81                 prototype = new Self();
82                 initializing = false;
83
84                 // Add mixins
85                 if (prop.Mixins) {
86                         each(prop.Mixins, function(mixin) {
87                                 mixin = mixin;
88
89                                 for (var name in mixin) {
90                                         if (name !== "init") {
91                                                 prop[name] = mixin[name];
92                                         }
93                                 }
94                         });
95
96                         if (_super.Mixins) {
97                                 prop.Mixins = _super.Mixins.concat(prop.Mixins);
98                         }
99                 }
100
101                 // Generate dummy methods
102                 if (prop.Methods) {
103                         each(prop.Methods.split(','), function(name) {
104                                 prop[name] = dummy;
105                         });
106                 }
107
108                 // Generate property methods
109                 if (prop.Properties) {
110                         each(prop.Properties.split(','), function(name) {
111                                 var fieldName = '_' + name;
112
113                                 prop[name] = function(value) {
114                                         var self = this, undef;
115
116                                         // Set value
117                                         if (value !== undef) {
118                                                 self[fieldName] = value;
119
120                                                 return self;
121                                         }
122
123                                         // Get value
124                                         return self[fieldName];
125                                 };
126                         });
127                 }
128
129                 // Static functions
130                 if (prop.Statics) {
131                         each(prop.Statics, function(func, name) {
132                                 Class[name] = func;
133                         });
134                 }
135
136                 // Default settings
137                 if (prop.Defaults && _super.Defaults) {
138                         prop.Defaults = extend({}, _super.Defaults, prop.Defaults);
139                 }
140
141                 // Copy the properties over onto the new prototype
142                 for (name in prop) {
143                         member = prop[name];
144
145                         if (typeof member == "function" && _super[name]) {
146                                 prototype[name] = createMethod(name, member);
147                         } else {
148                                 prototype[name] = member;
149                         }
150                 }
151
152                 // Populate our constructed prototype object
153                 Class.prototype = prototype;
154
155                 // Enforce the constructor to be what we expect
156                 Class.constructor = Class;
157
158                 // And make this class extendible
159                 Class.extend = extendClass;
160
161                 return Class;
162         };
163
164         return Class;
165 });