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