-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlivereload.min.js
5 lines (5 loc) · 1.7 KB
/
livereload.min.js
1
2
3
4
5
setTimeout(()=>{let isModal=!!document.querySelector("body.modal");if(isModal)return;let reloading=!1;let warningShown=!1;if(window.self!==window.top)return;let redirecttimeout=0;let evtSource;let startStream=function(){let url=LiveReloadUrl+"?rockfrontend-livereload="+LiveReloadPage;evtSource=new EventSource(url,{withCredentials:!0});evtSource.onmessage=function(event){let changed=event.data;if(!changed)return;if(reloading)return;console.log(changed);if(document.hidden){console.log("tab is not visible - waiting for reload");return}
if(LiveReloadForce){document.querySelectorAll(".InputfieldStateChanged").forEach((input)=>{input.classList.remove("InputfieldStateChanged")})}else{if(document.querySelectorAll(".InputfieldStateChanged").length){if(!warningShown){console.log("detected change - unsaved changes prevent reload");setTimeout(()=>{UIkit.notification({message:"Unsaved changes prevent reload - use $config->livereloadForce to force reload.",status:"warning",pos:"top-center",timeout:0,})},200);warningShown=!0}
return}
if(document.querySelectorAll("#pw-panel-shade").length){console.log("detected change - open panel prevents reload");UIkit.notification({message:"Open panel prevents reload - use $config->livereloadForce to force reload.",status:"warning",pos:"top-center",timeout:0,});return}}
let cnt=localStorage.getItem("livereload-count")||0;localStorage.setItem("livereload-count",++cnt);console.log("detected change - reloading "+cnt);reloading=!0;setTimeout(()=>{document.location.reload(!0)},redirecttimeout)};evtSource.onerror=function(event){if(document.querySelector("#tracy-bs"))return;console.log("Error occurred in EventSource.")}};startStream();console.log("RockFrontend is listening for file changes...")},1000)