if( $this.attr('type') == 'checkbox') {
var defaultState = '';
if( $this.is(':checked') ) {
$this.parent().addClass(defaultOpt.checkedCls);
defaultState = 'checked';
}
var item = $this.addClass(defaultOpt.hideCls).wrap(wrapTag);
item.change(function() {
console.log("EZMARK checkbox changed");
if( $(this).is(':checked') ) {
$(this).parent().addClass(defaultOpt.checkedCls);
}
else {
$(this).parent().removeClass(defaultOpt.checkedCls);
}
});
if(item.parents("form").find("[type=reset]").length>0){
item.parents("form").find("[type=reset]").click(function(){
console.log("EZMARK form reset");
if(defaultState=='checked'){
item.parent().addClass(defaultOpt.checkedCls);
}else{
item.parent().removeClass(defaultOpt.checkedCls);
}
});
}
}
else if( $this.attr('type') == 'radio') {
var defaultState = '';
if( $this.is(':checked') ) {
$this.parent().addClass(defaultOpt.selectedCls);
defaultState = 'checked';
}
var item = $this.addClass(defaultOpt.hideCls).wrap(wrapTag);
item.change(function() {
console.log("EZMARK radio changed");
// radio button may contain groups! - so check for group
$('input[name="'+$(this).attr('name')+'"]').each(function() {
if( $(this).is(':checked') ) {
$(this).parent().addClass(defaultOpt.selectedCls);
}
else {
$(this).parent().removeClass(defaultOpt.selectedCls);
}
});
});
if(item.parents("form").find("[type=reset]").length>0){
item.parents("form").find("[type=reset]").click(function(){
console.log("EZMARK form reset");
if(defaultState=='checked'){
item.parent().addClass(defaultOpt.selectedCls);
}else{
item.parent().removeClass(defaultOpt.selectedCls);
}
});
}
}