Skip to content

Commit

Permalink
Button: Remove core event/alias and deprecated module dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed May 20, 2015
1 parent 8b4ce80 commit 12df1b7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion demos/button/default.html
Expand Up @@ -13,7 +13,7 @@
$(function() {
$( "input[type=submit], a, button" )
.button()
.click(function( event ) {
.on( "click", function( event ) {
event.preventDefault();
});
});
Expand Down
4 changes: 2 additions & 2 deletions demos/button/splitbutton.html
Expand Up @@ -18,7 +18,7 @@
$(function() {
$( "#rerun" )
.button()
.click(function() {
.on( "click", function() {
alert( "Running the last action" );
})
.next()
Expand All @@ -28,7 +28,7 @@
primary: "ui-icon-triangle-1-s"
}
})
.click(function() {
.on( "click", function() {
var menu = $( this ).parent().next().show().position({
my: "left top",
at: "left bottom",
Expand Down
4 changes: 2 additions & 2 deletions demos/button/toolbar.html
Expand Up @@ -35,7 +35,7 @@
primary: "ui-icon-play"
}
})
.click(function() {
.on( "click", function() {
var options;
if ( $( this ).text() === "play" ) {
options = {
Expand All @@ -60,7 +60,7 @@
primary: "ui-icon-stop"
}
})
.click(function() {
.on( "click", function() {
$( "#play" ).button( "option", {
label: "play",
icons: {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/button/core.js
Expand Up @@ -44,15 +44,15 @@ test("radio groups", function( assert ) {
assertClasses(":eq(0)", ":eq(1)", ":eq(2)");

// click outside of forms
$("#radio0 .ui-button:eq(1)").click();
$("#radio0 .ui-button:eq(1)").trigger( "click" );
assertClasses(":eq(1)", ":eq(1)", ":eq(2)");

// click in first form
$("#radio1 .ui-button:eq(0)").click();
$("#radio1 .ui-button:eq(0)").trigger( "click" );
assertClasses(":eq(1)", ":eq(0)", ":eq(2)");

// click in second form
$("#radio2 .ui-button:eq(0)").click();
$("#radio2 .ui-button:eq(0)").trigger( "click" );
assertClasses(":eq(1)", ":eq(0)", ":eq(0)");
});

Expand Down Expand Up @@ -112,7 +112,7 @@ if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) {
asyncTest( "ensure checked and aria after single click on checkbox label button, see #5518", function( assert ) {
expect( 3 );

$("#check2").button().change( function() {
$("#check2").button().on( "change", function() {
var lbl = $( this ).button("widget");
ok( this.checked, "checked ok" );
ok( lbl.attr("aria-pressed") === "true", "aria ok" );
Expand Down Expand Up @@ -200,7 +200,7 @@ asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyb
var check = $( "#check" ).button(),
label = $( "label[for='check']" );
assert.lacksClasses( label, "ui-state-focus" );
check.focus();
check.trigger( "focus" );
setTimeout(function() {
assert.hasClasses( label, "ui-state-focus" );
start();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/button/events.js
Expand Up @@ -8,9 +8,9 @@ module("button: events");
test("buttonset works with single-quote named elements (#7505)", function() {
expect( 1 );
$("#radio3").buttonset();
$("#radio33").click( function(){
$("#radio33").on( "click", function(){
ok( true, "button clicks work with single-quote named elements" );
}).click();
}).trigger( "click" );
});

asyncTest( "when button loses focus, ensure active state is removed (#8559)", function( assert ) {
Expand All @@ -22,10 +22,10 @@ asyncTest( "when button loses focus, ensure active state is removed (#8559)", fu
element.one( "blur", function() {
assert.lacksClasses( element, "ui-state-active", "button loses active state appropriately" );
start();
}).blur();
}).trigger( "blur" );
});

element.focus();
element.trigger( "focus" );
setTimeout(function() {
element
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } )
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/button/options.js
Expand Up @@ -146,7 +146,7 @@ test("icons", function() {
test( "#5295 - button does not remove hoverstate if disabled" , function( assert ) {
expect( 1 );
var btn = $("#button").button();
btn.hover( function() {
btn.on( "hover", function() {
btn.button( "disable" );
});
btn.trigger( "mouseenter" );
Expand Down
28 changes: 14 additions & 14 deletions ui/button.js
Expand Up @@ -73,8 +73,8 @@ $.widget( "ui.button", {
},
_create: function() {
this.element.closest( "form" )
.unbind( "reset" + this.eventNamespace )
.bind( "reset" + this.eventNamespace, formResetHandler );
.off( "reset" + this.eventNamespace )
.on( "reset" + this.eventNamespace, formResetHandler );

if ( typeof this.options.disabled !== "boolean" ) {
this.options.disabled = !!this.element.prop( "disabled" );
Expand All @@ -99,21 +99,21 @@ $.widget( "ui.button", {
this.buttonElement
.addClass( baseClasses )
.attr( "role", "button" )
.bind( "mouseenter" + this.eventNamespace, function() {
.on( "mouseenter" + this.eventNamespace, function() {
if ( options.disabled ) {
return;
}
if ( this === lastActive ) {
$( this ).addClass( "ui-state-active" );
}
})
.bind( "mouseleave" + this.eventNamespace, function() {
.on( "mouseleave" + this.eventNamespace, function() {
if ( options.disabled ) {
return;
}
$( this ).removeClass( activeClass );
})
.bind( "click" + this.eventNamespace, function( event ) {
.on( "click" + this.eventNamespace, function( event ) {
if ( options.disabled ) {
event.preventDefault();
event.stopImmediatePropagation();
Expand All @@ -132,19 +132,19 @@ $.widget( "ui.button", {
});

if ( toggleButton ) {
this.element.bind( "change" + this.eventNamespace, function() {
this.element.on( "change" + this.eventNamespace, function() {
that.refresh();
});
}

if ( this.type === "checkbox" ) {
this.buttonElement.bind( "click" + this.eventNamespace, function() {
this.buttonElement.on( "click" + this.eventNamespace, function() {
if ( options.disabled ) {
return false;
}
});
} else if ( this.type === "radio" ) {
this.buttonElement.bind( "click" + this.eventNamespace, function() {
this.buttonElement.on( "click" + this.eventNamespace, function() {
if ( options.disabled ) {
return false;
}
Expand All @@ -162,7 +162,7 @@ $.widget( "ui.button", {
});
} else {
this.buttonElement
.bind( "mousedown" + this.eventNamespace, function() {
.on( "mousedown" + this.eventNamespace, function() {
if ( options.disabled ) {
return false;
}
Expand All @@ -172,13 +172,13 @@ $.widget( "ui.button", {
lastActive = null;
});
})
.bind( "mouseup" + this.eventNamespace, function() {
.on( "mouseup" + this.eventNamespace, function() {
if ( options.disabled ) {
return false;
}
$( this ).removeClass( "ui-state-active" );
})
.bind( "keydown" + this.eventNamespace, function(event) {
.on( "keydown" + this.eventNamespace, function(event) {
if ( options.disabled ) {
return false;
}
Expand All @@ -188,15 +188,15 @@ $.widget( "ui.button", {
})
// see #8559, we bind to blur here in case the button element loses
// focus between keydown and keyup, it would be left in an "active" state
.bind( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
.on( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
$( this ).removeClass( "ui-state-active" );
});

if ( this.buttonElement.is("a") ) {
this.buttonElement.keyup(function(event) {
this.buttonElement.on( "keyup", function(event) {
if ( event.keyCode === $.ui.keyCode.SPACE ) {
// TODO pass through original event correctly (just as 2nd argument doesn't work)
$( this ).click();
$( this ).trigger( "click" );
}
});
}
Expand Down

0 comments on commit 12df1b7

Please sign in to comment.