//############################## // jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms // By Dharmavirsinh Jhala - dharmavir@gmail.com // Date of Release: 13th March 10 // Version: 0.8 /* USAGE: $(document).ready(function(){ $(":radio").behaveLikeCheckbox(); } $(document).ready(function(){ $(".radio_d").dgStyle(); $(".checkbox_d").dgStyle(); }); */ var elmHeight = "24"; // should be specified based on image size // Extend JQuery Functionality For Custom Radio Button Functionality jQuery.fn.extend({ dgStyle: function() { // Initialize with initial load time control state $.each($(this), function(){ var elm = $(this).children().get(0); elmType = $(elm).attr("type"); $(this).data('type',elmType); $(this).data('checked', $(elm).prop("checked")); //$(this).data('checked',$(elm).attr(label)); $(this).dgClear(); }); $(this).mousedown(function() { $(this).dgEffect(); }); $(this).mouseup(function() { $(this).dgHandle(); }); }, dgClear: function() { if($(this).data("checked") == true) { $(this).css("backgroundPosition","left -"+(elmHeight*1)+"px"); } else { $(this).css("backgroundPosition","left 0"); } }, dgEffect: function() { if($(this).data("checked") == true) $(this).css({backgroundPosition:"left -"+(elmHeight*1)+"px"}); else $(this).css({backgroundPosition:"left -"+(elmHeight)+"px"}); }, dgHandle: function() { var elm = $(this).children().get(0); if($(this).data("checked") == true) $(elm).dgUncheck(this); else $(elm).dgCheck(this); if($(this).data('type') == 'radio') { $.each($("input[name='"+$(elm).attr("name")+"']"),function() { if(elm!=this) $(this).dgUncheck(-1); }); } }, dgCheck: function(div) { //alert("Hii--checked"); $(this).prop("checked",true); $(this).attr("checked",true); $(div).data('checked',true).css({backgroundPosition:"left -"+(elmHeight*1)+"px"}); try { if($(this).find(":checkbox") != undefined){ $(this).parent( ".checkbox_d" ).css('background-position','left -24px').data('checked',true).find(":checkbox").attr('checked', true).prop('checked',true);; } }catch(err){ } }, dgUncheck: function(div) { //alert("Hii-Un-checked"); $(this).prop("checked",false); $(this).attr("checked", false); if(div != -1) $(div).data('checked',false).css({backgroundPosition:"left 0"}); else $(this).parent().data("checked",false).css({backgroundPosition:"left 0"}); try { if($(this).find(":checkbox") != undefined){ $(this).parent(".checkbox_d").css('background-position','left 0px').data('checked',false).find(":checkbox").attr('checked', false).prop('checked',false);; } }catch(err){ } } });