Guest User

Untitled

a guest
Jul 21st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. //##############################
  2. // jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms
  3. // By Dharmavirsinh Jhala - dharmavir@gmail.com
  4. // Date of Release: 13th March 10
  5. // Version: 0.8
  6. /*
  7. USAGE:
  8. $(document).ready(function(){
  9. $(":radio").behaveLikeCheckbox();
  10. }
  11. */
  12.  
  13. var elmHeight = "25"; // should be specified based on image size
  14.  
  15. // Extend JQuery Functionality For Custom Radio Button Functionality
  16. jQuery.fn.extend({
  17. dgStyle: function()
  18. {
  19. // Initialize with initial load time control state
  20. $.each($(this), function(){
  21. var elm = $(this).children().get(0);
  22. elmType = $(elm).attr("type");
  23. $(this).data('type',elmType);
  24. $(this).data('checked',$(elm).attr("checked"));
  25. $(this).dgClear();
  26. });
  27. $(this).mouseup(function() { $(this).dgHandle(); });
  28. },
  29. dgClear: function()
  30. {
  31. if($(this).data("checked") == true)
  32. {
  33. $(this).addClass("checked");
  34. }
  35. else
  36. {
  37. $(this).removeClass("checked");
  38. }
  39. },
  40. dgHandle: function()
  41. {
  42. var elm = $(this).children().get(0);
  43. if($(this).data("checked") == true)
  44. $(elm).dgUncheck(this);
  45. else
  46. $(elm).dgCheck(this);
  47.  
  48. if($(this).data('type') == 'radio')
  49. {
  50. $.each($("input[name='"+$(elm).attr("name")+"']"),function()
  51. {
  52. if(elm!=this)
  53. $(this).dgUncheck(-1);
  54. });
  55. }
  56. },
  57. dgCheck: function(div)
  58. {
  59. $(this).attr("checked",true);
  60. $(div).data('checked',true).addClass('checked');
  61. },
  62. dgUncheck: function(div)
  63. {
  64. $(this).attr("checked",false);
  65. if(div != -1)
  66. $(div).data('checked',false).css({backgroundPosition:"center 0"});
  67. else
  68. $(this).parent().data("checked",false).removeClass("checked");
  69. }
  70. });
Add Comment
Please, Sign In to add comment