2010-01-20 14:00:14 +00:00
|
|
|
/*
|
|
|
|
* button_core.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
module("button: core");
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test("checkbox", function( assert ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 4 );
|
2012-04-19 14:50:09 +00:00
|
|
|
var input = $("#check"),
|
2010-01-20 14:00:14 +00:00
|
|
|
label = $("label[for=check]");
|
2012-02-28 14:56:32 +00:00
|
|
|
ok( input.is(":visible") );
|
2010-01-20 14:00:14 +00:00
|
|
|
ok( label.is(":not(.ui-button)") );
|
|
|
|
input.button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( input, "ui-helper-hidden-accessible" );
|
|
|
|
assert.hasClasses( label, "ui-button" );
|
2010-01-20 14:00:14 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test("radios", function( assert ) {
|
|
|
|
expect( 8 );
|
2012-04-19 14:50:09 +00:00
|
|
|
var inputs = $("#radio0 input"),
|
2010-01-20 14:00:14 +00:00
|
|
|
labels = $("#radio0 label");
|
2012-02-28 14:56:32 +00:00
|
|
|
ok( inputs.is(":visible") );
|
2010-01-20 14:00:14 +00:00
|
|
|
ok( labels.is(":not(.ui-button)") );
|
|
|
|
inputs.button();
|
2015-02-03 00:25:52 +00:00
|
|
|
inputs.each(function() {
|
|
|
|
assert.hasClasses( this, "ui-helper-hidden-accessible" );
|
|
|
|
});
|
|
|
|
labels.each(function() {
|
|
|
|
assert.hasClasses( this, "ui-button" );
|
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test("radio groups", function( assert ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 12 );
|
2015-02-03 00:25:52 +00:00
|
|
|
|
|
|
|
function assertClasses(noForm, form1, form2) {
|
|
|
|
assert.hasClasses( $("#radio0 .ui-button" + noForm ), "ui-state-active" );
|
|
|
|
assert.hasClasses( $("#radio1 .ui-button" + form1 ), "ui-state-active" );
|
|
|
|
assert.hasClasses( $("#radio2 .ui-button" + form2 ), "ui-state-active" );
|
|
|
|
}
|
|
|
|
|
2012-05-21 16:02:28 +00:00
|
|
|
$("input[type=radio]").button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assertClasses(":eq(0)", ":eq(1)", ":eq(2)");
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
// click outside of forms
|
|
|
|
$("#radio0 .ui-button:eq(1)").click();
|
2015-02-03 00:25:52 +00:00
|
|
|
assertClasses(":eq(1)", ":eq(1)", ":eq(2)");
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
// click in first form
|
|
|
|
$("#radio1 .ui-button:eq(0)").click();
|
2015-02-03 00:25:52 +00:00
|
|
|
assertClasses(":eq(1)", ":eq(0)", ":eq(2)");
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
// click in second form
|
|
|
|
$("#radio2 .ui-button:eq(0)").click();
|
2015-02-03 00:25:52 +00:00
|
|
|
assertClasses(":eq(1)", ":eq(0)", ":eq(0)");
|
2010-01-20 14:00:14 +00:00
|
|
|
});
|
|
|
|
|
2014-01-28 15:46:23 +00:00
|
|
|
test( "radio groups - ignore elements with same name", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var form = $( "form:first" ),
|
|
|
|
radios = form.find( "[type=radio]" ).button(),
|
|
|
|
checkbox = $( "<input>", {
|
|
|
|
type: "checkbox",
|
|
|
|
name: radios.attr( "name" )
|
|
|
|
});
|
|
|
|
|
|
|
|
form.append( checkbox );
|
|
|
|
radios.button( "refresh" );
|
|
|
|
ok( true, "no exception from accessing button instance of checkbox" );
|
|
|
|
});
|
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
test("input type submit, don't create child elements", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2012-04-19 14:50:09 +00:00
|
|
|
var input = $("#submit");
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( input.children().length, 0 );
|
2010-01-20 14:00:14 +00:00
|
|
|
input.button();
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( input.children().length, 0 );
|
2010-01-20 14:00:14 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test("buttonset", function( assert ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 6 );
|
2010-01-20 14:00:14 +00:00
|
|
|
var set = $("#radio1").buttonset();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( set, "ui-buttonset" );
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( set.children(".ui-button").length, 3 );
|
2012-05-21 16:02:28 +00:00
|
|
|
deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 );
|
2010-01-20 14:00:14 +00:00
|
|
|
ok( set.children("label:eq(0)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") );
|
|
|
|
ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") );
|
|
|
|
ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") );
|
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test("buttonset (rtl)", function( assert ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 6 );
|
2012-04-19 14:50:09 +00:00
|
|
|
var set,
|
|
|
|
parent = $("#radio1").parent();
|
2011-05-12 05:51:05 +00:00
|
|
|
// Set to rtl
|
|
|
|
parent.attr("dir", "rtl");
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-04-19 14:50:09 +00:00
|
|
|
set = $("#radio1").buttonset();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( set, "ui-buttonset" );
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( set.children(".ui-button").length, 3 );
|
2012-05-21 16:02:28 +00:00
|
|
|
deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 );
|
2011-05-12 05:51:05 +00:00
|
|
|
ok( set.children("label:eq(0)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") );
|
|
|
|
ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") );
|
|
|
|
ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") );
|
|
|
|
});
|
|
|
|
|
2012-11-28 16:21:52 +00:00
|
|
|
// TODO: simulated click events don't behave like real click events in IE
|
|
|
|
// remove this when simulate properly simulates this
|
|
|
|
// see http://yuilibrary.com/projects/yui2/ticket/2528826 fore more info
|
|
|
|
if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) {
|
2015-02-03 00:25:52 +00:00
|
|
|
asyncTest( "ensure checked and aria after single click on checkbox label button, see #5518", function( assert ) {
|
2012-11-28 16:21:52 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
$("#check2").button().change( function() {
|
|
|
|
var lbl = $( this ).button("widget");
|
|
|
|
ok( this.checked, "checked ok" );
|
|
|
|
ok( lbl.attr("aria-pressed") === "true", "aria ok" );
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( lbl, "ui-state-active" );
|
2012-11-29 14:08:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// support: Opera
|
|
|
|
// Opera doesn't trigger a change event when this is done synchronously.
|
|
|
|
// This seems to be a side effect of another test, but until that can be
|
|
|
|
// tracked down, this delay will have to do.
|
|
|
|
setTimeout(function() {
|
|
|
|
$("#check2").button("widget").simulate("click");
|
|
|
|
start();
|
|
|
|
}, 1 );
|
2012-11-28 16:21:52 +00:00
|
|
|
});
|
|
|
|
}
|
2012-11-27 01:24:31 +00:00
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test( "#7092 - button creation that requires a matching label does not find label in all cases", function( assert ) {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 5 );
|
|
|
|
var group = $( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" );
|
|
|
|
group.find( "input[type=checkbox]" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.find( "label" ), "ui-button" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
group = $( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" );
|
|
|
|
group.filter( "input[type=checkbox]" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.filter( "label" ), "ui-button" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
group = $( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" );
|
|
|
|
group.find( "input[type=checkbox]" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.filter( "label" ), "ui-button" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
group = $( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" );
|
|
|
|
group.find( "input[type=checkbox]" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.find( "label" ), "ui-button" );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
|
|
|
group = $( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" );
|
|
|
|
group.filter( "input[type=checkbox]" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.find( "label" ), "ui-button" );
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test( "#5946 - buttonset should ignore buttons that are not :visible", function( assert ) {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 2 );
|
2012-12-14 16:13:46 +00:00
|
|
|
$( "#radio01" ).next().addBack().hide();
|
2012-12-08 01:06:29 +00:00
|
|
|
var set = $( "#radio0" ).buttonset({ items: "input[type=radio]:visible" });
|
|
|
|
ok( set.find( "label:eq(0)" ).is( ":not(.ui-button):not(.ui-corner-left)" ) );
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( set.find( "label:eq(1)" ), "ui-button ui-corner-left" );
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test( "#6262 - buttonset not applying ui-corner to invisible elements", function( assert ) {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 3 );
|
|
|
|
$( "#radio0" ).hide();
|
|
|
|
var set = $( "#radio0" ).buttonset();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( set.find( "label:eq(0)" ), "ui-button ui-corner-left" );
|
|
|
|
assert.hasClasses( set.find( "label:eq(1)" ), "ui-button" );
|
|
|
|
assert.hasClasses( set.find( "label:eq(2)" ), "ui-button ui-corner-right" );
|
|
|
|
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function( assert ) {
|
2013-04-07 16:57:15 +00:00
|
|
|
expect( 2 );
|
|
|
|
var form = $( "<form>" +
|
|
|
|
"<button></button>" +
|
|
|
|
"<label for='c1'></label><input id='c1' type='checkbox' checked>" +
|
|
|
|
"</form>" ),
|
|
|
|
button = form.find( "button" ).button(),
|
|
|
|
checkbox = form.find( "input[type=checkbox]" ).button();
|
|
|
|
|
|
|
|
checkbox.prop( "checked", false ).button( "refresh" );
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.lacksClasses( checkbox.button( "widget" ), "ui-state-active" );
|
2013-04-07 16:57:15 +00:00
|
|
|
|
|
|
|
form.get( 0 ).reset();
|
2013-04-14 16:58:42 +00:00
|
|
|
|
2013-04-07 16:57:15 +00:00
|
|
|
// #9213: If a button has been removed, refresh should not be called on it when
|
|
|
|
// its corresponding form is reset.
|
|
|
|
button.remove();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( checkbox.button( "widget" ), "ui-state-active" );
|
2013-04-07 16:57:15 +00:00
|
|
|
start();
|
2013-11-25 14:53:51 +00:00
|
|
|
}, 1 );
|
2013-04-07 16:57:15 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function( assert ) {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 2 );
|
|
|
|
var check = $( "#check" ).button(),
|
|
|
|
label = $( "label[for='check']" );
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.lacksClasses( label, "ui-state-focus" );
|
2012-12-08 01:06:29 +00:00
|
|
|
check.focus();
|
2012-12-10 15:35:01 +00:00
|
|
|
setTimeout(function() {
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( label, "ui-state-focus" );
|
2012-12-10 15:35:01 +00:00
|
|
|
start();
|
|
|
|
});
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test( "#7534 - Button label selector works for ids with \":\"", function( assert ) {
|
2012-12-08 01:06:29 +00:00
|
|
|
expect( 1 );
|
|
|
|
var group = $( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" );
|
|
|
|
group.find( "input" ).button();
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( group.find( "label" ), "ui-button" , "Found an id with a :" );
|
2012-12-08 01:06:29 +00:00
|
|
|
});
|
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
asyncTest( "#9169 - Disabled button maintains ui-state-focus", function( assert ) {
|
2013-04-11 18:03:51 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#button1" ).button();
|
|
|
|
element[ 0 ].focus();
|
|
|
|
setTimeout(function() {
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.hasClasses( element, "ui-state-focus" );
|
2013-04-11 18:03:51 +00:00
|
|
|
element.button( "disable" );
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.lacksClasses( element, "ui-state-focus",
|
2013-04-11 18:03:51 +00:00
|
|
|
"button does not have ui-state-focus when disabled" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
})(jQuery);
|