Anonymous avatar Anonymous committed 3998983

reverts r1411625, providing a different fix for jumping to a better location for anchor links - for #289 (from olemis)

Comments (0)

Files changed (1)

bhtheme/htdocs/js/theme.js

   var h = target.height();
   target.parent('.stickyBox').height(h);
 
-  // Create style tag to fix anchor position
-  function _sticky_offset_rules(_h) {
-    return '.stickyBox~* form[id], .stickyBox~* div[id] { margin-top:-' +
-      _h + 'px; padding-top: ' + _h + 'px } ' +
-      '.stickyBox, .stickyBox [id] { margin-top: 0px ; padding-top: 0px }';
-  }
-  $('<style id="sticky-offset" /> ').text( _sticky_offset_rules(h) )
-      .appendTo('head');
-
   target = h = null;
   $(window).on('scroll.affix.data-api', function() {
-      var affix_data = $(selector).data('affix');
       var target = $(selector);
+      var affix_data = target.data('affix');
 
       if (affix_data && !affix_data.affixed) {
         var h = target.height();
         target.parent('.stickyBox').height(h);
-        $('style#sticky-offset').text(_sticky_offset_rules(h))
       }
       else {
         target.parent('.stickyBox').css('height', '');
       }
     })
+  $(function() {
+      var prev_onhashchange = window.onhashchange;
+
+      window.onhashchange = function() {
+        prev_onhashchange();
+        var target = $(selector);
+        var affix_data = target.data('affix');
+    
+        if (affix_data && !affix_data.affixed)
+          window.scrollBy(0, -target.height());
+      }
+    })
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.