From 10c8be0cb909e9473029890b95ea881f1a63c32f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 2 Dec 2013 14:25:45 -0800 Subject: [PATCH] Restore correct link behavior with modifier keys Fixes #562 --- app/assets/javascripts/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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) { -- 2.43.2