From 0516cd65be05516e0bf379b238c16e1191813345 Mon Sep 17 00:00:00 2001 From: mail6543210 Date: Tue, 22 Nov 2011 14:02:01 +0800 Subject: [PATCH 1/2] Button: support wrapped in Signed-off-by: mail6543210 --- ui/jquery.ui.button.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 18a95056330..7b2d73aa8f0 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -228,6 +228,26 @@ $.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 + + //if the 's parent is ( ie. implicit label), convert into explicit label. + if ( this.element.parent( "label" ).length ) { + //used when destroy -> convert back to implicit label. + this.isImplicit = true; + var id = this.element.attr( "id" ); + if ( !id ) { + //get the idList of :ui-button and :not([id])( we haven't built yet) + var idList=$( ":ui-button" ).filter( "[id^='ui-button-'], :not([id])" ).map(function(){ + return this.id.substr(10); + }).get(); + var max=Math.max.apply(Math,idList); + id = "ui-button-" + (max+1); + //set new_id = current_max+1, in case of duplicated + this.element.attr( "id", id); + } + this.element.parent( "label" ).attr( "for", id); + this.element.insertBefore(this.element.parent( "label" )); + } + var ancestor = this.element.parents().last(), labelSelector = "label[for='" + this.element.attr("id") + "']"; this.buttonElement = ancestor.find( labelSelector ); @@ -262,6 +282,19 @@ $.widget( "ui.button", { .removeAttr( "role" ) .removeAttr( "aria-pressed" ) .html( this.buttonElement.find(".ui-button-text").html() ); + if ( this.isImplicit ) { + if ( this.buttonElement.attr( "for" ).indexOf( "ui-button-" ) !== -1 ) { + this.buttonElement.removeAttr( "for" ); + this.element.removeAttr( "id" ); + } + this.element.prependTo(this.buttonElement); + } + if ( this.buttonElement.attr( "class" ) === "") { + this.buttonElement.removeAttr( "class" ); + } + if ( this.element.attr( "class" ) === "") { + this.element.removeAttr( "class" ); + } if ( !this.hasTitle ) { this.buttonElement.removeAttr( "title" ); From d2a25b6ee1183a4b5ed85991d57d58aa366572a5 Mon Sep 17 00:00:00 2001 From: mail6543210 Date: Tue, 22 Nov 2011 15:55:37 +0800 Subject: [PATCH 2/2] Unit-test for fix of #6063 --- tests/unit/button/button.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html index 5ec7e316afb..9458e601ef7 100644 --- a/tests/unit/button/button.html +++ b/tests/unit/button/button.html @@ -61,6 +61,13 @@ Choice 3 + + + Choice 1 + Choice 2 + Choice 3 + + Toggle