datepicker.js 71 KB

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