X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/jsbuilder/src/Ext.js?ds=inline diff --git a/jsbuilder/src/Ext.js b/jsbuilder/src/Ext.js new file mode 100644 index 00000000..0a595018 --- /dev/null +++ b/jsbuilder/src/Ext.js @@ -0,0 +1,267 @@ +Ext = { + /** + * Copies all the properties of config to obj. + * @param {Object} object The receiver of the properties + * @param {Object} config The source of the properties + * @param {Object} defaults A different object that will also be applied for default values + * @return {Object} returns obj + * @member Ext apply + */ + apply : function(object, config, defaults) { + // no "this" reference for friendly out of scope calls + if (defaults) { + Ext.apply(object, defaults); + } + if (object && config && typeof config == 'object') { + for (var key in config) { + object[key] = config[key]; + } + } + return object; + }, + + /** + * Copies all the properties of config to obj if they don't already exist. + * @param {Object} obj The receiver of the properties + * @param {Object} config The source of the properties + * @return {Object} returns obj + */ + applyIf : function(object, config) { + var property, undefined; + if (object) { + for (property in config) { + if (object[property] === undefined) { + object[property] = config[property]; + } + } + } + return object; + }, + + /** + *
Extends one class to create a subclass and optionally overrides members with the passed literal. This method + * also adds the function "override()" to the subclass that can be used to override members of the class.
+ * @param {Function} superclass The constructor of class being extended. + * @param {Object} overridesA literal with members which are copied into the subclass's + * prototype, and are therefore shared between all instances of the new class.
+ *This may contain a special member named constructor. This is used + * to define the constructor of the new class, and is returned. If this property is + * not specified, a constructor is generated and returned which just calls the + * superclass's constructor passing on its parameters.
+ *It is essential that you call the superclass constructor in any provided constructor. See example code.
+ * @return {Function} The subclass constructor from theoverrides
parameter, or a generated one if not provided.
+ */
+ extend : function() {
+ // inline overrides
+ var inlineOverrides = function(o){
+ for(var m in o){
+ this[m] = o[m];
+ }
+ };
+
+ var objectConstructor = Object.prototype.constructor;
+
+ return function(subclass, superclass, overrides){
+ // First we check if the user passed in just the superClass with overrides
+ if(Ext.isObject(superclass)){
+ overrides = superclass;
+ superclass = subclass;
+ subclass = overrides.constructor != objectConstructor
+ ? overrides.constructor
+ : function(){
+ superclass.apply(this, arguments);
+ };
+ }
+
+ // We create a new temporary class
+ var F = function(){},
+ subclassProto,
+ superclassProto = superclass.prototype;
+
+ F.prototype = superclassProto;
+ subclassProto = subclass.prototype = new F();
+ subclassProto.constructor = subclass;
+ subclass.superclass = superclassProto;
+
+ if(superclassProto.constructor == objectConstructor){
+ superclassProto.constructor = superclass;
+ }
+
+ subclass.override = function(overrides){
+ Ext.override(subclass, overrides);
+ };
+
+ subclassProto.superclass = subclassProto.supr = (function(){
+ return superclassProto;
+ });
+
+ subclassProto.override = inlineOverrides;
+ subclassProto.proto = subclassProto;
+ subclassProto.superproto = superclassProto;
+
+ subclass.override(overrides);
+ subclass.extend = function(o){
+ return Ext.extend(subclass, o);
+ };
+
+ return subclass;
+ };
+ }(),
+
+ /**
+ * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
+ * @param {Object} origclass The class to override
+ * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
+ * containing one or more methods.
+ * @method override
+ */
+ override : function(origclass, overrides) {
+ if (overrides) {
+ Ext.apply(origclass.prototype, overrides);
+ }
+ },
+
+ /**
+ * Returns true if the passed value is empty.
+ *The value is deemed to be empty if it is