'use strict';var novicell=novicell||{};novicell.overlay=novicell.overlay||new function(){var self=this;var options={};var overlayElem;var overlayContainer;var overlayContent;var backdrop;var content;var onCreate;var onLoaded;var onDestroy;var isVideo=false;this.create=function(opts){var self=this;options=opts;if(typeof options.onCreate==='function'){options.onCreate();}
self.destroy();if(options.hasOwnProperty('selector')&&options.selector!==null){var element=document.querySelector(options.selector);if(element){content=element.innerHTML;constructOverlay();}else{console.warn('novicell.overlay: element does not exist. Please provide a valid selector for use in document.querySelector.');return;}}
else if(options.hasOwnProperty('videoId')){if(options.videoId!==null){var src='';isVideo=true;if(options.type=='vimeo'){src='https://player.vimeo.com/video/'+ options.videoId;}
else if(options.type=='youtube'){src='https://www.youtube.com/embed/'+ options.videoId+'?ecver=2';}
else{return;}
var iframe=document.createElement('iframe');iframe.setAttribute('src',src);iframe.setAttribute('frameborder',0);iframe.setAttribute('allowfullscreen','');iframe.setAttribute('width','100%');iframe.setAttribute('height','100%');content=iframe.outerHTML;constructOverlay();}else{console.warn('novicell.overlay: video-id is empty. Please provide a video-id for use in video embed code (we support only Vimeo and YouTube).');return;}}
else{console.error('novicell.overlay: no content to display! Please set a selector or a url to load.')
return;}};this.destroy=function(){if(document.querySelector('#js-novi-overlay')){overlayElem.parentElement.removeChild(overlayElem);backdrop.parentElement.removeChild(backdrop);document.removeEventListener('keyup',self.destroy);document.documentElement.classList.remove('no-scroll','novi-overlay--open');isVideo=false;if(typeof options.onDestroy==='function'){options.onDestroy();}}};function constructOverlay(){setupBackdrop();setupOverlay();setupOverlayContainer();setupCloseButton();document.documentElement.classList.add('no-scroll');if(typeof options.onLoaded==='function'){options.onLoaded();}};function setupBackdrop(){backdrop=document.createElement('div');backdrop.classList.add('novi-backdrop');backdrop.id='js-novi-backdrop';backdrop.addEventListener('click',function(e){if(e.target.classList.contains('novi-overlay')||e.target.classList.contains('novi-overlay__container')){self.destroy();}});document.querySelector('body').appendChild(backdrop);};function setupOverlay(){overlayElem=document.createElement('div');overlayElem.classList.add('novi-overlay');overlayElem.id='js-novi-overlay';if(options.hasOwnProperty('class')){overlayElem.classList.add(options.class);}
backdrop.appendChild(overlayElem);};function setupOverlayContainer(){overlayContainer=document.createElement('div');overlayContainer.classList.add('novi-overlay__container');overlayContent=document.createElement('div');overlayContent.classList.add('novi-overlay__content');if(isVideo){overlayContent.classList.add('novi-overlay__content--video')}
overlayContent.innerHTML=content;overlayContainer.appendChild(overlayContent);overlayElem.appendChild(overlayContainer);};function setupCloseButton(){var btnClose=document.createElement('button');btnClose.classList.add('novi-overlay-close','button--close');btnClose.type='button';btnClose.id='js-novi-overlay-close';btnClose.addEventListener('click',self.destroy);document.addEventListener('keydown',function(e){if(e.keyCode===27){self.destroy();}});overlayContent.appendChild(btnClose);};function get(url){return new Promise(function(resolve,reject){var req=new XMLHttpRequest();req.open('GET',url);req.onload=function(){if(req.status>=200&&req.status<400){resolve(req.response);}else{reject(Error(req.statusText));}};req.onerror=function(){reject(Error("Network Error"));};req.send();});};}();