Craft and AJAX page transitions - how to exclude local hash links from executing AJAX?
The function you mention isn't the problem. It isn't being called because, as you say, the exclusion clause is working perfectly. 

But you also have a hook on the window.popstate which is triggered when you change the URL (by adding #contact to it for example).

This hook, as below, subsequently fires the loadPage function you have coded:

$(window).on("popstate", function(e) {
    // -------------------------------------
    //   If there was an AJAX page transition already,
    //   then AJAX page load the requested page from the back or forwards button click.
    //   Variable initially set after the $main variable.
    // -------------------------------------
    if (changedPage) loadPage(location.href);
  });


See more on the popstate event:

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate



As others have mentioned though, this is Javascript specific rather than Craft, so should probably be moved or archived?