jquery.spinner.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. function _1(_2){
  12. var _3=$.data(_2,"spinner");
  13. var _4=_3.options;
  14. var _5=$.extend(true,[],_4.icons);
  15. if(_4.spinAlign=="left"||_4.spinAlign=="right"){
  16. _4.spinArrow=true;
  17. _4.iconAlign=_4.spinAlign;
  18. var _6={iconCls:"spinner-button-updown",handler:function(e){
  19. var _7=$(e.target).closest(".spinner-arrow-up,.spinner-arrow-down");
  20. _13(e.data.target,_7.hasClass("spinner-arrow-down"));
  21. }};
  22. if(_4.spinAlign=="left"){
  23. _5.unshift(_6);
  24. }else{
  25. _5.push(_6);
  26. }
  27. }else{
  28. _4.spinArrow=false;
  29. if(_4.spinAlign=="vertical"){
  30. if(_4.buttonAlign!="top"){
  31. _4.buttonAlign="bottom";
  32. }
  33. _4.clsLeft="textbox-button-bottom";
  34. _4.clsRight="textbox-button-top";
  35. }else{
  36. _4.clsLeft="textbox-button-left";
  37. _4.clsRight="textbox-button-right";
  38. }
  39. }
  40. $(_2).addClass("spinner-f").textbox($.extend({},_4,{icons:_5,doSize:false,onResize:function(_8,_9){
  41. if(!_4.spinArrow){
  42. var _a=$(this).next();
  43. var _b=_a.find(".textbox-button:not(.spinner-button)");
  44. if(_b.length){
  45. var _c=_b.outerWidth();
  46. var _d=_b.outerHeight();
  47. var _e=_a.find(".spinner-button."+_4.clsLeft);
  48. var _f=_a.find(".spinner-button."+_4.clsRight);
  49. if(_4.buttonAlign=="right"){
  50. _f.css("marginRight",_c+"px");
  51. }else{
  52. if(_4.buttonAlign=="left"){
  53. _e.css("marginLeft",_c+"px");
  54. }else{
  55. if(_4.buttonAlign=="top"){
  56. _f.css("marginTop",_d+"px");
  57. }else{
  58. _e.css("marginBottom",_d+"px");
  59. }
  60. }
  61. }
  62. }
  63. }
  64. _4.onResize.call(this,_8,_9);
  65. }}));
  66. $(_2).attr("spinnerName",$(_2).attr("textboxName"));
  67. _3.spinner=$(_2).next();
  68. _3.spinner.addClass("spinner");
  69. if(_4.spinArrow){
  70. var _10=_3.spinner.find(".spinner-button-updown");
  71. _10.append("<span class=\"spinner-arrow spinner-button-top\">"+"<span class=\"spinner-arrow-up\"></span>"+"</span>"+"<span class=\"spinner-arrow spinner-button-bottom\">"+"<span class=\"spinner-arrow-down\"></span>"+"</span>");
  72. }else{
  73. var _11=$("<a href=\"javascript:;\" class=\"textbox-button spinner-button\"></a>").addClass(_4.clsLeft).appendTo(_3.spinner);
  74. var _12=$("<a href=\"javascript:;\" class=\"textbox-button spinner-button\"></a>").addClass(_4.clsRight).appendTo(_3.spinner);
  75. _11.linkbutton({iconCls:_4.reversed?"spinner-button-up":"spinner-button-down",onClick:function(){
  76. _13(_2,!_4.reversed);
  77. }});
  78. _12.linkbutton({iconCls:_4.reversed?"spinner-button-down":"spinner-button-up",onClick:function(){
  79. _13(_2,_4.reversed);
  80. }});
  81. if(_4.disabled){
  82. $(_2).spinner("disable");
  83. }
  84. if(_4.readonly){
  85. $(_2).spinner("readonly");
  86. }
  87. }
  88. $(_2).spinner("resize");
  89. };
  90. function _13(_14,_15){
  91. var _16=$(_14).spinner("options");
  92. _16.spin.call(_14,_15);
  93. _16[_15?"onSpinDown":"onSpinUp"].call(_14);
  94. $(_14).spinner("validate");
  95. };
  96. $.fn.spinner=function(_17,_18){
  97. if(typeof _17=="string"){
  98. var _19=$.fn.spinner.methods[_17];
  99. if(_19){
  100. return _19(this,_18);
  101. }else{
  102. return this.textbox(_17,_18);
  103. }
  104. }
  105. _17=_17||{};
  106. return this.each(function(){
  107. var _1a=$.data(this,"spinner");
  108. if(_1a){
  109. $.extend(_1a.options,_17);
  110. }else{
  111. _1a=$.data(this,"spinner",{options:$.extend({},$.fn.spinner.defaults,$.fn.spinner.parseOptions(this),_17)});
  112. }
  113. _1(this);
  114. });
  115. };
  116. $.fn.spinner.methods={options:function(jq){
  117. var _1b=jq.textbox("options");
  118. return $.extend($.data(jq[0],"spinner").options,{width:_1b.width,value:_1b.value,originalValue:_1b.originalValue,disabled:_1b.disabled,readonly:_1b.readonly});
  119. }};
  120. $.fn.spinner.parseOptions=function(_1c){
  121. return $.extend({},$.fn.textbox.parseOptions(_1c),$.parser.parseOptions(_1c,["min","max","spinAlign",{increment:"number",reversed:"boolean"}]));
  122. };
  123. $.fn.spinner.defaults=$.extend({},$.fn.textbox.defaults,{min:null,max:null,increment:1,spinAlign:"right",reversed:false,spin:function(_1d){
  124. },onSpinUp:function(){
  125. },onSpinDown:function(){
  126. }});
  127. })(jQuery);