datepicker.js 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. /*
  2. * jQuery UI Datepicker 1.8.5
  3. *
  4. * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT or GPL Version 2 licenses.
  6. * http://jquery.org/license
  7. *
  8. * http://docs.jquery.com/UI/Datepicker
  9. *
  10. * Depends:
  11. * jquery.ui.core.js
  12. */
  13. (function( $, undefined ) {
  14. $.extend($.ui, { datepicker: { version: "1.8.5" } });
  15. var PROP_NAME = 'datepicker';
  16. var dpuuid = new Date().getTime();
  17. /* Date picker manager.
  18. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  19. Settings for (groups of) date pickers are maintained in an instance object,
  20. allowing multiple different settings on the same page. */
  21. function Datepicker() {
  22. this.debug = false; // Change this to true to start debugging
  23. this._curInst = null; // The current instance in use
  24. this._keyEvent = false; // If the last event was a key event
  25. this._disabledInputs = []; // List of date picker inputs that have been disabled
  26. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  27. this._inDialog = false; // True if showing within a "dialog", false if not
  28. this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
  29. this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
  30. this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
  31. this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
  32. this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
  33. this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
  34. this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
  35. this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
  36. this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
  37. this.regional = []; // Available regional settings, indexed by language code
  38. this.regional[''] = { // Default regional settings
  39. closeText: '关闭', // Display text for close link
  40. prevText: '<上月', // Display text for previous month link
  41. nextText: '下月>', // Display text for next month link
  42. currentText: '今天', // Display text for current month link
  43. monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'], // Names of months for drop-down and formatting
  44. monthNamesShort: ['一','二','三','四','五','六','七','八','九','十','十一','十二'], // For formatting
  45. dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], // For formatting
  46. dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'], // For formatting
  47. dayNamesMin: ['日','一','二','三','四','五','六'], // Column headings for days starting at Sunday
  48. weekHeader: 'Wk', // Column header for week of the year
  49. dateFormat: 'yy-mm-dd', // See format options on parseDate
  50. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  51. isRTL: false, // True if right-to-left language, false if left-to-right
  52. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  53. yearSuffix: '', // Additional text to append to the year in the month headers
  54. length : 5
  55. };
  56. this._defaults = { // Global defaults for all the date picker instances
  57. showOn: 'focus', // 'focus' for popup on focus,
  58. // 'button' for trigger button, or 'both' for either
  59. showAnim: 'fadeIn', // Name of jQuery animation for popup
  60. showOptions: {}, // Options for enhanced animations
  61. defaultDate: null, // Used when field is blank: actual date,
  62. // +/-number for offset from today, null for today
  63. appendText: '', // Display text following the input box, e.g. showing the format
  64. buttonText: '...', // Text for trigger button
  65. buttonImage: '', // URL for trigger button image
  66. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  67. hideIfNoPrevNext: false, // True to hide next/previous month links
  68. // if not applicable, false to just disable them
  69. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  70. gotoCurrent: false, // True if today link goes back to current selection instead
  71. changeMonth: true, // True if month can be selected directly, false if only prev/next
  72. changeYear: true, // True if year can be selected directly, false if only prev/next
  73. yearRange: '-112:+100', // Range of years to display in drop-down,
  74. // either relative to today's year (-nn:+nn), relative to currently displayed year
  75. // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
  76. showOtherMonths: false, // True to show dates in other months, false to leave blank
  77. selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
  78. showWeek: false, // True to show week of the year, false to not show it
  79. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  80. // takes a Date and returns the number of the week for it
  81. shortYearCutoff: '+10', // Short year values < this are in the current century,
  82. // > this are in the previous century,
  83. // string value starting with '+' for current year + value
  84. minDate: null, // The earliest selectable date, or null for no limit
  85. maxDate: null, // The latest selectable date, or null for no limit
  86. duration: '', // Duration of display/closure
  87. beforeShowDay: null, // Function that takes a date and returns an array with
  88. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
  89. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  90. beforeShow: null, // Function that takes an input field and
  91. // returns a set of custom settings for the date picker
  92. onSelect: null, // Define a callback function when a date is selected
  93. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  94. onClose: null, // Define a callback function when the datepicker is closed
  95. numberOfMonths: 1, // Number of months to show at a time
  96. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  97. stepMonths: 1, // Number of months to step back/forward
  98. stepBigMonths: 12, // Number of months to step back/forward for the big links
  99. altField: '', // Selector for an alternate field to store selected dates into
  100. altFormat: '', // The date format to use for the alternate field
  101. constrainInput: true, // The input is constrained by the current date format
  102. showButtonPanel: true, // True to show button panel, false to not show it
  103. autoSize: false // True to size the input for the date format, false to leave as is
  104. };
  105. $.extend(this._defaults, this.regional['']);
  106. this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>');
  107. }
  108. $.extend(Datepicker.prototype, {
  109. /* Class name added to elements to indicate already configured with a date picker. */
  110. markerClassName: 'hasDatepicker',
  111. /* Debug logging (if enabled). */
  112. log: function () {
  113. if (this.debug)
  114. console.log.apply('', arguments);
  115. },
  116. // TODO rename to "widget" when switching to widget factory
  117. _widgetDatepicker: function() {
  118. return this.dpDiv;
  119. },
  120. /* Override the default settings for all instances of the date picker.
  121. @param settings object - the new settings to use as defaults (anonymous object)
  122. @return the manager object */
  123. setDefaults: function(settings) {
  124. extendRemove(this._defaults, settings || {});
  125. return this;
  126. },
  127. /* Attach the date picker to a jQuery selection.
  128. @param target element - the target input field or division or span
  129. @param settings object - the new settings to use for this date picker instance (anonymous) */
  130. _attachDatepicker: function(target, settings) {
  131. // check for settings on the control itself - in namespace 'date:'
  132. var inlineSettings = null;
  133. for (var attrName in this._defaults) {
  134. var attrValue = target.getAttribute('date:' + attrName);
  135. if (attrValue) {
  136. inlineSettings = inlineSettings || {};
  137. try {
  138. inlineSettings[attrName] = eval(attrValue);
  139. } catch (err) {
  140. inlineSettings[attrName] = attrValue;
  141. }
  142. }
  143. }
  144. var nodeName = target.nodeName.toLowerCase();
  145. var inline = (nodeName == 'div' || nodeName == 'span');
  146. if (!target.id) {
  147. this.uuid += 1;
  148. target.id = 'dp' + this.uuid;
  149. }
  150. var inst = this._newInst($(target), inline);
  151. inst.settings = $.extend({}, settings || {}, inlineSettings || {});
  152. if (nodeName == 'input') {
  153. this._connectDatepicker(target, inst);
  154. } else if (inline) {
  155. this._inlineDatepicker(target, inst);
  156. }
  157. },
  158. /* Create a new instance object. */
  159. _newInst: function(target, inline) {
  160. var id = target[0].id.replace(/([^A-Za-z0-9_])/g, '\\\\$1'); // escape jQuery meta chars
  161. return {id: id, input: target, // associated target
  162. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  163. drawMonth: 0, drawYear: 0, // month being drawn
  164. inline: inline, // is datepicker inline or not
  165. dpDiv: (!inline ? this.dpDiv : // presentation div
  166. $('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))};
  167. },
  168. /* Attach the date picker to an input field. */
  169. _connectDatepicker: function(target, inst) {
  170. var input = $(target);
  171. inst.append = $([]);
  172. inst.trigger = $([]);
  173. if (input.hasClass(this.markerClassName))
  174. return;
  175. this._attachments(input, inst);
  176. input.addClass(this.markerClassName).keydown(this._doKeyDown).
  177. keypress(this._doKeyPress).keyup(this._doKeyUp).
  178. bind("setData.datepicker", function(event, key, value) {
  179. inst.settings[key] = value;
  180. }).bind("getData.datepicker", function(event, key) {
  181. return this._get(inst, key);
  182. });
  183. this._autoSize(inst);
  184. $.data(target, PROP_NAME, inst);
  185. },
  186. /* Make attachments based on settings. */
  187. _attachments: function(input, inst) {
  188. var appendText = this._get(inst, 'appendText');
  189. var isRTL = this._get(inst, 'isRTL');
  190. if (inst.append)
  191. inst.append.remove();
  192. if (appendText) {
  193. inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
  194. input[isRTL ? 'before' : 'after'](inst.append);
  195. }
  196. input.unbind('focus', this._showDatepicker);
  197. if (inst.trigger)
  198. inst.trigger.remove();
  199. var showOn = this._get(inst, 'showOn');
  200. if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
  201. input.focus(this._showDatepicker);
  202. if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
  203. var buttonText = this._get(inst, 'buttonText');
  204. var buttonImage = this._get(inst, 'buttonImage');
  205. inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
  206. $('<img/>').addClass(this._triggerClass).
  207. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  208. $('<button type="button"></button>').addClass(this._triggerClass).
  209. html(buttonImage == '' ? buttonText : $('<img/>').attr(
  210. { src:buttonImage, alt:buttonText, title:buttonText })));
  211. input[isRTL ? 'before' : 'after'](inst.trigger);
  212. inst.trigger.click(function() {
  213. if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
  214. $.datepicker._hideDatepicker();
  215. else
  216. $.datepicker._showDatepicker(input[0]);
  217. return false;
  218. });
  219. }
  220. },
  221. /* Apply the maximum length for the date format. */
  222. _autoSize: function(inst) {
  223. if (this._get(inst, 'autoSize') && !inst.inline) {
  224. var date = new Date(2009, 12 - 1, 20); // Ensure double digits
  225. var dateFormat = this._get(inst, 'dateFormat');
  226. if (dateFormat.match(/[DM]/)) {
  227. var findMax = function(names) {
  228. var max = 0;
  229. var maxI = 0;
  230. for (var i = 0; i < names.length; i++) {
  231. if (names[i].length > max) {
  232. max = names[i].length;
  233. maxI = i;
  234. }
  235. }
  236. return maxI;
  237. };
  238. date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
  239. 'monthNames' : 'monthNamesShort'))));
  240. date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
  241. 'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
  242. }
  243. inst.input.attr('size', this._formatDate(inst, date).length);
  244. }
  245. },
  246. /* Attach an inline date picker to a div. */
  247. _inlineDatepicker: function(target, inst) {
  248. var divSpan = $(target);
  249. if (divSpan.hasClass(this.markerClassName))
  250. return;
  251. divSpan.addClass(this.markerClassName).append(inst.dpDiv).
  252. bind("setData.datepicker", function(event, key, value){
  253. inst.settings[key] = value;
  254. }).bind("getData.datepicker", function(event, key){
  255. return this._get(inst, key);
  256. });
  257. $.data(target, PROP_NAME, inst);
  258. this._setDate(inst, this._getDefaultDate(inst), true);
  259. this._updateDatepicker(inst);
  260. this._updateAlternate(inst);
  261. },
  262. /* Pop-up the date picker in a "dialog" box.
  263. @param input element - ignored
  264. @param date string or Date - the initial date to display
  265. @param onSelect function - the function to call when a date is selected
  266. @param settings object - update the dialog date picker instance's settings (anonymous object)
  267. @param pos int[2] - coordinates for the dialog's position within the screen or
  268. event - with x/y coordinates or
  269. leave empty for default (screen centre)
  270. @return the manager object */
  271. _dialogDatepicker: function(input, date, onSelect, settings, pos) {
  272. var inst = this._dialogInst; // internal instance
  273. if (!inst) {
  274. this.uuid += 1;
  275. var id = 'dp' + this.uuid;
  276. this._dialogInput = $('<input type="text" id="' + id +
  277. '" style="position: absolute; top: -100px; width: 0px; z-index: -10;"/>');
  278. this._dialogInput.keydown(this._doKeyDown);
  279. $('body').append(this._dialogInput);
  280. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  281. inst.settings = {};
  282. $.data(this._dialogInput[0], PROP_NAME, inst);
  283. }
  284. extendRemove(inst.settings, settings || {});
  285. date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
  286. this._dialogInput.val(date);
  287. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  288. if (!this._pos) {
  289. var browserWidth = document.documentElement.clientWidth;
  290. var browserHeight = document.documentElement.clientHeight;
  291. var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  292. var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  293. this._pos = // should use actual width/height below
  294. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  295. }
  296. // move input on screen for focus, but hidden behind dialog
  297. this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
  298. inst.settings.onSelect = onSelect;
  299. this._inDialog = true;
  300. this.dpDiv.addClass(this._dialogClass);
  301. this._showDatepicker(this._dialogInput[0]);
  302. if ($.blockUI)
  303. $.blockUI(this.dpDiv);
  304. $.data(this._dialogInput[0], PROP_NAME, inst);
  305. return this;
  306. },
  307. /* Detach a datepicker from its control.
  308. @param target element - the target input field or division or span */
  309. _destroyDatepicker: function(target) {
  310. var $target = $(target);
  311. var inst = $.data(target, PROP_NAME);
  312. if (!$target.hasClass(this.markerClassName)) {
  313. return;
  314. }
  315. var nodeName = target.nodeName.toLowerCase();
  316. $.removeData(target, PROP_NAME);
  317. if (nodeName == 'input') {
  318. inst.append.remove();
  319. inst.trigger.remove();
  320. $target.removeClass(this.markerClassName).
  321. unbind('focus', this._showDatepicker).
  322. unbind('keydown', this._doKeyDown).
  323. unbind('keypress', this._doKeyPress).
  324. unbind('keyup', this._doKeyUp);
  325. } else if (nodeName == 'div' || nodeName == 'span')
  326. $target.removeClass(this.markerClassName).empty();
  327. },
  328. /* Enable the date picker to a jQuery selection.
  329. @param target element - the target input field or division or span */
  330. _enableDatepicker: function(target) {
  331. var $target = $(target);
  332. var inst = $.data(target, PROP_NAME);
  333. if (!$target.hasClass(this.markerClassName)) {
  334. return;
  335. }
  336. var nodeName = target.nodeName.toLowerCase();
  337. if (nodeName == 'input') {
  338. target.disabled = false;
  339. inst.trigger.filter('button').
  340. each(function() { this.disabled = false; }).end().
  341. filter('img').css({opacity: '1.0', cursor: ''});
  342. }
  343. else if (nodeName == 'div' || nodeName == 'span') {
  344. var inline = $target.children('.' + this._inlineClass);
  345. inline.children().removeClass('ui-state-disabled');
  346. }
  347. this._disabledInputs = $.map(this._disabledInputs,
  348. function(value) { return (value == target ? null : value); }); // delete entry
  349. },
  350. /* Disable the date picker to a jQuery selection.
  351. @param target element - the target input field or division or span */
  352. _disableDatepicker: function(target) {
  353. var $target = $(target);
  354. var inst = $.data(target, PROP_NAME);
  355. if (!$target.hasClass(this.markerClassName)) {
  356. return;
  357. }
  358. var nodeName = target.nodeName.toLowerCase();
  359. if (nodeName == 'input') {
  360. target.disabled = true;
  361. inst.trigger.filter('button').
  362. each(function() { this.disabled = true; }).end().
  363. filter('img').css({opacity: '0.5', cursor: 'default'});
  364. }
  365. else if (nodeName == 'div' || nodeName == 'span') {
  366. var inline = $target.children('.' + this._inlineClass);
  367. inline.children().addClass('ui-state-disabled');
  368. }
  369. this._disabledInputs = $.map(this._disabledInputs,
  370. function(value) { return (value == target ? null : value); }); // delete entry
  371. this._disabledInputs[this._disabledInputs.length] = target;
  372. },
  373. /* Is the first field in a jQuery collection disabled as a datepicker?
  374. @param target element - the target input field or division or span
  375. @return boolean - true if disabled, false if enabled */
  376. _isDisabledDatepicker: function(target) {
  377. if (!target) {
  378. return false;
  379. }
  380. for (var i = 0; i < this._disabledInputs.length; i++) {
  381. if (this._disabledInputs[i] == target)
  382. return true;
  383. }
  384. return false;
  385. },
  386. /* Retrieve the instance data for the target control.
  387. @param target element - the target input field or division or span
  388. @return object - the associated instance data
  389. @throws error if a jQuery problem getting data */
  390. _getInst: function(target) {
  391. try {
  392. return $.data(target, PROP_NAME);
  393. }
  394. catch (err) {
  395. throw 'Missing instance data for this datepicker';
  396. }
  397. },
  398. /* Update or retrieve the settings for a date picker attached to an input field or division.
  399. @param target element - the target input field or division or span
  400. @param name object - the new settings to update or
  401. string - the name of the setting to change or retrieve,
  402. when retrieving also 'all' for all instance settings or
  403. 'defaults' for all global defaults
  404. @param value any - the new value for the setting
  405. (omit if above is an object or to retrieve a value) */
  406. _optionDatepicker: function(target, name, value) {
  407. var inst = this._getInst(target);
  408. if (arguments.length == 2 && typeof name == 'string') {
  409. return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
  410. (inst ? (name == 'all' ? $.extend({}, inst.settings) :
  411. this._get(inst, name)) : null));
  412. }
  413. var settings = name || {};
  414. if (typeof name == 'string') {
  415. settings = {};
  416. settings[name] = value;
  417. }
  418. if (inst) {
  419. if (this._curInst == inst) {
  420. this._hideDatepicker();
  421. }
  422. var date = this._getDateDatepicker(target, true);
  423. extendRemove(inst.settings, settings);
  424. this._attachments($(target), inst);
  425. this._autoSize(inst);
  426. this._setDateDatepicker(target, date);
  427. this._updateDatepicker(inst);
  428. }
  429. },
  430. // change method deprecated
  431. _changeDatepicker: function(target, name, value) {
  432. this._optionDatepicker(target, name, value);
  433. },
  434. /* Redraw the date picker attached to an input field or division.
  435. @param target element - the target input field or division or span */
  436. _refreshDatepicker: function(target) {
  437. var inst = this._getInst(target);
  438. if (inst) {
  439. this._updateDatepicker(inst);
  440. }
  441. },
  442. /* Set the dates for a jQuery selection.
  443. @param target element - the target input field or division or span
  444. @param date Date - the new date */
  445. _setDateDatepicker: function(target, date) {
  446. var inst = this._getInst(target);
  447. if (inst) {
  448. this._setDate(inst, date);
  449. this._updateDatepicker(inst);
  450. this._updateAlternate(inst);
  451. }
  452. },
  453. /* Get the date(s) for the first entry in a jQuery selection.
  454. @param target element - the target input field or division or span
  455. @param noDefault boolean - true if no default date is to be used
  456. @return Date - the current date */
  457. _getDateDatepicker: function(target, noDefault) {
  458. var inst = this._getInst(target);
  459. if (inst && !inst.inline)
  460. this._setDateFromField(inst, noDefault);
  461. return (inst ? this._getDate(inst) : null);
  462. },
  463. /* Handle keystrokes. */
  464. _doKeyDown: function(event) {
  465. var inst = $.datepicker._getInst(event.target);
  466. var handled = true;
  467. var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
  468. inst._keyEvent = true;
  469. if ($.datepicker._datepickerShowing)
  470. switch (event.keyCode) {
  471. case 9: $.datepicker._hideDatepicker();
  472. handled = false;
  473. break; // hide on tab out
  474. case 13:$.datepicker._hideDatepicker();
  475. return false; // don't submit the form
  476. break; // select the value on enter
  477. case 27: $.datepicker._hideDatepicker();
  478. break; // hide on escape
  479. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  480. -$.datepicker._get(inst, 'stepBigMonths') :
  481. -$.datepicker._get(inst, 'stepMonths')), 'M');
  482. break; // previous month/year on page up/+ ctrl
  483. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  484. +$.datepicker._get(inst, 'stepBigMonths') :
  485. +$.datepicker._get(inst, 'stepMonths')), 'M');
  486. break; // next month/year on page down/+ ctrl
  487. case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
  488. handled = event.ctrlKey || event.metaKey;
  489. break; // clear on ctrl or command +end
  490. case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
  491. handled = event.ctrlKey || event.metaKey;
  492. break; // current on ctrl or command +home
  493. case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
  494. handled = event.ctrlKey || event.metaKey;
  495. // -1 day on ctrl or command +left
  496. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  497. -$.datepicker._get(inst, 'stepBigMonths') :
  498. -$.datepicker._get(inst, 'stepMonths')), 'M');
  499. // next month/year on alt +left on Mac
  500. break;
  501. case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
  502. handled = event.ctrlKey || event.metaKey;
  503. break; // -1 week on ctrl or command +up
  504. case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
  505. handled = event.ctrlKey || event.metaKey;
  506. // +1 day on ctrl or command +right
  507. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  508. +$.datepicker._get(inst, 'stepBigMonths') :
  509. +$.datepicker._get(inst, 'stepMonths')), 'M');
  510. // next month/year on alt +right
  511. break;
  512. case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
  513. handled = event.ctrlKey || event.metaKey;
  514. break; // +1 week on ctrl or command +down
  515. default: handled = false;
  516. }
  517. else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
  518. $.datepicker._showDatepicker(this);
  519. else {
  520. handled = false;
  521. }
  522. if (handled) {
  523. event.preventDefault();
  524. event.stopPropagation();
  525. }
  526. },
  527. /* Filter entered characters - based on date format. */
  528. _doKeyPress: function(event) {
  529. var inst = $.datepicker._getInst(event.target);
  530. if ($.datepicker._get(inst, 'constrainInput')) {
  531. var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
  532. var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
  533. return event.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
  534. }
  535. },
  536. /* Synchronise manual entry and field/alternate field. */
  537. _doKeyUp: function(event) {
  538. var inst = $.datepicker._getInst(event.target);
  539. if (inst.input.val() != inst.lastVal) {
  540. try {
  541. var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  542. (inst.input ? inst.input.val() : null),
  543. $.datepicker._getFormatConfig(inst));
  544. if (date) { // only if valid
  545. $.datepicker._setDateFromField(inst);
  546. $.datepicker._updateAlternate(inst);
  547. $.datepicker._updateDatepicker(inst);
  548. }
  549. }
  550. catch (event) {
  551. $.datepicker.log(event);
  552. }
  553. }
  554. return true;
  555. },
  556. /* Pop-up the date picker for a given input field.
  557. @param input element - the input field attached to the date picker or
  558. event - if triggered by focus */
  559. _showDatepicker: function(input) {
  560. input = input.target || input;
  561. //zzy
  562. if(input.readOnly){return true;}
  563. if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
  564. input = $('input', input.parentNode)[0];
  565. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
  566. return;
  567. var inst = $.datepicker._getInst(input);
  568. if ($.datepicker._curInst && $.datepicker._curInst != inst) {
  569. $.datepicker._curInst.dpDiv.stop(true, true);
  570. }
  571. var beforeShow = $.datepicker._get(inst, 'beforeShow');
  572. extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
  573. inst.lastVal = null;
  574. $.datepicker._lastInput = input;
  575. $.datepicker._setDateFromField(inst);
  576. if ($.datepicker._inDialog) // hide cursor
  577. input.value = '';
  578. if (!$.datepicker._pos) { // position below input
  579. $.datepicker._pos = $.datepicker._findPos(input);
  580. $.datepicker._pos[1] += input.offsetHeight; // add the height
  581. }
  582. var isFixed = false;
  583. $(input).parents().each(function() {
  584. isFixed |= $(this).css('position') == 'fixed';
  585. return !isFixed;
  586. });
  587. if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
  588. $.datepicker._pos[0] -= document.documentElement.scrollLeft;
  589. $.datepicker._pos[1] -= document.documentElement.scrollTop;
  590. }
  591. var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  592. $.datepicker._pos = null;
  593. // determine sizing offscreen
  594. inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
  595. $.datepicker._updateDatepicker(inst);
  596. // fix width for dynamic number of date pickers
  597. // and adjust position before showing
  598. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  599. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  600. 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
  601. left: (offset.left-25) + 'px', top: offset.top + 'px'});
  602. if (!inst.inline) {
  603. var showAnim = $.datepicker._get(inst, 'showAnim');
  604. var duration = $.datepicker._get(inst, 'duration');
  605. var postProcess = function() {
  606. $.datepicker._datepickerShowing = true;
  607. var borders = $.datepicker._getBorders(inst.dpDiv);
  608. inst.dpDiv.find('iframe.ui-datepicker-cover'). // IE6- only
  609. css({left: -borders[0], top: -borders[1],
  610. width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
  611. };
  612. inst.dpDiv.zIndex($(input).zIndex()+1001);
  613. if ($.effects && $.effects[showAnim])
  614. inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  615. else
  616. inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
  617. if (!showAnim || !duration)
  618. postProcess();
  619. if (inst.input.is(':visible') && !inst.input.is(':disabled')) {
  620. //inst.input.focus(); 注册 FOCUS时候重复执行, 因此屏蔽 修改人 situxin
  621. }
  622. $.datepicker._curInst = inst;
  623. }
  624. },
  625. /* Generate the date picker content. */
  626. _updateDatepicker: function(inst) {
  627. var self = this;
  628. var borders = $.datepicker._getBorders(inst.dpDiv);
  629. inst.dpDiv.empty().append(this._generateHTML(inst))
  630. .find('iframe.ui-datepicker-cover') // IE6- only
  631. .css({left: -borders[0], top: -borders[1],
  632. width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
  633. .end()
  634. .find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a')
  635. .bind('mouseout', function(){
  636. $(this).removeClass('ui-state-hover');
  637. if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
  638. if(this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
  639. })
  640. .bind('mouseover', function(){
  641. if (!self._isDisabledDatepicker( inst.inline ? inst.dpDiv.parent()[0] : inst.input[0])) {
  642. $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
  643. $(this).addClass('ui-state-hover');
  644. if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
  645. if(this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
  646. }
  647. })
  648. .end()
  649. .find('.' + this._dayOverClass + ' a')
  650. .trigger('mouseover')
  651. .end();
  652. var numMonths = this._getNumberOfMonths(inst);
  653. var cols = numMonths[1];
  654. var width = 17;
  655. if (cols > 1)
  656. inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
  657. else
  658. inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
  659. inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
  660. 'Class']('ui-datepicker-multi');
  661. inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
  662. 'Class']('ui-datepicker-rtl');
  663. //if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
  664. // inst.input.is(':visible') && !inst.input.is(':disabled'))
  665. //inst.input.focus();
  666. },
  667. /* Retrieve the size of left and top borders for an element.
  668. @param elem (jQuery object) the element of interest
  669. @return (number[2]) the left and top borders */
  670. _getBorders: function(elem) {
  671. var convert = function(value) {
  672. return {thin: 1, medium: 2, thick: 3}[value] || value;
  673. };
  674. return [parseFloat(convert(elem.css('border-left-width'))),
  675. parseFloat(convert(elem.css('border-top-width')))];
  676. },
  677. /* Check positioning to remain on screen. */
  678. _checkOffset: function(inst, offset, isFixed) {
  679. var dpWidth = inst.dpDiv.outerWidth();
  680. var dpHeight = inst.dpDiv.outerHeight();
  681. var inputWidth = inst.input ? inst.input.outerWidth() : 0;
  682. var inputHeight = inst.input ? inst.input.outerHeight() : 0;
  683. var viewWidth = document.documentElement.clientWidth + $(document).scrollLeft();
  684. var viewHeight = document.documentElement.clientHeight + $(document).scrollTop();
  685. offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
  686. offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
  687. offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  688. // now check if datepicker is showing outside window viewport - move to a better place if so.
  689. offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
  690. Math.abs(offset.left + dpWidth - viewWidth) : 0);
  691. offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
  692. Math.abs(dpHeight + inputHeight) : 0);
  693. return offset;
  694. },
  695. /* Find an object's position on the screen. */
  696. _findPos: function(obj) {
  697. var inst = this._getInst(obj);
  698. var isRTL = this._get(inst, 'isRTL');
  699. while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
  700. obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
  701. }
  702. var position = $(obj).offset();
  703. return [position.left, position.top];
  704. },
  705. //zzy
  706. _CleanDate:function(){
  707. var inst=this._curInst;
  708. inst.input.val('');
  709. this._updateAlternate(inst);
  710. this._hideDatepicker(null);
  711. //herong add 20110602
  712. if (inst.input) {
  713. inst.input.trigger("change");
  714. }
  715. },
  716. /* Hide the date picker from view.
  717. @param input element - the input field attached to the date picker */
  718. _hideDatepicker: function(input) {
  719. var inst = this._curInst;
  720. if (!inst || (input && inst != $.data(input, PROP_NAME)))
  721. return;
  722. //herong add 20110602
  723. if (input && input.onchange) {
  724. input.change();
  725. }
  726. if (this._datepickerShowing) {
  727. var showAnim = this._get(inst, 'showAnim');
  728. var duration = this._get(inst, 'duration');
  729. var postProcess = function() {
  730. $.datepicker._tidyDialog(inst);
  731. this._curInst = null;
  732. };
  733. if ($.effects && $.effects[showAnim])
  734. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  735. else
  736. inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
  737. (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
  738. if (!showAnim)
  739. postProcess();
  740. var onClose = this._get(inst, 'onClose');
  741. if (onClose)
  742. onClose.apply((inst.input ? inst.input[0] : null),
  743. [(inst.input ? inst.input.val() : ''), inst]); // trigger custom callback
  744. this._datepickerShowing = false;
  745. this._lastInput = null;
  746. if (this._inDialog) {
  747. this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
  748. if ($.blockUI) {
  749. $.unblockUI();
  750. $('body').append(this.dpDiv);
  751. }
  752. }
  753. this._inDialog = false;
  754. }
  755. },
  756. /* Tidy up after a dialog display. */
  757. _tidyDialog: function(inst) {
  758. inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
  759. },
  760. /* Close date picker if clicked elsewhere. */
  761. _checkExternalClick: function(event) {
  762. if (!$.datepicker._curInst)
  763. return;
  764. var $target = $(event.target);
  765. if ($target[0].id != $.datepicker._mainDivId &&
  766. $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
  767. !$target.hasClass($.datepicker.markerClassName) &&
  768. !$target.hasClass($.datepicker._triggerClass) &&
  769. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI))
  770. $.datepicker._hideDatepicker();
  771. },
  772. /* Adjust one of the date sub-fields. */
  773. _adjustDate: function(id, offset, period) {
  774. var target = $(id);
  775. var inst = this._getInst(target[0]);
  776. if (this._isDisabledDatepicker(target[0])) {
  777. return;
  778. }
  779. this._adjustInstDate(inst, offset +
  780. (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
  781. period);
  782. this._updateDatepicker(inst);
  783. },
  784. /* Action for current link. */
  785. _gotoToday: function(id) {
  786. var target = $(id);
  787. var inst = this._getInst(target[0]);
  788. if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
  789. inst.selectedDay = inst.currentDay;
  790. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  791. inst.drawYear = inst.selectedYear = inst.currentYear;
  792. }
  793. else {
  794. var date = new Date();
  795. inst.selectedDay = date.getDate();
  796. inst.drawMonth = inst.selectedMonth = date.getMonth();
  797. inst.drawYear = inst.selectedYear = date.getFullYear();
  798. }
  799. this._selectDate(id, this._formatDate(inst,
  800. inst.selectedDay, inst.drawMonth, inst.drawYear));
  801. this._notifyChange(inst);
  802. this._adjustDate(target);
  803. },
  804. /* Action for selecting a new month/year. */
  805. _selectMonthYear: function(id, select, period) {
  806. var target = $(id);
  807. var inst = this._getInst(target[0]);
  808. inst._selectingMonthYear = false;
  809. inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
  810. inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
  811. parseInt(select.options[select.selectedIndex].value,10);
  812. this._notifyChange(inst);
  813. this._adjustDate(target);
  814. },
  815. /* Restore input focus after not changing month/year. */
  816. _clickMonthYear: function(id) {
  817. var target = $(id);
  818. var inst = this._getInst(target[0]);
  819. if (inst.input && inst._selectingMonthYear) {
  820. setTimeout(function() {
  821. inst.input.focus();
  822. }, 0);
  823. }
  824. inst._selectingMonthYear = !inst._selectingMonthYear;
  825. },
  826. /* Action for selecting a day. */
  827. _selectDay: function(id, month, year, td) {
  828. var target = $(id);
  829. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  830. return;
  831. }
  832. var inst = this._getInst(target[0]);
  833. inst.selectedDay = inst.currentDay = $('a', td).html();
  834. inst.selectedMonth = inst.currentMonth = month;
  835. inst.selectedYear = inst.currentYear = year;
  836. this._selectDate(id, this._formatDate(inst,
  837. inst.currentDay, inst.currentMonth, inst.currentYear));
  838. },
  839. /* Erase the input field and hide the date picker. */
  840. _clearDate: function(id) {
  841. var target = $(id);
  842. var inst = this._getInst(target[0]);
  843. this._selectDate(target, '');
  844. },
  845. /* Update the input field with the selected date. */
  846. _selectDate: function(id, dateStr) {
  847. var target = $(id);
  848. var inst = this._getInst(target[0]);
  849. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  850. if (inst.input){
  851. inst.input.val(dateStr);
  852. }
  853. this._updateAlternate(inst);
  854. var onSelect = this._get(inst, 'onSelect');
  855. if (onSelect)
  856. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  857. else if (inst.input)
  858. inst.input.trigger('change'); // fire the change event
  859. if (inst.inline)
  860. this._updateDatepicker(inst);
  861. else {
  862. this._hideDatepicker();
  863. this._lastInput = inst.input[0];
  864. if (typeof(inst.input[0]) != 'object')
  865. inst.input.focus(); // restore focus
  866. this._lastInput = null;
  867. }
  868. },
  869. /* Update any alternate field to synchronise with the main field. */
  870. _updateAlternate: function(inst) {
  871. var altField = this._get(inst, 'altField');
  872. if (altField) { // update alternate field too
  873. var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
  874. var date = this._getDate(inst);
  875. var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  876. $(altField).each(function() { $(this).val(dateStr); });
  877. }
  878. },
  879. /* Set as beforeShowDay function to prevent selection of weekends.
  880. @param date Date - the date to customise
  881. @return [boolean, string] - is this date selectable?, what is its CSS class? */
  882. noWeekends: function(date) {
  883. var day = date.getDay();
  884. return [(day > 0 && day < 6), ''];
  885. },
  886. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  887. @param date Date - the date to get the week for
  888. @return number - the number of the week within the year that contains this date */
  889. iso8601Week: function(date) {
  890. var checkDate = new Date(date.getTime());
  891. // Find Thursday of this week starting on Monday
  892. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  893. var time = checkDate.getTime();
  894. checkDate.setMonth(0); // Compare with Jan 1
  895. checkDate.setDate(1);
  896. return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  897. },
  898. /* Parse a string value into a date object.
  899. See formatDate below for the possible formats.
  900. @param format string - the expected format of the date
  901. @param value string - the date in the above format
  902. @param settings Object - attributes include:
  903. shortYearCutoff number - the cutoff year for determining the century (optional)
  904. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  905. dayNames string[7] - names of the days from Sunday (optional)
  906. monthNamesShort string[12] - abbreviated names of the months (optional)
  907. monthNames string[12] - names of the months (optional)
  908. @return Date - the extracted date value or null if value is blank */
  909. parseDate: function (format, value, settings) {
  910. if (format == null || value == null)
  911. throw 'Invalid arguments';
  912. value = (typeof value == 'object' ? value.toString() : value + '');
  913. if (value == '')
  914. return null;
  915. var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
  916. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  917. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  918. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  919. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  920. var year = -1;
  921. var month = -1;
  922. var day = -1;
  923. var doy = -1;
  924. var literal = false;
  925. // Check whether a format character is doubled
  926. var lookAhead = function(match) {
  927. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  928. if (matches)
  929. iFormat++;
  930. return matches;
  931. };
  932. // Extract a number from the string value
  933. var getNumber = function(match) {
  934. lookAhead(match);
  935. var size = (match == '@' ? 14 : (match == '!' ? 20 :
  936. (match == 'y' ? 4 : (match == 'o' ? 3 : 2))));
  937. var digits = new RegExp('^\\d{1,' + size + '}');
  938. var num = value.substring(iValue).match(digits);
  939. if (!num)
  940. throw 'Missing number at position ' + iValue;
  941. iValue += num[0].length;
  942. return parseInt(num[0], 10);
  943. };
  944. // Extract a name from the string value and convert to an index
  945. var getName = function(match, shortNames, longNames) {
  946. var names = (lookAhead(match) ? longNames : shortNames);
  947. for (var i = 0; i < names.length; i++) {
  948. if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
  949. iValue += names[i].length;
  950. return i + 1;
  951. }
  952. }
  953. throw 'Unknown name at position ' + iValue;
  954. };
  955. // Confirm that a literal character matches the string value
  956. var checkLiteral = function() {
  957. if (value.charAt(iValue) != format.charAt(iFormat))
  958. throw 'Unexpected literal at position ' + iValue;
  959. iValue++;
  960. };
  961. if(format == 'yy-mm' && value.length == 2 || value.length == 4){
  962. try{
  963. var intValue = parseInt(value);
  964. if(value.length == 2){
  965. value = '20' + value + '-01';
  966. }else if(value.length == 4){
  967. value = value + '-01';
  968. }
  969. }catch(e){}
  970. }
  971. var iValue = 0;
  972. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  973. if (literal)
  974. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  975. literal = false;
  976. else
  977. checkLiteral();
  978. else
  979. switch (format.charAt(iFormat)) {
  980. case 'd':
  981. day = getNumber('d');
  982. break;
  983. case 'D':
  984. getName('D', dayNamesShort, dayNames);
  985. break;
  986. case 'o':
  987. doy = getNumber('o');
  988. break;
  989. case 'm':
  990. month = getNumber('m');
  991. break;
  992. case 'M':
  993. month = getName('M', monthNamesShort, monthNames);
  994. break;
  995. case 'y':
  996. year = getNumber('y');
  997. break;
  998. case '@':
  999. var date = new Date(getNumber('@'));
  1000. year = date.getFullYear();
  1001. month = date.getMonth() + 1;
  1002. day = date.getDate();
  1003. break;
  1004. case '!':
  1005. var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
  1006. year = date.getFullYear();
  1007. month = date.getMonth() + 1;
  1008. day = date.getDate();
  1009. break;
  1010. case "'":
  1011. if (lookAhead("'"))
  1012. checkLiteral();
  1013. else
  1014. literal = true;
  1015. break;
  1016. default:
  1017. checkLiteral();
  1018. }
  1019. }
  1020. if (year == -1)
  1021. year = new Date().getFullYear();
  1022. else if (year < 100)
  1023. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  1024. (year <= shortYearCutoff ? 0 : -100);
  1025. if (doy > -1) {
  1026. month = 1;
  1027. day = doy;
  1028. do {
  1029. var dim = this._getDaysInMonth(year, month - 1);
  1030. if (day <= dim)
  1031. break;
  1032. month++;
  1033. day -= dim;
  1034. } while (true);
  1035. }
  1036. if(format == 'yy-mm'){
  1037. day = 1;
  1038. }
  1039. var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  1040. if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
  1041. throw 'Invalid date'; // E.g. 31/02/*
  1042. return date;
  1043. },
  1044. /* Standard date formats. */
  1045. ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
  1046. COOKIE: 'D, dd M yy',
  1047. ISO_8601: 'yy-mm-dd',
  1048. RFC_822: 'D, d M y',
  1049. RFC_850: 'DD, dd-M-y',
  1050. RFC_1036: 'D, d M y',
  1051. RFC_1123: 'D, d M yy',
  1052. RFC_2822: 'D, d M yy',
  1053. RSS: 'D, d M y', // RFC 822
  1054. TICKS: '!',
  1055. TIMESTAMP: '@',
  1056. W3C: 'yy-mm-dd', // ISO 8601
  1057. _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
  1058. Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
  1059. /* Format a date object into a string value.
  1060. The format can be combinations of the following:
  1061. d - day of month (no leading zero)
  1062. dd - day of month (two digit)
  1063. o - day of year (no leading zeros)
  1064. oo - day of year (three digit)
  1065. D - day name short
  1066. DD - day name long
  1067. m - month of year (no leading zero)
  1068. mm - month of year (two digit)
  1069. M - month name short
  1070. MM - month name long
  1071. y - year (two digit)
  1072. yy - year (four digit)
  1073. @ - Unix timestamp (ms since 01/01/1970)
  1074. ! - Windows ticks (100ns since 01/01/0001)
  1075. '...' - literal text
  1076. '' - single quote
  1077. @param format string - the desired format of the date
  1078. @param date Date - the date value to format
  1079. @param settings Object - attributes include:
  1080. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  1081. dayNames string[7] - names of the days from Sunday (optional)
  1082. monthNamesShort string[12] - abbreviated names of the months (optional)
  1083. monthNames string[12] - names of the months (optional)
  1084. @return string - the date in the above format */
  1085. formatDate: function (format, date, settings) {
  1086. if (!date)
  1087. return '';
  1088. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  1089. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  1090. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  1091. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  1092. // Check whether a format character is doubled
  1093. var lookAhead = function(match) {
  1094. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  1095. if (matches)
  1096. iFormat++;
  1097. return matches;
  1098. };
  1099. // Format a number, with leading zero if necessary
  1100. var formatNumber = function(match, value, len) {
  1101. var num = '' + value;
  1102. if (lookAhead(match))
  1103. while (num.length < len)
  1104. num = '0' + num;
  1105. return num;
  1106. };
  1107. // Format a name, short or long as requested
  1108. var formatName = function(match, value, shortNames, longNames) {
  1109. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  1110. };
  1111. var output = '';
  1112. var literal = false;
  1113. if (date)
  1114. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  1115. if (literal)
  1116. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  1117. literal = false;
  1118. else
  1119. output += format.charAt(iFormat);
  1120. else
  1121. switch (format.charAt(iFormat)) {
  1122. case 'd':
  1123. output += formatNumber('d', date.getDate(), 2);
  1124. break;
  1125. case 'D':
  1126. output += formatName('D', date.getDay(), dayNamesShort, dayNames);
  1127. break;
  1128. case 'o':
  1129. output += formatNumber('o',
  1130. (date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000, 3);
  1131. break;
  1132. case 'm':
  1133. output += formatNumber('m', date.getMonth() + 1, 2);
  1134. break;
  1135. case 'M':
  1136. output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
  1137. break;
  1138. case 'y':
  1139. output += (lookAhead('y') ? date.getFullYear() :
  1140. (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
  1141. break;
  1142. case '@':
  1143. output += date.getTime();
  1144. break;
  1145. case '!':
  1146. output += date.getTime() * 10000 + this._ticksTo1970;
  1147. break;
  1148. case "'":
  1149. if (lookAhead("'"))
  1150. output += "'";
  1151. else
  1152. literal = true;
  1153. break;
  1154. default:
  1155. output += format.charAt(iFormat);
  1156. }
  1157. }
  1158. return output;
  1159. },
  1160. /* Extract all possible characters from the date format. */
  1161. _possibleChars: function (format) {
  1162. var chars = '';
  1163. var literal = false;
  1164. // Check whether a format character is doubled
  1165. var lookAhead = function(match) {
  1166. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  1167. if (matches)
  1168. iFormat++;
  1169. return matches;
  1170. };
  1171. for (var iFormat = 0; iFormat < format.length; iFormat++)
  1172. if (literal)
  1173. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  1174. literal = false;
  1175. else
  1176. chars += format.charAt(iFormat);
  1177. else
  1178. switch (format.charAt(iFormat)) {
  1179. case 'd': case 'm': case 'y': case '@':
  1180. chars += '0123456789';
  1181. break;
  1182. case 'D': case 'M':
  1183. return null; // Accept anything
  1184. case "'":
  1185. if (lookAhead("'"))
  1186. chars += "'";
  1187. else
  1188. literal = true;
  1189. break;
  1190. default:
  1191. chars += format.charAt(iFormat);
  1192. }
  1193. return chars;
  1194. },
  1195. /* Get a setting value, defaulting if necessary. */
  1196. _get: function(inst, name) {
  1197. return inst.settings[name] !== undefined ?
  1198. inst.settings[name] : this._defaults[name];
  1199. },
  1200. /* Parse existing date and initialise date picker. */
  1201. _setDateFromField: function(inst, noDefault) {
  1202. if (inst.input.val() == inst.lastVal) {
  1203. return;
  1204. }
  1205. var dateFormat = this._get(inst, 'dateFormat');
  1206. var dates = inst.lastVal = inst.input ? inst.input.val() : null;
  1207. var date, defaultDate;
  1208. date = defaultDate = this._getDefaultDate(inst);
  1209. var settings = this._getFormatConfig(inst);
  1210. try {
  1211. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  1212. } catch (event) {
  1213. this.log(event);
  1214. dates = (noDefault ? '' : dates);
  1215. }
  1216. inst.selectedDay = date.getDate();
  1217. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1218. inst.drawYear = inst.selectedYear = date.getFullYear();
  1219. inst.currentDay = (dates ? date.getDate() : 0);
  1220. inst.currentMonth = (dates ? date.getMonth() : 0);
  1221. inst.currentYear = (dates ? date.getFullYear() : 0);
  1222. this._adjustInstDate(inst);
  1223. },
  1224. /* Retrieve the default date shown on opening. */
  1225. _getDefaultDate: function(inst) {
  1226. return this._restrictMinMax(inst,
  1227. this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
  1228. },
  1229. /* A date may be specified as an exact value or a relative one. */
  1230. _determineDate: function(inst, date, defaultDate) {
  1231. var offsetNumeric = function(offset) {
  1232. var date = new Date();
  1233. date.setDate(date.getDate() + offset);
  1234. return date;
  1235. };
  1236. var offsetString = function(offset) {
  1237. try {
  1238. return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  1239. offset, $.datepicker._getFormatConfig(inst));
  1240. }
  1241. catch (e) {
  1242. // Ignore
  1243. }
  1244. var date = (offset.toLowerCase().match(/^c/) ?
  1245. $.datepicker._getDate(inst) : null) || new Date();
  1246. var year = date.getFullYear();
  1247. var month = date.getMonth();
  1248. var day = date.getDate();
  1249. var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
  1250. var matches = pattern.exec(offset);
  1251. while (matches) {
  1252. switch (matches[2] || 'd') {
  1253. case 'd' : case 'D' :
  1254. day += parseInt(matches[1],10); break;
  1255. case 'w' : case 'W' :
  1256. day += parseInt(matches[1],10) * 7; break;
  1257. case 'm' : case 'M' :
  1258. month += parseInt(matches[1],10);
  1259. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  1260. break;
  1261. case 'y': case 'Y' :
  1262. year += parseInt(matches[1],10);
  1263. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  1264. break;
  1265. }
  1266. matches = pattern.exec(offset);
  1267. }
  1268. return new Date(year, month, day);
  1269. };
  1270. date = (date == null ? defaultDate : (typeof date == 'string' ? offsetString(date) :
  1271. (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : date)));
  1272. date = (date && date.toString() == 'Invalid Date' ? defaultDate : date);
  1273. if (date) {
  1274. date.setHours(0);
  1275. date.setMinutes(0);
  1276. date.setSeconds(0);
  1277. date.setMilliseconds(0);
  1278. }
  1279. return this._daylightSavingAdjust(date);
  1280. },
  1281. /* Handle switch to/from daylight saving.
  1282. Hours may be non-zero on daylight saving cut-over:
  1283. > 12 when midnight changeover, but then cannot generate
  1284. midnight datetime, so jump to 1AM, otherwise reset.
  1285. @param date (Date) the date to check
  1286. @return (Date) the corrected date */
  1287. _daylightSavingAdjust: function(date) {
  1288. if (!date) return null;
  1289. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  1290. return date;
  1291. },
  1292. /* Set the date(s) directly. */
  1293. _setDate: function(inst, date, noChange) {
  1294. var clear = !(date);
  1295. var origMonth = inst.selectedMonth;
  1296. var origYear = inst.selectedYear;
  1297. date = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
  1298. inst.selectedDay = inst.currentDay = date.getDate();
  1299. inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth();
  1300. inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear();
  1301. if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
  1302. this._notifyChange(inst);
  1303. this._adjustInstDate(inst);
  1304. if (inst.input) {
  1305. inst.input.val(clear ? '' : this._formatDate(inst));
  1306. }
  1307. },
  1308. /* Retrieve the date(s) directly. */
  1309. _getDate: function(inst) {
  1310. var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
  1311. this._daylightSavingAdjust(new Date(
  1312. inst.currentYear, inst.currentMonth, inst.currentDay)));
  1313. return startDate;
  1314. },
  1315. /* Generate the HTML for the current state of the date picker. */
  1316. _generateHTML: function(inst) {
  1317. var today = new Date();
  1318. today = this._daylightSavingAdjust(
  1319. new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
  1320. var isRTL = this._get(inst, 'isRTL');
  1321. var showButtonPanel = this._get(inst, 'showButtonPanel');
  1322. var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
  1323. var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
  1324. var numMonths = this._getNumberOfMonths(inst);
  1325. var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
  1326. var stepMonths = this._get(inst, 'stepMonths');
  1327. var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
  1328. var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  1329. new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  1330. var minDate = this._getMinMaxDate(inst, 'min');
  1331. var maxDate = this._getMinMaxDate(inst, 'max');
  1332. var drawMonth = inst.drawMonth - showCurrentAtPos;
  1333. var dateFormat = this._get(inst, 'dateFormat');
  1334. var drawYear = inst.drawYear;
  1335. if (drawMonth < 0) {
  1336. drawMonth += 12;
  1337. drawYear--;
  1338. }
  1339. if (maxDate) {
  1340. var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  1341. maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
  1342. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  1343. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  1344. drawMonth--;
  1345. if (drawMonth < 0) {
  1346. drawMonth = 11;
  1347. drawYear--;
  1348. }
  1349. }
  1350. }
  1351. inst.drawMonth = drawMonth;
  1352. inst.drawYear = drawYear;
  1353. var prevText = this._get(inst, 'prevText');
  1354. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  1355. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  1356. this._getFormatConfig(inst)));
  1357. var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  1358. '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
  1359. '.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
  1360. ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
  1361. (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
  1362. var nextText = this._get(inst, 'nextText');
  1363. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  1364. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  1365. this._getFormatConfig(inst)));
  1366. var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  1367. '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
  1368. '.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
  1369. ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
  1370. (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
  1371. var currentText = this._get(inst, 'currentText');
  1372. var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
  1373. currentText = (!navigationAsDateFormat ? currentText :
  1374. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  1375. currentText = dateFormat == 'yy-mm-dd' ? currentText : '本月';
  1376. var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
  1377. '.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
  1378. var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
  1379. (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
  1380. '.datepicker._gotoToday(\'#' + inst.id + '\');"' +
  1381. '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) +'<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +'.datepicker._CleanDate();">清空</button></div>':'';
  1382. var firstDay = parseInt(this._get(inst, 'firstDay'),10);
  1383. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  1384. var showWeek = this._get(inst, 'showWeek');
  1385. var dayNames = this._get(inst, 'dayNames');
  1386. var dayNamesShort = this._get(inst, 'dayNamesShort');
  1387. var dayNamesMin = this._get(inst, 'dayNamesMin');
  1388. var monthNames = this._get(inst, 'monthNames');
  1389. var monthNamesShort = this._get(inst, 'monthNamesShort');
  1390. var beforeShowDay = this._get(inst, 'beforeShowDay');
  1391. var showOtherMonths = this._get(inst, 'showOtherMonths');
  1392. var selectOtherMonths = this._get(inst, 'selectOtherMonths');
  1393. var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
  1394. var defaultDate = this._getDefaultDate(inst);
  1395. var html = '';
  1396. for (var row = 0; row < numMonths[0]; row++) {
  1397. var group = '';
  1398. for (var col = 0; col < numMonths[1]; col++) {
  1399. var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  1400. var cornerClass = ' ui-corner-all';
  1401. var calender = '';
  1402. if (isMultiMonth) {
  1403. calender += '<div class="ui-datepicker-group';
  1404. if (numMonths[1] > 1)
  1405. switch (col) {
  1406. case 0: calender += ' ui-datepicker-group-first';
  1407. cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
  1408. case numMonths[1]-1: calender += ' ui-datepicker-group-last';
  1409. cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
  1410. default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
  1411. }
  1412. calender += '">';
  1413. }
  1414. calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
  1415. (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
  1416. (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
  1417. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  1418. row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  1419. '</div><table class="ui-datepicker-calendar"><thead>' +
  1420. '<tr>';
  1421. if(dateFormat == 'yy-mm-dd'){
  1422. var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
  1423. for (var dow = 0; dow < 7; dow++) { // days of the week
  1424. var day = (dow + firstDay) % 7;
  1425. thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
  1426. '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
  1427. }
  1428. calender += thead + '</tr></thead><tbody>';
  1429. }
  1430. var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  1431. if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
  1432. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  1433. var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  1434. var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
  1435. var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  1436. if(dateFormat == 'yy-mm-dd'){
  1437. for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  1438. calender += '<tr>';
  1439. var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
  1440. this._get(inst, 'calculateWeek')(printDate) + '</td>');
  1441. for (var dow = 0; dow < 7; dow++) { // create date picker days
  1442. var daySettings = (beforeShowDay ?
  1443. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
  1444. var otherMonth = (printDate.getMonth() != drawMonth);
  1445. var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
  1446. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  1447. tbody += '<td class="' +
  1448. ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
  1449. (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
  1450. ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
  1451. (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
  1452. // or defaultDate is current printedDate and defaultDate is selectedDate
  1453. ' ' + this._dayOverClass : '') + // highlight selected day
  1454. (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
  1455. (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
  1456. (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
  1457. (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
  1458. ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
  1459. (unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
  1460. inst.id + '\',' + printDate.getMonth() + ',' + printDate.getFullYear() + ', this);return false;"') + '>' + // actions
  1461. (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
  1462. (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
  1463. (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
  1464. (printDate.getTime() == selectedDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
  1465. (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
  1466. '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
  1467. printDate.setDate(printDate.getDate() + 1);
  1468. printDate = this._daylightSavingAdjust(printDate);
  1469. }
  1470. calender += tbody + '</tr>';
  1471. }
  1472. }else{
  1473. var length = this._get(inst, 'length');
  1474. var le = Math.ceil(length/2);
  1475. for (var dRow = length; dRow >0; dRow--) { // create date picker rows
  1476. var drawDate = new Date(drawYear, drawMonth, 1);
  1477. drawDate.setMonth(drawDate.getMonth()+le-dRow);
  1478. var year = drawDate.getFullYear();
  1479. var month = drawDate.getMonth()+1;
  1480. if(month < 10){
  1481. month = "0" + month;
  1482. }
  1483. var selectDate = year+"-"+month;
  1484. //ui-state-active
  1485. calender += '<tr><td>';
  1486. calender += '<a class="ui-state-default '+ (selectedDate.getTime() == drawDate.getTime() ? ' ui-state-highlight' : '') +'" href="#" '
  1487. + 'onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' + inst.id + '\',' + (drawDate.getMonth()+1) + ',' + drawDate.getFullYear() + ', this);return false;">'
  1488. + '<span style="text-align:center">' +selectDate + '</span>'
  1489. + '</a>';
  1490. calender += '</td></tr>';
  1491. }
  1492. }
  1493. drawMonth++;
  1494. if (drawMonth > 11) {
  1495. drawMonth = 0;
  1496. drawYear++;
  1497. }
  1498. calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
  1499. ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
  1500. group += calender;
  1501. }
  1502. html += group;
  1503. }
  1504. html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
  1505. '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
  1506. inst._keyEvent = false;
  1507. return html;
  1508. },
  1509. /* Generate the month and year header. */
  1510. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  1511. secondary, monthNames, monthNamesShort) {
  1512. var changeMonth = this._get(inst, 'changeMonth');
  1513. var changeYear = this._get(inst, 'changeYear');
  1514. var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
  1515. var html = '<div class="ui-datepicker-title">';
  1516. var monthHtml = '';
  1517. // month selection
  1518. //var dateFormat = this._get(inst, 'dateFormat');
  1519. if (secondary || !changeMonth)
  1520. monthHtml += '<div class="ui-datepicker-month" >' + monthNames[drawMonth] + '</div>';
  1521. else {
  1522. var inMinYear = (minDate && minDate.getFullYear() == drawYear);
  1523. var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
  1524. monthHtml += '<select class="ui-datepicker-month" ' +
  1525. 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
  1526. 'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
  1527. '>';
  1528. for (var month = 0; month < 12; month++) {
  1529. if ((!inMinYear || month >= minDate.getMonth()) &&
  1530. (!inMaxYear || month <= maxDate.getMonth()))
  1531. monthHtml += '<option value="' + month + '"' +
  1532. (month == drawMonth ? ' selected="selected"' : '') +
  1533. '>' + monthNamesShort[month] + '</option>';
  1534. }
  1535. monthHtml += '</select>';
  1536. }
  1537. if (!showMonthAfterYear)
  1538. html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
  1539. // year selection
  1540. if (secondary || !changeYear)
  1541. html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
  1542. else {
  1543. // determine range of years to display
  1544. var years = this._get(inst, 'yearRange').split(':');
  1545. var thisYear = new Date().getFullYear();
  1546. var determineYear = function(value) {
  1547. var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
  1548. (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
  1549. parseInt(value, 10)));
  1550. return (isNaN(year) ? thisYear : year);
  1551. };
  1552. var year = determineYear(years[0]);
  1553. var endYear = Math.max(year, determineYear(years[1] || ''));
  1554. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  1555. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  1556. html += '<select class="ui-datepicker-year" ' +
  1557. 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
  1558. 'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
  1559. '>';
  1560. for (; year <= endYear; year++) {
  1561. html += '<option value="' + year + '"' +
  1562. (year == drawYear ? ' selected="selected"' : '') +
  1563. '>' + year + '</option>';
  1564. }
  1565. html += '</select>';
  1566. }
  1567. html += this._get(inst, 'yearSuffix');
  1568. if (showMonthAfterYear)
  1569. html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
  1570. html += '</div>'; // Close datepicker_header
  1571. return html;
  1572. },
  1573. /* Adjust one of the date sub-fields. */
  1574. _adjustInstDate: function(inst, offset, period) {
  1575. var year = inst.drawYear + (period == 'Y' ? offset : 0);
  1576. var month = inst.drawMonth + (period == 'M' ? offset : 0);
  1577. var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
  1578. (period == 'D' ? offset : 0);
  1579. var date = this._restrictMinMax(inst,
  1580. this._daylightSavingAdjust(new Date(year, month, day)));
  1581. inst.selectedDay = date.getDate();
  1582. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1583. inst.drawYear = inst.selectedYear = date.getFullYear();
  1584. if (period == 'M' || period == 'Y')
  1585. this._notifyChange(inst);
  1586. },
  1587. /* Ensure a date is within any min/max bounds. */
  1588. _restrictMinMax: function(inst, date) {
  1589. var minDate = this._getMinMaxDate(inst, 'min');
  1590. var maxDate = this._getMinMaxDate(inst, 'max');
  1591. date = (minDate && date < minDate ? minDate : date);
  1592. date = (maxDate && date > maxDate ? maxDate : date);
  1593. return date;
  1594. },
  1595. /* Notify change of month/year. */
  1596. _notifyChange: function(inst) {
  1597. var onChange = this._get(inst, 'onChangeMonthYear');
  1598. if (onChange)
  1599. onChange.apply((inst.input ? inst.input[0] : null),
  1600. [inst.selectedYear, inst.selectedMonth + 1, inst]);
  1601. },
  1602. /* Determine the number of months to show. */
  1603. _getNumberOfMonths: function(inst) {
  1604. var numMonths = this._get(inst, 'numberOfMonths');
  1605. return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
  1606. },
  1607. /* Determine the current maximum date - ensure no time components are set. */
  1608. _getMinMaxDate: function(inst, minMax) {
  1609. return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
  1610. },
  1611. /* Find the number of days in a given month. */
  1612. _getDaysInMonth: function(year, month) {
  1613. return 32 - new Date(year, month, 32).getDate();
  1614. },
  1615. /* Find the day of the week of the first of a month. */
  1616. _getFirstDayOfMonth: function(year, month) {
  1617. return new Date(year, month, 1).getDay();
  1618. },
  1619. /* Determines if we should allow a "next/prev" month display change. */
  1620. _canAdjustMonth: function(inst, offset, curYear, curMonth) {
  1621. var numMonths = this._getNumberOfMonths(inst);
  1622. var date = this._daylightSavingAdjust(new Date(curYear,
  1623. curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
  1624. if (offset < 0)
  1625. date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
  1626. return this._isInRange(inst, date);
  1627. },
  1628. /* Is the given date in the accepted range? */
  1629. _isInRange: function(inst, date) {
  1630. var minDate = this._getMinMaxDate(inst, 'min');
  1631. var maxDate = this._getMinMaxDate(inst, 'max');
  1632. return ((!minDate || date.getTime() >= minDate.getTime()) &&
  1633. (!maxDate || date.getTime() <= maxDate.getTime()));
  1634. },
  1635. /* Provide the configuration settings for formatting/parsing. */
  1636. _getFormatConfig: function(inst) {
  1637. var shortYearCutoff = this._get(inst, 'shortYearCutoff');
  1638. shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
  1639. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  1640. return {shortYearCutoff: shortYearCutoff,
  1641. dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
  1642. monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
  1643. },
  1644. /* Format the given date for display. */
  1645. _formatDate: function(inst, day, month, year) {
  1646. if (!day) {
  1647. inst.currentDay = inst.selectedDay;
  1648. inst.currentMonth = inst.selectedMonth;
  1649. inst.currentYear = inst.selectedYear;
  1650. }
  1651. var date = (day ? (typeof day == 'object' ? day :
  1652. this._daylightSavingAdjust(new Date(year, month, day))) :
  1653. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  1654. return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
  1655. }
  1656. });
  1657. /* jQuery extend now ignores nulls! */
  1658. function extendRemove(target, props) {
  1659. $.extend(target, props);
  1660. for (var name in props)
  1661. if (props[name] == null || props[name] == undefined)
  1662. target[name] = props[name];
  1663. return target;
  1664. };
  1665. /* Determine whether an object is an array. */
  1666. function isArray(a) {
  1667. return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
  1668. (a.constructor && a.constructor.toString().match(/\Array\(\)/))));
  1669. };
  1670. /* Invoke the datepicker functionality.
  1671. @param options string - a command, optionally followed by additional parameters or
  1672. Object - settings for attaching new datepicker functionality
  1673. @return jQuery object */
  1674. $.fn.datepicker = function(options){
  1675. /* Initialise the date picker. */
  1676. if (!$.datepicker.initialized) {
  1677. $(document).mousedown($.datepicker._checkExternalClick).
  1678. find('body').append($.datepicker.dpDiv);
  1679. $.datepicker.initialized = true;
  1680. }
  1681. var otherArgs = Array.prototype.slice.call(arguments, 1);
  1682. if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
  1683. return $.datepicker['_' + options + 'Datepicker'].
  1684. apply($.datepicker, [this[0]].concat(otherArgs));
  1685. if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
  1686. return $.datepicker['_' + options + 'Datepicker'].
  1687. apply($.datepicker, [this[0]].concat(otherArgs));
  1688. return this.each(function() {
  1689. typeof options == 'string' ?
  1690. $.datepicker['_' + options + 'Datepicker'].
  1691. apply($.datepicker, [this].concat(otherArgs)) :
  1692. $.datepicker._attachDatepicker(this, options);
  1693. });
  1694. };
  1695. $.datepicker = new Datepicker(); // singleton instance
  1696. $.datepicker.initialized = false;
  1697. $.datepicker.uuid = new Date().getTime();
  1698. $.datepicker.version = "1.8.5";
  1699. // Workaround for #4055
  1700. // Add another global to avoid noConflict issues with inline event handlers
  1701. window['DP_jQuery_' + dpuuid] = $;
  1702. })(jQuery);