You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to MkDocs and love it so far. To make it fit my needs, I'm writing a live-edit inspired plugin. During editing "livereload" shall be disabled for that specific page and for that client. Is there a way to do this from the client or from the server for that specific client?
I tried many things, but so far the best solution I cam up with is making the stop and poll functions as well as the callback for the "visibilitychange" event in "livereload" global.
letlivereload_poll;letlivereload_stop;letlivereload_onVisibilitychange;varlivereload=function(epoch,requestId){varreq,timeout;livereload_poll=function(){req=newXMLHttpRequest();req.onloadend=function(){if(parseFloat(this.responseText)>epoch){location.reload();}else{timeout=setTimeout(livereload_poll,this.status===200 ? 0 : 3000);}};req.open("GET","/livereload/"+epoch+"/"+requestId);req.send();}livereload_stop=function(){if(req){req.abort();}if(timeout){clearTimeout(timeout);}req=timeout=undefined;};window.addEventListener("load",function(){if(document.visibilityState==="visible"){livereload_poll();}});livereload_onVisibilitychange=function(){if(document.visibilityState==="visible"){livereload_poll();}else{livereload_stop();}}document.addEventListener("visibilitychange",livereload_onVisibilitychange);window.addEventListener("beforeunload",livereload_stop);console.log('Enabled live reload');}
This allows me to stop "livereload" by calling livereload_stop and removing the event. Reactivating "livereload" is then done by adding the event and calling livereload_poll.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm new to MkDocs and love it so far. To make it fit my needs, I'm writing a live-edit inspired plugin. During editing "livereload" shall be disabled for that specific page and for that client. Is there a way to do this from the client or from the server for that specific client?
I tried many things, but so far the best solution I cam up with is making the
stop
andpoll
functions as well as the callback for the "visibilitychange" event in "livereload" global.This allows me to stop "livereload" by calling
livereload_stop
and removing the event. Reactivating "livereload" is then done by adding the event and callinglivereload_poll
.Beta Was this translation helpful? Give feedback.
All reactions