diff options
Diffstat (limited to 'pastepy/static/js/view.js')
-rw-r--r-- | pastepy/static/js/view.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pastepy/static/js/view.js b/pastepy/static/js/view.js new file mode 100644 index 0000000..0242aa3 --- /dev/null +++ b/pastepy/static/js/view.js @@ -0,0 +1,30 @@ +function set_highlight(line) { + var line = 'codeline-' + line + var codeline = document.getElementById(line); + if (codeline) { + codeline.className = 'selected'; + } +} +function cleanup() { + var elements = document.getElementsByClassName('selected'); + for (var i = 0; i < elements.length; i++) { + elements[i].className = ''; + } +} +window.addEventListener('load', function(event) { + var line = document.location.hash.substr(6); + if (line) { + set_highlight(line); + } + var linenodivs = document.getElementsByClassName('linenodiv'); + if (linenodivs.length === 0) { + return; + } + var as = linenodivs[0].getElementsByTagName('a'); + for (var i = 0; i < as.length; i++) { + as[i].onclick = function(event) { + cleanup(); + set_highlight(event.target.text.trim()); + } + } +}); |