/* Copyright (c) 2019 Synology Inc. All rights reserved. */

ModPhotoStationUtil={showChooser:function(){document.querySelector("html").style.overflow="hidden";document.querySelector("#photostation-div-chooser").style.visibility="visible"},origin:(function(){var a;if(!window.location.origin){a=window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")}else{a=window.location.origin}return a})(),initChooser:function(){var b=document.querySelector("#photostation-div-chooser").children[0],a="";if(!b){return}a="origin="+window.encodeURIComponent(ModPhotoStationUtil.origin);a+="&lang="+window.encodeURIComponent(ModPhotoStationUtil.lang);a+="&t=1";b.src=ModPhotoStationUtil.target+"/photo/cms/ImageChooser.php?"+a},initSlideShow:function(){var c=document.querySelector("#photostation-iframe-slideshow"),a="";if(!c){return}var b=document.querySelector("#photostation-div-slideshow").children[0];b.innerHTML="";b.appendChild(c);a="origin="+window.encodeURIComponent(ModPhotoStationUtil.origin);a+="&id="+window.encodeURIComponent(ModPhotoStationUtil.photostation_id);c.src=ModPhotoStationUtil.target+"/photo/cms/slideshow.php?"+a},initLightBox:function(){var b=document.querySelector("#photostation-iframe-lightbox"),a="";if(!b){return}a="origin="+window.encodeURIComponent(ModPhotoStationUtil.origin);a+="&id="+window.encodeURIComponent(ModPhotoStationUtil.photostation_id);a+="&target="+window.encodeURIComponent(ModPhotoStationUtil.target);a+="&lang="+window.encodeURIComponent(ModPhotoStationUtil.lang);a+="&lang="+window.encodeURIComponent(ModPhotoStationUtil.lang);a+="&share="+window.encodeURIComponent(ModPhotoStationUtil.photostation_share);b.src=ModPhotoStationUtil.target+"/photo/cms/lightbox.php?"+a}};window.addEventListener("message",function(c){switch(c.data.cls){case"lightbox":switch(c.data.act){case"ready":ModPhotoStationUtil.originLightbox=c.data.data.origin;break;case"show":var d=document.querySelector("#photostation-iframe-lightbox");d.contentWindow.postMessage(c.data.data,ModPhotoStationUtil.originLightbox);d.style.visibility="visible";break;case"hide":document.querySelector("#photostation-iframe-lightbox").style.visibility="hidden";break;default:console.log("Unknown action for lightbox: "+c.data.act);break}break;case"slideshow":switch(c.data.act){case"show":document.querySelector("#photostation-iframe-slideshow").style.visibility="visible";break;default:console.log("Unknown action for slideshow: "+c.data.act);break}break;case"chooser":switch(c.data.act){case"ready":var b=document.querySelector("#photostation-button-chooser");if(b){b.disabled=false}break;case"insert":var a=document.querySelector("#photostation-iframe-slideshow");a.style.visibility="hidden";a.src=ModPhotoStationUtil.target+"/photo/cms/slideshow.php?origin="+ModPhotoStationUtil.origin+"&id="+c.data.data.id;document.querySelector("#photostation-iframe-lightbox").src=ModPhotoStationUtil.target+"/photo/cms/lightbox.php?origin="+ModPhotoStationUtil.origin+"&id="+c.data.data.id+"&target="+encodeURIComponent(ModPhotoStationUtil.target)+"&lang="+ModPhotoStationUtil.lang+"&share="+c.data.share;var e=new XMLHttpRequest();e.onreadystatechange=function(){if(this.readyState!==this.DONE){return}};e.open("GET","wp-admin/admin-ajax.php?action=photostation_save&id="+c.data.data.id+"&share="+c.data.share);e.send();case"hide":document.querySelector("#photostation-div-chooser").style.visibility="hidden";document.querySelector("html").style.overflow="scroll";break;default:console.log("Unknown action for chooser: "+c.data.act);break}break;default:console.log("Unknown message class: "+c.data.cls);break}});