2022-12-07 22:10:09 +00:00
|
|
|
const features = require( './features.js' );
|
|
|
|
const LIMITED_WIDTH_FEATURE_NAME = 'limited-width';
|
2022-10-21 18:14:54 +00:00
|
|
|
|
2022-11-17 21:51:11 +00:00
|
|
|
/**
|
|
|
|
* Sets data attribute for click tracking purposes.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} toggleBtn
|
|
|
|
*/
|
|
|
|
function setDataAttribute( toggleBtn ) {
|
|
|
|
toggleBtn.dataset.eventName = features.isEnabled( LIMITED_WIDTH_FEATURE_NAME ) ?
|
|
|
|
'limited-width-toggle-off' : 'limited-width-toggle-on';
|
|
|
|
}
|
2022-10-21 18:14:54 +00:00
|
|
|
/**
|
|
|
|
* adds a toggle button
|
|
|
|
*/
|
|
|
|
function init() {
|
2022-12-07 22:10:09 +00:00
|
|
|
const toggle = document.createElement( 'button' );
|
2023-01-04 20:37:15 +00:00
|
|
|
toggle.setAttribute( 'title', mw.msg( 'vector-limited-width-toggle' ) );
|
|
|
|
toggle.setAttribute( 'aria-hidden', 'true' );
|
|
|
|
toggle.textContent = mw.msg( 'vector-limited-width-toggle' );
|
2022-10-21 18:14:54 +00:00
|
|
|
toggle.classList.add( 'mw-ui-icon', 'mw-ui-icon-element', 'mw-ui-button', 'vector-limited-width-toggle' );
|
2022-11-17 21:51:11 +00:00
|
|
|
setDataAttribute( toggle );
|
2022-10-21 18:14:54 +00:00
|
|
|
document.body.appendChild( toggle );
|
|
|
|
toggle.addEventListener( 'click', function () {
|
2022-11-17 21:51:11 +00:00
|
|
|
features.toggle( LIMITED_WIDTH_FEATURE_NAME );
|
|
|
|
setDataAttribute( toggle );
|
2022-10-21 18:14:54 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = init;
|