convert($datetime_formats['datepicker']['pattern']); } catch (\Exception $e) { // Report the error and fall through to the 'custom' format trigger_error($e->getMessage(), E_USER_WARNING); } } return 'custom'; } http_headers(array("Content-type: application/x-javascript"), 60*30); // 30 minute expiry ?> 'use strict'; function iPadMobileFix() { return function(instance) { return { onParseConfig: function() { if (instance.isMobile) { return; } if (isIos()) { instance.isMobile = true; } } }; }; } function getISODate(year, month, day) { var date = new Date(Date.UTC(year, month, day)); return date.toISOString().split('T')[0]; } // Given a JavaScript Date object returns a date string in YYYY-MM-DD // format. (Note that toISOString() returns a date in UTC time). function getLocalISODateString(date) { var month = (date.getMonth() + 1).toString().padStart(2, '0'); var day = date.getDate().toString().padStart(2, '0'); var year = date.getFullYear().toString(); return [year, month, day].join('-'); } function weekStart(date, weekStarts) { var d = new Date(date + "T00:00:00"); var diff = d.getDay() - weekStarts; if (diff < 0) { diff += 7; } d.setDate(d.getDate() - diff); return getLocalISODateString(d); } function weekEnd(date, weekStarts) { var d = new Date(weekStart(date, weekStarts) + "T00:00:00"); d.setDate(d.getDate() + 6); return getLocalISODateString(d); } function monthStart(date) { var d = new Date(date + "T00:00:00"); d.setDate(1); return getLocalISODateString(d); } function monthEnd(date) { var d = new Date(date + "T00:00:00"); d.setDate(1); d.setMonth(d.getMonth() + 1); d.setDate(0); return getLocalISODateString(d); } // Returns an array of dates in the range startDate..endDate, optionally // excluding hidden days. function datesInRange(startDate, endDate, excludeHiddenDays) { var result=[]; var e=new Date(endDate + "T00:00:00"); var hiddenDays = []; and < but not == or === ?> for (var d=new Date(startDate + "T00:00:00"); !(d>e); d.setDate(d.getDate()+1)) { if (excludeHiddenDays && (hiddenDays.indexOf(d.getDay()) >= 0)) { continue; } result.push(getLocalISODateString(d)); } return result; } $(document).on('page_ready', function() { const locales = args.langPrefs; getFlatpickrLangPath())) { // Map the flatpickr lang file onto a flatpickr l10ns property and then localize echo 'flatpickr.localize(flatpickr.l10ns["' . Language::getFlatpickrProperty($flatpickr_lang_path) . '"]);'; } // Custom date formatter. At the moment, only two format strings are supported: // // 'custom' The date is formatted in numeric form in the user's preferred locale, // as expressed by their browser preferences and subject to any // overriding config settings. Note that 'custom' is not supported on // IE10, as it requires Intl.DateTimeFormat(), and so IE10 users // are given a date in 'Y-m-d' format. // // everything All other format strings are treated as 'Y-m-d'. // else ?> var formatDate = function(dateObj, formatStr) { if (window.Intl && (formatStr === 'custom')) { console.debug("MRBS language preferences: " + JSON.stringify(locales)); console.debug("MRBS: locales supported by Intl.DateTimeFormat: " + JSON.stringify(Intl.DateTimeFormat.supportedLocalesOf(locales))); if (!Intl.DateTimeFormat.supportedLocalesOf(locales[0]).length) { console.warn("MRBS: Intl.DateTimeFormat in this browser does not support the '" + locales[0] + "' locale."); } return (typeof locales === 'undefined') ? new Intl.DateTimeFormat().format(dateObj) : new Intl.DateTimeFormat(locales).format(dateObj); } return getISODate(dateObj.getFullYear(), dateObj.getMonth(), dateObj.getDate()); }; var onDayCreate = function(dObj, dStr, fp, dayElem) { const hiddenDays = []; if (hiddenDays.length && args.isBookAdmin && fp.altInput.classList.contains('navigation') && (hiddenDays.indexOf(dayElem.dateObj.getDay()) >= 0)) { dayElem.classList.add('mrbs-hidden'); } const weekDays = []; if (weekDays.indexOf(dayElem.dateObj.getDay()) < 0) { dayElem.classList.add('mrbs-weekend'); } }; function syncCals(instance) { var thisId = instance.element.attributes.id.nodeValue, thisIndex = parseInt(thisId.substring(3), 10), currentMonth = parseInt(instance.currentMonth, 10), currentYear = parseInt(instance.currentYear, 10); $.each(minicalendars, function(key, value) { if (value.element.attributes.id.nodeValue !== thisId) { var index = parseInt(value.element.attributes.id.nodeValue.substring(3), 10); value.jumpToDate(getISODate(currentYear, currentMonth + index - thisIndex, 1)); } }); } var onMonthChange = function(selectedDates, dateStr, instance) { syncCals(instance); }; var onYearChange = function(selectedDates, dateStr, instance) { syncCals(instance); }; var onMinicalChange = function(selectedDates, dateStr, instance) { var href = 'index.php'; href += '?view=' + args.view; href += '&page_date=' + dateStr; href += '&area=' + args.area; href += '&room=' + args.room; if (args.site) { href += '&site=' + encodeURIComponent(args.site); } instance.setDate([selectedDates[0], selectedDates[0]], false); updateBody(href); }; var lastValidDate = {}; var config = { plugins: [iPadMobileFix()], dateFormat: 'Y-m-d', altInput: true, altFormat: , onDayCreate: onDayCreate, locale: {firstDayOfWeek: }, onChange: function(selectedDates, dateStr, instance) { var element = $(instance.element); var submit = element.data('submit'); var elementName = element.attr('name'); if (dateStr) { lastValidDate[elementName] = dateStr; } else if (element.prop('required') && lastValidDate[elementName]) { instance.setDate(lastValidDate[elementName]); } if (submit) { $('#' + submit).trigger('submit'); } else { element.trigger('change'); } }, onReady: function(selectedDates, dateStr, instance) { if (instance.altInput.ariaLabel === null) { instance.altInput.ariaLabel = instance.input.ariaLabel; } if (dateStr) { lastValidDate[instance.element.getAttribute('name')] = dateStr; } } }; if (isMobile()) { $('input.flatpickr-input').width('auto'); } else { config.weekNumbers = getWebLocale()))) ? 'true' : 'false' ?>; } let fps = flatpickr('input[type="date"]:not(.navigation)', config); // flatpickr will either return a single instance or an array of instances, // so convert a single instance to an array so that the iteration works. fps = (Array.isArray(fps) ? fps : [fps]); fps.forEach(function(fp) { let minDate = $(fp.input).data('min'); if (minDate) { fp.set('minDate', minDate); // Note that although the flatpickr documentation says this should work on mobiles, it doesn't seem to. // So we manually set the 'min' attribute for mobiles. $('input[type="hidden"][data-min]').next('.flatpickr-input.flatpickr-mobile').attr('min', minDate); } }); if (!args.isBookAdmin) { config.disable = [ function (date) { return ([].indexOf(date.getDay()) >= 0); } ]; } flatpickr('input[type="date"].navigation', config); if (!isMobile()) { var div = $('.minicalendars'); if (div.length > 0) { for (var i = 0; i < 2; i++) { div.append($('')); } config.inline = true; config.onMonthChange = onMonthChange; config.onYearChange = onYearChange; config.onChange = onMinicalChange; config.mode = 'range'; var minicalendars = flatpickr('span.minicalendar', config); $.each(minicalendars, function (key, value) { var startDate, endDate; if (args.view === 'month') { startDate = monthStart(args.pageDate); endDate = monthEnd(args.pageDate); } else if (args.view === 'week') { startDate = weekStart(args.pageDate, ); endDate = weekEnd(args.pageDate, ); } else { startDate = args.pageDate; endDate = startDate; } value.setDate([startDate, endDate]); value.setDate(datesInRange(startDate, endDate, true)); value.changeMonth(key); }); div.css('margin-top', $('.view_container h2').outerHeight(true) + 'px'); div.addClass('formed'); } } $('.view_container').removeClass('js_hidden'); $('#form_nav').removeClass('js_hidden'); });