Skip to content

Commit 9608e98

Browse files
committed
Widget: Rename _bind() to _on(). Partial fix for #7795 - Widget: _on and _off.
1 parent e8b6232 commit 9608e98

10 files changed

+33
-34
lines changed

demos/widget/default.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
.button();
5757

5858
// bind click events on the changer button to the random method
59-
this._bind( this.changer, {
60-
// _bind won't call random when widget is disabled
59+
this._on( this.changer, {
60+
// _on won't call random when widget is disabled
6161
click: "random"
6262
});
6363
this._refresh();
@@ -90,7 +90,7 @@
9090
}
9191
},
9292

93-
// events bound via _bind are removed automatically
93+
// events bound via _on are removed automatically
9494
// revert other modifications here
9595
_destroy: function() {
9696
// remove generated elements

tests/unit/widget/widget_core.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,13 @@ test( ".widget() - overriden", function() {
610610
deepEqual( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] );
611611
});
612612

613-
test( "._bind() to element (default)", function() {
613+
test( "._on() to element (default)", function() {
614614
expect( 12 );
615615
var that, widget;
616616
$.widget( "ui.testWidget", {
617617
_create: function() {
618618
that = this;
619-
this._bind({
619+
this._on({
620620
keyup: this.keyup,
621621
keydown: "keydown"
622622
});
@@ -650,13 +650,13 @@ test( "._bind() to element (default)", function() {
650650
.trigger( "keydown" );
651651
});
652652

653-
test( "._bind() to descendent", function() {
653+
test( "._on() to descendent", function() {
654654
expect( 12 );
655655
var that, widget, descendant;
656656
$.widget( "ui.testWidget", {
657657
_create: function() {
658658
that = this;
659-
this._bind( this.element.find( "strong" ), {
659+
this._on( this.element.find( "strong" ), {
660660
keyup: this.keyup,
661661
keydown: "keydown"
662662
});
@@ -707,7 +707,7 @@ test( "._bind() to descendent", function() {
707707
.trigger( "keydown" );
708708
});
709709

710-
test( "_bind() with delegate", function() {
710+
test( "_on() with delegate", function() {
711711
expect( 8 );
712712
$.widget( "ui.testWidget", {
713713
_create: function() {
@@ -727,7 +727,7 @@ test( "_bind() with delegate", function() {
727727
}
728728
};
729729
};
730-
this._bind({
730+
this._on({
731731
"click": "handler",
732732
"click a": "handler"
733733
});
@@ -740,7 +740,7 @@ test( "_bind() with delegate", function() {
740740
}
741741
};
742742
};
743-
this._bind({
743+
this._on({
744744
"change form fieldset > input": "handler"
745745
});
746746
}

ui/jquery.ui.accordion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ $.widget( "ui.accordion", {
137137
});
138138
}
139139

140-
this._bind( this.headers, { keydown: "_keydown" });
141-
this._bind( this.headers.next(), { keydown: "_panelKeyDown" });
140+
this._on( this.headers, { keydown: "_keydown" });
141+
this._on( this.headers.next(), { keydown: "_panelKeyDown" });
142142
this._setupEvents( options.event );
143143
},
144144

@@ -376,7 +376,7 @@ $.widget( "ui.accordion", {
376376
$.each( event.split(" "), function( index, eventName ) {
377377
events[ eventName ] = "_eventHandler";
378378
});
379-
this._bind( this.headers, events );
379+
this._on( this.headers, events );
380380
},
381381

382382
_eventHandler: function( event ) {

ui/jquery.ui.autocomplete.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $.widget( "ui.autocomplete", {
6363
.addClass( "ui-autocomplete-input" )
6464
.attr( "autocomplete", "off" );
6565

66-
this._bind({
66+
this._on({
6767
keydown: function( event ) {
6868
if ( this.element.prop( "readOnly" ) ) {
6969
suppressKeyPress = true;
@@ -190,7 +190,7 @@ $.widget( "ui.autocomplete", {
190190
.zIndex( this.element.zIndex() + 1 )
191191
.hide()
192192
.data( "menu" );
193-
this._bind( this.menu.element, {
193+
this._on( this.menu.element, {
194194
mousedown: function( event ) {
195195
// prevent moving focus out of the text field
196196
event.preventDefault();
@@ -297,7 +297,7 @@ $.widget( "ui.autocomplete", {
297297
// turning off autocomplete prevents the browser from remembering the
298298
// value when navigating through history, so we re-enable autocomplete
299299
// if the page is unloaded before the widget is destroyed. #7790
300-
this._bind( this.window, {
300+
this._on( this.window, {
301301
beforeunload: function() {
302302
this.element.removeAttr( "autocomplete" );
303303
}

ui/jquery.ui.menu.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $.widget( "ui.menu", {
4343
tabIndex: 0
4444
})
4545
// need to catch all clicks on disabled menu
46-
// not possible through _bind
46+
// not possible through _on
4747
.bind( "click.menu", $.proxy(function( event ) {
4848
if ( this.options.disabled ) {
4949
event.preventDefault();
@@ -56,7 +56,7 @@ $.widget( "ui.menu", {
5656
.attr( "aria-disabled", "true" );
5757
}
5858

59-
this._bind({
59+
this._on({
6060
// Prevent focus from sticking to links inside menu after clicking
6161
// them (focus should always stay on UL during navigation).
6262
"mousedown .ui-menu-item > a": function( event ) {
@@ -122,8 +122,7 @@ $.widget( "ui.menu", {
122122
this.refresh();
123123

124124
// TODO: We probably shouldn't bind to document for each menu.
125-
// TODO: This isn't being cleaned up on destroy.
126-
this._bind( this.document, {
125+
this._on( this.document, {
127126
click: function( event ) {
128127
if ( !$( event.target ).closest( ".ui-menu" ).length ) {
129128
this.collapseAll( event );

ui/jquery.ui.slider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ $.widget( "ui.slider", $.ui.mouse, {
114114
$( this ).data( "ui-slider-handle-index", i );
115115
});
116116

117-
this._bind( this.handles, {
117+
this._on( this.handles, {
118118
keydown: function( event ) {
119119
var allowed, curVal, newVal, step,
120120
index = $( event.target ).data( "ui-slider-handle-index" );

ui/jquery.ui.spinner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ $.widget( "ui.spinner", {
5454
this._value( this.element.val(), true );
5555

5656
this._draw();
57-
this._bind( this._events );
57+
this._on( this._events );
5858
this._refresh();
5959

6060
// turning off autocomplete prevents the browser from remembering the
6161
// value when navigating through history, so we re-enable autocomplete
6262
// if the page is unloaded before the widget is destroyed. #7790
63-
this._bind( this.window, {
63+
this._on( this.window, {
6464
beforeunload: function() {
6565
this.element.removeAttr( "autocomplete" );
6666
}

ui/jquery.ui.tabs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ $.widget( "ui.tabs", {
481481
}
482482

483483
this.anchors.add( this.tabs ).add( this.panels ).unbind( ".tabs" );
484-
this._bind( this.anchors, events );
485-
this._bind( this.tabs, { keydown: "_tabKeydown" } );
486-
this._bind( this.panels, { keydown: "_panelKeydown" } );
484+
this._on( this.anchors, events );
485+
this._on( this.tabs, { keydown: "_tabKeydown" } );
486+
this._on( this.panels, { keydown: "_panelKeydown" } );
487487

488488
this._focusable( this.tabs );
489489
this._hoverable( this.tabs );
@@ -943,7 +943,7 @@ if ( $.uiBackCompat !== false ) {
943943
},
944944
_create: function() {
945945
this._super();
946-
this._bind({
946+
this._on({
947947
tabsbeforeload: function( event, ui ) {
948948
if ( !this.options.spinner ) {
949949
return;

ui/jquery.ui.tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $.widget( "ui.tooltip", {
6161
},
6262

6363
_create: function() {
64-
this._bind({
64+
this._on({
6565
mouseover: "open",
6666
focusin: "open"
6767
});
@@ -185,7 +185,7 @@ $.widget( "ui.tooltip", {
185185

186186
this._trigger( "open", event, { tooltip: tooltip } );
187187

188-
this._bind( target, {
188+
this._on( target, {
189189
mouseleave: "close",
190190
focusout: "close",
191191
keyup: function( event ) {

ui/jquery.ui.widget.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ $.Widget.prototype = {
224224
// TODO remove dual storage
225225
$.data( element, this.widgetName, this );
226226
$.data( element, this.widgetFullName, this );
227-
this._bind({ remove: "destroy" });
227+
this._on({ remove: "destroy" });
228228
this.document = $( element.style ?
229229
// element within the document
230230
element.ownerDocument :
@@ -245,7 +245,7 @@ $.Widget.prototype = {
245245
destroy: function() {
246246
this._destroy();
247247
// we can probably remove the unbind calls in 2.0
248-
// all event bindings should go through this._bind()
248+
// all event bindings should go through this._on()
249249
this.element
250250
.unbind( "." + this.widgetName )
251251
// 1.9 BC for #7810
@@ -342,7 +342,7 @@ $.Widget.prototype = {
342342
return this._setOption( "disabled", true );
343343
},
344344

345-
_bind: function( element, handlers ) {
345+
_on: function( element, handlers ) {
346346
// no element argument, shuffle and use this.element
347347
if ( !handlers ) {
348348
handlers = element;
@@ -395,7 +395,7 @@ $.Widget.prototype = {
395395

396396
_hoverable: function( element ) {
397397
this.hoverable = this.hoverable.add( element );
398-
this._bind( element, {
398+
this._on( element, {
399399
mouseenter: function( event ) {
400400
$( event.currentTarget ).addClass( "ui-state-hover" );
401401
},
@@ -407,7 +407,7 @@ $.Widget.prototype = {
407407

408408
_focusable: function( element ) {
409409
this.focusable = this.focusable.add( element );
410-
this._bind( element, {
410+
this._on( element, {
411411
focusin: function( event ) {
412412
$( event.currentTarget ).addClass( "ui-state-focus" );
413413
},

0 commit comments

Comments
 (0)