Skip to content

Commit

Permalink
Fix but with with checked="checked"
Browse files Browse the repository at this point in the history
http://stackoverflow.com/questions/6637723/jquery-uniform-checkbox-does-not-uncheck

Query 1.6.4 changed the meaning of the attr()
function, which is used by jquery.uniform.js.
attr() now returns the state that the attribute
WAS in when the page loaded - not what the
state of the attribute is NOW. There is a
replacement function called prop(), which does
the job that attr()
used to do.

To fix the plugin, replace each occurrence
of attr("checked") with prop("checked").
Also, change attr("disabled") to
prop("disabled").

That should fix your project up. It worked for
me ;-)

See also:
AudithSoftworks#167,
which attempts to address the issue with better
backwards compatibility.
  • Loading branch information
hkirsman committed Feb 25, 2012
1 parent b0e68d1 commit f70ee4f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
102 changes: 51 additions & 51 deletions jquery.uniform.js
Expand Up @@ -66,50 +66,50 @@ Enjoy!
setTimeout(resetThis, 10);
});
}

function doInput(elem){
$el = $(elem);
$el.addClass($el.attr("type"));
storeElement(elem);
}

function doTextarea(elem){
$(elem).addClass("uniform");
storeElement(elem);
}

function doButton(elem){
var $el = $(elem);

var divTag = $("<div>"),
spanTag = $("<span>");

divTag.addClass(options.buttonClass);

if(options.useID && $el.attr("id") != "") divTag.attr("id", options.idPrefix+"-"+$el.attr("id"));

var btnText;

if($el.is("a") || $el.is("button")){
btnText = $el.html();
}else if($el.is(":submit") || $el.is(":reset") || $el.is("input[type=button]")){
btnText = $el.attr("value");
}

btnText = btnText == "" ? $el.is(":reset") ? "Reset" : "Submit" : btnText;

spanTag.html(btnText);

$el.css("opacity", 0);
$el.wrap(divTag);
$el.wrap(spanTag);

//redefine variables
divTag = $el.closest("div");
spanTag = $el.closest("span");

if($el.is(":disabled")) divTag.addClass(options.disabledClass);

divTag.bind({
"mouseenter.uniform": function(){
divTag.addClass(options.hoverClass);
Expand All @@ -125,7 +125,7 @@ Enjoy!
divTag.removeClass(options.activeClass);
},
"click.uniform touchend.uniform": function(e){
if($(e.target).is("span") || $(e.target).is("div")){
if($(e.target).is("span") || $(e.target).is("div")){
if(elem[0].dispatchEvent){
var ev = document.createEvent('MouseEvents');
ev.initEvent( 'click', true, true );
Expand All @@ -136,7 +136,7 @@ Enjoy!
}
}
});

elem.bind({
"focus.uniform": function(){
divTag.addClass(options.focusClass);
Expand All @@ -145,14 +145,14 @@ Enjoy!
divTag.removeClass(options.focusClass);
}
});

$.uniform.noSelect(divTag);
storeElement(elem);

}

function doSelect(elem){

var divTag = $('<div />'),
spanTag = $('<span />');

Expand All @@ -165,17 +165,17 @@ Enjoy!
if(options.useID && elem.attr("id") != ""){
divTag.attr("id", options.idPrefix+"-"+elem.attr("id"));
}

var selected = elem.find(":selected:first");
if(selected.length == 0){
selected = elem.find("option:first");
}
spanTag.html(selected.html());

elem.css('opacity', 0);
elem.wrap(divTag);
elem.before(spanTag);

//redefine variables
divTag = elem.parent("div");
spanTag = elem.siblings("span");
Expand Down Expand Up @@ -216,27 +216,27 @@ Enjoy!
spanTag.html(elem.find(":selected").html());
}
});

//handle disabled state
if(elem.attr("disabled")){
if(elem.prop("disabled")){
//box is checked by default, check our box
divTag.addClass(options.disabledClass);
}
$.uniform.noSelect(spanTag);

storeElement(elem);
}

