/*! * fancyCheckbox v1.0.0 - change checkbox's style jQuery plug-in. * http://web.r-studio.jp/javascript/jquery/fancyCheckboxes.html * * Copyright 2010, Risa Yuguchi * licensed under the MIT License * http://www.opensource.org/licenses/mit-license.php * * Original code and Special Thanks: Aaron Weyenberg * see: http://aaronweyenberg.com/90/pretty-checkboxes-with-jquery/ * * Demo: * http://www.r-studio.jp/demo/jqueryform/fancyCheckboxes.html * */ (function($) { var fancyCheckboxMethod = { fancyCheckbox: function(options){ var setting = $.extend({ select:"select", cancel:"cancel" }, options); this.each(function(i){ /* in the case of no checkbox, return */ if ($(":checkbox", this).length<1) return; /* reset form ... */ var target = this; $(":reset", $(this).parents("form")).click( function(){ $("li", target).each( function(){ if($.data(this,"defaultValue")){ $(this).addClass("selected"); } else { $(this).removeClass("selected"); } } ); } ); /* set id on the parent node & select-link and deselect-link */ $("label", this).click(function(event){event.preventDefalt();}).each( function(index){ var pid = $(this).attr("for"); $(this).parent().attr("id","box-"+pid); } ).after(''+setting.select+''+setting.cancel+''); /* see if anything is previously checked and reflect that in the view */ $("input:checked", this).parent().addClass("selected"); /* handle the user selections */ $("li",this).click(function(event) { event.preventDefault(); if($(this).hasClass("selected")) { // to false $(this).removeClass("selected"); $(":checkbox",this).attr("checked",false); } else { // to true $(this).addClass("selected"); $(":checkbox",this).attr("checked",true); } }).each( function(){ var cursorStyle = "pointer"; if("msie" == $.browser) { cursorStyle = "hand"; } $(this).addClass("fancyCheckbox"); $(this).css("cursor",cursorStyle); $.data(this,"defaultValue",$(":checkbox",this).attr("checked")); $(":checkbox",this).css("display","none"); } ); }); return this; } }; $.each(fancyCheckboxMethod,function(index){ $.fn[index] = this; }); }(jQuery));