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