diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-01-31 22:04:09 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-01-31 22:04:09 -0500 |
commit | cb8f5b7f2679ab5473229cac432f28c72521048c (patch) | |
tree | 60b63ec0b7f190832dcadef9e04a195985e61621 /ui/jquery.ui.widget.js | |
parent | bb857ddd8d6d4ac7620b49bf765352cd064494c0 (diff) | |
parent | effbb2c0ec2e60bea6ec5e5822ee52f8ea9e18bc (diff) | |
download | jquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.tar.gz jquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.zip |
Merge branch 'master' into widget-events
Conflicts:
ui/jquery.ui.widget.js
Diffstat (limited to 'ui/jquery.ui.widget.js')
-rw-r--r-- | ui/jquery.ui.widget.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 4f092f9d8..c8e5348ac 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -37,7 +37,13 @@ $.widget = function( name, base, prototype ) { $[ namespace ] = $[ namespace ] || {}; $[ namespace ][ name ] = function( options, element ) { + // allow instantiation without "new" keyword + if ( !this._createWidget ) { + return new $[ namespace ][ name ]( options, element ); + } + // allow instantiation without initializing for simple inheritance + // must use "new" keyword (the code above always passes args) if ( arguments.length ) { this._createWidget( options, element ); } @@ -97,7 +103,7 @@ $.widget.bridge = function( name, object ) { if ( instance ) { instance.option( options || {} )._init(); } else { - $.data( this, name, new object( options, this ) ); + object( options, this ); } }); } @@ -107,7 +113,13 @@ $.widget.bridge = function( name, object ) { }; $.Widget = function( options, element ) { + // allow instantiation without "new" keyword + if ( !this._createWidget ) { + return new $[ namespace ][ name ]( options, element ); + } + // allow instantiation without initializing for simple inheritance + // must use "new" keyword (the code above always passes args) if ( arguments.length ) { this._createWidget( options, element ); } @@ -116,13 +128,12 @@ $.Widget = function( options, element ) { $.Widget.prototype = { widgetName: "widget", widgetEventPrefix: "", + defaultElement: "<div>", options: { disabled: false }, _createWidget: function( options, element ) { - // $.widget.bridge stores the plugin instance, but we do it anyway - // so that it's stored even before the _create function runs - $.data( element, this.widgetName, this ); + element = $( element || this.defaultElement || this )[ 0 ]; this.element = $( element ); this.options = $.extend( true, {}, this.options, @@ -132,7 +143,11 @@ $.Widget.prototype = { this.bindings = $(); this.hoverable = $(); this.focusable = $(); - this._bind({ remove: "destroy" }); + + if ( element !== this ) { + $.data( element, this.widgetName, this ); + this._bind({ remove: "destroy" }); + } this._create(); this._trigger( "create" ); |