diff options
author | Rasmus Andersson <rasmus@notion.se> | 2018-02-20 12:38:51 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2018-02-20 12:38:51 +0300 |
commit | 9f367901ef4e6df00eb786ac99fcdc21ed5e69f0 (patch) | |
tree | 44ea3e320dd96f541ed94f5a032bff70050afc51 /docs/_includes | |
parent | 761638ef42ec443429889c548b758c06a516839a (diff) | |
download | inter-9f367901ef4e6df00eb786ac99fcdc21ed5e69f0.tar.xz |
website: major update
Diffstat (limited to 'docs/_includes')
-rw-r--r-- | docs/_includes/autoreload-in-debug.html | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/docs/_includes/autoreload-in-debug.html b/docs/_includes/autoreload-in-debug.html new file mode 100644 index 000000000..13840defa --- /dev/null +++ b/docs/_includes/autoreload-in-debug.html @@ -0,0 +1,46 @@ +{% if site.safe == false %} +<!-- During authoring, this automatically reloads the post as its changing --> +<script type="text/javascript"> +(function() { +var qs = document.location.search; +var current_etag = qs.match(/etag=("?[a-zA-Z0-9_-]+)/); +if (current_etag !== null) { current_etag = current_etag[1]; } +var scrolly = qs.match(/scrolly=([0-9]+)/); +if (scrolly) { + scrolly = parseInt(scrolly[1]); + if (scrolly > 0) { + window.scrollTo(window.scrollX, scrolly); + setTimeout(function () { + window.scrollTo(window.scrollX, scrolly); + }, 10); + } +} + +function check() { + var r = new XMLHttpRequest(); + var url = document.location.href + ((qs && qs !== '') ? '&' : '?') + 'r=' + Math.random(); + r.open('GET', url, true); + r.onreadystatechange = function() { + if (r.readyState == 4){ + var found_etag = r.getResponseHeader('Etag'); + if (found_etag) { + found_etag = found_etag.replace(/^"|"$/g); + } + //console.log('current_etag:', current_etag, 'found_etag:', found_etag); + if (current_etag === null) { + current_etag = found_etag; + } else if (found_etag !== current_etag) { + document.location.search = + '?etag=' + encodeURIComponent(found_etag) + + '&scrolly=' + window.scrollY; + return; + } + setTimeout(check, 500); + } + }; + r.send(null); +} +check(); +})(); +</script> +{% endif %}
\ No newline at end of file |