From: John Firebaugh Date: Mon, 2 Dec 2013 22:25:45 +0000 (-0800) Subject: Restore correct link behavior with modifier keys X-Git-Tag: live~5129^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/10c8be0cb909e9473029890b95ea881f1a63c32f Restore correct link behavior with modifier keys Fixes #562 --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 273ce581a..c5532cfc4 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -287,8 +287,19 @@ $(document).ready(function () { OSM.router.load(); $(document).on("click", "a", function(e) { - if (e.isDefaultPrevented() || e.isPropagationStopped()) return; - if (this.host === window.location.host && OSM.router.route(this.pathname + this.search + this.hash)) e.preventDefault(); + if (e.isDefaultPrevented() || e.isPropagationStopped()) + return; + + // Open links in a new tab as normal. + if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) + return; + + // Ignore cross-protocol and cross-origin links. + if (location.protocol !== this.protocol || location.host !== this.host) + return; + + if (OSM.router.route(this.pathname + this.search + this.hash)) + e.preventDefault(); }); $(".search_form").on("submit", function(e) {