jquery.datetimebox.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * jQuery EasyUI 1.3.6
  3. *
  4. * Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
  7. * To use it on other terms please contact us at info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(_2){
  12. var _3=$.data(_2,"datetimebox");
  13. var _4=_3.options;
  14. $(_2).datebox($.extend({},_4,{onShowPanel:function(){
  15. var _5=$(_2).datetimebox("getValue");
  16. _8(_2,_5,true);
  17. _4.onShowPanel.call(_2);
  18. },formatter:$.fn.datebox.defaults.formatter,parser:$.fn.datebox.defaults.parser}));
  19. $(_2).removeClass("datebox-f").addClass("datetimebox-f");
  20. $(_2).datebox("calendar").calendar({onSelect:function(_6){
  21. _4.onSelect.call(_2,_6);
  22. }});
  23. var _7=$(_2).datebox("panel");
  24. if(!_3.spinner){
  25. var p=$("<div style=\"padding:2px\"><input style=\"width:80px\"></div>").insertAfter(_7.children("div.datebox-calendar-inner"));
  26. _3.spinner=p.children("input");
  27. }
  28. _3.spinner.timespinner({showSeconds:_4.showSeconds,separator:_4.timeSeparator}).unbind(".datetimebox").bind("mousedown.datetimebox",function(e){
  29. e.stopPropagation();
  30. });
  31. _8(_2,_4.value);
  32. };
  33. function _9(_a){
  34. var c=$(_a).datetimebox("calendar");
  35. var t=$(_a).datetimebox("spinner");
  36. var _b=c.calendar("options").current;
  37. return new Date(_b.getFullYear(),_b.getMonth(),_b.getDate(),t.timespinner("getHours"),t.timespinner("getMinutes"),t.timespinner("getSeconds"));
  38. };
  39. function _c(_d,q){
  40. _8(_d,q,true);
  41. };
  42. function _e(_f){
  43. var _10=$.data(_f,"datetimebox").options;
  44. var _11=_9(_f);
  45. _8(_f,_10.formatter.call(_f,_11));
  46. $(_f).combo("hidePanel");
  47. };
  48. function _8(_12,_13,_14){
  49. var _15=$.data(_12,"datetimebox").options;
  50. $(_12).combo("setValue",_13);
  51. if(!_14){
  52. if(_13){
  53. var _16=_15.parser.call(_12,_13);
  54. $(_12).combo("setValue",_15.formatter.call(_12,_16));
  55. $(_12).combo("setText",_15.formatter.call(_12,_16));
  56. }else{
  57. $(_12).combo("setText",_13);
  58. }
  59. }
  60. var _16=_15.parser.call(_12,_13);
  61. $(_12).datetimebox("calendar").calendar("moveTo",_16);
  62. $(_12).datetimebox("spinner").timespinner("setValue",_17(_16));
  63. function _17(_18){
  64. function _19(_1a){
  65. return (_1a<10?"0":"")+_1a;
  66. };
  67. var tt=[_19(_18.getHours()),_19(_18.getMinutes())];
  68. if(_15.showSeconds){
  69. tt.push(_19(_18.getSeconds()));
  70. }
  71. return tt.join($(_12).datetimebox("spinner").timespinner("options").separator);
  72. };
  73. };
  74. $.fn.datetimebox=function(_1b,_1c){
  75. if(typeof _1b=="string"){
  76. var _1d=$.fn.datetimebox.methods[_1b];
  77. if(_1d){
  78. return _1d(this,_1c);
  79. }else{
  80. return this.datebox(_1b,_1c);
  81. }
  82. }
  83. _1b=_1b||{};
  84. return this.each(function(){
  85. var _1e=$.data(this,"datetimebox");
  86. if(_1e){
  87. $.extend(_1e.options,_1b);
  88. }else{
  89. $.data(this,"datetimebox",{options:$.extend({},$.fn.datetimebox.defaults,$.fn.datetimebox.parseOptions(this),_1b)});
  90. }
  91. _1(this);
  92. });
  93. };
  94. $.fn.datetimebox.methods={options:function(jq){
  95. var _1f=jq.datebox("options");
  96. return $.extend($.data(jq[0],"datetimebox").options,{originalValue:_1f.originalValue,disabled:_1f.disabled,readonly:_1f.readonly});
  97. },spinner:function(jq){
  98. return $.data(jq[0],"datetimebox").spinner;
  99. },setValue:function(jq,_20){
  100. return jq.each(function(){
  101. _8(this,_20);
  102. });
  103. },reset:function(jq){
  104. return jq.each(function(){
  105. var _21=$(this).datetimebox("options");
  106. $(this).datetimebox("setValue",_21.originalValue);
  107. });
  108. }};
  109. $.fn.datetimebox.parseOptions=function(_22){
  110. var t=$(_22);
  111. return $.extend({},$.fn.datebox.parseOptions(_22),$.parser.parseOptions(_22,["timeSeparator",{showSeconds:"boolean"}]));
  112. };
  113. $.fn.datetimebox.defaults=$.extend({},$.fn.datebox.defaults,{showSeconds:true,timeSeparator:":",keyHandler:{up:function(e){
  114. },down:function(e){
  115. },left:function(e){
  116. },right:function(e){
  117. },enter:function(e){
  118. _e(this);
  119. },query:function(q,e){
  120. _c(this,q);
  121. }},buttons:[{text:function(_23){
  122. return $(_23).datetimebox("options").currentText;
  123. },handler:function(_24){
  124. $(_24).datetimebox("calendar").calendar({year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date()});
  125. _e(_24);
  126. }},{text:function(_25){
  127. return $(_25).datetimebox("options").okText;
  128. },handler:function(_26){
  129. _e(_26);
  130. }},{text:function(_27){
  131. return $(_27).datetimebox("options").closeText;
  132. },handler:function(_28){
  133. $(this).closest("div.combo-panel").panel("close");
  134. }}],formatter:function(_29){
  135. var h=_29.getHours();
  136. var M=_29.getMinutes();
  137. var s=_29.getSeconds();
  138. function _2a(_2b){
  139. return (_2b<10?"0":"")+_2b;
  140. };
  141. var _2c=$(this).datetimebox("spinner").timespinner("options").separator;
  142. var r=$.fn.datebox.defaults.formatter(_29)+" "+_2a(h)+_2c+_2a(M);
  143. if($(this).datetimebox("options").showSeconds){
  144. r+=_2c+_2a(s);
  145. }
  146. return r;
  147. },parser:function(s){
  148. if($.trim(s)==""){
  149. return new Date();
  150. }
  151. var dt=s.split(" ");
  152. var d=$.fn.datebox.defaults.parser(dt[0]);
  153. if(dt.length<2){
  154. return d;
  155. }
  156. var _2d=$(this).datetimebox("spinner").timespinner("options").separator;
  157. var tt=dt[1].split(_2d);
  158. var _2e=parseInt(tt[0],10)||0;
  159. var _2f=parseInt(tt[1],10)||0;
  160. var _30=parseInt(tt[2],10)||0;
  161. return new Date(d.getFullYear(),d.getMonth(),d.getDate(),_2e,_2f,_30);
  162. }});
  163. })(jQuery);