/* * Assorted javascript functions used on Calendars. */ /* Hover over one thing shows the other with a timeout by adding the hoverClass specified */ function Hover(sourceId, targetId, hoverClass, timeout) { this.$source = jQuery('#' + sourceId); this.$target = jQuery('#' + targetId); this.hoverClass = hoverClass; this.isVisible = false; this.closeTimer = null; const _this = this; this.$source.on('hover', function() { _this.open(); clearTimeout(_this.closeTimer); }, function(){ _this.closeTimer = setTimeout(function() { _this.close(); }, timeout); }); } //Instance methods Hover.prototype = { open : function() { this.$target.addClass(this.hoverClass); this.isVisible = true; }, close : function() { this.$target.removeClass(this.hoverClass); this.isVisible = false; } }; function setAllTags(checked) { const checkBoxes = document.getElementById('tagList').getElementsByTagName('input'); for (let i = 0; i maxY) { bestPosition.left = maxY - $target.width(); } // shift up if necessary const maxX = $container.offset().top + $container.height() - 32; // bit of tolerance if (bestPosition.top + $target.height() > maxX) { bestPosition.top = maxX - $target.height(); } // jQuery can only correctly position a displayed element $target.css({ visibility: 'hidden' }).show().offset(bestPosition).css({ visibility: 'visible' }); } const Checkbox = function(sourceCheckbox) { const name = sourceCheckbox.name; const id = sourceCheckbox.id; const span = document.createElement('span'); const hidden = document.createElement('input'); hidden.setAttribute('type','hidden'); hidden.setAttribute('name', name); hidden.setAttribute('id', id); const image = document.createElement('img'); image.src = Checkbox.shim; span.appendChild(hidden); span.appendChild(image); sourceCheckbox.parentNode.replaceChild(sourceCheckbox, span); }; Checkbox.shim = '/static_war/images/shim.gif'; const DateFormat = { d_names : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], m_names : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], padNumber : function(number) { let n = '' + number; while (n.length < 2) { n = "0" + n; } return n; }, dayName: function(dayNum) { return DateFormat.d_names[dayNum]; }, monthName: function(monthNum) { return DateFormat.m_names[monthNum]; }, toDateTime: function(dateObj, pattern) { let result = DateFormat.toShortDate(); if (showTime) { result += ' ' + DateFormat.toTime(); } return result; }, toShortDate: function(dateObj) { let result = DateFormat.dayName(dateObj.getDay())+' '+dateObj.getDate()+' ' + DateFormat.monthName(dateObj.getMonth()); if (dateObj.getFullYear() !== new Date().getFullYear) { result += ' ' + dateObj.getFullYear(); } return result; }, toTime: function(dateObj) { return DateFormat.padNumber(dateObj.getHours()) + ':' + DateFormat.padNumber(dateObj.getMinutes()); } }; function pluralise(count,singular,plural) { if (count === 1) return singular; if (count === 2) return 'other ' + singular; return count + ' ' + plural; } function toGMT(date, serverTimeOffset) { // eslint-disable-next-line no-param-reassign serverTimeOffset = serverTimeOffset || 0; return new Date(date.getTime() + (date.getTimezoneOffset() * 60000) + (serverTimeOffset * 60000)) } function shareButtonHTML(url, title) { const itemUrl = encodeURIComponent(url); const itemTitle = encodeURIComponent(title); return `
Share this
`; } jQuery(document).ready(function($) { $('.triggerPopover').on('click', function (e) { e.preventDefault(); const el = jQuery(this); this.hide = jQuery.noop; const eventTitle = el.data('title'); const event = el.data('event'); const occurrence = el.data('occurrence'); const location = el.data('location'); const notes = el.data('notes'); const detail = el.data('detail'); const categories = el.data('categories').split(','); const moreInfo = el.data('more'); const editingHost = el.data('editinghost'); const sourceUrl = el.data('sourceurl'); const sourceName = el.data('sourcename'); const urlPath = el.data('urlpath'); const showShareButtons = el.data('show-share-buttons'); const pagePubliclyViewable = el.data('page-publicly-viewable'); $('.triggerPopover').not(el).popover('hide'); // Hide other open popovers el.popover({ placement: 'bottom', title: function() { let title = '
' + ''; if(el.data('canedit')) { title += '
' + '' + '' + '' + '' + '' + '' + '' + '' + ''; if(el.data('recurring')) { title += '' + '' + ''; } } title += '' + '' + '' + '
'; return title; }, content: function () { let content = '

When:
' + el.find('.time').html() + '

'; if (location) { content += '

Where:
' + location + '

'; } if (notes) { content += 'Notes:
' + notes; } if (detail) { content += 'Detail:
' + detail; } if (showShareButtons && pagePubliclyViewable) { content += shareButtonHTML(sourceUrl + '?calendarItem=' + event, eventTitle) } if (categories) { content += "
"; const categoriesCSS = el.data('categoriescss').split(','); for(let i = 0; i < categories.length - 1; i++ ) { content += '' + categories[i] + ' '; } content += "
" } if (sourceName) { content += '

Source:
' + sourceName + '

'; } if (moreInfo) { content += '

More info…

'; } return content; }, html: true, template: '

' }); el.popover('show'); }); const $calendar = $('.calendar'); $calendar.on('shown.bs.popover', function(e) { const $po = $(e.target).popover().data('bs.popover').tip(); $po.data('creator', $(e.target)); }); $calendar.on('hidden.bs.popover', function(e) { const $creator = $(e.target); if ($creator) { $creator.data("bs.popover").inState.click = false; } }); $calendar.on('click', '.popover .close', function(e) { e.preventDefault(); const $creator = $(e.target).parents('.popover').data('creator'); if ($creator) { $creator.popover('hide'); } }); $('body').on('click', '[data-target="#calendarModal"], [aria-controls="calendarModal"]', function (e) { e.preventDefault(); const el = jQuery(this); const $calendarModal = jQuery('#calendarModal'); const modalContent = $calendarModal.find('.dialog-content'); const modal = $calendarModal[0]; if (!modal.hasAttribute('open')) { // Throws unhelpful errors if it's already open for some reason window.customElements.whenDefined('sb-dialog-wrapper').then(() => { modal.showModal(); }); } modalContent.html( '
Loading
' ); jQuery.get('/sitebuilder2/render/edit/calendaritems/' + el.data('action') + '.htm', { sbrPage: el.data('page'), calendarItem: el.data('event'), occurrenceId: el.data('occurrence'), rn: new Date().getTime(), }).done(function(data) { modalContent.html(data); }); }); $(".dayLink").on("focus", function (e) { $(e.target).parents(".sb-calendar-date, td").find(".createNewItem").addClass("createNewItemHover"); }); $(".createNewItem").on("focusout", function () { $(this).removeClass("createNewItemHover"); }) });