Mobile and standard anchor link fix

This is Sarah Martin's script for fixing anchor links in Brine family.

problem 1
Mobile menu links don’t work
problem 2
If you use regular anchor links in the nav (not index page sections) then the page doesn’t scroll to the correct spot on page change (assumes multi page set up).

<script>
 function anchorLinks(){
      Y.all("a.Mobile-overlay-nav-item").on('click', function() {
         Y.one('body').removeClass('is-mobile-overlay-active');
      });
      Y.all("a.Mobile-overlay-folder-item").on('click', function() {
      Y.one('body').removeClass('is-mobile-overlay-active');
   });



  if(!Y.one('.collection-type-index')){

      Y.all(".Mobile-overlay-nav--primary .Mobile-overlay-nav-item").each(function(){
      this.on("click", function(){
         var newURL = "http://"+window.location.host + (this.getAttribute('href'));
         window.location.href = newURL;
       });
    });
  }
}


function scrollToURLAnchor(){
 setTimeout(function(){
   if(window.location.hash){

     $('html, body').animate({
         scrollTop: $(window.location.hash).offset().top
     }, 500,  function () {

     });
   }
   }, 500);
}

Y.on('domready', function(){
  anchorLinks();
  scrollToURLAnchor();
});

window.addEventListener('mercury:load', anchorLinks);
window.addEventListener('mercury:load', scrollToURLAnchor);

</script>

Reference

Circle forum