lib/rdoc/generator/template/rails/resources/js/main.js in sdoc-1.1.0 vs lib/rdoc/generator/template/rails/resources/js/main.js in sdoc-2.0.0

- old
+ new

@@ -5,21 +5,37 @@ } window.highlight = function(url) { var hash = url.match(/#([^#]+)$/); if (hash) { - var parent = document.querySelector('a[name=' + hash[1] + ']').parentElement; + var link = document.querySelector('a[name=' + hash[1] + ']'); + if(link) { + var parent = link.parentElement; - parent.classList.add('highlight'); + parent.classList.add('highlight'); - setTimeout(function() { - parent.classList.remove('highlight'); - }, 1000); + setTimeout(function() { + parent.classList.remove('highlight'); + }, 1000); + } } }; -$(function() { +document.addEventListener("turbolinks:load", function() { highlight('#' + location.hash); $('.description pre').each(function() { hljs.highlightBlock(this); }); }); + +// Keep scroll position for panel +(function() { + var scrollTop = 0; + + addEventListener("turbolinks:before-render", function() { + scrollTop = $('#panel').first().scrollTop(); + }) + + addEventListener("turbolinks:render", function() { + $('#panel').first().scrollTop(scrollTop); + }) +})()