Optimize widget's _createWidget method to not store data and bind remove

when dealing with an instance without an element (element == instance).
This commit is contained in:
jzaefferer 2011-01-31 16:33:45 +01:00
parent 6309061a2b
commit 03dcdd6373

View File

@ -134,18 +134,19 @@ $.Widget.prototype = {
}, },
_createWidget: function( options, element ) { _createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ]; element = $( element || this.defaultElement || this )[ 0 ];
$.data( element, this.widgetName, this );
this.element = $( element ); this.element = $( element );
this.options = $.extend( true, {}, this.options = $.extend( true, {},
this.options, this.options,
this._getCreateOptions(), this._getCreateOptions(),
options ); options );
if (element !== this) {
var self = this; $.data(element, this.widgetName, this);
this.element.bind( "remove." + this.widgetName, function() {
self.destroy(); var self = this;
}); this.element.bind("remove." + this.widgetName, function(){
self.destroy();
});
}
this._create(); this._create();
this._trigger( "create" ); this._trigger( "create" );
this._init(); this._init();