jquery.checkbox.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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=\"checkbox inputbox\">"+"<span class=\"checkbox-inner\">"+"<svg xml:space=\"preserve\" focusable=\"false\" version=\"1.1\" viewBox=\"0 0 24 24\"><path d=\"M4.1,12.7 9,17.6 20.3,6.3\" fill=\"none\" stroke=\"white\"></path></svg>"+"</span>"+"<input type=\"checkbox\" class=\"checkbox-value\">"+"</span>").insertAfter(_3);
  14. var t=$(_3);
  15. t.addClass("checkbox-f").hide();
  16. var _5=t.attr("name");
  17. if(_5){
  18. t.removeAttr("name").attr("checkboxName",_5);
  19. _4.find(".checkbox-value").attr("name",_5);
  20. }
  21. return _4;
  22. };
  23. function _6(_7){
  24. var _8=$.data(_7,"checkbox");
  25. var _9=_8.options;
  26. var _a=_8.checkbox;
  27. var _b="_easyui_checkbox_"+(++_1);
  28. _a.find(".checkbox-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).checkbox("setValue",_9.value);
  49. _c(_7,_9.checked);
  50. _d(_7,_9.disabled);
  51. };
  52. function _e(_f){
  53. var _10=$.data(_f,"checkbox");
  54. var _11=_10.options;
  55. var _12=_10.checkbox;
  56. _12.unbind(".checkbox").bind("click.checkbox",function(){
  57. if(!_11.disabled){
  58. _c(_f,!_11.checked);
  59. }
  60. });
  61. };
  62. function _13(_14){
  63. var _15=$.data(_14,"checkbox");
  64. var _16=_15.options;
  65. var _17=_15.checkbox;
  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. var _1a=$.data(_18,"checkbox");
  78. var _1b=_1a.options;
  79. var _1c=_1a.checkbox;
  80. _1c.find(".checkbox-value")._propAttr("checked",_19);
  81. var _1d=_1c.find(".checkbox-inner").css("display",_19?"":"none");
  82. if(_19){
  83. _1d.addClass("checkbox-checked");
  84. }else{
  85. _1d.removeClass("checkbox-checked");
  86. }
  87. if(_1b.checked!=_19){
  88. _1b.checked=_19;
  89. _1b.onChange.call(_18,_19);
  90. }
  91. };
  92. function _d(_1e,_1f){
  93. var _20=$.data(_1e,"checkbox");
  94. var _21=_20.options;
  95. var _22=_20.checkbox;
  96. var rv=_22.find(".checkbox-value");
  97. _21.disabled=_1f;
  98. if(_1f){
  99. $(_1e).add(rv)._propAttr("disabled",true);
  100. _22.addClass("checkbox-disabled");
  101. }else{
  102. $(_1e).add(rv)._propAttr("disabled",false);
  103. _22.removeClass("checkbox-disabled");
  104. }
  105. };
  106. $.fn.checkbox=function(_23,_24){
  107. if(typeof _23=="string"){
  108. return $.fn.checkbox.methods[_23](this,_24);
  109. }
  110. _23=_23||{};
  111. return this.each(function(){
  112. var _25=$.data(this,"checkbox");
  113. if(_25){
  114. $.extend(_25.options,_23);
  115. }else{
  116. _25=$.data(this,"checkbox",{options:$.extend({},$.fn.checkbox.defaults,$.fn.checkbox.parseOptions(this),_23),checkbox:_2(this)});
  117. }
  118. _25.options.originalChecked=_25.options.checked;
  119. _6(this);
  120. _e(this);
  121. _13(this);
  122. });
  123. };
  124. $.fn.checkbox.methods={options:function(jq){
  125. var _26=jq.data("checkbox");
  126. return $.extend(_26.options,{value:_26.checkbox.find(".checkbox-value").val()});
  127. },setValue:function(jq,_27){
  128. return jq.each(function(){
  129. $(this).val(_27);
  130. $.data(this,"checkbox").checkbox.find(".checkbox-value").val(_27);
  131. });
  132. },enable:function(jq){
  133. return jq.each(function(){
  134. _d(this,false);
  135. });
  136. },disable:function(jq){
  137. return jq.each(function(){
  138. _d(this,true);
  139. });
  140. },check:function(jq){
  141. return jq.each(function(){
  142. _c(this,true);
  143. });
  144. },uncheck:function(jq){
  145. return jq.each(function(){
  146. _c(this,false);
  147. });
  148. },clear:function(jq){
  149. return jq.each(function(){
  150. _c(this,false);
  151. });
  152. },reset:function(jq){
  153. return jq.each(function(){
  154. var _28=$(this).checkbox("options");
  155. _c(this,_28.originalChecked);
  156. });
  157. }};
  158. $.fn.checkbox.parseOptions=function(_29){
  159. var t=$(_29);
  160. 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)});
  161. };
  162. $.fn.checkbox.defaults={width:20,height:20,value:null,disabled:false,checked:false,label:null,labelWidth:"auto",labelPosition:"before",labelAlign:"left",onChange:function(_2a){
  163. }};
  164. })(jQuery);