From 5fda4f6828ad523bd0692b76f903010a458fcac4 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 1 Mar 2012 14:30:02 +0100 Subject: Update data naming for Widget, including backwards compability. Updated tests and added one for the custom expression. Partial fix for #7810 --- ui/jquery.ui.widget.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ui/jquery.ui.widget.js') diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 2d48ae26d..d11f993c6 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -36,7 +36,7 @@ $.widget = function( name, base, prototype ) { // create selector for plugin $.expr[ ":" ][ fullName ] = function( elem ) { - return !!$.data( elem, name ); + return !!$.data( elem, fullName ); }; $[ namespace ] = $[ namespace ] || {}; @@ -148,6 +148,7 @@ $.widget.extend = function( target ) { }; $.widget.bridge = function( name, object ) { + var fullName = object.prototype.widgetBaseClass; $.fn[ name ] = function( options ) { var isMethodCall = typeof options === "string", args = slice.call( arguments, 1 ), @@ -160,7 +161,9 @@ $.widget.bridge = function( name, object ) { if ( isMethodCall ) { this.each(function() { - var instance = $.data( this, name ); + // 1.9 BC for #7810 + // TODO remove fallback to name + var instance = $.data( this, fullName ) || $.data( this, name ); if ( !instance ) { return $.error( "cannot call methods on " + name + " prior to initialization; " + "attempted to call method '" + options + "'" ); @@ -178,7 +181,9 @@ $.widget.bridge = function( name, object ) { }); } else { this.each(function() { - var instance = $.data( this, name ); + // 1.9 BC for #7810 + // TODO remove fallback to name + var instance = $.data( this, fullName ) || $.data( this, name ); if ( instance ) { instance.option( options || {} )._init(); } else { @@ -217,7 +222,10 @@ $.Widget.prototype = { this.focusable = $(); if ( element !== this ) { + // 1.9 BC for #7810 + // TODO remove dual storage $.data( element, this.widgetName, this ); + $.data( element, this.widgetBaseClass, this ); this._bind({ remove: "destroy" }); this.document = $( element.style ? // element within the document -- cgit v1.2.3 From 1b80154832611f8f440f4559c429fbdc4e773177 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 1 Mar 2012 14:36:17 +0100 Subject: Widget: Rename widgetBaseClass to widgetFullName. Deprecates widgetBaseClass, to be removed later. Fixes #8154 --- ui/jquery.ui.widget.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ui/jquery.ui.widget.js') diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index d11f993c6..d06b2654f 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -105,7 +105,9 @@ $.widget = function( name, base, prototype ) { constructor: constructor, namespace: namespace, widgetName: name, - widgetBaseClass: fullName + // TODO remove widgetBaseClass, see #8155 + widgetBaseClass: fullName, + widgetFullName: fullName }); // If this widget is being redefined then we need to find all widgets that @@ -148,7 +150,7 @@ $.widget.extend = function( target ) { }; $.widget.bridge = function( name, object ) { - var fullName = object.prototype.widgetBaseClass; + var fullName = object.prototype.widgetFullName; $.fn[ name ] = function( options ) { var isMethodCall = typeof options === "string", args = slice.call( arguments, 1 ), @@ -225,7 +227,7 @@ $.Widget.prototype = { // 1.9 BC for #7810 // TODO remove dual storage $.data( element, this.widgetName, this ); - $.data( element, this.widgetBaseClass, this ); + $.data( element, this.widgetFullName, this ); this._bind({ remove: "destroy" }); this.document = $( element.style ? // element within the document @@ -255,7 +257,7 @@ $.Widget.prototype = { .unbind( "." + this.widgetName ) .removeAttr( "aria-disabled" ) .removeClass( - this.widgetBaseClass + "-disabled " + + this.widgetFullName + "-disabled " + "ui-state-disabled" ); // clean up events and states @@ -322,7 +324,7 @@ $.Widget.prototype = { if ( key === "disabled" ) { this.widget() - .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value ) + .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value ) .attr( "aria-disabled", value ); this.hoverable.removeClass( "ui-state-hover" ); this.focusable.removeClass( "ui-state-focus" ); -- cgit v1.2.3 From 5e51b8db284b23bf818148051aaf5b41a7b9c7b1 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 1 Mar 2012 15:03:30 +0100 Subject: Update Widget data naming/usage. Remove unnecessary fallbacks, update .removeData to use full name. --- tests/unit/widget/widget_core.js | 5 ++++- ui/jquery.ui.widget.js | 10 +++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'ui/jquery.ui.widget.js') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index b4bb6356d..e104d4ae9 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -82,7 +82,7 @@ test( "custom selector expression", function() { }); test( "jQuery usage", function() { - expect( 15 ); + expect( 16 ); var shouldCreate = false; @@ -140,6 +140,9 @@ test( "jQuery usage", function() { ret = elem.testWidget( "jQueryObject" ); equal( ret[ 0 ], document.body, "returned jQuery object" ); equal( ret.end(), elem, "stack preserved" ); + + elem.testWidget( "destroy" ); + equal( elem.data( "ui-testWidget" ), null ); }); test( "direct usage", function() { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index d06b2654f..17416ff9f 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -163,9 +163,7 @@ $.widget.bridge = function( name, object ) { if ( isMethodCall ) { this.each(function() { - // 1.9 BC for #7810 - // TODO remove fallback to name - var instance = $.data( this, fullName ) || $.data( this, name ); + var instance = $.data( this, fullName ); if ( !instance ) { return $.error( "cannot call methods on " + name + " prior to initialization; " + "attempted to call method '" + options + "'" ); @@ -183,9 +181,7 @@ $.widget.bridge = function( name, object ) { }); } else { this.each(function() { - // 1.9 BC for #7810 - // TODO remove fallback to name - var instance = $.data( this, fullName ) || $.data( this, name ); + var instance = $.data( this, fullName ); if ( instance ) { instance.option( options || {} )._init(); } else { @@ -252,7 +248,7 @@ $.Widget.prototype = { // all event bindings should go through this._bind() this.element .unbind( "." + this.widgetName ) - .removeData( this.widgetName ); + .removeData( this.widgetFullName ); this.widget() .unbind( "." + this.widgetName ) .removeAttr( "aria-disabled" ) -- cgit v1.2.3 From 2321ae06cbe44b86d14c82ebd452d06e3922dca9 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 1 Mar 2012 15:13:52 +0100 Subject: Remove both widgetName and widgetFullName data --- ui/jquery.ui.widget.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ui/jquery.ui.widget.js') diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 17416ff9f..40abd67de 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -248,6 +248,9 @@ $.Widget.prototype = { // all event bindings should go through this._bind() this.element .unbind( "." + this.widgetName ) + // 1.9 BC for #7810 + // TODO remove dual storage + .removeData( this.widgetName ) .removeData( this.widgetFullName ); this.widget() .unbind( "." + this.widgetName ) -- cgit v1.2.3