jquery.ui.datepicker.js 76 KB

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