diff --git a/bi/core.js b/bi/core.js index 5525ad41d..dfaa57f48 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4292,8 +4292,7 @@ BI.OB = function (config) { }; $.extend(BI.OB.prototype, { props: {}, - init: function () { - }, + init: null, _defaultConfig: function (config) { return {}; @@ -4301,7 +4300,7 @@ $.extend(BI.OB.prototype, { _init: function () { this._initListeners(); - this.init(); + this.init && this.init(); }, _initListeners: function () { @@ -4439,41 +4438,30 @@ BI.Widget = BI.inherit(BI.OB, { }, //生命周期函数 - beforeCreate: function () { - - }, - - created: function () { - - }, - - render: function () { - - }, + beforeCreate: null, - beforeMounted: function () { + created: null, - }, + render: null, - mounted: function () { + beforeMounted: null, - }, + mounted: null, update: null, - destroyed: function () { - }, + destroyed: null, _init: function () { BI.Widget.superclass._init.apply(this, arguments); - this.beforeCreate(); + this.beforeCreate && this.beforeCreate(); this._initRoot(); this._initElementWidth(); this._initElementHeight(); this._initVisualEffects(); this._initState(); this._initElement(); - this.created(); + this.created && this.created(); }, /** @@ -4546,7 +4534,7 @@ BI.Widget = BI.inherit(BI.OB, { _initElement: function () { var self = this; - var els = this.render(); + var els = this.render && this.render(); if (BI.isPlainObject(els)) { els = [els]; } @@ -4580,13 +4568,13 @@ BI.Widget = BI.inherit(BI.OB, { if (!isMounted) { return; } - this.beforeMounted(); + this.beforeMounted && this.beforeMounted(); this._isMounted = true; this._mountChildren(); BI.each(this._children, function (i, widget) { widget._mount && widget._mount(); }); - this.mounted(); + this.mounted && this.mounted(); }, _mountChildren: function () { @@ -4612,7 +4600,7 @@ BI.Widget = BI.inherit(BI.OB, { this._parent = null; this._isMounted = false; this.purgeListeners(); - this.destroyed(); + this.destroyed && this.destroyed(); }, setWidth: function (w) { @@ -4799,7 +4787,7 @@ BI.Widget = BI.inherit(BI.OB, { empty: function () { BI.each(this._children, function (i, widget) { - widget._unMount(); + widget._unMount && widget._unMount(); }); this._children = {}; this.element.empty(); @@ -4812,7 +4800,7 @@ BI.Widget = BI.inherit(BI.OB, { this._children = {}; this._parent = null; this._isMounted = false; - this.destroyed(); + this.destroyed && this.destroyed(); this.element.destroy(); this.fireEvent(BI.Events.DESTROY); this.purgeListeners(); diff --git a/dist/core.js b/dist/core.js index 531b4886e..762d4e0b6 100644 --- a/dist/core.js +++ b/dist/core.js @@ -14213,8 +14213,7 @@ BI.OB = function (config) { }; $.extend(BI.OB.prototype, { props: {}, - init: function () { - }, + init: null, _defaultConfig: function (config) { return {}; @@ -14222,7 +14221,7 @@ $.extend(BI.OB.prototype, { _init: function () { this._initListeners(); - this.init(); + this.init && this.init(); }, _initListeners: function () { @@ -14360,41 +14359,30 @@ BI.Widget = BI.inherit(BI.OB, { }, //生命周期函数 - beforeCreate: function () { - - }, - - created: function () { - - }, + beforeCreate: null, - render: function () { - - }, + created: null, - beforeMounted: function () { + render: null, - }, + beforeMounted: null, - mounted: function () { - - }, + mounted: null, update: null, - destroyed: function () { - }, + destroyed: null, _init: function () { BI.Widget.superclass._init.apply(this, arguments); - this.beforeCreate(); + this.beforeCreate && this.beforeCreate(); this._initRoot(); this._initElementWidth(); this._initElementHeight(); this._initVisualEffects(); this._initState(); this._initElement(); - this.created(); + this.created && this.created(); }, /** @@ -14467,7 +14455,7 @@ BI.Widget = BI.inherit(BI.OB, { _initElement: function () { var self = this; - var els = this.render(); + var els = this.render && this.render(); if (BI.isPlainObject(els)) { els = [els]; } @@ -14501,13 +14489,13 @@ BI.Widget = BI.inherit(BI.OB, { if (!isMounted) { return; } - this.beforeMounted(); + this.beforeMounted && this.beforeMounted(); this._isMounted = true; this._mountChildren(); BI.each(this._children, function (i, widget) { widget._mount && widget._mount(); }); - this.mounted(); + this.mounted && this.mounted(); }, _mountChildren: function () { @@ -14533,7 +14521,7 @@ BI.Widget = BI.inherit(BI.OB, { this._parent = null; this._isMounted = false; this.purgeListeners(); - this.destroyed(); + this.destroyed && this.destroyed(); }, setWidth: function (w) { @@ -14720,7 +14708,7 @@ BI.Widget = BI.inherit(BI.OB, { empty: function () { BI.each(this._children, function (i, widget) { - widget._unMount(); + widget._unMount && widget._unMount(); }); this._children = {}; this.element.empty(); @@ -14733,7 +14721,7 @@ BI.Widget = BI.inherit(BI.OB, { this._children = {}; this._parent = null; this._isMounted = false; - this.destroyed(); + this.destroyed && this.destroyed(); this.element.destroy(); this.fireEvent(BI.Events.DESTROY); this.purgeListeners(); @@ -23226,184 +23214,7 @@ BI.HorizontalFillLayoutLogic = BI.inherit(BI.Logic, { _init: function () { BI.HorizontalFillLayoutLogic.superclass._init.apply(this, arguments); } -});// BI.M = BI.inherit(BI.OB, { -// validationError: null, -// -// _init: function () { -// BI.M.superclass._init.apply(this, arguments); -// this.attributes = {}; -// _.extend(this, _.pick(this.options, ['rootURL', 'parent', 'data', 'id'])); -// this.set(this.options); -// this.changed = {}; -// }, -// -// _validate: function (attrs, options) { -// if (!options.validate || !this.validate) return true; -// attrs = _.extend({}, this.attributes, attrs); -// var error = this.validationError = this.validate(attrs, options) || null; -// if (!error) return true; -// this.fireEvent('invalid', error, this, _.extend(options, {validationError: error})); -// return false; -// }, -// -// toJSON: function (options) { -// return _.clone(this.attributes); -// }, -// -// get: function (attr) { -// return this.attributes[attr]; -// }, -// -// has: function (attr) { -// return _.has(this.attributes, attr); -// }, -// -// matches: function (attrs) { -// var keys = _.keys(attrs), length = keys.length; -// var obj = Object(this.attributes); -// for (var i = 0; i < length; i++) { -// var key = keys[i]; -// if (!_.isEqual(attrs[key], obj[key]) || !(key in obj)) return false; -// } -// return true; -// }, -// -// set: function (key, val, options) { -// var attr, attrs, unset, changes, silent, changing, changed, prev, current; -// if (key == null) return this; -// -// // Handle both `"key", value` and `{key: value}` -style arguments. -// if (typeof key === 'object') { -// attrs = key; -// options = val; -// } else { -// (attrs = {})[key] = val; -// } -// -// options || (options = {}); -// -// // Run validation. -// if (!this._validate(attrs, options)) return false; -// -// // Extract attributes and options. -// unset = options.unset; -// silent = options.silent; -// changes = []; -// changing = this._changing; -// this._changing = true; -// -// if (!changing) { -// this._previousAttributes = _.clone(this.attributes); -// this.changed = {}; -// } -// current = this.attributes, prev = this._previousAttributes; -// -// // Check for changes of `id`. -// if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; -// -// // For each `set` attribute, update or delete the current value. -// for (attr in attrs) { -// val = attrs[attr]; -// if (!_.isEqual(current[attr], val)) changes.push(attr); -// if (!_.isEqual(prev[attr], val)) { -// this.changed[attr] = val; -// } else { -// delete this.changed[attr]; -// } -// unset ? delete current[attr] : current[attr] = val; -// } -// -// // Trigger all relevant attribute changes. -// if (!silent) { -// if (changes.length) this._pending = options; -// for (var i = 0, length = changes.length; i < length; i++) { -// this.trigger('change:' + changes[i], this, current[changes[i]], options); -// } -// } -// -// // You might be wondering why there's a `while` loop here. Changes can -// // be recursively nested within `"change"` events. -// if (changing) return this; -// changed = BI.clone(this.changed); -// if (!silent) { -// while (this._pending) { -// options = this._pending; -// this._pending = false; -// this.trigger('change', changed, prev, this, options); -// } -// } -// this._pending = false; -// this._changing = false; -// if (!silent && changes.length) this.trigger("changed", changed, prev, this, options); -// return this; -// }, -// -// unset: function (attr, options) { -// return this.set(attr, void 0, _.extend({}, options, {unset: true})); -// }, -// -// clear: function (options) { -// var attrs = {}; -// for (var key in this.attributes) attrs[key] = void 0; -// return this.set(attrs, _.extend({}, options, {unset: true})); -// }, -// -// hasChanged: function (attr) { -// if (attr == null) return !_.isEmpty(this.changed); -// return _.has(this.changed, attr); -// }, -// -// changedAttributes: function (diff) { -// if (!diff) return this.hasChanged() ? _.clone(this.changed) : false; -// var val, changed = false; -// var old = this._changing ? this._previousAttributes : this.attributes; -// for (var attr in diff) { -// if (_.isEqual(old[attr], (val = diff[attr]))) continue; -// (changed || (changed = {}))[attr] = val; -// } -// return changed; -// }, -// -// // Get the previous value of an attribute, recorded at the time the last -// // `"change"` event was fired. -// previous: function (attr) { -// if (attr == null || !this._previousAttributes) return null; -// return this._previousAttributes[attr]; -// }, -// -// // Get all of the attributes of the model at the time of the previous -// // `"change"` event. -// previousAttributes: function () { -// return _.clone(this._previousAttributes); -// }, -// -// destroy: function (options) { -// options = options ? _.clone(options) : {}; -// var model = this; -// var success = options.success; -// -// var destroy = function () { -// model.stopListening(); -// model.trigger('destroy', model.collection, model, options); -// }; -// -// options.success = function (resp) { -// if (options.wait || model.isNew()) destroy(); -// if (success) success(resp, model, options); -// if (!model.isNew()) model.trigger('sync', resp, model, options).trigger('delete', resp, model, options); -// }; -// -// if (this.isNew()) { -// options.success(); -// return false; -// } -// wrapError(this, options); -// -// var xhr = this.sync('delete', this, options); -// if (!options.wait) destroy(); -// return xhr; -// }, -// });BI.Plugin = BI.Plugin || {}; +});BI.Plugin = BI.Plugin || {}; ; (function () { var _WidgetsPlugin = {}; diff --git a/src/core/m.js b/src/core/m.js deleted file mode 100644 index 028ed01b6..000000000 --- a/src/core/m.js +++ /dev/null @@ -1,178 +0,0 @@ -// BI.M = BI.inherit(BI.OB, { -// validationError: null, -// -// _init: function () { -// BI.M.superclass._init.apply(this, arguments); -// this.attributes = {}; -// _.extend(this, _.pick(this.options, ['rootURL', 'parent', 'data', 'id'])); -// this.set(this.options); -// this.changed = {}; -// }, -// -// _validate: function (attrs, options) { -// if (!options.validate || !this.validate) return true; -// attrs = _.extend({}, this.attributes, attrs); -// var error = this.validationError = this.validate(attrs, options) || null; -// if (!error) return true; -// this.fireEvent('invalid', error, this, _.extend(options, {validationError: error})); -// return false; -// }, -// -// toJSON: function (options) { -// return _.clone(this.attributes); -// }, -// -// get: function (attr) { -// return this.attributes[attr]; -// }, -// -// has: function (attr) { -// return _.has(this.attributes, attr); -// }, -// -// matches: function (attrs) { -// var keys = _.keys(attrs), length = keys.length; -// var obj = Object(this.attributes); -// for (var i = 0; i < length; i++) { -// var key = keys[i]; -// if (!_.isEqual(attrs[key], obj[key]) || !(key in obj)) return false; -// } -// return true; -// }, -// -// set: function (key, val, options) { -// var attr, attrs, unset, changes, silent, changing, changed, prev, current; -// if (key == null) return this; -// -// // Handle both `"key", value` and `{key: value}` -style arguments. -// if (typeof key === 'object') { -// attrs = key; -// options = val; -// } else { -// (attrs = {})[key] = val; -// } -// -// options || (options = {}); -// -// // Run validation. -// if (!this._validate(attrs, options)) return false; -// -// // Extract attributes and options. -// unset = options.unset; -// silent = options.silent; -// changes = []; -// changing = this._changing; -// this._changing = true; -// -// if (!changing) { -// this._previousAttributes = _.clone(this.attributes); -// this.changed = {}; -// } -// current = this.attributes, prev = this._previousAttributes; -// -// // Check for changes of `id`. -// if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; -// -// // For each `set` attribute, update or delete the current value. -// for (attr in attrs) { -// val = attrs[attr]; -// if (!_.isEqual(current[attr], val)) changes.push(attr); -// if (!_.isEqual(prev[attr], val)) { -// this.changed[attr] = val; -// } else { -// delete this.changed[attr]; -// } -// unset ? delete current[attr] : current[attr] = val; -// } -// -// // Trigger all relevant attribute changes. -// if (!silent) { -// if (changes.length) this._pending = options; -// for (var i = 0, length = changes.length; i < length; i++) { -// this.trigger('change:' + changes[i], this, current[changes[i]], options); -// } -// } -// -// // You might be wondering why there's a `while` loop here. Changes can -// // be recursively nested within `"change"` events. -// if (changing) return this; -// changed = BI.clone(this.changed); -// if (!silent) { -// while (this._pending) { -// options = this._pending; -// this._pending = false; -// this.trigger('change', changed, prev, this, options); -// } -// } -// this._pending = false; -// this._changing = false; -// if (!silent && changes.length) this.trigger("changed", changed, prev, this, options); -// return this; -// }, -// -// unset: function (attr, options) { -// return this.set(attr, void 0, _.extend({}, options, {unset: true})); -// }, -// -// clear: function (options) { -// var attrs = {}; -// for (var key in this.attributes) attrs[key] = void 0; -// return this.set(attrs, _.extend({}, options, {unset: true})); -// }, -// -// hasChanged: function (attr) { -// if (attr == null) return !_.isEmpty(this.changed); -// return _.has(this.changed, attr); -// }, -// -// changedAttributes: function (diff) { -// if (!diff) return this.hasChanged() ? _.clone(this.changed) : false; -// var val, changed = false; -// var old = this._changing ? this._previousAttributes : this.attributes; -// for (var attr in diff) { -// if (_.isEqual(old[attr], (val = diff[attr]))) continue; -// (changed || (changed = {}))[attr] = val; -// } -// return changed; -// }, -// -// // Get the previous value of an attribute, recorded at the time the last -// // `"change"` event was fired. -// previous: function (attr) { -// if (attr == null || !this._previousAttributes) return null; -// return this._previousAttributes[attr]; -// }, -// -// // Get all of the attributes of the model at the time of the previous -// // `"change"` event. -// previousAttributes: function () { -// return _.clone(this._previousAttributes); -// }, -// -// destroy: function (options) { -// options = options ? _.clone(options) : {}; -// var model = this; -// var success = options.success; -// -// var destroy = function () { -// model.stopListening(); -// model.trigger('destroy', model.collection, model, options); -// }; -// -// options.success = function (resp) { -// if (options.wait || model.isNew()) destroy(); -// if (success) success(resp, model, options); -// if (!model.isNew()) model.trigger('sync', resp, model, options).trigger('delete', resp, model, options); -// }; -// -// if (this.isNew()) { -// options.success(); -// return false; -// } -// wrapError(this, options); -// -// var xhr = this.sync('delete', this, options); -// if (!options.wait) destroy(); -// return xhr; -// }, -// }); \ No newline at end of file diff --git a/src/core/ob.js b/src/core/ob.js index 182c68f07..bb71c3874 100644 --- a/src/core/ob.js +++ b/src/core/ob.js @@ -14,8 +14,7 @@ BI.OB = function (config) { }; $.extend(BI.OB.prototype, { props: {}, - init: function () { - }, + init: null, _defaultConfig: function (config) { return {}; @@ -23,7 +22,7 @@ $.extend(BI.OB.prototype, { _init: function () { this._initListeners(); - this.init(); + this.init && this.init(); }, _initListeners: function () { diff --git a/src/core/widget.js b/src/core/widget.js index 90c1e8eb1..29bc55f37 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -23,41 +23,30 @@ BI.Widget = BI.inherit(BI.OB, { }, //生命周期函数 - beforeCreate: function () { + beforeCreate: null, - }, - - created: function () { - - }, - - render: function () { - - }, - - beforeMounted: function () { + created: null, - }, + render: null, - mounted: function () { + beforeMounted: null, - }, + mounted: null, update: null, - destroyed: function () { - }, + destroyed: null, _init: function () { BI.Widget.superclass._init.apply(this, arguments); - this.beforeCreate(); + this.beforeCreate && this.beforeCreate(); this._initRoot(); this._initElementWidth(); this._initElementHeight(); this._initVisualEffects(); this._initState(); this._initElement(); - this.created(); + this.created && this.created(); }, /** @@ -130,7 +119,7 @@ BI.Widget = BI.inherit(BI.OB, { _initElement: function () { var self = this; - var els = this.render(); + var els = this.render && this.render(); if (BI.isPlainObject(els)) { els = [els]; } @@ -164,13 +153,13 @@ BI.Widget = BI.inherit(BI.OB, { if (!isMounted) { return; } - this.beforeMounted(); + this.beforeMounted && this.beforeMounted(); this._isMounted = true; this._mountChildren(); BI.each(this._children, function (i, widget) { widget._mount && widget._mount(); }); - this.mounted(); + this.mounted && this.mounted(); }, _mountChildren: function () { @@ -196,7 +185,7 @@ BI.Widget = BI.inherit(BI.OB, { this._parent = null; this._isMounted = false; this.purgeListeners(); - this.destroyed(); + this.destroyed && this.destroyed(); }, setWidth: function (w) { @@ -383,7 +372,7 @@ BI.Widget = BI.inherit(BI.OB, { empty: function () { BI.each(this._children, function (i, widget) { - widget._unMount(); + widget._unMount && widget._unMount(); }); this._children = {}; this.element.empty(); @@ -396,7 +385,7 @@ BI.Widget = BI.inherit(BI.OB, { this._children = {}; this._parent = null; this._isMounted = false; - this.destroyed(); + this.destroyed && this.destroyed(); this.element.destroy(); this.fireEvent(BI.Events.DESTROY); this.purgeListeners();