jquery.timespinner.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * EasyUI for jQuery 1.7.0
  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,"timespinner").options;
  13. $(_2).addClass("timespinner-f").spinner(_3);
  14. var _4=_3.formatter.call(_2,_3.parser.call(_2,_3.value));
  15. $(_2).timespinner("initValue",_4);
  16. };
  17. function _5(e){
  18. var _6=e.data.target;
  19. var _7=$.data(_6,"timespinner").options;
  20. var _8=$(_6).timespinner("getSelectionStart");
  21. for(var i=0;i<_7.selections.length;i++){
  22. var _9=_7.selections[i];
  23. if(_8>=_9[0]&&_8<=_9[1]){
  24. _a(_6,i);
  25. return;
  26. }
  27. }
  28. };
  29. function _a(_b,_c){
  30. var _d=$.data(_b,"timespinner").options;
  31. if(_c!=undefined){
  32. _d.highlight=_c;
  33. }
  34. var _e=_d.selections[_d.highlight];
  35. if(_e){
  36. var tb=$(_b).timespinner("textbox");
  37. $(_b).timespinner("setSelectionRange",{start:_e[0],end:_e[1]});
  38. tb.focus();
  39. }
  40. };
  41. function _f(_10,_11){
  42. var _12=$.data(_10,"timespinner").options;
  43. var _11=_12.parser.call(_10,_11);
  44. var _13=_12.formatter.call(_10,_11);
  45. $(_10).spinner("setValue",_13);
  46. };
  47. function _14(_15,_16){
  48. var _17=$.data(_15,"timespinner").options;
  49. var s=$(_15).timespinner("getValue");
  50. var _18=_17.selections[_17.highlight];
  51. var s1=s.substring(0,_18[0]);
  52. var s2=s.substring(_18[0],_18[1]);
  53. var s3=s.substring(_18[1]);
  54. if(s2==_17.ampm[0]){
  55. s2=_17.ampm[1];
  56. }else{
  57. if(s2==_17.ampm[1]){
  58. s2=_17.ampm[0];
  59. }else{
  60. s2=parseInt(s2,10)||0;
  61. if(_17.selections.length-4==_17.highlight&&_17.hour12){
  62. if(s2==12){
  63. s2=0;
  64. }else{
  65. if(s2==11&&!_16){
  66. var tmp=s3.replace(_17.ampm[0],_17.ampm[1]);
  67. if(s3!=tmp){
  68. s3=tmp;
  69. }else{
  70. s3=s3.replace(_17.ampm[1],_17.ampm[0]);
  71. }
  72. }
  73. }
  74. }
  75. s2=s2+_17.increment*(_16?-1:1);
  76. }
  77. }
  78. var v=s1+s2+s3;
  79. $(_15).timespinner("setValue",v);
  80. _a(_15);
  81. };
  82. $.fn.timespinner=function(_19,_1a){
  83. if(typeof _19=="string"){
  84. var _1b=$.fn.timespinner.methods[_19];
  85. if(_1b){
  86. return _1b(this,_1a);
  87. }else{
  88. return this.spinner(_19,_1a);
  89. }
  90. }
  91. _19=_19||{};
  92. return this.each(function(){
  93. var _1c=$.data(this,"timespinner");
  94. if(_1c){
  95. $.extend(_1c.options,_19);
  96. }else{
  97. $.data(this,"timespinner",{options:$.extend({},$.fn.timespinner.defaults,$.fn.timespinner.parseOptions(this),_19)});
  98. }
  99. _1(this);
  100. });
  101. };
  102. $.fn.timespinner.methods={options:function(jq){
  103. var _1d=jq.data("spinner")?jq.spinner("options"):{};
  104. return $.extend($.data(jq[0],"timespinner").options,{width:_1d.width,value:_1d.value,originalValue:_1d.originalValue,disabled:_1d.disabled,readonly:_1d.readonly});
  105. },setValue:function(jq,_1e){
  106. return jq.each(function(){
  107. _f(this,_1e);
  108. });
  109. },getHours:function(jq){
  110. var _1f=$.data(jq[0],"timespinner").options;
  111. var _20=_1f.parser.call(jq[0],jq.timespinner("getValue"));
  112. return _20?_20.getHours():null;
  113. },getMinutes:function(jq){
  114. var _21=$.data(jq[0],"timespinner").options;
  115. var _22=_21.parser.call(jq[0],jq.timespinner("getValue"));
  116. return _22?_22.getMinutes():null;
  117. },getSeconds:function(jq){
  118. var _23=$.data(jq[0],"timespinner").options;
  119. var _24=_23.parser.call(jq[0],jq.timespinner("getValue"));
  120. return _24?_24.getSeconds():null;
  121. }};
  122. $.fn.timespinner.parseOptions=function(_25){
  123. return $.extend({},$.fn.spinner.parseOptions(_25),$.parser.parseOptions(_25,["separator",{hour12:"boolean",showSeconds:"boolean",highlight:"number"}]));
  124. };
  125. $.fn.timespinner.defaults=$.extend({},$.fn.spinner.defaults,{inputEvents:$.extend({},$.fn.spinner.defaults.inputEvents,{click:function(e){
  126. _5.call(this,e);
  127. },blur:function(e){
  128. var t=$(e.data.target);
  129. t.timespinner("setValue",t.timespinner("getText"));
  130. },keydown:function(e){
  131. if(e.keyCode==13){
  132. var t=$(e.data.target);
  133. t.timespinner("setValue",t.timespinner("getText"));
  134. }
  135. }}),formatter:function(_26){
  136. if(!_26){
  137. return "";
  138. }
  139. var _27=$(this).timespinner("options");
  140. var _28=_26.getHours();
  141. var _29=_26.getMinutes();
  142. var _2a=_26.getSeconds();
  143. var _2b="";
  144. if(_27.hour12){
  145. _2b=_28>=12?_27.ampm[1]:_27.ampm[0];
  146. _28=_28%12;
  147. if(_28==0){
  148. _28=12;
  149. }
  150. }
  151. var tt=[_2c(_28),_2c(_29)];
  152. if(_27.showSeconds){
  153. tt.push(_2c(_2a));
  154. }
  155. var s=tt.join(_27.separator)+" "+_2b;
  156. return $.trim(s);
  157. function _2c(_2d){
  158. return (_2d<10?"0":"")+_2d;
  159. };
  160. },parser:function(s){
  161. var _2e=$(this).timespinner("options");
  162. var _2f=_30(s);
  163. if(_2f){
  164. var min=_30(_2e.min);
  165. var max=_30(_2e.max);
  166. if(min&&min>_2f){
  167. _2f=min;
  168. }
  169. if(max&&max<_2f){
  170. _2f=max;
  171. }
  172. }
  173. return _2f;
  174. function _30(s){
  175. if(!s){
  176. return null;
  177. }
  178. var ss=s.split(" ");
  179. var tt=ss[0].split(_2e.separator);
  180. var _31=parseInt(tt[0],10)||0;
  181. var _32=parseInt(tt[1],10)||0;
  182. var _33=parseInt(tt[2],10)||0;
  183. if(_2e.hour12){
  184. var _34=ss[1];
  185. if(_34==_2e.ampm[1]&&_31<12){
  186. _31+=12;
  187. }else{
  188. if(_34==_2e.ampm[0]&&_31==12){
  189. _31-=12;
  190. }
  191. }
  192. }
  193. return new Date(1900,0,0,_31,_32,_33);
  194. };
  195. },selections:[[0,2],[3,5],[6,8],[9,11]],separator:":",showSeconds:false,highlight:0,hour12:false,ampm:["AM","PM"],spin:function(_35){
  196. _14(this,_35);
  197. }});
  198. })(jQuery);