jqueryUI - datepicker & keycode only

JqueryUI avec uniquement les widgets Datepicker et Keycode.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/486572/1322825/jqueryUI%20-%20datepicker%20%20keycode%20only.js

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