ui.datepicker.js 70 KB

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