]> source.dussan.org Git - jquery-ui.git/commitdiff
Optimize widget's _createWidget method to not store data and bind remove
authorjzaefferer <joern.zaefferer@gmail.com>
Mon, 31 Jan 2011 15:33:45 +0000 (16:33 +0100)
committerjzaefferer <joern.zaefferer@gmail.com>
Mon, 31 Jan 2011 15:33:45 +0000 (16:33 +0100)
when dealing with an instance without an element (element == instance).

ui/jquery.ui.widget.js

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