]> granicus.if.org Git - docbook-dsssl/commitdiff
Fixed bug where anchors in pages landed beneath the banner.
authorDavid Cramer <david@thingbag.net>
Tue, 26 Apr 2011 02:33:11 +0000 (02:33 +0000)
committerDavid Cramer <david@thingbag.net>
Tue, 26 Apr 2011 02:33:11 +0000 (02:33 +0000)
xsl/webhelp/template/common/main.js

index 449cda8b501e2bf3ecff92c1fbdd5d2264dba229..925d6565d0aa654f2924beadb81aeb8b74365db8 100755 (executable)
@@ -13,6 +13,28 @@ var treesettings = {
 };
 
 $(document).ready(function() {
+
+
+       // When you click on a link to an anchor, scroll down 
+       // 105 px to cope with the fact that the banner
+       // hides the top 95px or so of the page.
+       // This code deals with the problem when 
+       // you click on a link within a page.
+       $('a[href*=#]').click(function() {
+               if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
+                   && location.hostname == this.hostname) {
+                   var $target = $(this.hash);
+                   $target = $target.length && $target
+                       || $('[name=' + this.hash.slice(1) +']');
+                   if ($target.length) {
+                       var targetOffset = $target.offset().top - 105;
+                       $('html,body')
+                           .animate({scrollTop: targetOffset}, 200);
+                       return false;
+                   }
+               }
+           });
+
     //  $("#showHideHighlight").button(); //add jquery button styling to 'Go' button
     //Generate tabs in nav-pane with JQuery
     $(function() {
@@ -53,6 +75,18 @@ $(document).ready(function() {
 
     syncToc(); //Synchronize the toc tree with the content pane, when loading the page.
     //$("#doSearch").button(); //add jquery button styling to 'Go' button
+
+    // When you click on a link to an anchor, scroll down 
+    // 105 px to cope with the fact that the banner
+    // hides the top 95px or so of the page.
+    // This code deals with the problem when 
+    // you click on a link from another page. 
+    var hash = window.location.hash;
+    if(hash){ 
+       var targetOffset = $(hash).offset().top - 105;
+       $('html,body').animate({scrollTop: targetOffset}, 200);
+       return false;
+    }
 });
 
 /**
@@ -173,7 +207,7 @@ function showHideToc() {
 }
 
 /**
- * Code for searh highlighting
+ * Code for search highlighting
  */
 var highlightOn = true;
 function searchHighlight(searchText) {