jquery.radiobutton.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * EasyUI for jQuery 1.6.10
  3. *
  4. * Copyright (c) 2009-2018 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. _a.find(".radiobutton-value").attr("id",_b);
  29. if(_9.label){
  30. if(typeof _9.label=="object"){
  31. _8.label=$(_9.label);
  32. _8.label.attr("for",_b);
  33. }else{
  34. $(_8.label).remove();
  35. _8.label=$("<label class=\"textbox-label\"></label>").html(_9.label);
  36. _8.label.css("textAlign",_9.labelAlign).attr("for",_b);
  37. if(_9.labelPosition=="after"){
  38. _8.label.insertAfter(_a);
  39. }else{
  40. _8.label.insertBefore(_7);
  41. }
  42. _8.label.removeClass("textbox-label-left textbox-label-right textbox-label-top");
  43. _8.label.addClass("textbox-label-"+_9.labelPosition);
  44. }
  45. }else{
  46. $(_8.label).remove();
  47. }
  48. $(_7).radiobutton("setValue",_9.value);
  49. _c(_7,_9.checked);
  50. _d(_7,_9.disabled);
  51. };
  52. function _e(_f){
  53. var _10=$.data(_f,"radiobutton");
  54. var _11=_10.options;
  55. var _12=_10.radiobutton;
  56. _12.unbind(".radiobutton").bind("click.radiobutton",function(){
  57. if(!_11.disabled){
  58. _c(_f,true);
  59. }
  60. });
  61. };
  62. function _13(_14){
  63. var _15=$.data(_14,"radiobutton");
  64. var _16=_15.options;
  65. var _17=_15.radiobutton;
  66. _17._size(_16,_17.parent());
  67. if(_16.label&&_16.labelPosition){
  68. if(_16.labelPosition=="top"){
  69. _15.label._size({width:_16.labelWidth},_17);
  70. }else{
  71. _15.label._size({width:_16.labelWidth,height:_17.outerHeight()},_17);
  72. _15.label.css("lineHeight",_17.outerHeight()+"px");
  73. }
  74. }
  75. };
  76. function _c(_18,_19){
  77. if(_19){
  78. var f=$(_18).closest("form");
  79. var _1a=$(_18).attr("radiobuttonName");
  80. f.find(".radiobutton-f[radiobuttonName=\""+_1a+"\"]").each(function(){
  81. if(this!=_18){
  82. _1b(this,false);
  83. }
  84. });
  85. _1b(_18,true);
  86. }else{
  87. _1b(_18,false);
  88. }
  89. function _1b(b,c){
  90. var _1c=$(b).radiobutton("options");
  91. var _1d=$(b).data("radiobutton").radiobutton;
  92. _1d.find(".radiobutton-inner").css("display",c?"":"none");
  93. _1d.find(".radiobutton-value")._propAttr("checked",c);
  94. if(_1c.checked!=c){
  95. _1c.checked=c;
  96. _1c.onChange.call($(b)[0],c);
  97. }
  98. };
  99. };
  100. function _d(_1e,_1f){
  101. var _20=$.data(_1e,"radiobutton");
  102. var _21=_20.options;
  103. var _22=_20.radiobutton;
  104. var rv=_22.find(".radiobutton-value");
  105. _21.disabled=_1f;
  106. if(_1f){
  107. $(_1e).add(rv)._propAttr("disabled",true);
  108. _22.addClass("radiobutton-disabled");
  109. }else{
  110. $(_1e).add(rv)._propAttr("disabled",false);
  111. _22.removeClass("radiobutton-disabled");
  112. }
  113. };
  114. $.fn.radiobutton=function(_23,_24){
  115. if(typeof _23=="string"){
  116. return $.fn.radiobutton.methods[_23](this,_24);
  117. }
  118. _23=_23||{};
  119. return this.each(function(){
  120. var _25=$.data(this,"radiobutton");
  121. if(_25){
  122. $.extend(_25.options,_23);
  123. }else{
  124. _25=$.data(this,"radiobutton",{options:$.extend({},$.fn.radiobutton.defaults,$.fn.radiobutton.parseOptions(this),_23),radiobutton:_2(this)});
  125. }
  126. _25.options.originalChecked=_25.options.checked;
  127. _6(this);
  128. _e(this);
  129. _13(this);
  130. });
  131. };
  132. $.fn.radiobutton.methods={options:function(jq){
  133. var _26=jq.data("radiobutton");
  134. return $.extend(_26.options,{value:_26.radiobutton.find(".radiobutton-value").val()});
  135. },setValue:function(jq,_27){
  136. return jq.each(function(){
  137. $(this).val(_27);
  138. $.data(this,"radiobutton").radiobutton.find(".radiobutton-value").val(_27);
  139. });
  140. },enable:function(jq){
  141. return jq.each(function(){
  142. _d(this,false);
  143. });
  144. },disable:function(jq){
  145. return jq.each(function(){
  146. _d(this,true);
  147. });
  148. },check:function(jq){
  149. return jq.each(function(){
  150. _c(this,true);
  151. });
  152. },uncheck:function(jq){
  153. return jq.each(function(){
  154. _c(this,false);
  155. });
  156. },clear:function(jq){
  157. return jq.each(function(){
  158. _c(this,false);
  159. });
  160. },reset:function(jq){
  161. return jq.each(function(){
  162. var _28=$(this).radiobutton("options");
  163. _c(this,_28.originalChecked);
  164. });
  165. }};
  166. $.fn.radiobutton.parseOptions=function(_29){
  167. var t=$(_29);
  168. return $.extend({},$.parser.parseOptions(_29,["label","labelPosition","labelAlign",{labelWidth:"number"}]),{value:(t.val()||undefined),checked:(t.attr("checked")?true:undefined),disabled:(t.attr("disabled")?true:undefined)});
  169. };
  170. $.fn.radiobutton.defaults={width:20,height:20,value:null,disabled:false,checked:false,label:null,labelWidth:"auto",labelPosition:"before",labelAlign:"left",onChange:function(_2a){
  171. }};
  172. })(jQuery);