(function () {
if ( typeof window.CustomEvent === "function" ) return false;
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();
function removeElement( element ) {
element && element.parentNode && element.parentNode.removeChild( element );
}
function scrollTo( element, to, duration ) {
if ( duration < 0 ) return;
var difference = to - element.scrollTop;
var perTick = difference / duration * 10;
setTimeout( function () {
element.scrollTop = element.scrollTop + perTick;
if ( element.scrollTop == to ) return;
scrollTo( element, to, duration - 10 );
}, 10 );
}
var myEventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var myEventListener = window[myEventMethod];
var myEventMessage = ( myEventMethod == "attachEvent" ) ? "onmessage" : "message";
myEventListener( myEventMessage, function ( e ) {
/*console.log( 'container > message received:', e, '(', typeof( e ),')' );*/
var val = {};
if ( typeof e.data === 'object' && e.data.id_widget && e.data.id_widget === 13168 ) {
document.getElementById( 'my-iframe-13168' ).height = e.data.height + "px";
var iframeContainer = document.getElementById( 'my-iframe-13168' ).parentNode;
if ( iframeContainer.parentNode.style.position === 'absolute' && iframeContainer.style.overflow !== 'auto' ) {
iframeContainer.style['max-height'] = '100%';
iframeContainer.style.overflow = 'auto';
}
}
if (e.data === 'scrollToTop_13168') {
console.log( 'container > "scrollToTop" message received' );
console.log('scroll Y : ' + window.pageYOffset);
console.log('top iframe : ' + document.getElementById( 'my-iframe-13168' ).getBoundingClientRect().top);
window.scroll(0,window.pageYOffset + document.getElementById( 'my-iframe-13168' ).getBoundingClientRect().top - 50)
document.body.scrollTop = document.body.scrollTop + document.getElementById( 'my-iframe-13168' ).getBoundingClientRect().top - 50;
}
if (/^scrollToProductTop_13168_/.test(e.data)) {
var product_top_position = Number.parseInt(e.data.split("_")[2]);
console.log( 'container > "scrollToProductTop" message received' );
window.scroll(0,window.pageYOffset + document.getElementById( 'my-iframe-13168' ).getBoundingClientRect().top - 50 + product_top_position);
/*document.body.scrollTop = document.body.scrollTop + document.getElementById( 'my-iframe-13168' ).getBoundingClientRect().top - 50 + product_top_position;*/
}
}, false );
document.write( 'Booking Widget in process, please wait' );
var myIframe = document.getElementById( 'my-iframe-13168' );
var toScrollWidget13168 = myIframe.getBoundingClientRect().top-50;
myEventListener( 'scroll', function ( e ) {
if ( myIframe.getBoundingClientRect().top > 0 ) {
var topIframeTmtc = ( window.parent.innerHeight - Math.abs( myIframe.getBoundingClientRect().top ) ) / 2 + 'px';
}else {
var topIframeTmtc = ( ( window.parent.innerHeight - Math.abs( myIframe.getBoundingClientRect().top ) ) / 2 ) + Math.abs( myIframe.getBoundingClientRect().top * 1.5 ) + 'px';
}
/**/console.log( 'container > "scroll" event detected' );
myIframe.contentWindow.postMessage( JSON.stringify({
"scrollTopIframeBound":topIframeTmtc
}), 'https://widget.yoplanning.com/id/13168/' );
});