Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Upgrade widget factory to 1.9 beta version - FIxes #4629
Browse files Browse the repository at this point in the history
  • Loading branch information
gseguin committed Aug 1, 2012
1 parent f629dc1 commit 225be4a
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions js/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -163,15 +163,16 @@ $.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 + "'" );
}
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() ) :
Expand Down Expand Up @@ -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(),
Expand All @@ -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 :
Expand All @@ -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" );
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand All @@ -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" );
},
Expand All @@ -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" );
},
Expand Down

0 comments on commit 225be4a

Please sign in to comment.