ligerCheckBox.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * jQuery ligerUI 1.1.9
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2012 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. $.fn.ligerCheckBox = function (options)
  12. {
  13. return $.ligerui.run.call(this, "ligerCheckBox", arguments);
  14. };
  15. $.fn.ligerGetCheckBoxManager = function ()
  16. {
  17. return $.ligerui.run.call(this, "ligerGetCheckBoxManager", arguments);
  18. };
  19. $.ligerDefaults.CheckBox = { disabled: false };
  20. $.ligerMethos.CheckBox = {};
  21. $.ligerui.controls.CheckBox = function (element, options)
  22. {
  23. $.ligerui.controls.CheckBox.base.constructor.call(this, element, options);
  24. };
  25. $.ligerui.controls.CheckBox.ligerExtend($.ligerui.controls.Input, {
  26. __getType: function ()
  27. {
  28. return 'CheckBox';
  29. },
  30. __idPrev: function ()
  31. {
  32. return 'CheckBox';
  33. },
  34. _extendMethods: function ()
  35. {
  36. return $.ligerMethos.CheckBox;
  37. },
  38. _render: function ()
  39. {
  40. var g = this, p = this.options;
  41. g.input = $(g.element);
  42. g.link = $('<a class="l-checkbox"></a>');
  43. g.wrapper = g.input.addClass('l-hidden').wrap('<div class="l-checkbox-wrapper"></div>').parent();
  44. g.wrapper.prepend(g.link);
  45. g.link.click(function ()
  46. {
  47. if (g.input.attr('disabled')) { return false; }
  48. if (p.disabled) return false;
  49. if (g.trigger('beforeClick', [g.element]) == false) return false;
  50. if ($(this).hasClass("l-checkbox-checked"))
  51. {
  52. g._setValue(false);
  53. }
  54. else
  55. {
  56. g._setValue(true);
  57. }
  58. g.input.trigger("change");
  59. });
  60. g.wrapper.hover(function ()
  61. {
  62. if (!p.disabled)
  63. $(this).addClass("l-over");
  64. }, function ()
  65. {
  66. $(this).removeClass("l-over");
  67. });
  68. this.set(p);
  69. this.updateStyle();
  70. },
  71. _setCss: function (value)
  72. {
  73. this.wrapper.css(value);
  74. },
  75. _setValue: function (value)
  76. {
  77. var g = this, p = this.options;
  78. if (!value)
  79. {
  80. g.input[0].checked = false;
  81. g.link.removeClass('l-checkbox-checked');
  82. }
  83. else
  84. {
  85. g.input[0].checked = true;
  86. g.link.addClass('l-checkbox-checked');
  87. }
  88. },
  89. _setDisabled: function (value)
  90. {
  91. if (value)
  92. {
  93. this.input.attr('disabled', true);
  94. this.wrapper.addClass("l-disabled");
  95. }
  96. else
  97. {
  98. this.input.attr('disabled', false);
  99. this.wrapper.removeClass("l-disabled");
  100. }
  101. },
  102. _getValue: function ()
  103. {
  104. return this.element.checked;
  105. },
  106. updateStyle: function ()
  107. {
  108. if (this.input.attr('disabled'))
  109. {
  110. this.wrapper.addClass("l-disabled");
  111. this.options.disabled = true;
  112. }
  113. if (this.input[0].checked)
  114. {
  115. this.link.addClass('l-checkbox-checked');
  116. }
  117. else
  118. {
  119. this.link.removeClass('l-checkbox-checked');
  120. }
  121. }
  122. });
  123. })(jQuery);