From 54d47e1e245d59b5844e181fcb3154c862c956eb Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 7 Mar 2016 15:37:14 -0500 Subject: [PATCH] allow data-ajaxify=false for external links to override config.openOutgoingLinksInNewTab --- public/src/ajaxify.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 0d894b588e..98efc424f1 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -275,17 +275,26 @@ $(document).ready(function() { $(document.body).on('click', 'a', function (e) { if (this.target !== '' || (this.protocol !== 'http:' && this.protocol !== 'https:')) { return; - } else if (hrefEmpty(this.href) || this.protocol === 'javascript:' || $(this).attr('data-ajaxify') === 'false' || $(this).attr('href') === '#') { + } + + var internalLink = this.host === '' || // Relative paths are always internal links + (this.host === window.location.host && this.protocol === window.location.protocol && // Otherwise need to check if protocol and host match + (RELATIVE_PATH.length > 0 ? this.pathname.indexOf(RELATIVE_PATH) === 0 : true)); // Subfolder installs need this additional check + + if ($(this).attr('data-ajaxify') === 'false') { + if (!internalLink) { + return; + } else { + return e.preventDefault(); + } + } + + if (hrefEmpty(this.href) || this.protocol === 'javascript:' || $(this).attr('href') === '#') { return e.preventDefault(); } if (!e.ctrlKey && !e.shiftKey && !e.metaKey && e.which === 1) { - if ( - this.host === '' || // Relative paths are always internal links... - (this.host === window.location.host && this.protocol === window.location.protocol && // Otherwise need to check that protocol and host match - (RELATIVE_PATH.length > 0 ? this.pathname.indexOf(RELATIVE_PATH) === 0 : true)) // Subfolder installs need this additional check - ) { - // Internal link + if (internalLink) { var pathname = this.href.replace(rootUrl + RELATIVE_PATH + '/', ''); // Special handling for urls with hashes @@ -297,7 +306,6 @@ $(document).ready(function() { } } } else if (window.location.pathname !== '/outgoing') { - // External Link if (config.openOutgoingLinksInNewTab) { window.open(this.href, '_blank'); e.preventDefault();