" ).checkboxradio();
+ },
+ error,
+ "Proper error thrown"
+ );
+ error = new Error( "Can't create checkboxradio on element.nodeName=input and element.type=button" );
+ assert.raises(
+ function() {
+ $( "
" ).checkboxradio();
+ },
+ error,
+ "Proper error thrown"
+ );
+});
+test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
+ expect( 1 );
+ var error = new Error( "No label found for checkboxradio widget" );
+ assert.raises(
+ function() {
+ $( "
" ).checkboxradio();
+ },
+ error,
+ "Proper error thrown"
+ );
+});
+
+} );
diff --git a/tests/unit/checkboxradio/events.js b/tests/unit/checkboxradio/events.js
new file mode 100644
index 000000000..e5909a386
--- /dev/null
+++ b/tests/unit/checkboxradio/events.js
@@ -0,0 +1,113 @@
+define( [
+ "jquery",
+ "ui/checkboxradio"
+], function( $ ) {
+
+module( "Checkboxradio: events" );
+
+asyncTest( "form reset / click", function( assert ) {
+ expect( 35 );
+
+ var radios = [
+ $( "#radio11" ).checkboxradio(),
+ $( "#radio12" ).checkboxradio(),
+ $( "#radio13" ).checkboxradio()
+ ],
+ widgets = [
+ radios[ 0 ].checkboxradio( "widget" ),
+ radios[ 1 ].checkboxradio( "widget" ),
+ radios[ 2 ].checkboxradio( "widget" )
+ ],
+ form1 = $( "#form1" ),
+ form2 = $( "#form2" );
+
+ // Checkes that only the specified radio is checked in the group
+ function assertChecked( checked ) {
+ $.each( widgets, function( index ) {
+ var method = index === checked ? "hasClasses" : "lacksClasses";
+
+ assert[ method ]( widgets[ index ], "ui-checkboxradio-checked ui-state-active" );
+ } );
+ }
+
+ // Checks the form count on each form
+ function assertFormCount( count ) {
+ equal( form1.data( "uiCheckboxradioCount" ), count, "Form1 has a count of " + count );
+ equal( form2.data( "uiCheckboxradioCount" ), 3, "Form2 has a count of 3" );
+ }
+
+ // Run the tests
+ function testForms( current, start ) {
+ assertChecked( 2 );
+
+ if ( !start && current !== 0 ) {
+ radios[ current - 1 ].checkboxradio( "destroy" );
+ }
+
+ assertFormCount( 3 - current );
+
+ radios[ current ].prop( "checked", true );
+ radios[ current ].trigger( "change" );
+ assertChecked( current );
+
+ form1.trigger( "reset" );
+ }
+
+ // Recoursivly run the tests in a setTimeout with call back for the resets
+ function iterate( i ) {
+ setTimeout( function() {
+ if ( i < 3 ) {
+ testForms( i );
+ iterate( i + 1 );
+ return;
+ }
+ radios[ 2 ].checkboxradio( "destroy" );
+ assertChecked( false );
+ start();
+ } );
+ }
+
+ $( "#form2 input" ).checkboxradio();
+
+ // Check the starting state then kick everything off
+ testForms( 0, true );
+ iterate( 0 );
+
+} );
+
+asyncTest(
+ "Resetting a checkbox's form should refresh the visual state of the checkbox",
+ function( assert ) {
+ expect( 2 );
+ var form = $( "
" ),
+ checkbox = form.find( "input[type=checkbox]" ).checkboxradio(),
+ widget = checkbox.checkboxradio( "widget" );
+
+ checkbox.prop( "checked", false ).checkboxradio( "refresh" );
+ assert.lacksClasses( widget, "ui-state-active" );
+
+ form.get( 0 ).reset();
+
+ setTimeout(function() {
+ assert.hasClasses( widget, "ui-state-active" );
+ start();
+ }, 1 );
+ }
+);
+
+asyncTest( "Checkbox shows focus when using keyboard navigation", function( assert ) {
+ expect( 2 );
+ var check = $( "#check" ).checkboxradio(),
+ label = $( "label[for='check']" );
+ assert.lacksClasses( label, "ui-state-focus" );
+ check.focus();
+ setTimeout(function() {
+ assert.hasClasses( label, "ui-state-focus" );
+ start();
+ } );
+ }
+);
+
+} );
diff --git a/tests/unit/checkboxradio/methods.js b/tests/unit/checkboxradio/methods.js
new file mode 100644
index 000000000..f189c9eea
--- /dev/null
+++ b/tests/unit/checkboxradio/methods.js
@@ -0,0 +1,97 @@
+define( [
+ "jquery",
+ "ui/checkboxradio"
+], function( $ ) {
+
+module( "Checkboxradio: methods" );
+
+$.each( [ "checkbox", "radio" ], function( index, value ) {
+ test( value + ": refresh", function( assert ) {
+ var widget, icon,
+ checkbox = value === "checkbox",
+ input = $( "#" + value + "-method-refresh" );
+
+ expect( checkbox ? 11 : 8 );
+
+ input.checkboxradio();
+
+ widget = input.checkboxradio( "widget" );
+ icon = widget.find( ".ui-icon" );
+ strictEqual( icon.length, 1,
+ "There is initally one icon" );
+
+ icon.remove();
+ input.checkboxradio( "refresh" );
+ icon = widget.find( ".ui-icon" );
+ strictEqual( icon.length, 1,
+ "Icon is recreated on refresh if absent" );
+ assert.hasClasses( icon, "ui-icon-blank" );
+ if ( checkbox ) {
+ assert.lacksClasses( icon, "ui-icon-check" );
+ }
+ assert.lacksClasses( widget, "ui-checkboxradio-checked" );
+
+ input.prop( "checked", true );
+ input.checkboxradio( "refresh" );
+ if ( checkbox ) {
+ assert.hasClasses( icon, "ui-icon-check" );
+ }
+ assert[ !checkbox ? "hasClasses" : "lacksClasses" ]( icon, "ui-icon-blank" );
+ assert.hasClasses( widget, "ui-checkboxradio-checked" );
+
+ input.prop( "checked", false );
+ input.checkboxradio( "refresh" );
+ assert.hasClasses( icon, "ui-icon-blank" );
+ if ( checkbox ) {
+ assert.lacksClasses( icon, "ui-icon-check" );
+ }
+ assert.lacksClasses( widget, "ui-checkboxradio-checked" );
+ });
+
+ test( value + ": destroy", function( assert ){
+ expect( 1 );
+ assert.domEqual( "#" + value + "-method-destroy", function() {
+ $( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
+ });
+ });
+
+ test( value + ": disable / enable", function( assert ) {
+ expect( 4 );
+ var input = $( "#" + value + "-method-disable" ),
+ widget = input.checkboxradio().checkboxradio( "widget" );
+
+ input.checkboxradio( "disable" );
+ assert.hasClasses( widget, "ui-state-disabled" );
+ strictEqual( input.is( ":disabled" ), true,
+ value + " is disabled when disable is called" );
+
+ input.checkboxradio( "enable" );
+ assert.lacksClasses( widget, "ui-state-disabled" );
+ strictEqual( input.is( ":disabled" ), false,
+ value + " has disabled prop removed when enable is called" );
+ });
+
+ test( value + ": widget returns the label", function(){
+ var input = $( "#" + value + "-method-refresh" ),
+ label = $( "#" + value + "-method-refresh-label" );
+
+ expect( 1 );
+
+ input.checkboxradio();
+ strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
+ "widget method returns label" );
+ });
+
+} );
+
+test( "Input wrapped in a label preserved on refresh", function() {
+ var input = $( "#label-with-no-for" ).checkboxradio(),
+ element = input.checkboxradio( "widget" );
+
+ expect( 1 );
+
+ input.checkboxradio( "refresh" );
+ strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
+});
+
+} );
diff --git a/tests/unit/checkboxradio/options.js b/tests/unit/checkboxradio/options.js
new file mode 100644
index 000000000..11bd072ca
--- /dev/null
+++ b/tests/unit/checkboxradio/options.js
@@ -0,0 +1,189 @@
+define( [
+ "jquery",
+ "ui/checkboxradio"
+], function( $ ) {
+
+module( "Checkboxradio: options" );
+
+function assertDisabled( checkbox, assert ) {
+ assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
+ "label gets ui-state-disabled" );
+ strictEqual( checkbox.is( ":disabled" ), true,
+ "checkbox is disabled" );
+}
+
+function assertEnabled( checkbox, assert ) {
+ assert.lacksClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",
+ "label has ui-state-disabled removed when disabled set to false" );
+ strictEqual( checkbox.is( ":disabled" ), false,
+ "checkbox has disabled prop removed when disabled set to false" );
+}
+
+test( "disabled", function( assert ) {
+ var checkbox = $( "#checkbox-option-disabled" );
+ expect( 6 );
+ checkbox.checkboxradio({
+ disabled: true
+ });
+
+ assertDisabled( checkbox, assert );
+
+ checkbox.checkboxradio( "option", "disabled", false );
+ assertEnabled( checkbox, assert );
+
+ checkbox.checkboxradio( "option", "disabled", true );
+ assertDisabled( checkbox, assert );
+});
+test( "disabled - prop true on init", function( assert ) {
+ expect( 2 );
+ var checkbox = $( "#checkbox-option-disabled" );
+
+ checkbox.prop( "disabled", true );
+ checkbox.checkboxradio();
+
+ assertDisabled( checkbox, assert );
+});
+test( "disabled - explicit null value, checks the DOM", function( assert ) {
+ expect( 2 );
+ var checkbox = $( "#checkbox-option-disabled" );
+
+ checkbox.prop( "disabled", true );
+ checkbox.checkboxradio({
+ disabled: null
+ });
+ assertDisabled( checkbox, assert );
+});
+
+function assertNoIcon( checkbox ) {
+ strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0,
+ "Label does not contain an icon" );
+}
+function assertIcon( checkbox, icon, assert ) {
+ var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" );
+
+ icon = icon || "blank";
+ strictEqual( iconElement.length, 1,
+ "Label contains icon" );
+ assert.hasClasses( iconElement, "ui-checkboxradio-icon ui-corner-all ui-icon " +
+ "ui-icon-background ui-icon-" + icon,
+ "Icon has proper classes" );
+}
+test( "icon - false on init", function() {
+ var checkbox = $( "#checkbox-option-icon" );
+
+ expect( 1 );
+
+ checkbox.checkboxradio({ icon: false });
+ assertNoIcon( checkbox );
+});
+
+test( "icon - default unchecked", function( assert ) {
+ var checkbox = $( "#checkbox-option-icon" );
+
+ expect( 2 );
+
+ checkbox.checkboxradio();
+ assertIcon( checkbox, false, assert );
+});
+test( "icon", function( assert ){
+ var checkbox = $( "#checkbox-option-icon" );
+
+ expect( 8 );
+
+ checkbox.prop( "checked", true );
+
+ checkbox.checkboxradio();
+ assertIcon( checkbox, "check", assert );
+
+ checkbox.checkboxradio( "option", "icon", false );
+ assertNoIcon( checkbox );
+
+ checkbox.checkboxradio( "option", "icon", true );
+ assertIcon( checkbox, "check", assert );
+
+ checkbox.checkboxradio( "option", "icon", false );
+ assertNoIcon( checkbox );
+
+ checkbox.prop( "checked", false ).checkboxradio( "refresh" );
+ checkbox.checkboxradio( "option", "icon", true );
+ assertIcon( checkbox, false, assert );
+
+});
+
+test( "label - default", function() {
+ var checkbox = $( "#checkbox-option-label" ),
+ widget;
+
+ expect( 2 );
+
+ checkbox.checkboxradio();
+ widget = checkbox.checkboxradio( "widget" );
+ strictEqual( checkbox.checkboxradio( "option", "label" ),
+ "checkbox label", "When no value passed on create text from dom is used for option" );
+ strictEqual( widget.text(),
+ " checkbox label", "When no value passed on create text from dom is used in dom" );
+});
+test( "label - explicit value", function() {
+ expect( 5 );
+ var checkbox = $( "#checkbox-option-label" ).checkboxradio({
+ label: "foo"
+ }),
+ widget = checkbox.checkboxradio( "widget" ),
+ icon = widget.find( ".ui-icon" ),
+ iconSpace = widget.find( ".ui-checkboxradio-icon-space" );
+
+ strictEqual( checkbox.checkboxradio( "option", "label" ),
+ "foo", "When value is passed on create value is used for option" );
+ strictEqual( widget.text(),
+ " foo", "When value is passed on create value is used in dom" );
+ strictEqual( icon.length, 1,
+ "Icon is preserved when label is set on init when wrapped in label" );
+ strictEqual( iconSpace.length, 1,
+ "Icon space is preserved when label is set on init when wrapped in label" );
+ strictEqual( $( "#checkbox-option-label" ).length, 1,
+ "Element is preserved when label is set on init when wrapped in label" );
+});
+
+test( "label - explicit null value", function() {
+ var checkbox = $( "#checkbox-option-label" ),
+ widget;
+
+ expect( 2 );
+
+ // We are testing the default here because the default null is a special value which means to check
+ // the DOM, so we need to make sure this happens correctly checking the options should never return
+ // null. It should always be true or false
+ checkbox.checkboxradio({
+ label: null
+ });
+ widget = checkbox.checkboxradio( "widget" );
+ strictEqual( checkbox.checkboxradio( "option", "label" ),
+ "checkbox label", "When null is passed on create text from dom is used for option" );
+ strictEqual( widget.text(),
+ " checkbox label", "When null is passed on create text from dom is used in dom" );
+
+});
+
+test( "label", function() {
+ var checkbox = $( "#checkbox-option-label" ),
+ widget;
+
+ expect( 4 );
+
+ checkbox.checkboxradio();
+ widget = checkbox.checkboxradio( "widget" );
+ checkbox.checkboxradio( "option", "label", "bar" );
+ strictEqual( checkbox.checkboxradio( "option", "label" ),
+ "bar", "When value is passed value is used for option" );
+ strictEqual( widget.text(),
+ " bar", "When value is passed value is used in dom" );
+
+ checkbox.checkboxradio( "option", "label", null );
+ strictEqual( checkbox.checkboxradio( "option", "label" ),
+ "bar", "When null is passed text from dom is used for option" );
+ strictEqual( widget.text(),
+ " bar", "When null is passed text from dom is used in dom" );
+
+});
+
+} );
diff --git a/tests/unit/controlgroup/controlgroup_core.js b/tests/unit/controlgroup/controlgroup_core.js
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/unit/index.html b/tests/unit/index.html
index 418cfd34c..fe358cb6c 100644
--- a/tests/unit/index.html
+++ b/tests/unit/index.html
@@ -40,6 +40,7 @@
Accordion
Autocomplete
Button
+
Checkboxradio
Datepicker
Dialog
Menu
diff --git a/tests/visual/checkboxradio/checkboxradio.html b/tests/visual/checkboxradio/checkboxradio.html
new file mode 100644
index 000000000..634e8df81
--- /dev/null
+++ b/tests/visual/checkboxradio/checkboxradio.html
@@ -0,0 +1,65 @@
+
+
+
+
+
jQuery UI - Checkboxes
+
+
+
+
+
+
+
+
+
+
+
+ Easy way to toggle through various combinations of options and states to make sure non lead to
+ a broken appearence.
+
+
+ Create
+ Destroy
+ Enable
+ Disable
+ Refresh
+ Icon
+ Disabled
+ Label
+
+
+
+
diff --git a/tests/visual/index.html b/tests/visual/index.html
index 98753c827..39168c9f4 100644
--- a/tests/visual/index.html
+++ b/tests/visual/index.html
@@ -31,6 +31,11 @@
Performance
+
Checkboxradio
+
+
Dialog
Animations
diff --git a/themes/base/base.css b/themes/base/base.css
index 3ed02661f..7194eba27 100644
--- a/themes/base/base.css
+++ b/themes/base/base.css
@@ -13,6 +13,7 @@
@import url("accordion.css");
@import url("autocomplete.css");
@import url("button.css");
+@import url("checkboxradio.css");
@import url("datepicker.css");
@import url("dialog.css");
@import url("draggable.css");
diff --git a/themes/base/checkboxradio.css b/themes/base/checkboxradio.css
new file mode 100644
index 000000000..063ed5b5c
--- /dev/null
+++ b/themes/base/checkboxradio.css
@@ -0,0 +1,33 @@
+/*!
+ * jQuery UI Checkboxradio @VERSION
+ * http://jqueryui.com
+ *
+ * Copyright 2013 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ *
+ * http://api.jqueryui.com/checkboxradio/#theming
+ */
+
+.ui-checkboxradio-label .ui-icon-background {
+ border-radius: .12em;
+ border: none;
+}
+.ui-checkboxradio-radio-label .ui-icon-background {
+ width: 16px;
+ height: 16px;
+ border-radius: 1em;
+ overflow: visible;
+ border: none;
+}
+.ui-checkboxradio-radio-label.ui-checkboxradio-checked .ui-icon,
+.ui-checkboxradio-radio-label.ui-checkboxradio-checked:hover .ui-icon {
+ background-image: none;
+ width: 8px;
+ height: 8px;
+ border-width: 4px;
+ border-style: solid;
+}
+.ui-checkboxradio-disabled {
+ pointer-events: none;
+}
diff --git a/themes/base/theme.css b/themes/base/theme.css
index eddbc8a0b..7553d4c58 100644
--- a/themes/base/theme.css
+++ b/themes/base/theme.css
@@ -102,12 +102,18 @@ a.ui-button:focus {
.ui-widget-content .ui-state-active,
.ui-widget-header .ui-state-active,
a.ui-button:active,
-.ui-button:active {
+.ui-button:active,
+.ui-button.ui-state-active:hover {
border: 1px solid #003eff/*{borderColorActive}*/;
background: #007fff/*{bgColorActive}*/ /*{bgImgUrlActive}*/ /*{bgActiveXPos}*/ /*{bgActiveYPos}*/ /*{bgActiveRepeat}*/;
font-weight: normal/*{fwDefault}*/;
color: #ffffff/*{fcActive}*/;
}
+.ui-icon-background,
+.ui-state-active .ui-icon-background {
+ border: #003eff/*{borderColorActive}*/;
+ background-color: #ffffff/*{bgColorActive}*/;
+}
.ui-state-active a,
.ui-state-active a:link,
.ui-state-active a:visited {
@@ -184,7 +190,6 @@ a.ui-button:active,
.ui-widget-header .ui-icon {
background-image: url("images/ui-icons_444444_256x240.png")/*{iconsHeader}*/;
}
-.ui-state-default .ui-icon,
.ui-button .ui-icon {
background-image: url("images/ui-icons_777777_256x240.png")/*{iconsDefault}*/;
}
@@ -198,7 +203,8 @@ a.ui-button:active,
.ui-button:active .ui-icon {
background-image: url("images/ui-icons_ffffff_256x240.png")/*{iconsActive}*/;
}
-.ui-state-highlight .ui-icon {
+.ui-state-highlight .ui-icon,
+.ui-button .ui-state-highlight.ui-icon {
background-image: url("images/ui-icons_777620_256x240.png")/*{iconsHighlight}*/;
}
.ui-state-error .ui-icon,
diff --git a/ui/checkboxradio.js b/ui/checkboxradio.js
new file mode 100644
index 000000000..84f69afaa
--- /dev/null
+++ b/ui/checkboxradio.js
@@ -0,0 +1,289 @@
+/*!
+ * jQuery UI Checkboxradio @VERSION
+ * http://jqueryui.com
+ *
+ * Copyright 2014 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ *
+ * http://api.jqueryui.com/checkboxradio/
+ */
+( function( factory ) {
+ if ( typeof define === "function" && define.amd ) {
+
+ // AMD. Register as an anonymous module.
+ define( [
+ "jquery",
+ "./core",
+ "./widget"
+ ], factory );
+ } else {
+
+ // Browser globals
+ factory( jQuery );
+ }
+}( function( $ ) {
+
+// Remove and replace with reset handler extension
+var formResetHandler = function() {
+ var form = $( this );
+
+ // Wait for the form reset to actually happen before refreshing
+ setTimeout( function() {
+
+ // We dont filter for css only versions since css only is not supported
+ form.find( ".ui-checkboxradio" ).checkboxradio( "refresh" );
+ } );
+ };
+
+$.widget( "ui.checkboxradio", {
+ version: "@VERSION",
+ options: {
+ disabled: null,
+ label: null,
+ icon: true,
+ classes: {
+ "ui-checkboxradio-label": "ui-corner-all",
+ "ui-checkboxradio-icon": "ui-corner-all"
+ }
+ },
+
+ _getCreateOptions: function() {
+ var disabled, labels,
+ that = this,
+ options = this._super() || {};
+
+ // We read the type here, because it makes more sense to throw a element type error first,
+ // rather then the error for lack of a label. Often if its the wrong type, it
+ // won't have a label (e.g. calling on a div, btn, etc)
+ this._readType();
+
+ labels = this.element.labels();
+
+ // Todo: For now we will use the last label we need to check about the best
+ // way to handle multiple labels with some accessability experts
+ this.label = $( labels[ labels.length - 1 ] );
+ if ( !this.label.length ) {
+ $.error( "No label found for checkboxradio widget" );
+ }
+
+ this.originalLabel = "";
+
+ // We need to get the label text but this may also need to make sure it does not contain the
+ // input itself.
+ this.label.contents().not( this.element ).each( function() {
+
+ // The label contents could be text html or a mix we concat each element to get a string
+ // representation of the label without the input as part of it.
+ that.originalLabel += this.nodeType === 3 ? $( this ).text() : this.outerHTML;
+ } );
+
+ // Set the label option if we found label text
+ if ( this.originalLabel ) {
+ options.label = this.originalLabel;
+ }
+
+ disabled = this.element[ 0 ].disabled;
+ if ( disabled != null ) {
+ options.disabled = disabled;
+ }
+ return options;
+ },
+
+ _create: function() {
+ var formCount,
+ checked = this.element[ 0 ].checked,
+ form = this.element.form();
+ this.formParent = !!form.length ? form : $( "body" );
+
+ formCount = this.formParent.data( "uiCheckboxradioCount" ) || 0;
+
+ // We don't use _on and _off here because we want all the checkboxes in the same form to use
+ // single handler which handles all the checkboxradio widgets in the form
+ if ( formCount === 0 ) {
+ this.formParent.on( "reset." + this.widgetFullName, formResetHandler );
+ }
+
+ this.formParent.data( "uiCheckboxradioCount", formCount + 1 );
+
+ if ( this.options.disabled == null ) {
+ this.options.disabled = this.element[ 0 ].disabled || false;
+ }
+
+ this._setOption( "disabled", this.options.disabled );
+ this._addClass( "ui-checkboxradio", "ui-helper-hidden-accessible" );
+ this._addClass( this.label, "ui-checkboxradio-label", "ui-button ui-widget" );
+
+ if ( this.type === "radio" ) {
+ this._addClass( this.label, "ui-checkboxradio-radio-label" );
+ }
+
+ if ( this.options.label && this.options.label !== this.originalLabel ) {
+ this._updateLabel();
+ } else if ( this.originalLabel ) {
+ this.options.label = this.originalLabel;
+ }
+
+ this._enhance();
+
+ if ( checked ) {
+ this._addClass( this.label, "ui-checkboxradio-checked", "ui-state-active" );
+ this._addClass( this.icon, null, "ui-state-hover" );
+ }
+
+ this._on( {
+ "change": "_toggleClasses",
+ "focus": function() {
+ this._addClass( this.label, null, "ui-state-focus ui-visual-focus" );
+ },
+ "blur": function() {
+ this._removeClass( this.label, null, "ui-state-focus ui-visual-focus" );
+ }
+ } );
+ },
+
+ _readType: function() {
+ var nodeName = this.element[ 0 ].nodeName.toLowerCase();
+ this.type = this.element[ 0 ].type;
+ if ( nodeName !== "input" || !/radio|checkbox/.test( this.type ) ) {
+ $.error( "Can't create checkboxradio on element.nodeName=" + nodeName +
+ " and element.type=" + this.type );
+ }
+ },
+
+ // Support jQuery Mobile enhanced option
+ _enhance: function() {
+ this._updateIcon( this.element[ 0 ].checked );
+ },
+
+ widget: function() {
+ return this.label;
+ },
+
+ _getRadioGroup: function() {
+ var name = this.element[ 0 ].name,
+ that = this,
+ radios = $( [] );
+
+ if ( name ) {
+ name = $.ui.escapeSelector( name );
+ radios = this.formParent.find( "[name='" + $.ui.escapeSelector( name ) + "']" ).filter( function() {
+ var form = $( this ).form();
+ return ( form.length ? form : $( "body" ) )[ 0 ] === that.formParent[ 0 ];
+ } );
+ }
+ return radios.not( this.element );
+ },
+
+ _toggleClasses: function() {
+ var checked = this.element[ 0 ].checked;
+ this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
+
+ if ( this.options.icon && this.type === "checkbox" ) {
+
+ // We add ui-state-highlight to change the icon color
+ this._toggleClass( this.icon, null, "ui-icon-check ui-state-highlight", checked )
+ ._toggleClass( this.icon, null, "ui-icon-blank", !checked );
+ }
+ if ( this.type === "radio" ) {
+ this._getRadioGroup()
+ .each( function() {
+ var instance = $( this ).checkboxradio( "instance" );
+
+ if ( instance ) {
+ instance._removeClass( instance.label,
+ "ui-checkboxradio-checked", "ui-state-active" );
+ }
+ } );
+ }
+ },
+
+ _destroy: function() {
+ var formCount = this.formParent.data( "uiCheckboxradioCount" ) - 1;
+
+ this.formParent.data( "uiCheckboxradioCount", formCount );
+
+ if ( formCount === 0 ) {
+ this.formParent.off( "reset." + this.widgetFullName, formResetHandler );
+ }
+
+ if ( this.icon ) {
+ this.icon.remove();
+ this.iconSpace.remove();
+ }
+ },
+
+ _setOption: function( key, value ) {
+
+ // We don't alow the value to be set to nothing
+ if ( key === "label" && !value ) {
+ return;
+ }
+
+ this._super( key, value );
+
+ if ( key === "disabled" ) {
+ this._toggleClass( this.label, null, "ui-state-disabled", value );
+ this.element[ 0 ].disabled = value;
+
+ // Don't refresh if disabled
+ return;
+ }
+ this.refresh();
+ },
+
+ _updateIcon: function( checked ) {
+ var toAdd = "ui-icon ui-icon-background ";
+
+ if ( this.options.icon ) {
+ if ( !this.icon ) {
+ this.icon = $( "" );
+ this.iconSpace = $( " " );
+ this._addClass( this.iconSpace, "ui-checkboxradio-icon-space" );
+ }
+
+ if ( this.type === "checkbox" ) {
+ toAdd += checked ? "ui-icon-check" : "ui-icon-blank";
+ this._removeClass( this.icon, null, checked ? "ui-icon-blank" : "ui-icon-check" );
+ } else {
+ toAdd += "ui-icon-blank";
+ }
+ this._addClass( this.icon, "ui-checkboxradio-icon", toAdd );
+ if ( !checked ) {
+ this._removeClass( this.icon, null, "ui-icon-check" );
+ }
+ this.icon.prependTo( this.label ).after( this.iconSpace );
+ } else if ( this.icon !== undefined ) {
+ this.icon.remove();
+ this.iconSpace.remove();
+ delete this.icon;
+ }
+ },
+
+ _updateLabel: function() {
+
+ // Remove the contents of the label ( minus the icon, icon space, and input )
+ this.label.contents().not( this.element.add( this.icon ).add( this.iconSpace ) ).remove();
+ this.label.append( this.options.label );
+ },
+
+ refresh: function() {
+ var checked = this.element[ 0 ].checked,
+ isDisabled = this.element[ 0 ].disabled;
+
+ this._updateIcon( checked );
+ this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
+ if ( this.options.label !== null ) {
+ this._updateLabel();
+ }
+
+ if ( isDisabled !== this.options.disabled ) {
+ this._setOptions( { "disabled": isDisabled } );
+ }
+ }
+
+} );
+
+return $.ui.checkboxradio;
+
+} ) );