| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /* http://keith-wood.name/datepick.html |
| 2 | 2 | Datepicker for jQuery 3.7.1. |
| 3 | 3 | Written by Marc Grabanski ([email protected]) and |
| 4 | 4 | Keith Wood (kbwood{at}iinet.com.au). |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | var PROP_NAME = 'datepick'; |
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | // https://github.com/jquery/jquery-migrate/blob/master/src/core.js#L50 |
| 32 | - //FixIn: 8.7.10.1 | |
| 32 | + // FixIn: 8.7.10.1. | |
| 33 | 33 | if (!$.browser_is_supported_datepick) { |
| 34 | 34 | var uaMatch = function(ua) { |
| 35 | 35 | ua = ua.toLowerCase(); |
| 36 | 36 | |
| @@ -96,9 +96,9 @@ | ||
| 96 | 96 | showMonthAfterYear: false, // True if the year select precedes month, false for month then year |
| 97 | 97 | yearSuffix: '' // Additional text to append to the year in the month headers |
| 98 | 98 | }; |
| 99 | 99 | this._defaults = { // Global defaults for all the date picker instances |
| 100 | - wpbc_resource_id: 0, // ID of booking resource - customization //FixIn: 9.4.4.13 | |
| 100 | + wpbc_resource_id: 0, // ID of booking resource - customization // FixIn: 9.4.4.13. | |
| 101 | 101 | useThemeRoller: false, // True to apply ThemeRoller styling, false for default styling |
| 102 | 102 | showOn: 'focus', // 'focus' for popup on focus, |
| 103 | 103 | // 'button' for trigger button, or 'both' for either |
| 104 | 104 | showAnim: 'show', // Name of jQuery animation for popup |
| @@ -155,9 +155,10 @@ | ||
| 155 | 155 | beforeShowDay: null, // Function that takes a date and returns an array with |
| 156 | 156 | // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '', |
| 157 | 157 | // [2] = cell title (optional), e.g. $.datepick.noWeekends |
| 158 | 158 | onChangeMonthYear: null, // Define a callback function when the month or year is changed |
| 159 | - onHover: null, // Define a callback function when hovering over a day | |
| 159 | + onHover: null, // Define a callback function when hovering over a day | |
| 160 | + beforeSelectDay: null, // Optional (Date, instance) callback; false vetoes selection before any state change. | |
| 160 | 161 | onSelect: null, // Define a callback function when a date is selected |
| 161 | 162 | onClose: null, // Define a callback function when the datepicker is closed |
| 162 | 163 | altField: '', // Selector for an alternate field to store selected dates into |
| 163 | 164 | altFormat: '', // The date format to use for the alternate field |
| @@ -239,8 +240,9 @@ | ||
| 239 | 240 | var inst = this._newInst($(target), (nodeName == 'div' || nodeName == 'span')); |
| 240 | 241 | // Check for settings on the control itself |
| 241 | 242 | var inlineSettings = ($.fn.metadata ? $(target).metadata() : {}); |
| 242 | 243 | inst.settings = $.extend({}, settings || {}, inlineSettings || {}); |
| 244 | + this._adjustInstDate(inst); // FixIn: Adjust cursor date (currently rendering Month, if we define the minDate in the future !!! // FixIn: 10.13.1.4. | |
| 243 | 245 | if (inst.inline) { |
| 244 | 246 | inst.dpDiv.addClass(this._inlineClass[ |
| 245 | 247 | this._get(inst, 'useThemeRoller') ? 1 : 0]); |
| 246 | 248 | this._inlineDatepick(target, inst); |
| @@ -279,9 +281,9 @@ | ||
| 279 | 281 | inst.siblings = inst.siblings.add(append); |
| 280 | 282 | } |
| 281 | 283 | var showOn = this._get(inst, 'showOn'); |
| 282 | 284 | if (showOn == 'focus' || showOn == 'both') // Pop-up date picker when in the marked field |
| 283 | - input.on('focus.wpbc_datepick', this._showDatepick); //FixIn: 10.0.0.45 | |
| 285 | + input.on('focus.wpbc_datepick', this._showDatepick); // FixIn: 10.0.0.45. | |
| 284 | 286 | if (showOn == 'button' || showOn == 'both') { // Pop-up date picker when button clicked |
| 285 | 287 | var buttonText = this._get(inst, 'buttonText'); |
| 286 | 288 | var buttonImage = this._get(inst, 'buttonImage'); |
| 287 | 289 | var trigger = $(this._get(inst, 'buttonImageOnly') ? |
| @@ -291,9 +293,9 @@ | ||
| 291 | 293 | html(buttonImage == '' ? buttonText : $('<img/>').attr( |
| 292 | 294 | {src: buttonImage, alt: buttonText, title: buttonText}))); |
| 293 | 295 | input[isRTL ? 'before' : 'after'](trigger); |
| 294 | 296 | inst.siblings = inst.siblings.add(trigger); |
| 295 | - //FixIn: 8.7.11.12 | |
| 297 | + // FixIn: 8.7.11.12. | |
| 296 | 298 | trigger.on( 'click', function (){ |
| 297 | 299 | if ($.datepick._datepickerShowing && $.datepick._lastInput == target) |
| 298 | 300 | $.datepick._hideDatepick(); |
| 299 | 301 | else |
| @@ -300,9 +302,9 @@ | ||
| 300 | 302 | $.datepick._showDatepick(target); |
| 301 | 303 | return false; |
| 302 | 304 | }); |
| 303 | 305 | } |
| 304 | - input.addClass( this.markerClassName ).on( 'keydown.wpbc_datepick', this._doKeyDown ).on( 'keypress.wpbc_datepick', this._doKeyPress ).on( 'keyup.wpbc_datepick', this._doKeyUp ); //FixIn: 10.0.0.45 //FixIn: 8.7.11.12 | |
| 306 | + input.addClass( this.markerClassName ).on( 'keydown.wpbc_datepick', this._doKeyDown ).on( 'keypress.wpbc_datepick', this._doKeyPress ).on( 'keyup.wpbc_datepick', this._doKeyUp ); //FixIn: 10.0.0.45 // FixIn: 8.7.11.12. | |
| 305 | 307 | if (this._get(inst, 'showDefault') && !inst.input.val()) { |
| 306 | 308 | inst.dates = [this._getDefaultDate(inst)]; |
| 307 | 309 | this._showDate(inst); |
| 308 | 310 | } |
| @@ -359,13 +361,13 @@ | ||
| 359 | 361 | */ |
| 360 | 362 | divSpan.append(inst.dpDiv); |
| 361 | 363 | this._updateAlternate(inst); |
| 362 | 364 | |
| 363 | - //FixIn: 9.4.4.13 | |
| 365 | + // FixIn: 9.4.4.13. | |
| 364 | 366 | var resource_id = parseInt( divSpan.get( 0 ).getAttribute( 'id' ).replace( 'calendar_booking', '' ) ); |
| 365 | 367 | inst.settings.wpbc_resource_id = resource_id; // To get this property use: this._get(inst, 'wpbc_resource_id') |
| 366 | 368 | |
| 367 | - //FixIn: 9.4.4.12 | |
| 369 | + // FixIn: 9.4.4.12. | |
| 368 | 370 | $( 'body' ).trigger( |
| 369 | 371 | 'wpbc_datepick_inline_calendar_loaded' // event name |
| 370 | 372 | , [ |
| 371 | 373 | divSpan.get( 0 ).getAttribute( 'id' ).replace( 'calendar_booking', '' ) // Resource ID - '1' |
| @@ -390,9 +392,9 @@ | ||
| 390 | 392 | if (!inst) { |
| 391 | 393 | var id = 'dp' + (++this._uuid); |
| 392 | 394 | this._dialogInput = $('<input type="text" id="' + id + |
| 393 | 395 | '" style="position: absolute; width: 1px; z-index: -1"/>'); |
| 394 | - this._dialogInput.on( 'keydown.wpbc_datepick', this._doKeyDown); //FixIn: 10.0.0.45 | |
| 396 | + this._dialogInput.on( 'keydown.wpbc_datepick', this._doKeyDown); // FixIn: 10.0.0.45. | |
| 395 | 397 | $('body').append(this._dialogInput); |
| 396 | 398 | inst = this._dialogInst = this._newInst(this._dialogInput, false); |
| 397 | 399 | inst.settings = {}; |
| 398 | 400 | $.data(this._dialogInput[0], PROP_NAME, inst); |
| @@ -432,11 +434,11 @@ | ||
| 432 | 434 | if (inst.inline) |
| 433 | 435 | $target.removeClass(this.markerClassName).empty(); |
| 434 | 436 | else { |
| 435 | 437 | $(inst.siblings).remove(); |
| 436 | - //$target.removeClass(this.markerClassName).unbind('focus', this._showDatepick).unbind('keydown', this._doKeyDown).unbind('keypress', this._doKeyPress).unbind('keyup', this._doKeyUp); //FixIn: 10.0.0.45 | |
| 437 | - //$target.removeClass(this.markerClassName).off('focus', this._showDatepick).off('keydown', this._doKeyDown).off('keypress', this._doKeyPress).off('keyup', this._doKeyUp); //FixIn: 10.0.0.45 | |
| 438 | - $target.removeClass( this.markerClassName ).off( 'focus.wpbc_datepick' ).off( 'keydown.wpbc_datepick' ).off( 'keypress.wpbc_datepick' ).off( 'keyup.wpbc_datepick' ); //FixIn: 10.0.0.45 | |
| 438 | + //$target.removeClass(this.markerClassName).unbind('focus', this._showDatepick).unbind('keydown', this._doKeyDown).unbind('keypress', this._doKeyPress).unbind('keyup', this._doKeyUp); // FixIn: 10.0.0.45. | |
| 439 | + //$target.removeClass(this.markerClassName).off('focus', this._showDatepick).off('keydown', this._doKeyDown).off('keypress', this._doKeyPress).off('keyup', this._doKeyUp); // FixIn: 10.0.0.45. | |
| 440 | + $target.removeClass( this.markerClassName ).off( 'focus.wpbc_datepick' ).off( 'keydown.wpbc_datepick' ).off( 'keypress.wpbc_datepick' ).off( 'keyup.wpbc_datepick' ); // FixIn: 10.0.0.45. | |
| 439 | 441 | } |
| 440 | 442 | }, |
| 441 | 443 | |
| 442 | 444 | /* Enable the date picker to a jQuery selection. |
| @@ -883,9 +885,9 @@ | ||
| 883 | 885 | inst.dpDiv[showAnim](duration, postProcess); |
| 884 | 886 | if (duration == '') |
| 885 | 887 | postProcess(); |
| 886 | 888 | if (inst.input[0].type != 'hidden') |
| 887 | - $( inst.input ).trigger( 'focus' ); //FixIn: 8.7.11.12 | |
| 889 | + $( inst.input ).trigger( 'focus' ); // FixIn: 8.7.11.12. | |
| 888 | 890 | $.datepick._curInst = inst; |
| 889 | 891 | } |
| 890 | 892 | }, |
| 891 | 893 | |
| @@ -891,8 +893,11 @@ | ||
| 891 | 893 | |
| 892 | 894 | /* Generate the date picker content. |
| 893 | 895 | @param inst (object) the instance settings for this datepicker */ |
| 894 | 896 | _updateDatepick: function(inst) { |
| 897 | + if ( null === inst ) { | |
| 898 | + return; | |
| 899 | + } | |
| 895 | 900 | var borders = this._getBorders(inst.dpDiv); |
| 896 | 901 | var useTR = this._get(inst, 'useThemeRoller') ? 1 : 0; |
| 897 | 902 | inst.dpDiv.empty().append(this._generateHTML(inst)). |
| 898 | 903 | find('iframe.' + this._coverClass[useTR]). // IE6- only |
| @@ -908,11 +913,11 @@ | ||
| 908 | 913 | addClass(numMonths[0] != 1 || numMonths[1] != 1 ? this._multiClass[useTR] : ''). |
| 909 | 914 | removeClass(this._rtlClass.join(' ')). |
| 910 | 915 | addClass(this._get(inst, 'isRTL') ? this._rtlClass[useTR] : ''); |
| 911 | 916 | if (inst.input && inst.input[0].type != 'hidden' && inst == $.datepick._curInst) |
| 912 | - $( inst.input ).trigger( 'focus' ); //FixIn: 8.7.11.12 | |
| 917 | + $( inst.input ).trigger( 'focus' ); // FixIn: 8.7.11.12. | |
| 913 | 918 | |
| 914 | - //FixIn: 9.4.4.13 | |
| 919 | + // FixIn: 9.4.4.13. | |
| 915 | 920 | var resource_id = this._get(inst, 'wpbc_resource_id'); |
| 916 | 921 | if ( resource_id > 0 ){ |
| 917 | 922 | $( 'body' ).trigger( |
| 918 | 923 | 'wpbc_datepick_inline_calendar_refresh' // event name |
| @@ -1045,10 +1050,10 @@ | ||
| 1045 | 1050 | /* Tidy up after a dialog display. |
| 1046 | 1051 | @param inst (object) the instance settings for this datepicker */ |
| 1047 | 1052 | _tidyDialog: function(inst) { |
| 1048 | 1053 | var useTR = this._get(inst, 'useThemeRoller') ? 1 : 0; |
| 1049 | - //inst.dpDiv.removeClass(this._dialogClass[useTR]).unbind('.datepick'); //FixIn: 10.0.0.45 | |
| 1050 | - inst.dpDiv.removeClass(this._dialogClass[useTR]).off('.datepick'); //FixIn: 10.0.0.45 | |
| 1054 | + //inst.dpDiv.removeClass(this._dialogClass[useTR]).unbind('.datepick'); // FixIn: 10.0.0.45. | |
| 1055 | + inst.dpDiv.removeClass(this._dialogClass[useTR]).off('.datepick'); // FixIn: 10.0.0.45. | |
| 1051 | 1056 | $('.' + this._promptClass[useTR], inst.dpDiv).remove(); |
| 1052 | 1057 | }, |
| 1053 | 1058 | |
| 1054 | 1059 | /* Close date picker if clicked elsewhere. |
| @@ -1057,9 +1062,9 @@ | ||
| 1057 | 1062 | if (!$.datepick._curInst) |
| 1058 | 1063 | return; |
| 1059 | 1064 | var $target = $(event.target); |
| 1060 | 1065 | var useTR = $.datepick._get($.datepick._curInst, 'useThemeRoller') ? 1 : 0; |
| 1061 | - // replaced .andSelf to .addBack //FixIn: 10.0.0.45 | |
| 1066 | + // replaced .andSelf to .addBack // FixIn: 10.0.0.45. | |
| 1062 | 1067 | if (!$target.parents().addBack().is('#' + $.datepick._mainDivId[useTR]) && |
| 1063 | 1068 | !$target.hasClass($.datepick.markerClassName) && |
| 1064 | 1069 | !$target.parents().addBack().hasClass($.datepick._triggerClass[useTR]) && |
| 1065 | 1070 | $.datepick._datepickerShowing && !($.datepick._inDialog && $.blockUI)) |
| @@ -1117,9 +1122,9 @@ | ||
| 1117 | 1122 | @param id (string) the ID of the target field */ |
| 1118 | 1123 | _clickMonthYear: function(id) { |
| 1119 | 1124 | var inst = this._getInst($(id)[0]); |
| 1120 | 1125 | if (inst.input && inst.selectingMonthYear && !$.browser_is_supported_datepick.msie) |
| 1121 | - $( inst.input ).trigger( 'focus' ); //FixIn: 8.7.11.12 | |
| 1126 | + $( inst.input ).trigger( 'focus' ); // FixIn: 8.7.11.12. | |
| 1122 | 1127 | inst.selectingMonthYear = !inst.selectingMonthYear; |
| 1123 | 1128 | }, |
| 1124 | 1129 | |
| 1125 | 1130 | /* Action for changing the first week day. |
| @@ -1140,11 +1145,16 @@ | ||
| 1140 | 1145 | var inst = this._getInst($(id)[0]); |
| 1141 | 1146 | var useTR = this._get(inst, 'useThemeRoller') ? 1 : 0; |
| 1142 | 1147 | if ($(td).hasClass(this._unselectableClass[useTR])) |
| 1143 | 1148 | return false; |
| 1144 | - var rangeSelect = this._get(inst, 'rangeSelect'); | |
| 1145 | - var multiSelect = this._get(inst, 'multiSelect'); | |
| 1146 | - if (rangeSelect) | |
| 1149 | + var rangeSelect = this._get(inst, 'rangeSelect'); | |
| 1150 | + var multiSelect = this._get(inst, 'multiSelect'); | |
| 1151 | + // Allow a domain validator to veto activation before native selection state changes. | |
| 1152 | + var beforeSelectDay = this._get(inst, 'beforeSelectDay'); | |
| 1153 | + if (beforeSelectDay && beforeSelectDay.apply((inst.input ? inst.input[0] : null), | |
| 1154 | + [this._daylightSavingAdjust(new Date(timestamp)), inst]) === false) | |
| 1155 | + return false; | |
| 1156 | + if (rangeSelect) | |
| 1147 | 1157 | inst.stayOpen = !inst.stayOpen; |
| 1148 | 1158 | else if (multiSelect) |
| 1149 | 1159 | inst.stayOpen = true; |
| 1150 | 1160 | if (inst.stayOpen) { |
| @@ -1907,9 +1917,9 @@ | ||
| 1907 | 1917 | drawMonth == inst.cursorDate.getMonth() && inst.keyEvent) || // User pressed key |
| 1908 | 1918 | (defaultDate.getTime() == printDate.getTime() && |
| 1909 | 1919 | defaultDate.getTime() == cursorDate.getTime()) ? |
| 1910 | 1920 | // Or defaultDate is selected printedDate and defaultDate is cursorDate |
| 1911 | - ' ' /*+ $.datepick._dayOverClass[useTR]*/ : '') + // Highlight selected day //FixIn: 9.2.1.7 | |
| 1921 | + ' ' /*+ $.datepick._dayOverClass[useTR]*/ : '') + // Highlight selected day // FixIn: 9.2.1.7. | |
| 1912 | 1922 | (unselectable ? ' ' + this._unselectableClass[useTR] : |
| 1913 | 1923 | ' ' + this._selectableClass[useTR]) + // Highlight unselectable days |
| 1914 | 1924 | (empty ? '' : ' ' + daySettings[1] + // Highlight custom dates |
| 1915 | 1925 | (selected ? ' ' + this._selectedClass[useTR] : '') + // Currently selected |
| @@ -1923,9 +1933,9 @@ | ||
| 1923 | 1933 | ' onclick="jQuery.datepick._selectDay(this,\'#' + // Select |
| 1924 | 1934 | inst.id + '\',' + printDate.getTime() + ')"') + '>'; |
| 1925 | 1935 | |
| 1926 | 1936 | /** Start content of Day cell *************************************************************/ |
| 1927 | - html += '<div class="wpbc-cell-box">' + //FixIn: 8.9.4.13 | |
| 1937 | + html += '<div class="wpbc-cell-box">' + // FixIn: 8.9.4.13. | |
| 1928 | 1938 | '<div class="wpbc-diagonal-el">' + |
| 1929 | 1939 | '<div class="wpbc-co-out">' + |
| 1930 | 1940 | '<svg height="100%" width="100%" viewBox="0 0 100 100" preserveAspectRatio="none">' + |
| 1931 | 1941 | '<polygon points="0,0 0,99 99,0"></polygon>' + |
| @@ -1940,14 +1950,14 @@ | ||
| 1940 | 1950 | '</div>' + |
| 1941 | 1951 | '</div>' + |
| 1942 | 1952 | //'<div class="check-in-div"><div></div></div>' + // Deprecated! remove this line |
| 1943 | 1953 | //'<div class="check-out-div"><div></div></div>' + // Deprecated! remove this line |
| 1944 | - '<div class="date-cell-content">' + //FixIn: 8.9.4.13 | |
| 1954 | + '<div class="date-cell-content">' + // FixIn: 8.9.4.13. | |
| 1945 | 1955 | '<div class="date-content-top">' + |
| 1946 | 1956 | (unselectable ? '' : ((typeof (wpbc_show_date_info_top) == 'function') ? wpbc_show_date_info_top( inst.id, printDate.getTime() ) : '')) + |
| 1947 | 1957 | '</div>' + |
| 1948 | - (empty ? ' ' : // Not showing other months //FixIn:6.0.1.2 | |
| 1949 | - (unselectable ? '<span>' + printDate.getDate()+ '</span>' : '<a href="javascript:void(0)" >' + printDate.getDate() + '</a>')) + //FixIn: 10.0.0.19 | |
| 1958 | + (empty ? ' ' : // Not showing other months // FixIn: 6.0.1.2. | |
| 1959 | + (unselectable ? '<span>' + printDate.getDate()+ '</span>' : '<a href="javascript:void(0)" >' + printDate.getDate() + '</a>')) + // FixIn: 10.0.0.19. | |
| 1950 | 1960 | '<div class="date-content-bottom">'+ |
| 1951 | 1961 | (unselectable ? '' : ((typeof (wpbc_show_date_info_bottom) == 'function') ? wpbc_show_date_info_bottom( inst.id, printDate.getTime() ) : '')) + |
| 1952 | 1962 | '</div>' + |
| 1953 | 1963 | '</div>' + |
| @@ -2256,8 +2266,8 @@ | ||
| 2256 | 2266 | $.datepick = new Datepick(); // Singleton instance |
| 2257 | 2267 | |
| 2258 | 2268 | $(function() { |
| 2259 | 2269 | |
| 2260 | - $( document ).on( 'mousedown', $.datepick._checkExternalClick ).find( 'body' ).append( $.datepick.dpDiv ); //FixIn: 8.7.11.12 | |
| 2270 | + $( document ).on( 'mousedown', $.datepick._checkExternalClick ).find( 'body' ).append( $.datepick.dpDiv ); // FixIn: 8.7.11.12. | |
| 2261 | 2271 | }); |
| 2262 | 2272 | |
| 2263 | 2273 | })(jQuery); |