$(function() {

    var $documentNav = $('.document-nav');

    if($documentNav.length) {

        var targets = []
          , $window = $(window);

        $documentNav.find('a').each(function() {
            targets.push( $($(this).attr('href')) )
        });

        function setActive($current) {
            var $parent = $current.closest('li')
              , $parentParent = $parent.parent().closest('li');


            $documentNav.find('.current, .active').removeClass('current active')
            $current.addClass('current')

            if($parentParent.length) {
                $parentParent.addClass('active')
            } else {
                $parent.addClass('active')
            }
        }

        // HASH change, update menu
        // ========================
        $window.on('hashchange', function() {
            setTimeout(function() {
                setActive($documentNav.find('[href='+location.hash+']'))
            }, 1);
        });

        // Scroll, update menu
        // ===================
        $window.on('scroll', function() {
            var scrollTop = $window.scrollTop();

            $.each( targets, function($index, $el) {
                var sectionBottom = (targets[$index+1] && targets[$index+1].offset().top - 1) || $window.height()
                if ($el.length && scrollTop - sectionBottom < -48) {
                    setActive($documentNav.find('[href=#'+$el.attr('id')+']'))
                    return false;
                }
            });
        });
    }
});

@@ -140,16 +140,47 @@
 (window)
+%0A          , changeHash = false
 ;%0A%0A     
@@ -319,19 +319,79 @@
 ive(
-$current) %7B
+hash) %7B%0A            var $current = $documentNav.find('%5Bhref='+hash+'%5D')
 %0A   
@@ -399,19 +399,19 @@
         
-var
+  ,
  $parent
@@ -727,16 +727,29 @@
       %7D 
+%0A            
 else %7B%0A 
@@ -808,226 +808,147 @@
   %7D%0A
-   
+%0A
      
-%7D%0A%0A
        
- // HASH change, update menu%0A        // ========================%0A        $window.on('hashchange', function() %7B%0A            setTimeout(function() %7B%0A                setActive($documentNav.find('%5Bhref='+
+if(history.pushState) %7B%0A                history.pushState(null, null, hash);%0A            %7D%0A            else %7B%0A                
 loca
@@ -956,22 +956,24 @@
 ion.hash
-+'%5D'))
+ = hash;
 %0A       
@@ -982,13 +982,8 @@
    %7D
-, 1);
 %0A   
@@ -980,34 +980,32 @@
      %7D%0A        %7D
-);
 %0A%0A        // Scr
@@ -1142,16 +1142,63 @@
 llTop();
+%0A            console.log ('scroll', scrollTop);
 %0A%0A      
@@ -1461,33 +1461,9 @@
 ive(
-$documentNav.find('%5Bhref=
+'
 #'+$
@@ -1475,21 +1475,16 @@
 tr('id')
-+'%5D')
 )%0A      

Fix scrollSpy bug preventing original scroll to happen if a hash is present