Skip to content

Commit

Permalink
Widget: Rename _bind() to _on(). Partial fix for #7795 - Widget: _on …
Browse files Browse the repository at this point in the history
…and _off.
  • Loading branch information
scottgonzalez committed Jun 13, 2012
1 parent e8b6232 commit 9608e98
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
6 changes: 3 additions & 3 deletions demos/widget/default.html
Expand Up @@ -56,8 +56,8 @@
.button();

// bind click events on the changer button to the random method
this._bind( this.changer, {
// _bind won't call random when widget is disabled
this._on( this.changer, {
// _on won't call random when widget is disabled
click: "random"
});
this._refresh();
Expand Down Expand Up @@ -90,7 +90,7 @@
}
},

// events bound via _bind are removed automatically
// events bound via _on are removed automatically
// revert other modifications here
_destroy: function() {
// remove generated elements
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/widget/widget_core.js
Expand Up @@ -610,13 +610,13 @@ test( ".widget() - overriden", function() {
deepEqual( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] );
});

test( "._bind() to element (default)", function() {
test( "._on() to element (default)", function() {
expect( 12 );
var that, widget;
$.widget( "ui.testWidget", {
_create: function() {
that = this;
this._bind({
this._on({
keyup: this.keyup,
keydown: "keydown"
});
Expand Down Expand Up @@ -650,13 +650,13 @@ test( "._bind() to element (default)", function() {
.trigger( "keydown" );
});

test( "._bind() to descendent", function() {
test( "._on() to descendent", function() {
expect( 12 );
var that, widget, descendant;
$.widget( "ui.testWidget", {
_create: function() {
that = this;
this._bind( this.element.find( "strong" ), {
this._on( this.element.find( "strong" ), {
keyup: this.keyup,
keydown: "keydown"
});
Expand Down Expand Up @@ -707,7 +707,7 @@ test( "._bind() to descendent", function() {
.trigger( "keydown" );
});

test( "_bind() with delegate", function() {
test( "_on() with delegate", function() {
expect( 8 );
$.widget( "ui.testWidget", {
_create: function() {
Expand All @@ -727,7 +727,7 @@ test( "_bind() with delegate", function() {
}
};
};
this._bind({
this._on({
"click": "handler",
"click a": "handler"
});
Expand All @@ -740,7 +740,7 @@ test( "_bind() with delegate", function() {
}
};
};
this._bind({
this._on({
"change form fieldset > input": "handler"
});
}
Expand Down
6 changes: 3 additions & 3 deletions ui/jquery.ui.accordion.js
Expand Up @@ -137,8 +137,8 @@ $.widget( "ui.accordion", {
});
}

this._bind( this.headers, { keydown: "_keydown" });
this._bind( this.headers.next(), { keydown: "_panelKeyDown" });
this._on( this.headers, { keydown: "_keydown" });
this._on( this.headers.next(), { keydown: "_panelKeyDown" });
this._setupEvents( options.event );
},

Expand Down Expand Up @@ -376,7 +376,7 @@ $.widget( "ui.accordion", {
$.each( event.split(" "), function( index, eventName ) {
events[ eventName ] = "_eventHandler";
});
this._bind( this.headers, events );
this._on( this.headers, events );
},

_eventHandler: function( event ) {
Expand Down
6 changes: 3 additions & 3 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -63,7 +63,7 @@ $.widget( "ui.autocomplete", {
.addClass( "ui-autocomplete-input" )
.attr( "autocomplete", "off" );

this._bind({
this._on({
keydown: function( event ) {
if ( this.element.prop( "readOnly" ) ) {
suppressKeyPress = true;
Expand Down Expand Up @@ -190,7 +190,7 @@ $.widget( "ui.autocomplete", {
.zIndex( this.element.zIndex() + 1 )
.hide()
.data( "menu" );
this._bind( this.menu.element, {
this._on( this.menu.element, {
mousedown: function( event ) {
// prevent moving focus out of the text field
event.preventDefault();
Expand Down Expand Up @@ -297,7 +297,7 @@ $.widget( "ui.autocomplete", {
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
this._bind( this.window, {
this._on( this.window, {
beforeunload: function() {
this.element.removeAttr( "autocomplete" );
}
Expand Down
7 changes: 3 additions & 4 deletions ui/jquery.ui.menu.js
Expand Up @@ -43,7 +43,7 @@ $.widget( "ui.menu", {
tabIndex: 0
})
// need to catch all clicks on disabled menu
// not possible through _bind
// not possible through _on
.bind( "click.menu", $.proxy(function( event ) {
if ( this.options.disabled ) {
event.preventDefault();
Expand All @@ -56,7 +56,7 @@ $.widget( "ui.menu", {
.attr( "aria-disabled", "true" );
}

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

// TODO: We probably shouldn't bind to document for each menu.
// TODO: This isn't being cleaned up on destroy.
this._bind( this.document, {
this._on( this.document, {
click: function( event ) {
if ( !$( event.target ).closest( ".ui-menu" ).length ) {
this.collapseAll( event );
Expand Down
2 changes: 1 addition & 1 deletion ui/jquery.ui.slider.js
Expand Up @@ -114,7 +114,7 @@ $.widget( "ui.slider", $.ui.mouse, {
$( this ).data( "ui-slider-handle-index", i );
});

this._bind( this.handles, {
this._on( this.handles, {
keydown: function( event ) {
var allowed, curVal, newVal, step,
index = $( event.target ).data( "ui-slider-handle-index" );
Expand Down
4 changes: 2 additions & 2 deletions ui/jquery.ui.spinner.js
Expand Up @@ -54,13 +54,13 @@ $.widget( "ui.spinner", {
this._value( this.element.val(), true );

this._draw();
this._bind( this._events );
this._on( this._events );
this._refresh();

// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
this._bind( this.window, {
this._on( this.window, {
beforeunload: function() {
this.element.removeAttr( "autocomplete" );
}
Expand Down
8 changes: 4 additions & 4 deletions ui/jquery.ui.tabs.js
Expand Up @@ -481,9 +481,9 @@ $.widget( "ui.tabs", {
}

this.anchors.add( this.tabs ).add( this.panels ).unbind( ".tabs" );
this._bind( this.anchors, events );
this._bind( this.tabs, { keydown: "_tabKeydown" } );
this._bind( this.panels, { keydown: "_panelKeydown" } );
this._on( this.anchors, events );
this._on( this.tabs, { keydown: "_tabKeydown" } );
this._on( this.panels, { keydown: "_panelKeydown" } );

this._focusable( this.tabs );
this._hoverable( this.tabs );
Expand Down Expand Up @@ -943,7 +943,7 @@ if ( $.uiBackCompat !== false ) {
},
_create: function() {
this._super();
this._bind({
this._on({
tabsbeforeload: function( event, ui ) {
if ( !this.options.spinner ) {
return;
Expand Down
4 changes: 2 additions & 2 deletions ui/jquery.ui.tooltip.js
Expand Up @@ -61,7 +61,7 @@ $.widget( "ui.tooltip", {
},

_create: function() {
this._bind({
this._on({
mouseover: "open",
focusin: "open"
});
Expand Down Expand Up @@ -185,7 +185,7 @@ $.widget( "ui.tooltip", {

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

this._bind( target, {
this._on( target, {
mouseleave: "close",
focusout: "close",
keyup: function( event ) {
Expand Down
10 changes: 5 additions & 5 deletions ui/jquery.ui.widget.js
Expand Up @@ -224,7 +224,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,7 +245,7 @@ $.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 )
// 1.9 BC for #7810
Expand Down Expand Up @@ -342,7 +342,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 @@ -395,7 +395,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 @@ -407,7 +407,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

3 comments on commit 9608e98

@jzaefferer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to make sure to mention this change for the next milestone release. Also docs need an update: https://github.com/jquery/api.jqueryui.com/blob/master/entries/widget.xml#L79

@scottgonzalez
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'll have another milestone release. Next will be beta, but yeah, we should mention it there.

@gnarf
Copy link
Member

@gnarf gnarf commented on 9608e98 Jun 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay - this looks nice!

Please sign in to comment.