diff options
| author | Tom Christie | 2014-11-25 16:04:38 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-11-25 16:04:38 +0000 | 
| commit | 330c13296de35d4055c30b5b3642421707565e2b (patch) | |
| tree | b0e568ab66ebd3eef1aad36f104068b90aca8047 /js/base.js | |
| parent | 5769306c10a6ad7a809f2e96b1c82dc61935b9eb (diff) | |
| download | django-rest-framework-330c13296de35d4055c30b5b3642421707565e2b.tar.bz2 | |
Update documentation
Diffstat (limited to 'js/base.js')
| -rw-r--r-- | js/base.js | 53 | 
1 files changed, 53 insertions, 0 deletions
| diff --git a/js/base.js b/js/base.js new file mode 100644 index 00000000..7f18720c --- /dev/null +++ b/js/base.js @@ -0,0 +1,53 @@ + +/* Highlight */ +$( document ).ready(function() { +    hljs.initHighlightingOnLoad(); +    $('table').addClass('table'); +}); + + +/* Scrollspy */ +var navHeight = $('.navbar').outerHeight(true) + 10 + +$('body').scrollspy({ +    target: '.bs-sidebar', +    offset: navHeight +}) + + +/* Prevent disabled links from causing a page reload */ +$("li.disabled a").click(function() { +    event.preventDefault(); +}); + + +/* Adjust the scroll height of anchors to compensate for the fixed navbar */ +window.disableShift = false; +var shiftWindow = function() { +    if (window.disableShift) { +        window.disableShift = false; +    } else { +        /* If we're at the bottom of the page, don't erronously scroll up */ +        var scrolledToBottomOfPage = ( +            (window.innerHeight + window.scrollY) >= document.body.offsetHeight +        ); +        if (!scrolledToBottomOfPage) { +            scrollBy(0, -60); +        }; +    }; +}; +if (location.hash) {shiftWindow();} +window.addEventListener("hashchange", shiftWindow); + + +/* Deal with clicks on nav links that do not change the current anchor link. */ +$("ul.nav a" ).click(function() { +    var href = this.href; +    var suffix = location.hash; +    var matchesCurrentHash = (href.indexOf(suffix, href.length - suffix.length) !== -1); +    if (location.hash && matchesCurrentHash) { +        /* Force a single 'hashchange' event to occur after the click event */ +        window.disableShift = true; +        location.hash=''; +    }; +}); | 
