Skip to content
This repository
Browse code

Upgrade widget factory to 1.9 beta version - FIxes #4629

  • Loading branch information...
commit 225be4aef61375345e7219fe0e27e60fd7363460 1 parent f629dc1
Ghislain Seguin authored August 01, 2012

Showing 1 changed file with 32 additions and 21 deletions. Show diff stats Hide diff stats

  1. 53  js/jquery.ui.widget.js
53  js/jquery.ui.widget.js
@@ -9,9 +9,9 @@
9 9
  */
10 10
 (function( $, undefined ) {
11 11
 
12  
-var slice = Array.prototype.slice;
13  
-
14  
-var _cleanData = $.cleanData;
  12
+var uuid = 0,
  13
+	slice = Array.prototype.slice,
  14
+	_cleanData = $.cleanData;
15 15
 $.cleanData = function( elems ) {
16 16
 	for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
17 17
 		try {
@@ -73,11 +73,11 @@ $.widget = function( name, base, prototype ) {
73 73
 		if ( $.isFunction( value ) ) {
74 74
 			prototype[ prop ] = (function() {
75 75
 				var _super = function() {
76  
-					return base.prototype[ prop ].apply( this, arguments );
77  
-				};
78  
-				var _superApply = function( args ) {
79  
-					return base.prototype[ prop ].apply( this, args );
80  
-				};
  76
+						return base.prototype[ prop ].apply( this, arguments );
  77
+					},
  78
+					_superApply = function( args ) {
  79
+						return base.prototype[ prop ].apply( this, args );
  80
+					};
81 81
 				return function() {
82 82
 					var __super = this._super,
83 83
 						__superApply = this._superApply,
@@ -163,7 +163,8 @@ $.widget.bridge = function( name, object ) {
163 163
 
164 164
 		if ( isMethodCall ) {
165 165
 			this.each(function() {
166  
-				var instance = $.data( this, fullName );
  166
+				var methodValue,
  167
+					instance = $.data( this, fullName );
167 168
 				if ( !instance ) {
168 169
 					return $.error( "cannot call methods on " + name + " prior to initialization; " +
169 170
 						"attempted to call method '" + options + "'" );
@@ -171,7 +172,7 @@ $.widget.bridge = function( name, object ) {
171 172
 				if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
172 173
 					return $.error( "no such method '" + options + "' for " + name + " widget instance" );
173 174
 				}
174  
-				var methodValue = instance[ options ].apply( instance, args );
  175
+				methodValue = instance[ options ].apply( instance, args );
175 176
 				if ( methodValue !== instance && methodValue !== undefined ) {
176 177
 					returnValue = methodValue && methodValue.jquery ?
177 178
 						returnValue.pushStack( methodValue.get() ) :
@@ -210,6 +211,8 @@ $.Widget.prototype = {
210 211
 	_createWidget: function( options, element ) {
211 212
 		element = $( element || this.defaultElement || this )[ 0 ];
212 213
 		this.element = $( element );
  214
+		this.uuid = uuid++;
  215
+		this.eventNamespace = "." + this.widgetName + this.uuid;
213 216
 		this.options = $.widget.extend( {},
214 217
 			this.options,
215 218
 			this._getCreateOptions(),
@@ -224,7 +227,7 @@ $.Widget.prototype = {
224 227
 			// TODO remove dual storage
225 228
 			$.data( element, this.widgetName, this );
226 229
 			$.data( element, this.widgetFullName, this );
227  
-			this._bind({ remove: "destroy" });
  230
+			this._on({ remove: "destroy" });
228 231
 			this.document = $( element.style ?
229 232
 				// element within the document
230 233
 				element.ownerDocument :
@@ -245,22 +248,25 @@ $.Widget.prototype = {
245 248
 	destroy: function() {
246 249
 		this._destroy();
247 250
 		// we can probably remove the unbind calls in 2.0
248  
-		// all event bindings should go through this._bind()
  251
+		// all event bindings should go through this._on()
249 252
 		this.element
250  
-			.unbind( "." + this.widgetName )
  253
+			.unbind( this.eventNamespace )
251 254
 			// 1.9 BC for #7810
252 255
 			// TODO remove dual storage
253 256
 			.removeData( this.widgetName )
254  
-			.removeData( this.widgetFullName );
  257
+			.removeData( this.widgetFullName )
  258
+			// support: jquery <1.6.3
  259
+			// http://bugs.jquery.com/ticket/9413
  260
+			.removeData( $.camelCase( this.widgetFullName ) );
255 261
 		this.widget()
256  
-			.unbind( "." + this.widgetName )
  262
+			.unbind( this.eventNamespace )
257 263
 			.removeAttr( "aria-disabled" )
258 264
 			.removeClass(
259 265
 				this.widgetFullName + "-disabled " +
260 266
 				"ui-state-disabled" );
261 267
 
262 268
 		// clean up events and states
263  
-		this.bindings.unbind( "." + this.widgetName );
  269
+		this.bindings.unbind( this.eventNamespace );
264 270
 		this.hoverable.removeClass( "ui-state-hover" );
265 271
 		this.focusable.removeClass( "ui-state-focus" );
266 272
 	},
@@ -339,7 +345,7 @@ $.Widget.prototype = {
339 345
 		return this._setOption( "disabled", true );
340 346
 	},
341 347
 
342  
-	_bind: function( element, handlers ) {
  348
+	_on: function( element, handlers ) {
343 349
 		// no element argument, shuffle and use this.element
344 350
 		if ( !handlers ) {
345 351
 			handlers = element;
@@ -367,11 +373,11 @@ $.Widget.prototype = {
367 373
 			// copy the guid so direct unbinding works
368 374
 			if ( typeof handler !== "string" ) {
369 375
 				handlerProxy.guid = handler.guid =
370  
-					handler.guid || handlerProxy.guid || jQuery.guid++;
  376
+					handler.guid || handlerProxy.guid || $.guid++;
371 377
 			}
372 378
 
373 379
 			var match = event.match( /^(\w+)\s*(.*)$/ ),
374  
-				eventName = match[1] + "." + instance.widgetName,
  380
+				eventName = match[1] + instance.eventNamespace,
375 381
 				selector = match[2];
376 382
 			if ( selector ) {
377 383
 				instance.widget().delegate( selector, eventName, handlerProxy );
@@ -381,6 +387,11 @@ $.Widget.prototype = {
381 387
 		});
382 388
 	},
383 389
 
  390
+	_off: function( element, eventName ) {
  391
+		eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  392
+		element.unbind( eventName ).undelegate( eventName );
  393
+	},
  394
+
384 395
 	_delay: function( handler, delay ) {
385 396
 		function handlerProxy() {
386 397
 			return ( typeof handler === "string" ? instance[ handler ] : handler )
@@ -392,7 +403,7 @@ $.Widget.prototype = {
392 403
 
393 404
 	_hoverable: function( element ) {
394 405
 		this.hoverable = this.hoverable.add( element );
395  
-		this._bind( element, {
  406
+		this._on( element, {
396 407
 			mouseenter: function( event ) {
397 408
 				$( event.currentTarget ).addClass( "ui-state-hover" );
398 409
 			},
@@ -404,7 +415,7 @@ $.Widget.prototype = {
404 415
 
405 416
 	_focusable: function( element ) {
406 417
 		this.focusable = this.focusable.add( element );
407  
-		this._bind( element, {
  418
+		this._on( element, {
408 419
 			focusin: function( event ) {
409 420
 				$( event.currentTarget ).addClass( "ui-state-focus" );
410 421
 			},

0 notes on commit 225be4a

Please sign in to comment.
Something went wrong with that request. Please try again.