mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-23 21:55:49 +00:00
small refactor to disable check for checkbox radio
This commit is contained in:
parent
2bb94172cf
commit
58b16a94b6
1 changed files with 26 additions and 26 deletions
|
|
@ -3,7 +3,7 @@
|
|||
* Copyright (c) jQuery Project
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*/
|
||||
*/
|
||||
(function($, undefined ) {
|
||||
$.widget( "mobile.checkboxradio", $.mobile.widget, {
|
||||
options: {
|
||||
|
|
@ -30,17 +30,17 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
icon: this.element.parents( "[data-type='horizontal']" ).length ? undefined : uncheckedicon,
|
||||
shadow: false
|
||||
});
|
||||
|
||||
// wrap the input + label in a div
|
||||
|
||||
// wrap the input + label in a div
|
||||
input
|
||||
.add( label )
|
||||
.wrapAll( "<div class='ui-" + inputtype +"'></div>" );
|
||||
|
||||
|
||||
label.bind({
|
||||
mouseover: function() {
|
||||
if( $(this).parent().is('.ui-disabled') ){ return false; }
|
||||
},
|
||||
|
||||
|
||||
"touchmove": function( event ){
|
||||
var oe = event.originalEvent.touches[0];
|
||||
if( label.data("movestart") ){
|
||||
|
|
@ -53,13 +53,13 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
label.data("movestart", [ parseFloat( oe.pageX ), parseFloat( oe.pageY ) ]);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
"touchend mouseup": function( event ){
|
||||
if ( input.is( ":disabled" ) )
|
||||
{
|
||||
if ( input.is( ":disabled" ) ){
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
label.removeData("movestart");
|
||||
if( label.data("etype") && label.data("etype") !== event.type || label.data("moved") ){
|
||||
label.removeData("etype").removeData("moved");
|
||||
|
|
@ -74,46 +74,46 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
self._updateAll();
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
|
||||
click: false
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
input
|
||||
.bind({
|
||||
mousedown: function(){
|
||||
this._cacheVals();
|
||||
},
|
||||
|
||||
|
||||
click: function(){
|
||||
self._updateAll();
|
||||
},
|
||||
|
||||
focus: function() {
|
||||
label.addClass( "ui-focus" );
|
||||
focus: function() {
|
||||
label.addClass( "ui-focus" );
|
||||
},
|
||||
|
||||
blur: function() {
|
||||
label.removeClass( "ui-focus" );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.refresh();
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
_cacheVals: function(){
|
||||
this._getInputSet().each(function(){
|
||||
$(this).data("cacheVal", $(this).is(":checked") );
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//returns either a set of radios with the same name attribute, or a single checkbox
|
||||
_getInputSet: function(){
|
||||
return this.element.closest( "form,fieldset,[data-role='page']" )
|
||||
.find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.element.attr( "type" ) +"']" );
|
||||
},
|
||||
|
||||
|
||||
_updateAll: function(){
|
||||
this._getInputSet().each(function(){
|
||||
var dVal = $(this).data("cacheVal");
|
||||
|
|
@ -123,7 +123,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
})
|
||||
.checkboxradio( "refresh" );
|
||||
},
|
||||
|
||||
|
||||
refresh: function( ){
|
||||
var input = this.element,
|
||||
label = input.closest("form,fieldset,[data-role='page']").find("label[for='" + input.attr( "id" ) + "']"),
|
||||
|
|
@ -131,18 +131,18 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
icon = label.find( ".ui-icon" ),
|
||||
checkedicon = "ui-icon-" + inputtype + "-on",
|
||||
uncheckedicon = "ui-icon-" + inputtype + "-off";
|
||||
|
||||
|
||||
if ( input[0].checked ) {
|
||||
label.addClass( "ui-btn-active" );
|
||||
icon.addClass( checkedicon );
|
||||
icon.removeClass( uncheckedicon );
|
||||
|
||||
} else {
|
||||
label.removeClass( "ui-btn-active" );
|
||||
label.removeClass( "ui-btn-active" );
|
||||
icon.removeClass( checkedicon );
|
||||
icon.addClass( uncheckedicon );
|
||||
}
|
||||
|
||||
|
||||
if( input.is( ":disabled" ) ){
|
||||
this.disable();
|
||||
}
|
||||
|
|
@ -150,11 +150,11 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
|
|||
this.enable();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
disable: function(){
|
||||
this.element.attr("disabled",true).parent().addClass("ui-disabled");
|
||||
},
|
||||
|
||||
|
||||
enable: function(){
|
||||
this.element.attr("disabled",false).parent().removeClass("ui-disabled");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue