fix(prefs): 🐛 incorrect function call for addPortlet

Closes: #832
This commit is contained in:
alistair3149 2024-04-27 18:02:23 -04:00
parent 354ae255f7
commit 4bc4301f90
No known key found for this signature in database

View file

@ -40,16 +40,22 @@ function addDefaultPortlet( portlet ) {
} }
/** /**
* Polyfill for mw.util.addPortlet for < MW 1.42 * Polyfill for mw.util.addPortlet for < MW 1.41
* Creates a detached portlet Element in the skin with no elements.
* *
* @return {Element} * @param {string} id of the new portlet.
* @param {string} [label] of the new portlet.
* @param {string} [before] selector of the element preceding the new portlet. If not passed
* the caller is responsible for appending the element to the DOM before using addPortletLink.
* @return {HTMLElement|null} will be null if it was not possible to create an portlet with
* the required information e.g. the selector given in before parameter could not be resolved
* to an existing element in the page.
*/ */
function addPortlet() { function addPortlet( id, label, before ) {
if ( mw.util.addPortlet ) { if ( mw.util.addPortlet ) {
return addDefaultPortlet( mw.util.addPortlet ); return addDefaultPortlet( mw.util.addPortlet( id, label, before ) );
} }
return function ( id, label, before ) {
const portlet = document.createElement( 'div' ); const portlet = document.createElement( 'div' );
portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet', portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet',
// Additional class is added to allow skins to track portlets added via this mechanism. // Additional class is added to allow skins to track portlets added via this mechanism.
@ -81,7 +87,6 @@ function addPortlet() {
} }
mw.hook( 'util.addPortlet' ).fire( portlet, before ); mw.hook( 'util.addPortlet' ).fire( portlet, before );
return addDefaultPortlet( portlet ); return addDefaultPortlet( portlet );
};
} }
/** @module addPortlet */ /** @module addPortlet */