jquery.datebox.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * jQuery EasyUI 1.3.4
  3. *
  4. * Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL or commercial licenses
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. * http://www.gnu.org/licenses/gpl.txt
  9. * http://www.jeasyui.com/license_commercial.php
  10. *
  11. */
  12. (function($){
  13. function _1(_2){
  14. var _3=$.data(_2,"datebox");
  15. var _4=_3.options;
  16. $(_2).addClass("datebox-f").combo($.extend({},_4,{onShowPanel:function(){
  17. _5();
  18. _4.onShowPanel.call(_2);
  19. }}));
  20. $(_2).combo("textbox").parent().addClass("datebox");
  21. if(!_3.calendar){
  22. _6();
  23. }
  24. function _6(){
  25. var _7=$(_2).combo("panel");
  26. _3.calendar=$("<div></div>").appendTo(_7).wrap("<div class=\"datebox-calendar-inner\"></div>");
  27. _3.calendar.calendar({fit:true,border:false,onSelect:function(_8){
  28. var _9=_4.formatter(_8);
  29. _11(_2,_9);
  30. $(_2).combo("hidePanel");
  31. _4.onSelect.call(_2,_8);
  32. }});
  33. _11(_2,_4.value);
  34. var _a=$("<div class=\"datebox-button\"></div>").appendTo(_7);
  35. var _b=$("<a href=\"javascript:void(0)\" class=\"datebox-current\"></a>").html(_4.currentText).appendTo(_a);
  36. var _c=$("<a href=\"javascript:void(0)\" class=\"datebox-close\"></a>").html(_4.closeText).appendTo(_a);
  37. _b.click(function(){
  38. _3.calendar.calendar({year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date()});
  39. });
  40. _c.click(function(){
  41. $(_2).combo("hidePanel");
  42. });
  43. };
  44. function _5(){
  45. if(_4.panelHeight!="auto"){
  46. var _d=$(_2).combo("panel");
  47. var ci=_d.children("div.datebox-calendar-inner");
  48. var _e=_d.height();
  49. _d.children().not(ci).each(function(){
  50. _e-=$(this).outerHeight();
  51. });
  52. ci._outerHeight(_e);
  53. }
  54. _3.calendar.calendar("resize");
  55. };
  56. };
  57. function _f(_10,q){
  58. _11(_10,q);
  59. };
  60. function _12(_13){
  61. var _14=$.data(_13,"datebox");
  62. var _15=_14.options;
  63. var c=_14.calendar;
  64. var _16=_15.formatter(c.calendar("options").current);
  65. _11(_13,_16);
  66. $(_13).combo("hidePanel");
  67. };
  68. function _11(_17,_18){
  69. var _19=$.data(_17,"datebox");
  70. var _1a=_19.options;
  71. $(_17).combo("setValue",_18).combo("setText",_18);
  72. _19.calendar.calendar("moveTo",_1a.parser(_18));
  73. };
  74. $.fn.datebox=function(_1b,_1c){
  75. if(typeof _1b=="string"){
  76. var _1d=$.fn.datebox.methods[_1b];
  77. if(_1d){
  78. return _1d(this,_1c);
  79. }else{
  80. return this.combo(_1b,_1c);
  81. }
  82. }
  83. _1b=_1b||{};
  84. return this.each(function(){
  85. var _1e=$.data(this,"datebox");
  86. if(_1e){
  87. $.extend(_1e.options,_1b);
  88. }else{
  89. $.data(this,"datebox",{options:$.extend({},$.fn.datebox.defaults,$.fn.datebox.parseOptions(this),_1b)});
  90. }
  91. _1(this);
  92. });
  93. };
  94. $.fn.datebox.methods={options:function(jq){
  95. var _1f=jq.combo("options");
  96. return $.extend($.data(jq[0],"datebox").options,{originalValue:_1f.originalValue,disabled:_1f.disabled,readonly:_1f.readonly});
  97. },calendar:function(jq){
  98. return $.data(jq[0],"datebox").calendar;
  99. },setValue:function(jq,_20){
  100. return jq.each(function(){
  101. _11(this,_20);
  102. });
  103. },reset:function(jq){
  104. return jq.each(function(){
  105. var _21=$(this).datebox("options");
  106. $(this).datebox("setValue",_21.originalValue);
  107. });
  108. }};
  109. $.fn.datebox.parseOptions=function(_22){
  110. var t=$(_22);
  111. return $.extend({},$.fn.combo.parseOptions(_22),{});
  112. };
  113. $.fn.datebox.defaults=$.extend({},$.fn.combo.defaults,{panelWidth:180,panelHeight:"auto",keyHandler:{up:function(){
  114. },down:function(){
  115. },enter:function(){
  116. _12(this);
  117. },query:function(q){
  118. _f(this,q);
  119. }},currentText:"Today",closeText:"Close",okText:"Ok",formatter:function(_23){
  120. var y=_23.getFullYear();
  121. var m=_23.getMonth()+1;
  122. var d=_23.getDate();
  123. return m+"/"+d+"/"+y;
  124. },parser:function(s){
  125. var t=Date.parse(s);
  126. if(!isNaN(t)){
  127. return new Date(t);
  128. }else{
  129. return new Date();
  130. }
  131. },onSelect:function(_24){
  132. }});
  133. })(jQuery);