From 869c721e916ea2c46694ec7571be7662931124be Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Tue, 31 Aug 2021 13:45:48 -0700 Subject: [PATCH] Language button should prevent default click behavior In Vector the language button is a checkbox. It uses the checkbox hack to provide non-JS dropdown behaviour. When the JS upgrades such a button, the checkbox behavior continues to work. An unsatisfying hack in Vector workarounds this problem. This provides a neater way to disable that behavior in Vector once the button is clicked by adding support for the well documented checkbox hack. Bug: T283757 Change-Id: I97a69c30b27cb1ded06451389e086229561c3589 --- resources/js/ext.uls.interface.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 3cc71849..eca35256 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -439,8 +439,23 @@ * @param {jQuery.Event} ev */ function loadContentLanguageSelector( ev ) { - var $target = $( ev.currentTarget ); + var targetNode = ev.currentTarget, + $target = $( targetNode ); ev.preventDefault(); + // Special handling for checkboxes + if ( + targetNode && + targetNode.tagName === 'INPUT' && + targetNode.getAttribute( 'type' ) === 'checkbox' + ) { + // Disabled checked status. If the ULS button is also a checkbox, we can + // conclude that it's using the checkbox hack. + // Setting checked to false disables the default behavior of that checkbox. + targetNode.checked = false; + $target.on( 'click', function () { + targetNode.checked = false; + } ); + } // Avoid reinitializing ULS multiple times for an element if ( $target.attr( 'data-uls-loaded' ) ) {