# HG changeset patch # User Marcin Lulek # Date 2016-09-13 15:31:44 # Node ID 1deb9d88b49f5dc59412b6b0beebf177ba9c8e58 # Parent 5bb62bb1e73af8c7454c6d208987aa18e173ed7f frontend: use splitDelimitedHash when dealing with hash parsing diff --git a/rhodecode/public/js/src/rhodecode.js b/rhodecode/public/js/src/rhodecode.js --- a/rhodecode/public/js/src/rhodecode.js +++ b/rhodecode/public/js/src/rhodecode.js @@ -366,15 +366,9 @@ function offsetScroll(element, offset){ // At the time of development, Chrome didn't seem to support jquery's :target // element, so I had to scroll manually if (location.hash) { - var splitIx = location.hash.indexOf('/?/'); - if (splitIx !== -1){ - var loc = location.hash.slice(0, splitIx); - var remainder = location.hash.slice(splitIx + 2); - } - else{ - var loc = location.hash; - var remainder = null; - } + var result = splitDelimitedHash(location.hash); + var loc = result.loc; + var remainder = result.remainder; if (loc.length > 1){ var lineno = $(loc+'.lineno'); if (lineno.length > 0){ diff --git a/rhodecode/public/js/src/rhodecode/utils/string.js b/rhodecode/public/js/src/rhodecode/utils/string.js --- a/rhodecode/public/js/src/rhodecode/utils/string.js +++ b/rhodecode/public/js/src/rhodecode/utils/string.js @@ -74,6 +74,29 @@ String.prototype.capitalizeFirstLetter = /** + * Splits remainder + * + * @param input + */ +function splitDelimitedHash(input){ + var splitIx = input.indexOf('/?/'); + if (splitIx !== -1){ + var loc = input.slice(0, splitIx); + var remainder = input.slice(splitIx + 2); + } + else{ + var loc = input; + var remainder = null; + } + //fixes for some urls generated incorrectly + var result = loc.match('#+(.*)'); + if (result !== null){ + loc = '#' + result[1]; + } + return {loc:loc, remainder: remainder} +} + +/** * Escape html characters in string */ var entityMap = { diff --git a/rhodecode/templates/changeset/changeset.html b/rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html +++ b/rhodecode/templates/changeset/changeset.html @@ -372,9 +372,9 @@ } }); - if (location.href.indexOf('#') != -1) { - var id = '#'+location.href.substring(location.href.indexOf('#') + 1).split('#'); - var line = $('html').find(id); + if (location.hash) { + var result = splitDelimitedHash(location.hash); + var line = $('html').find(result.loc); offsetScroll(line, 70); } diff --git a/rhodecode/templates/pullrequests/pullrequest_show.html b/rhodecode/templates/pullrequests/pullrequest_show.html --- a/rhodecode/templates/pullrequests/pullrequest_show.html +++ b/rhodecode/templates/pullrequests/pullrequest_show.html @@ -412,9 +412,9 @@ %endif