Skip to content

Commit 00d4beb

Browse files
committed
Widget: Create eventNamespace property instead of constantly rebuilding it.
1 parent 28b14ec commit 00d4beb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/unit/widget/widget_core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,11 @@ test( "_on() with delegate", function() {
749749
$.ui.testWidget();
750750
});
751751

752-
test( "_bind() to common element", function() {
752+
test( "_on() to common element", function() {
753753
expect( 1 );
754754
$.widget( "ui.testWidget", {
755755
_create: function() {
756-
this._bind( this.document, {
756+
this._on( this.document, {
757757
"customevent": "_handler"
758758
});
759759
},

ui/jquery.ui.widget.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ $.Widget.prototype = {
211211
_createWidget: function( options, element ) {
212212
element = $( element || this.defaultElement || this )[ 0 ];
213213
this.element = $( element );
214+
this.uuid = uuid++;
215+
this.eventNamespace = "." + this.widgetName + this.uuid;
214216
this.options = $.widget.extend( {},
215217
this.options,
216218
this._getCreateOptions(),
217219
options );
218-
this.uuid = uuid++;
219220

220221
this.bindings = $();
221222
this.hoverable = $();
@@ -249,7 +250,7 @@ $.Widget.prototype = {
249250
// we can probably remove the unbind calls in 2.0
250251
// all event bindings should go through this._on()
251252
this.element
252-
.unbind( "." + this.widgetName + this.uuid )
253+
.unbind( this.eventNamespace )
253254
// 1.9 BC for #7810
254255
// TODO remove dual storage
255256
.removeData( this.widgetName )
@@ -258,14 +259,14 @@ $.Widget.prototype = {
258259
// http://bugs.jquery.com/ticket/9413
259260
.removeData( $.camelCase( this.widgetFullName ) );
260261
this.widget()
261-
.unbind( "." + this.widgetName + this.uuid )
262+
.unbind( this.eventNamespace )
262263
.removeAttr( "aria-disabled" )
263264
.removeClass(
264265
this.widgetFullName + "-disabled " +
265266
"ui-state-disabled" );
266267

267268
// clean up events and states
268-
this.bindings.unbind( "." + this.widgetName + this.uuid );
269+
this.bindings.unbind( this.eventNamespace );
269270
this.hoverable.removeClass( "ui-state-hover" );
270271
this.focusable.removeClass( "ui-state-focus" );
271272
},
@@ -376,7 +377,7 @@ $.Widget.prototype = {
376377
}
377378

378379
var match = event.match( /^(\w+)\s*(.*)$/ ),
379-
eventName = match[1] + "." + instance.widgetName + instance.uuid,
380+
eventName = match[1] + instance.eventNamespace,
380381
selector = match[2];
381382
if ( selector ) {
382383
instance.widget().delegate( selector, eventName, handlerProxy );

0 commit comments

Comments
 (0)