|
|
|
@ -35,20 +35,38 @@ |
|
|
|
|
// handled by Rails. As such, we disable the default link-hijacking that
|
|
|
|
|
// Angular's HTML5-mode turns on.
|
|
|
|
|
$(function() { |
|
|
|
|
$(document.body) |
|
|
|
|
.off('click') |
|
|
|
|
$(document.documentElement) |
|
|
|
|
// Prevent angular handling clicks on href="#..." links from other libraries
|
|
|
|
|
// (especially jquery-ui and its datepicker) from routing to <base url>/#
|
|
|
|
|
.on('click', 'a[href^="#"]', (evt) => { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
.on('click', (evt) => { |
|
|
|
|
const target = jQuery(evt.target); |
|
|
|
|
|
|
|
|
|
// Avoid defaulting clicks on elements already removed from DOM
|
|
|
|
|
if (!document.contains(evt.target)) { |
|
|
|
|
evt.preventDefault(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Avoid handling clicks on anything other than a
|
|
|
|
|
const linkElement = target.closest('a'); |
|
|
|
|
if (linkElement.length === 0) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const link = linkElement.attr('href') || ''; |
|
|
|
|
const hashPos = link.indexOf('#'); |
|
|
|
|
|
|
|
|
|
// If link is neither empty nor starts with hash, ignore it
|
|
|
|
|
if (link !== '' && hashPos === -1) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the location to the hash if there is any
|
|
|
|
|
// Since with the base tag, links like href="#whatever" otherwise target to <base>/#whatever
|
|
|
|
|
const link = evt.target.getAttribute('href'); |
|
|
|
|
if (link && link !== '#') { |
|
|
|
|
if (hashPos !== -1 && link !== '#') { |
|
|
|
|
window.location.hash = link; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
evt.preventDefault(); |
|
|
|
|
return false; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|