diff --git a/rfc/xr.go b/rfc/xr.go index 5da6b2b..227feea 100644 --- a/rfc/xr.go +++ b/rfc/xr.go @@ -292,6 +292,7 @@ var indexHTML = ` @@ -300,11 +301,11 @@ body { margin: 0; padding: 0; font-family: 'ubuntu', 'lato', sans-serif; }
..., index
- +
..., index
- +
@@ -325,12 +326,15 @@ function updateHash() { const rfc = trimDotHTML(rfciframe.contentWindow.location.pathname.substring(basepath.length))+hashline(rfciframe.contentWindow.location.hash) codefile.innerText = code rfcfile.innerText = rfc - console.log('updating window hash') + const nhash = '#' + code + ',' + rfc + if (location.hash === nhash || location.hash === '' && nhash === '#code,rfc') { + return + } + console.log('updating window hash', {code, rfc}) changinghash = true - location.hash = '#' + code + ',' + rfc + location.hash = nhash window.setTimeout(() => { changinghash = false - console.log('done updating updating window hash') }, 0) } codeiframe.addEventListener('load', function(e) { @@ -356,13 +360,10 @@ rfciframe.addEventListener('load', function(e) { }) }) window.addEventListener('hashchange', function() { - console.log('window hashchange', location.hash) - if (changinghash) { - console.log('not updating iframes src') - return + console.log('window hashchange', location.hash, changinghash) + if (!changinghash) { + updateIframes() } - console.log('updating iframes src') - updateIframes() }) function hashlink2src(s) { const t = s.split(':') @@ -377,22 +378,32 @@ function hashlink2src(s) { console.log('hashlink', s, h) return h } +// We need to replace iframes. Before, we replaced the "src" attribute. But +// that adds a new entry to the history, while replacing an iframe element does +// not. The added entries would break the browser back button... +function replaceIframe(iframe, src) { + const o = iframe + iframe = document.createElement('iframe') + iframe.classList.add('iframe') + iframe.setAttribute('src', src) + o.replaceWith(iframe) + return iframe +} function updateIframes() { const h = location.hash.length > 1 ? location.hash.substring(1) : 'code,rfc' const t = h.split(',') const codesrc = hashlink2src(t[0]) const rfcsrc = hashlink2src(t[1]) - codeiframe.src = codesrc - rfciframe.src = rfcsrc - if (codesrc) { + if (codeiframe.src !== codesrc) { + codeiframe = replaceIframe(codeiframe, codesrc) codefile.innerText = t[0] } - if (rfcsrc) { + if (rfciframe.src !== rfcsrc) { + rfciframe = replaceIframe(rfciframe, rfcsrc) rfcfile.innerText = t[1] } } window.addEventListener('load', function() { - console.log('document load') updateIframes() }) @@ -407,6 +418,7 @@ var codeTemplate = htmltemplate.Must(htmltemplate.New("code").Parse(`code index @@ -433,6 +445,7 @@ var rfcTemplate = htmltemplate.Must(htmltemplate.New("rfc").Parse(`