function doCheckbox(elem){
var $el = $(elem);

var divTag = $('<div />'),
spanTag = $('<span />');

if(!$el.css("display") == "none" && options.autoHide){
divTag.hide();
}

divTag.addClass(options.checkboxClass);

//assign the id of the element
Expand All @@ -263,7 +263,7 @@ Enjoy!
divTag.removeClass(options.focusClass);
},
"click.uniform touchend.uniform": function(){
if(!$(elem).attr("checked")){
if(!$(elem).prop("checked")){
//box was just unchecked, uncheck span
spanTag.removeClass(options.checkedClass);
}else{
Expand All @@ -285,15 +285,15 @@ Enjoy!
divTag.removeClass(options.activeClass);
}
});

//handle defaults
if($(elem).attr("checked")){
if($(elem).prop("checked")){
//box is checked by default, check our box
spanTag.addClass(options.checkedClass);
}

//handle disabled state
if($(elem).attr("disabled")){
if($(elem).prop("disabled")){
//box is checked by default, check our box
divTag.addClass(options.disabledClass);
}
Expand All @@ -303,10 +303,10 @@ Enjoy!

function doRadio(elem){
var $el = $(elem);

var divTag = $('<div />'),
spanTag = $('<span />');

if(!$el.css("display") == "none" && options.autoHide){
divTag.hide();
}
Expand Down Expand Up @@ -336,7 +336,7 @@ Enjoy!
divTag.removeClass(options.focusClass);
},
"click.uniform touchend.uniform": function(){
if(!$(elem).attr("checked")){
if(!$(elem).prop("checked")){
//box was just unchecked, uncheck span
spanTag.removeClass(options.checkedClass);
}else{
Expand Down Expand Up @@ -364,12 +364,12 @@ Enjoy!
});

//handle defaults
if($(elem).attr("checked")){
if($(elem).prop("checked")){
//box is checked by default, check span
spanTag.addClass(options.checkedClass);
}
//handle disabled state
if($(elem).attr("disabled")){
if($(elem).prop("disabled")){
//box is checked by default, check our box
divTag.addClass(options.disabledClass);
}
Expand All @@ -385,7 +385,7 @@ Enjoy!
var divTag = $('<div />'),
filenameTag = $('<span>'+options.fileDefaultText+'</span>'),
btnTag = $('<span>'+options.fileBtnText+'</span>');

if(!$el.css("display") == "none" && options.autoHide){
divTag.hide();
}
Expand Down Expand Up @@ -473,23 +473,23 @@ Enjoy!
}

//handle defaults
if($el.attr("disabled")){
if($el.prop("disabled")){
//box is checked by default, check our box
divTag.addClass(options.disabledClass);
}

$.uniform.noSelect(filenameTag);
$.uniform.noSelect(btnTag);

storeElement(elem);

}

$.uniform.restore = function(elem){
if(elem == undefined){
elem = $($.uniform.elements);
}

$(elem).each(function(){
if($(this).is(":checkbox")){
//unwrap from span and div
Expand All @@ -511,13 +511,13 @@ Enjoy!
//unwrap from span and div
$(this).unwrap().unwrap();
}

//unbind events
$(this).unbind(".uniform");

//reset inline style
$(this).css("opacity", "1");

//remove item from list of uniformed elements
var index = $.inArray($(elem), $.uniform.elements);
$.uniform.elements.splice(index, 1);
Expand All @@ -535,7 +535,7 @@ Enjoy!
$.uniform.elements.push(elem);
}
}

//noSelect v1.0
$.uniform.noSelect = function(elem) {
function f() {
Expand Down Expand Up @@ -632,15 +632,15 @@ Enjoy!
}else if($e.is(":submit") || $e.is(":reset") || $e.is("button") || $e.is("a") || elem.is("input[type=button]")){
var divTag = $e.closest("div");
divTag.removeClass(options.hoverClass+" "+options.focusClass+" "+options.activeClass);

if($e.is(":disabled")){
divTag.addClass(options.disabledClass);
}else{
divTag.removeClass(options.disabledClass);
}

}

});
};

Expand Down Expand Up @@ -672,7 +672,7 @@ Enjoy!
}else if(elem.is("a") || elem.is(":submit") || elem.is(":reset") || elem.is("button") || elem.is("input[type=button]")){
doButton(elem);
}

}
});
};
Expand Down

0 comments on commit f70ee4f

Please sign in to comment.