diff options
-rw-r--r-- | views/message.erb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/views/message.erb b/views/message.erb index fa58a63..40c333a 100644 --- a/views/message.erb +++ b/views/message.erb @@ -86,11 +86,39 @@ </div> <script> + // highlight based on the specified reference in url var lineNumber = window.location.hash.substr(1).replace("L", ""); + highlightLine(lineNumber); - if(!isNaN(parseFloat(lineNumber)) && isFinite(lineNumber)){ - var lines = document.getElementById("ag-message-body").innerHTML.split("\n"); - lines[parseFloat(lineNumber) - 1] = '<div style="display: inline-block;background-color:#FFF3CD;">' + lines[parseFloat(lineNumber) - 1] + '</div>' - document.getElementById("ag-message-body").innerHTML = lines.join("\n"); + // highlight based on parameter "h" + var url = new URL(window.location.href); + var highlights = url.searchParams.get("h"); + + highlights.split(",").forEach(function(highlight){ + if(highlight.split("-").length == 2){ + var leftPart = highlight.split("-")[0]; + var rightPart = highlight.split("-")[1]; + if(isNumeric(leftPart) && isNumeric(rightPart) && parseFloat(leftPart) <= parseFloat(rightPart)){ + for(var i = parseFloat(leftPart); i <= parseFloat(rightPart); i++){ + highlightLine(i); + } + } + }else{ + highlightLine(highlight); + } + }) + + // utility functions + + function highlightLine(lineNumber) { + if(isNumeric(lineNumber)){ + var lines = document.getElementById("ag-message-body").innerHTML.split("\n"); + lines[parseFloat(lineNumber) - 1] = '<div style="display: inline-block;background-color:#FFF3CD;">' + lines[parseFloat(lineNumber) - 1] + '</div>' + document.getElementById("ag-message-body").innerHTML = lines.join("\n"); + } + } + + function isNumeric(possibleNumber) { + return !isNaN(parseFloat(possibleNumber)) && isFinite(possibleNumber) } </script>
\ No newline at end of file |