diff --git a/assets/javascript/ajax.js b/assets/javascript/ajax.js index 9855381e5..90e6f206f 100644 --- a/assets/javascript/ajax.js +++ b/assets/javascript/ajax.js @@ -67,6 +67,23 @@ $contribList = $('.contrib-list-container'), $search = $('#category-search'); + // The address is about to change directory depth, which would make the + // browser re-resolve every relative URL on the page against the new + // path. Pin them to the URL the document was rendered against first. + var resolver = document.createElement('a'); + $('a[href], form[action]').each(function() { + var name = (this.nodeName === 'FORM') ? 'action' : 'href', + value = this.getAttribute(name); + + // Skip absolute URLs, protocol-relative URLs, root-relative URLs, and in-page anchors. + if (!value || value[0] === '#' || value[0] === '/' || value.indexOf('//') === 0 || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(value)) { + return; + } + + resolver.href = value; + this.setAttribute(name, resolver.href); + }); + phpbb.history.replaceUrl($this.attr('href')); var getParents = function($self) {