2021-06-21 19:30:11 +00:00
|
|
|
/**
|
|
|
|
* @external MenuDefinition
|
|
|
|
*/
|
|
|
|
|
2020-03-09 18:31:36 +00:00
|
|
|
/**
|
|
|
|
* @param {string} msg
|
|
|
|
* @param {number} [height=200]
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-01-09 22:11:00 +00:00
|
|
|
const placeholder = ( msg, height ) => {
|
|
|
|
return `<div style="width: 100%; height: ${height || 200}px; margin-bottom: 2px;
|
|
|
|
font-size: 12px; padding: 8px; box-sizing: border-box;
|
|
|
|
display: flex; background: #eee; align-items: center;justify-content: center;">${msg}</div>`;
|
|
|
|
};
|
|
|
|
|
2021-02-08 23:10:21 +00:00
|
|
|
/**
|
|
|
|
* @param {string} html
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
const portletAfter = ( html ) => {
|
|
|
|
return `<div class="after-portlet after-portlet-tb">${html}</div>`;
|
|
|
|
};
|
|
|
|
|
2020-07-14 21:40:28 +00:00
|
|
|
const htmlUserLanguageAttributes = `dir="ltr" lang="en-GB"`;
|
2020-01-09 22:11:00 +00:00
|
|
|
|
2021-05-27 21:47:55 +00:00
|
|
|
/**
|
|
|
|
* @param {string} [additionalClassString] to add to the menu class
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
function helperClassName( additionalClassString = '' ) {
|
|
|
|
return { class: additionalClassString };
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:29:04 +00:00
|
|
|
/**
|
|
|
|
* @param {string} name of the menu
|
|
|
|
* @param {string} htmlItems
|
2021-05-27 21:47:55 +00:00
|
|
|
* @param {Object} [additionalData] to add to the menu template data
|
|
|
|
* @param {string} [additionalData.class]
|
2021-05-26 23:29:04 +00:00
|
|
|
* @return {MenuDefinition}
|
|
|
|
*/
|
2021-05-27 21:47:55 +00:00
|
|
|
function helperMakeMenuData( name, htmlItems, additionalData = {} ) {
|
2021-05-26 23:29:04 +00:00
|
|
|
let label;
|
|
|
|
switch ( name ) {
|
|
|
|
case 'personal':
|
|
|
|
label = 'Personal tools';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
label = 'Menu label';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-27 21:47:55 +00:00
|
|
|
// Handle "class" property separately to ensure it is appended to existing classes
|
|
|
|
const additionalClassString = additionalData.class;
|
|
|
|
const additionalDataWithoutClass = Object.assign( {}, additionalData );
|
|
|
|
delete additionalDataWithoutClass.class;
|
|
|
|
|
|
|
|
return Object.assign( {
|
2021-05-26 23:29:04 +00:00
|
|
|
id: `p-${name}`,
|
|
|
|
class: `mw-portlet mw-portlet-${name} vector-menu ${additionalClassString}`,
|
|
|
|
label,
|
|
|
|
'html-user-language-attributes': htmlUserLanguageAttributes,
|
|
|
|
'html-items': htmlItems
|
2021-05-27 21:47:55 +00:00
|
|
|
}, additionalDataWithoutClass );
|
2021-05-26 23:29:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 21:47:55 +00:00
|
|
|
export {
|
|
|
|
placeholder,
|
|
|
|
htmlUserLanguageAttributes,
|
|
|
|
portletAfter,
|
|
|
|
helperClassName,
|
|
|
|
helperMakeMenuData
|
|
|
|
};
|