UU跑腿标准版

ligerCheckBox.js 3.6KB

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