From 6b4a55331f89b433663c75392d65aaaa5a08ac1e Mon Sep 17 00:00:00 2001 From: ddstreet Date: Wed, 9 Mar 2011 23:13:34 -0500 Subject: [PATCH 1/4] Button: find associated label even without common ancestor. Fixed #7092 - button creation that requires a matching label does not find label in all cases --- ui/jquery.ui.button.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 134dae3d370..375f45a74f2 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -201,8 +201,30 @@ $.widget( "ui.button", { if ( this.type === "checkbox" || this.type === "radio" ) { // we don't search against the document in case the element // is disconnected from the DOM + var label = "label[for=" + this.element.attr("id") + "]"; + // in most cases there is a shared ancestor this.buttonElement = this.element.parents().last() - .find( "label[for=" + this.element.attr("id") + "]" ); + .find( label ); + // if not, maybe the label is an "cousin" + if (!this.buttonElement.is( label )) { + this.buttonElement = this.element.parents().last() + .siblings().find( label ); + } + // if not, maybe the label is an "uncle" + if (!this.buttonElement.is( label )) { + this.buttonElement = this.element.parents().last() + .siblings().andSelf().filter( label ); + } + // if not, maybe the label is a "nephew" + if (!this.buttonElement.is( label )) { + this.buttonElement = this.element + .siblings().find( label ); + } + // if not, maybe the label is a sibling (without a parent) + if (!this.buttonElement.is( label )) { + this.buttonElement = this.element + .siblings().filter( label ); + } this.element.addClass( "ui-helper-hidden-accessible" ); var checked = this.element.is( ":checked" ); From c089127d45ec18776daf0882c7ccd776623ea4d7 Mon Sep 17 00:00:00 2001 From: ddstreet Date: Fri, 11 Mar 2011 09:29:27 -0500 Subject: [PATCH 2/4] revert proposed patch for Ticket #7092 --- ui/jquery.ui.button.js | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 375f45a74f2..134dae3d370 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -201,30 +201,8 @@ $.widget( "ui.button", { if ( this.type === "checkbox" || this.type === "radio" ) { // we don't search against the document in case the element // is disconnected from the DOM - var label = "label[for=" + this.element.attr("id") + "]"; - // in most cases there is a shared ancestor this.buttonElement = this.element.parents().last() - .find( label ); - // if not, maybe the label is an "cousin" - if (!this.buttonElement.is( label )) { - this.buttonElement = this.element.parents().last() - .siblings().find( label ); - } - // if not, maybe the label is an "uncle" - if (!this.buttonElement.is( label )) { - this.buttonElement = this.element.parents().last() - .siblings().andSelf().filter( label ); - } - // if not, maybe the label is a "nephew" - if (!this.buttonElement.is( label )) { - this.buttonElement = this.element - .siblings().find( label ); - } - // if not, maybe the label is a sibling (without a parent) - if (!this.buttonElement.is( label )) { - this.buttonElement = this.element - .siblings().filter( label ); - } + .find( "label[for=" + this.element.attr("id") + "]" ); this.element.addClass( "ui-helper-hidden-accessible" ); var checked = this.element.is( ":checked" ); From 678925d27a5c078b58293ea55b56170e756269ea Mon Sep 17 00:00:00 2001 From: ddstreet Date: Fri, 11 Mar 2011 10:33:10 -0500 Subject: [PATCH 3/4] Add patch from https://gist.github.com/864880 --- ui/jquery.ui.button.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 134dae3d370..9cf8974b209 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -201,8 +201,16 @@ $.widget( "ui.button", { if ( this.type === "checkbox" || this.type === "radio" ) { // we don't search against the document in case the element // is disconnected from the DOM - this.buttonElement = this.element.parents().last() - .find( "label[for=" + this.element.attr("id") + "]" ); + var ancestor = this.element.parents().last(), + labelSelector = "label[for=" + this.element.attr("id") + "]"; + this.buttonElement = ancestor.find( labelSelector ); + if ( !this.buttonElement.length ) { + ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings(); + this.buttonElement = ancestor.filter( labelSelector ); + if ( !this.buttonElement.length ) { + this.buttonElement = ancestor.find( labelSelector ); + } + } this.element.addClass( "ui-helper-hidden-accessible" ); var checked = this.element.is( ":checked" ); From 893c54adf59ff3b13740e4a263fb5ba30f2953aa Mon Sep 17 00:00:00 2001 From: ddstreet Date: Fri, 11 Mar 2011 10:36:48 -0500 Subject: [PATCH 4/4] Button: test cases for finding associated label. Test #7092 - button creation that requires a matching label does not find label in all cases --- tests/unit/button/button_tickets.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/button/button_tickets.js b/tests/unit/button/button_tickets.js index 5c5053ded55..79bbfeb5c0a 100644 --- a/tests/unit/button/button_tickets.js +++ b/tests/unit/button/button_tickets.js @@ -20,4 +20,26 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) ); }); +test( "#7092 - button creation that requires a matching label does not find label in all cases", function() { + var group = $( "" ); + group.find( "input:checkbox" ).button(); + ok( group.find( "label" ).is( ".ui-button" ) ); + + group = $( "