jquery.radiobutton.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * EasyUI for jQuery 1.8.3
  3. *
  4. * Copyright (c) 2009-2019 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. var _1=1;
  12. function _2(_3){
  13. var _4=$("<span class=\"radiobutton inputbox\">"+"<span class=\"radiobutton-inner\" style=\"display:none\"></span>"+"<input type=\"radio\" class=\"radiobutton-value\">"+"</span>").insertAfter(_3);
  14. var t=$(_3);
  15. t.addClass("radiobutton-f").hide();
  16. var _5=t.attr("name");
  17. if(_5){
  18. t.removeAttr("name").attr("radiobuttonName",_5);
  19. _4.find(".radiobutton-value").attr("name",_5);
  20. }
  21. return _4;
  22. };
  23. function _6(_7){
  24. var _8=$.data(_7,"radiobutton");
  25. var _9=_8.options;
  26. var _a=_8.radiobutton;
  27. var _b="_easyui_radiobutton_"+(++_1);
  28. var _c=_a.find(".radiobutton-value").attr("id",_b);
  29. _c.unbind(".radiobutton").bind("change.radiobutton",function(e){
  30. return false;
  31. });
  32. if(_9.label){
  33. if(typeof _9.label=="object"){
  34. _8.label=$(_9.label);
  35. _8.label.attr("for",_b);
  36. }else{
  37. $(_8.label).remove();
  38. _8.label=$("<label class=\"textbox-label\"></label>").html(_9.label);
  39. _8.label.css("textAlign",_9.labelAlign).attr("for",_b);
  40. if(_9.labelPosition=="after"){
  41. _8.label.insertAfter(_a);
  42. }else{
  43. _8.label.insertBefore(_7);
  44. }
  45. _8.label.removeClass("textbox-label-left textbox-label-right textbox-label-top");
  46. _8.label.addClass("textbox-label-"+_9.labelPosition);
  47. }
  48. }else{
  49. $(_8.label).remove();
  50. }
  51. $(_7).radiobutton("setValue",_9.value);
  52. _d(_7,_9.checked);
  53. _e(_7,_9.readonly);
  54. _f(_7,_9.disabled);
  55. };
  56. function _10(_11){
  57. var _12=$.data(_11,"radiobutton");
  58. var _13=_12.options;
  59. var _14=_12.radiobutton;
  60. _14.unbind(".radiobutton").bind("click.radiobutton",function(){
  61. if(!_13.disabled&&!_13.readonly){
  62. _d(_11,true);
  63. }
  64. });
  65. };
  66. function _15(_16){
  67. var _17=$.data(_16,"radiobutton");
  68. var _18=_17.options;
  69. var _19=_17.radiobutton;
  70. _19._size(_18,_19.parent());
  71. if(_18.label&&_18.labelPosition){
  72. if(_18.labelPosition=="top"){
  73. _17.label._size({width:_18.labelWidth},_19);
  74. }else{
  75. _17.label._size({width:_18.labelWidth,height:_19.outerHeight()},_19);
  76. _17.label.css("lineHeight",_19.outerHeight()+"px");
  77. }
  78. }
  79. };
  80. function _d(_1a,_1b){
  81. if(_1b){
  82. var f=$(_1a).closest("form");
  83. var _1c=$(_1a).attr("radiobuttonName");
  84. f.find(".radiobutton-f[radiobuttonName=\""+_1c+"\"]").each(function(){
  85. if(this!=_1a){
  86. _1d(this,false);
  87. }
  88. });
  89. _1d(_1a,true);
  90. }else{
  91. _1d(_1a,false);
  92. }
  93. function _1d(b,c){
  94. var _1e=$(b).radiobutton("options");
  95. var _1f=$(b).data("radiobutton").radiobutton;
  96. _1f.find(".radiobutton-inner").css("display",c?"":"none");
  97. _1f.find(".radiobutton-value")._propAttr("checked",c);
  98. if(_1e.checked!=c){
  99. _1e.checked=c;
  100. _1e.onChange.call($(b)[0],c);
  101. $(b).closest("form").trigger("_change",[$(b)[0]]);
  102. }
  103. };
  104. };
  105. function _f(_20,_21){
  106. var _22=$.data(_20,"radiobutton");
  107. var _23=_22.options;
  108. var _24=_22.radiobutton;
  109. var rv=_24.find(".radiobutton-value");
  110. _23.disabled=_21;
  111. if(_21){
  112. $(_20).add(rv)._propAttr("disabled",true);
  113. _24.addClass("radiobutton-disabled");
  114. $(_22.label).addClass("textbox-label-disabled");
  115. }else{
  116. $(_20).add(rv)._propAttr("disabled",false);
  117. _24.removeClass("radiobutton-disabled");
  118. $(_22.label).removeClass("textbox-label-disabled");
  119. }
  120. };
  121. function _e(_25,_26){
  122. var _27=$.data(_25,"radiobutton");
  123. var _28=_27.options;
  124. _28.readonly=_26==undefined?true:_26;
  125. _27.radiobutton.removeClass("radiobutton-readonly").addClass(_28.readonly?"radiobutton-readonly":"");
  126. };
  127. $.fn.radiobutton=function(_29,_2a){
  128. if(typeof _29=="string"){
  129. return $.fn.radiobutton.methods[_29](this,_2a);
  130. }
  131. _29=_29||{};
  132. return this.each(function(){
  133. var _2b=$.data(this,"radiobutton");
  134. if(_2b){
  135. $.extend(_2b.options,_29);
  136. }else{
  137. _2b=$.data(this,"radiobutton",{options:$.extend({},$.fn.radiobutton.defaults,$.fn.radiobutton.parseOptions(this),_29),radiobutton:_2(this)});
  138. }
  139. _2b.options.originalChecked=_2b.options.checked;
  140. _6(this);
  141. _10(this);
  142. _15(this);
  143. });
  144. };
  145. $.fn.radiobutton.methods={options:function(jq){
  146. var _2c=jq.data("radiobutton");
  147. return $.extend(_2c.options,{value:_2c.radiobutton.find(".radiobutton-value").val()});
  148. },setValue:function(jq,_2d){
  149. return jq.each(function(){
  150. $(this).val(_2d);
  151. $.data(this,"radiobutton").radiobutton.find(".radiobutton-value").val(_2d);
  152. });
  153. },enable:function(jq){
  154. return jq.each(function(){
  155. _f(this,false);
  156. });
  157. },disable:function(jq){
  158. return jq.each(function(){
  159. _f(this,true);
  160. });
  161. },readonly:function(jq,_2e){
  162. return jq.each(function(){
  163. _e(this,_2e);
  164. });
  165. },check:function(jq){
  166. return jq.each(function(){
  167. _d(this,true);
  168. });
  169. },uncheck:function(jq){
  170. return jq.each(function(){
  171. _d(this,false);
  172. });
  173. },clear:function(jq){
  174. return jq.each(function(){
  175. _d(this,false);
  176. });
  177. },reset:function(jq){
  178. return jq.each(function(){
  179. var _2f=$(this).radiobutton("options");
  180. _d(this,_2f.originalChecked);
  181. });
  182. }};
  183. $.fn.radiobutton.parseOptions=function(_30){
  184. var t=$(_30);
  185. return $.extend({},$.parser.parseOptions(_30,["label","labelPosition","labelAlign",{labelWidth:"number"}]),{value:(t.val()||undefined),checked:(t.attr("checked")?true:undefined),disabled:(t.attr("disabled")?true:undefined),readonly:(t.attr("readonly")?true:undefined)});
  186. };
  187. $.fn.radiobutton.defaults={width:20,height:20,value:null,disabled:false,readonly:false,checked:false,label:null,labelWidth:"auto",labelPosition:"before",labelAlign:"left",onChange:function(_31){
  188. }};
  189. })(jQuery);