jquery.ui.datepicker.js 75 KB

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