You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2239 lines
81 KiB

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