( function() { var $ = function ( q ) { return document.querySelector( q ); }; var add = function ( str, element ) { var div = document.createElement( 'div' ); div.innerHTML = str; if ( element ) { element.parentNode.insertBefore( div, element ); } else { document.body.appendChild( div ); } }; // Add FES button styles var fesButtonStyles = ( stylesheet ) => { stylesheet += `.timely-embedded-fes-btn { color: #8089a7; background-color: transparent; padding:5px; font-size: 14px; border-radius: 5px; border: 1px solid #8089a7; display: inline-block; font-family: Sans-serif; width: -webkit-fit-content; width: -moz-fit-content; width: fit-content; text-align: center; text-transform: uppercase; cursor: pointer; }`; return stylesheet; }; var timely_script = $( '#timely_script' ); if ( timely_script ) { // Below attributes are set when adding embedded snippet // from Dashboard to customers website var src = timely_script.getAttribute( 'data-src' ); var embeddedFES = timely_script.getAttribute( 'data-fes' ); script = timely_script; // Change id of the script so we won't initialize it again. timely_script.id = 'timely_' + Math.random(); const eventHash = location.hash.match( /^\#event=(\d+)/ ); /* Automatically open ED of the specified event */ if ( eventHash ) { // Open ED. var s = src.split('?')[0]; if ( s.indexOf( '.time.ly' ) == -1 && s.indexOf( 'localhost' ) == -1 ) { while ( s.lastIndexOf( '/' ) > 9 ) { s = s.substr( 0, s.lastIndexOf( '/' ) ); } } if ( s.lastIndexOf( '/' ) > -1 && s.lastIndexOf( '/' ) === s.length - 1 ) { s = s.substr( 0,s.length - 1 ); } s += '/event/' + eventHash[1]; const instanceHash = location.hash.match( /;instance=(\d+)/ ); if ( instanceHash ) { s+= '/' + instanceHash[1]; } setTimeout( function() { window.postMessage( {timelyED : s}, '*' ); }, 500 ); } src += ( src.indexOf( '?' ) > -1 ? '&' : '?' ) + 'timely_id=' + timely_script.id; if ( embeddedFES ) { // Add embedded FES button add( ``, timely_script); } else { // Add main calendar frame const isTop = window.top == window.self; const isSlider = src.indexOf( 'slider' ) > -1; var maxHeight = timely_script.getAttribute( 'data-max-height' ); if ( maxHeight > 0 ) { maxHeight = 'style="max-height:' + maxHeight + 'px;"'; } add('', timely_script); } } // Add common CSS and iframe for ED just once if ( ! window.timely_embed_handlers ) { add( '\
\
\ \
\ ', false ); // Add CSS var stylesheet = ` #timely-backdrop { display: none; position: fixed; left: 0; top: 0; width: 100%; height: 100%; background: rgba( 0, 0, 0, 0.5 ); z-index: 100000; } #timely-event-details-popup { display: none; position: fixed; left: 0; top: 0; width: 100%; height: 100%; padding: 3px; text-align: center; z-index: 100100; overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; } #timely-event-details-popup::-webkit-scrollbar { display: none; } #timely_ed { border: none; padding: 0px; width: 100% !important; max-width: 900px; height: 100%; min-height: 600px; overflow: hidden; margin: 0px auto; } .timely-frame { position: relative; border: none; width: 100%; margin: 0px auto; display: block; transition: none; } /* Initial iFrame height before dynamically updating */ .timely-frame:not(.timely-slider) { height: 400px; } `, /* FES Button style */ stylesheet = fesButtonStyles( stylesheet ); head = document.head || document.getElementsByTagName( 'head' )[0]; style = document.createElement( 'style' ); style.type = 'text/css'; if ( style.styleSheet ) { style.styleSheet.cssText = stylesheet; } else { style.appendChild( document.createTextNode( stylesheet ) ); } if ( head ) { head.appendChild(style); } else { add( '', script ); } window.addEventListener( 'message', function(e) { var message = JSON.parse( JSON.stringify( e.data ) ); if ( message.height && document.getElementById( message.n ) ) { document.getElementById( message.n ).style.height = 'calc(' + message.height + ')'; frame_width = document.getElementById( message.n ).offsetWidth; } if ( message.n && window.frames[message.n] ) { window.frames[message.n].postMessage( { topWindow : location.href }, '*' ); } if ( message.navigate && document.getElementsByClassName( 'timely-script' ).length == 1 ) { window.history.pushState( {}, '', '#' + unescape( message.navigate ) ); if ( message.propagate ) { var f = $( '.timely-frame:not(.timely-slider)' ).id; window.frames[f].postMessage( { hashchange: '#' + message.navigate }, '*' ); } } if ( message.timelyFilters ) { var f = $( '.timely-frame:not(.timely-slider)' ).id; if ( f ) { window.frames[f].postMessage( { timelyFilters: message.timelyFilters }, '*' ); } } // Open ED popup. if ( message.timelyED ) { if ( $( '#timely_ed' ).src != message.timelyED + '?popup=1' ) { $( '#timely-event-details-popup' ).style.display = 'block'; $( '#timely-event-details-popup' ).style.overflowY = 'auto'; $( '#timely-backdrop' ).style.display = 'block'; $( '#timely_ed' ).style.maxWidth = '900px'; $( '#timely_ed' ).style.height = 'calc(100vh - 6px)'; // 6px based on 3px padding add to timely-event-details-popup above $( '#timely_ed' ).src = message.timelyED + ( message.timelyED.indexOf( '?' ) > -1 ? '&' : '?' ) + 'popup=1'; window.timely_url_state = location.hash; /* By passing timelyHash, we ask the parent frame to change it's location hash. When event with such URL and hash will be shared or opedn again, it will display the ED. */ if ( message.timelyHash ) { window.history.pushState( {}, '', unescape( message.timelyHash ) ); } if ( message.timelyFrame && window.frames[message.timelyFrame] ) { window.frames[message.timelyFrame].postMessage( {topWindow : location.href}, '*' ); } } } if ( message.timely_close_popup ) { window.timely_close_popup(); } }, false ); // Send scroll events to the frame for the lazy load. var timely_scroll; window.addEventListener( 'scroll', function ( e ) { if ( ! $( '.timely-frame:not(.timely-slider)' ) || $( '.timely-frame:not(.timely-slider)' ).src.indexOf( '&range=today' ) > -1 ) return; if ( timely_scroll ) return; timely_scroll = setTimeout( function() { var scroll = ( document.documentElement && document.documentElement.scrollTop ) || document.body.scrollTop; if ( scroll > ( ( document.body.offsetHeight / 2 ) - window.innerHeight ) ) { var f = $( '.timely-frame:not(.timely-slider)' ).id; window.frames[f].postMessage( { loadMore: 1 }, '*' ); } setTimeout( function() { timely_scroll = null; }, 500 ); }, 50 ); }, false); // Close the ED popup window.timely_close_popup = function () { $( '#timely-event-details-popup' ).style.display = 'none'; $( '#timely-backdrop' ).style.display = 'none'; $( '#timely_ed' ).style.height = ''; // document.getElementById( 'timely_ed' ).style.height = ''; $( '#timely_ed' ).src = ''; /* Remove hash without causing page to jump */ history.pushState( '', document.title, window.location.pathname + window.location.search ); return false; }; // Open FES popup window.timely_show_fes = function ( url ) { $( '#timely-event-details-popup' ).style.display = 'block'; $( '#timely-event-details-popup' ).style.overflowY = 'visible'; $( '#timely-backdrop' ).style.display = 'block'; $( '#timely_ed' ).style.maxWidth = '100vw'; $( '#timely_ed' ).style.height = '100vh'; $( '#timely_ed' ).src = url; return false; }; window.timely_embed_handlers = true; } } )();

Leave A Comment