Website progressive enhancement: titles anchors Section titles are now clickable and link to #whatever-section-id Allow for easy deep-linking
Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/1df6d40c Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/1df6d40c Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/1df6d40c Branch: refs/heads/develop Commit: 1df6d40cb0c99319c3ff351e1c898a35f9a7b785 Parents: e110875 Author: Paul Merlin <[email protected]> Authored: Sat Jul 11 17:39:12 2015 +0200 Committer: Paul Merlin <[email protected]> Committed: Sat Jul 11 17:39:12 2015 +0200 ---------------------------------------------------------------------- .../src/resources/js/progressive-enhancement.js | 29 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/1df6d40c/manual/src/resources/js/progressive-enhancement.js ---------------------------------------------------------------------- diff --git a/manual/src/resources/js/progressive-enhancement.js b/manual/src/resources/js/progressive-enhancement.js index 17d899f..bbf6f86 100644 --- a/manual/src/resources/js/progressive-enhancement.js +++ b/manual/src/resources/js/progressive-enhancement.js @@ -45,9 +45,7 @@ $( document ).ready( function($){ var dt = target.parent(); var dd = dt.next(); // Scroll - $.scrollTo( dt, 200, { - 'offset': -96 - }); + $.scrollTo( dt, 200, { 'offset': -96 }); // Highlight dd.fadeOut(50).fadeIn(200); } @@ -110,6 +108,31 @@ $( document ).ready( function($){ } } ); + // Title links to their own anchor + $( "body > div.section .title" ).each( function( idx, title ) { + var $title = $( title ); + var id = $title.find( 'a' ).attr( 'id' ); + if( id ) { + $title.click( function() { + window.location.hash = id; + } ); + } + } ); + + // Scroll down a bit on hash change so that target is not hidden under the floating top menu + function scrollToHash( hash ) { + if( hash ) { + var $target = $( hash ); + if( $target ) { + setTimeout( function() { $.scrollTo( $target, 100, { 'offset': -96 }) }, 50 ); + } + } + }; + $( window ).bind( 'hashchange', function() { + scrollToHash( window.location.hash ); + }); + scrollToHash( window.location.hash ); + // Enhance left nav $( "div.sub-nav div.toc dt" ).each( function( idx, dt ) { var $dt = $( dt );
