Skip to content

Commit 03dcdd6

Browse files
committed
Optimize widget's _createWidget method to not store data and bind remove
when dealing with an instance without an element (element == instance).
1 parent 6309061 commit 03dcdd6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ui/jquery.ui.widget.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,19 @@ $.Widget.prototype = {
134134
},
135135
_createWidget: function( options, element ) {
136136
element = $( element || this.defaultElement || this )[ 0 ];
137-
$.data( element, this.widgetName, this );
138137
this.element = $( element );
139138
this.options = $.extend( true, {},
140139
this.options,
141140
this._getCreateOptions(),
142141
options );
143-
144-
var self = this;
145-
this.element.bind( "remove." + this.widgetName, function() {
146-
self.destroy();
147-
});
148-
142+
if (element !== this) {
143+
$.data(element, this.widgetName, this);
144+
145+
var self = this;
146+
this.element.bind("remove." + this.widgetName, function(){
147+
self.destroy();
148+
});
149+
}
149150
this._create();
150151
this._trigger( "create" );
151152
this._init();

0 commit comments

Comments
 (0)