jquery.datepick.js 83 KB

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