From 353bf866d72e6f1341c279b0f438fa99535c88f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 29 Sep 2015 17:09:04 +0200 Subject: [PATCH] mw.widgets.TitleOptionWidget: Prevent page navigation by clicking labels However, allow opening the link in a new tab. The same code is used in other components, e.g. jquery.suggestions. Follow-up to ba358947bfb81b58d64489063bd4be816d1a46da. Change-Id: Ie6840a20c1cc1a10fb1fb74717982dbe7e331d36 --- .../src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js index 138715ad3a..9b0b2709f5 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js @@ -51,6 +51,14 @@ this.$label.attr( 'href', config.url ); this.$element.addClass( 'mw-widget-titleOptionWidget' ); + // Allow opening the link in new tab, but not regular navigation. + this.$label.on( 'click', function ( e ) { + // Do not interfere with non-left clicks or if modifier keys are pressed (e.g. ctrl-click). + if ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) { + e.preventDefault(); + } + } ); + // Highlight matching parts of link suggestion this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } ); -- 2.20.1