Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade widget factory to 1.9 beta version - FIxes #4629

  • Loading branch information...
commit 225be4aef61375345e7219fe0e27e60fd7363460 1 parent f629dc1
@gseguin gseguin authored
Showing with 32 additions and 21 deletions.
  1. +32 −21 js/jquery.ui.widget.js
View
53 js/jquery.ui.widget.js
@@ -9,9 +9,9 @@
*/
(function( $, undefined ) {
-var slice = Array.prototype.slice;
-
-var _cleanData = $.cleanData;
+var uuid = 0,
+ slice = Array.prototype.slice,
+ _cleanData = $.cleanData;
$.cleanData = function( elems ) {
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
try {
@@ -73,11 +73,11 @@ $.widget = function( name, base, prototype ) {
if ( $.isFunction( value ) ) {
prototype[ prop ] = (function() {
var _super = function() {
- return base.prototype[ prop ].apply( this, arguments );
- };
- var _superApply = function( args ) {
- return base.prototype[ prop ].apply( this, args );
- };
+ return base.prototype[ prop ].apply( this, arguments );
+ },
+ _superApply = function( args ) {
+ return base.prototype[ prop ].apply( this, args );
+ };
return function() {
var __super = this._super,
__superApply = this._superApply,
@@ -163,7 +163,8 @@ $.widget.bridge = function( name, object ) {
if ( isMethodCall ) {
this.each(function() {
- var instance = $.data( this, fullName );
+ var methodValue,
+ instance = $.data( this, fullName );
if ( !instance ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" );
@@ -171,7 +172,7 @@ $.widget.bridge = function( name, object ) {
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
- var methodValue = instance[ options ].apply( instance, args );
+ methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
@@ -210,6 +211,8 @@ $.Widget.prototype = {
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
+ this.uuid = uuid++;
+ this.eventNamespace = "." + this.widgetName + this.uuid;
this.options = $.widget.extend( {},
this.options,
this._getCreateOptions(),
@@ -224,7 +227,7 @@ $.Widget.prototype = {
// TODO remove dual storage
$.data( element, this.widgetName, this );
$.data( element, this.widgetFullName, this );
- this._bind({ remove: "destroy" });
+ this._on({ remove: "destroy" });
this.document = $( element.style ?
// element within the document
element.ownerDocument :
@@ -245,22 +248,25 @@ $.Widget.prototype = {
destroy: function() {
this._destroy();
// we can probably remove the unbind calls in 2.0
- // all event bindings should go through this._bind()
+ // all event bindings should go through this._on()
this.element
- .unbind( "." + this.widgetName )
+ .unbind( this.eventNamespace )
// 1.9 BC for #7810
// TODO remove dual storage
.removeData( this.widgetName )
- .removeData( this.widgetFullName );
+ .removeData( this.widgetFullName )
+ // support: jquery <1.6.3
+ // http://bugs.jquery.com/ticket/9413
+ .removeData( $.camelCase( this.widgetFullName ) );
this.widget()
- .unbind( "." + this.widgetName )
+ .unbind( this.eventNamespace )
.removeAttr( "aria-disabled" )
.removeClass(
this.widgetFullName + "-disabled " +
"ui-state-disabled" );
// clean up events and states
- this.bindings.unbind( "." + this.widgetName );
+ this.bindings.unbind( this.eventNamespace );
this.hoverable.removeClass( "ui-state-hover" );
this.focusable.removeClass( "ui-state-focus" );
},
@@ -339,7 +345,7 @@ $.Widget.prototype = {
return this._setOption( "disabled", true );
},
- _bind: function( element, handlers ) {
+ _on: function( element, handlers ) {
// no element argument, shuffle and use this.element
if ( !handlers ) {
handlers = element;
@@ -367,11 +373,11 @@ $.Widget.prototype = {
// copy the guid so direct unbinding works
if ( typeof handler !== "string" ) {
handlerProxy.guid = handler.guid =
- handler.guid || handlerProxy.guid || jQuery.guid++;
+ handler.guid || handlerProxy.guid || $.guid++;
}
var match = event.match( /^(\w+)\s*(.*)$/ ),
- eventName = match[1] + "." + instance.widgetName,
+ eventName = match[1] + instance.eventNamespace,
selector = match[2];
if ( selector ) {
instance.widget().delegate( selector, eventName, handlerProxy );
@@ -381,6 +387,11 @@ $.Widget.prototype = {
});
},
+ _off: function( element, eventName ) {
+ eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
+ element.unbind( eventName ).undelegate( eventName );
+ },
+
_delay: function( handler, delay ) {
function handlerProxy() {
return ( typeof handler === "string" ? instance[ handler ] : handler )
@@ -392,7 +403,7 @@ $.Widget.prototype = {
_hoverable: function( element ) {
this.hoverable = this.hoverable.add( element );
- this._bind( element, {
+ this._on( element, {
mouseenter: function( event ) {
$( event.currentTarget ).addClass( "ui-state-hover" );
},
@@ -404,7 +415,7 @@ $.Widget.prototype = {
_focusable: function( element ) {
this.focusable = this.focusable.add( element );
- this._bind( element, {
+ this._on( element, {
focusin: function( event ) {
$( event.currentTarget ).addClass( "ui-state-focus" );
},
Please sign in to comment.
Something went wrong with that request. Please try again.