ligerRadio.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.ligerRadio = function ()
  12. {
  13. return $.ligerui.run.call(this, "ligerRadio", arguments);
  14. };
  15. $.fn.ligerGetRadioManager = function ()
  16. {
  17. return $.ligerui.run.call(this, "ligerGetRadioManager", arguments);
  18. };
  19. $.ligerDefaults.Radio = { disabled: false };
  20. $.ligerMethos.Radio = {};
  21. $.ligerui.controls.Radio = function (element, options)
  22. {
  23. $.ligerui.controls.Radio.base.constructor.call(this, element, options);
  24. };
  25. $.ligerui.controls.Radio.ligerExtend($.ligerui.controls.Input, {
  26. __getType: function ()
  27. {
  28. return 'Radio';
  29. },
  30. __idPrev: function ()
  31. {
  32. return 'Radio';
  33. },
  34. _extendMethods: function ()
  35. {
  36. return $.ligerMethos.Radio;
  37. },
  38. _render: function ()
  39. {
  40. var g = this, p = this.options;
  41. g.input = $(this.element);
  42. g.link = $('<a href="javascript:void(0)" class="l-radio"></a>');
  43. g.wrapper = g.input.addClass('l-hidden').wrap('<div class="l-radio-wrapper"></div>').parent();
  44. g.wrapper.prepend(g.link);
  45. g.input.change(function ()
  46. {
  47. if (this.checked)
  48. {
  49. g.link.addClass('l-radio-checked');
  50. }
  51. else
  52. {
  53. g.link.removeClass('l-radio-checked');
  54. }
  55. return true;
  56. });
  57. g.link.click(function ()
  58. {
  59. g._doclick();
  60. });
  61. g.wrapper.hover(function ()
  62. {
  63. if (!p.disabled)
  64. $(this).addClass("l-over");
  65. }, function ()
  66. {
  67. $(this).removeClass("l-over");
  68. });
  69. this.element.checked && g.link.addClass('l-radio-checked');
  70. if (this.element.id)
  71. {
  72. $("label[for=" + this.element.id + "]").click(function ()
  73. {
  74. g._doclick();
  75. });
  76. }
  77. g.set(p);
  78. },
  79. setValue: function (value)
  80. {
  81. var g = this, p = this.options;
  82. if (!value)
  83. {
  84. g.input[0].checked = false;
  85. g.link.removeClass('l-radio-checked');
  86. }
  87. else
  88. {
  89. g.input[0].checked = true;
  90. g.link.addClass('l-radio-checked');
  91. }
  92. },
  93. getValue: function ()
  94. {
  95. return this.input[0].checked;
  96. },
  97. setEnabled: function ()
  98. {
  99. this.input.attr('disabled', false);
  100. this.wrapper.removeClass("l-disabled");
  101. this.options.disabled = false;
  102. },
  103. setDisabled: function ()
  104. {
  105. this.input.attr('disabled', true);
  106. this.wrapper.addClass("l-disabled");
  107. this.options.disabled = true;
  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. _doclick: function ()
  126. {
  127. var g = this, p = this.options;
  128. if (g.input.attr('disabled')) { return false; }
  129. g.input.trigger('click').trigger('change');
  130. var formEle;
  131. if (g.input[0].form) formEle = g.input[0].form;
  132. else formEle = document;
  133. $("input:radio[name=" + g.input[0].name + "]", formEle).not(g.input).trigger("change");
  134. return false;
  135. }
  136. });
  137. })(jQuery);