From 12df1b7dad135aa57640be631277db3f7d75d672 Mon Sep 17 00:00:00 2001 From: Alexander Schmitz Date: Wed, 13 May 2015 21:54:37 -0400 Subject: [PATCH] Button: Remove core event/alias and deprecated module dependencies --- demos/button/default.html | 2 +- demos/button/splitbutton.html | 4 ++-- demos/button/toolbar.html | 4 ++-- tests/unit/button/core.js | 10 +++++----- tests/unit/button/events.js | 8 ++++---- tests/unit/button/options.js | 2 +- ui/button.js | 28 ++++++++++++++-------------- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/demos/button/default.html b/demos/button/default.html index 8c16909698a..1bd4f91916f 100644 --- a/demos/button/default.html +++ b/demos/button/default.html @@ -13,7 +13,7 @@ $(function() { $( "input[type=submit], a, button" ) .button() - .click(function( event ) { + .on( "click", function( event ) { event.preventDefault(); }); }); diff --git a/demos/button/splitbutton.html b/demos/button/splitbutton.html index 441e0a912f2..333d54bd766 100644 --- a/demos/button/splitbutton.html +++ b/demos/button/splitbutton.html @@ -18,7 +18,7 @@ $(function() { $( "#rerun" ) .button() - .click(function() { + .on( "click", function() { alert( "Running the last action" ); }) .next() @@ -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", diff --git a/demos/button/toolbar.html b/demos/button/toolbar.html index e2eac055c82..e13b4a1d1c9 100644 --- a/demos/button/toolbar.html +++ b/demos/button/toolbar.html @@ -35,7 +35,7 @@ primary: "ui-icon-play" } }) - .click(function() { + .on( "click", function() { var options; if ( $( this ).text() === "play" ) { options = { @@ -60,7 +60,7 @@ primary: "ui-icon-stop" } }) - .click(function() { + .on( "click", function() { $( "#play" ).button( "option", { label: "play", icons: { diff --git a/tests/unit/button/core.js b/tests/unit/button/core.js index 4bc8d9fe5ae..8539464baea 100644 --- a/tests/unit/button/core.js +++ b/tests/unit/button/core.js @@ -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)"); }); @@ -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" ); @@ -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(); diff --git a/tests/unit/button/events.js b/tests/unit/button/events.js index ec930077caa..63550e2f829 100644 --- a/tests/unit/button/events.js +++ b/tests/unit/button/events.js @@ -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 ) { @@ -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 } ) diff --git a/tests/unit/button/options.js b/tests/unit/button/options.js index 70470e671a1..23020fc100c 100644 --- a/tests/unit/button/options.js +++ b/tests/unit/button/options.js @@ -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" ); diff --git a/ui/button.js b/ui/button.js index 5182b1f1201..70cc3168034 100644 --- a/ui/button.js +++ b/ui/button.js @@ -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" ); @@ -99,7 +99,7 @@ $.widget( "ui.button", { this.buttonElement .addClass( baseClasses ) .attr( "role", "button" ) - .bind( "mouseenter" + this.eventNamespace, function() { + .on( "mouseenter" + this.eventNamespace, function() { if ( options.disabled ) { return; } @@ -107,13 +107,13 @@ $.widget( "ui.button", { $( 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(); @@ -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; } @@ -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; } @@ -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; } @@ -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" ); } }); }