Skip to content
Permalink
Browse files

Widget: Rename _bind() to _on(). Partial fix for #7795 - Widget: _on …

…and _off.
  • Loading branch information
scottgonzalez committed Jun 13, 2012
1 parent e8b6232 commit 9608e981498846b3727cc4dad723a7fa7252fd86
@@ -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();
@@ -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
@@ -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"
});
@@ -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"
});
@@ -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() {
@@ -727,7 +727,7 @@ test( "_bind() with delegate", function() {
}
};
};
this._bind({
this._on({
"click": "handler",
"click a": "handler"
});
@@ -740,7 +740,7 @@ test( "_bind() with delegate", function() {
}
};
};
this._bind({
this._on({
"change form fieldset > input": "handler"
});
}
@@ -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 );
},

@@ -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 ) {
@@ -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;
@@ -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();
@@ -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" );
}
@@ -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();
@@ -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 ) {
@@ -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 );
@@ -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" );
@@ -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" );
}
@@ -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 );
@@ -943,7 +943,7 @@ if ( $.uiBackCompat !== false ) {
},
_create: function() {
this._super();
this._bind({
this._on({
tabsbeforeload: function( event, ui ) {
if ( !this.options.spinner ) {
return;
@@ -61,7 +61,7 @@ $.widget( "ui.tooltip", {
},

_create: function() {
this._bind({
this._on({
mouseover: "open",
focusin: "open"
});
@@ -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 ) {
@@ -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 :
@@ -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
@@ -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;
@@ -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" );
},
@@ -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" );
},

3 comments on commit 9608e98

@jzaefferer

This comment has been minimized.

Copy link
Member

@jzaefferer jzaefferer replied Jun 13, 2012

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

This comment has been minimized.

Copy link
Member Author

@scottgonzalez scottgonzalez replied Jun 13, 2012

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

@gnarf

This comment has been minimized.

Copy link
Member

@gnarf gnarf replied Jun 13, 2012

Yay - this looks nice!

Please sign in to comment.
You can’t perform that action at this time.