datepicker.js 80 KB

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