From b6d31db5aab06e0462a6a8c124ae05fe2e8f7ad5 Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Wed, 3 Nov 2021 14:19:22 +0800 Subject: [PATCH] * task #41233, fix open in new tab on pressed ctrl key not work as expected and improve perf. --- www/js/my.full.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/www/js/my.full.js b/www/js/my.full.js index a1ba191b7f..f2bc12adf6 100644 --- a/www/js/my.full.js +++ b/www/js/my.full.js @@ -871,13 +871,19 @@ $(document).ready(function() $(document).on('click', '#helpMenuItem .close-help-tab', function(){$('#helpMenuItem').prev().remove();$('#helpMenuItem').remove();}); - $(document).keydown(function(event) + /* Open link in new tab when pressed ctrl key in windows */ + if(window.navigator.userAgent.match(/Windows/i)) { - if(event.ctrlKey) $('a').attr('target', '_blank'); - }).keyup(function() - { - $('a').attr('target', ''); - }); + $(document).on('mousedown', 'a', function(e) + { + var $a = $(this); + if(!e.ctrlKey || $a.attr('target')) return; + $a.attr('target', '_blank'); + clearTimeout($a.data('ctrlTimer')); + $a.data('ctrlTimer', setTimeout(function(){$a.attr('target', null).data('ctrlTimer', 0)}, 100)); + e.preventDefault(); + }); + } /* Hide the global create drop-down when hovering over the avatar. */ $('.has-avatar').hover(function()