mirror of
https://github.com/discourse/discourse-header-submenus.git
synced 2025-05-09 09:47:41 +00:00
prettier
This commit is contained in:
parent
6dbd02a9c3
commit
f94d936622
@ -1,5 +1,5 @@
|
|||||||
// Used instead of dasherize for backwards compatibility with stable
|
// Used instead of dasherize for backwards compatibility with stable
|
||||||
const getClassName = text => {
|
const getClassName = (text) => {
|
||||||
return text.toLowerCase().replace(/\s/g, "-");
|
return text.toLowerCase().replace(/\s/g, "-");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -7,22 +7,21 @@ export default {
|
|||||||
setupComponent() {
|
setupComponent() {
|
||||||
try {
|
try {
|
||||||
const splitMenuItems = settings.Menu_items.split("|").filter(Boolean);
|
const splitMenuItems = settings.Menu_items.split("|").filter(Boolean);
|
||||||
const splitSubmenuItems = settings.Submenu_items.split("|").filter(
|
const splitSubmenuItems =
|
||||||
Boolean
|
settings.Submenu_items.split("|").filter(Boolean);
|
||||||
);
|
|
||||||
|
|
||||||
const menuItemsArray = [];
|
const menuItemsArray = [];
|
||||||
const SubmenuItemsArray = [];
|
const SubmenuItemsArray = [];
|
||||||
|
|
||||||
splitSubmenuItems.forEach(item => {
|
splitSubmenuItems.forEach((item) => {
|
||||||
const fragments = item.split(",").map(fragment => fragment.trim());
|
const fragments = item.split(",").map((fragment) => fragment.trim());
|
||||||
const parent = fragments[0].toLowerCase();
|
const parent = fragments[0].toLowerCase();
|
||||||
const text = fragments[1];
|
const text = fragments[1];
|
||||||
|
|
||||||
if (text.toLowerCase() === "divider") {
|
if (text.toLowerCase() === "divider") {
|
||||||
const divider = {
|
const divider = {
|
||||||
parent,
|
parent,
|
||||||
divider: true
|
divider: true,
|
||||||
};
|
};
|
||||||
return SubmenuItemsArray.push(divider);
|
return SubmenuItemsArray.push(divider);
|
||||||
}
|
}
|
||||||
@ -43,13 +42,13 @@ export default {
|
|||||||
icon,
|
icon,
|
||||||
href,
|
href,
|
||||||
target,
|
target,
|
||||||
title
|
title,
|
||||||
};
|
};
|
||||||
SubmenuItemsArray.push(submenuItem);
|
SubmenuItemsArray.push(submenuItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
splitMenuItems.forEach(item => {
|
splitMenuItems.forEach((item) => {
|
||||||
const fragments = item.split(",").map(fragment => fragment.trim());
|
const fragments = item.split(",").map((fragment) => fragment.trim());
|
||||||
const parentFor = fragments[0].toLowerCase();
|
const parentFor = fragments[0].toLowerCase();
|
||||||
const text = fragments[0];
|
const text = fragments[0];
|
||||||
const className = getClassName(text);
|
const className = getClassName(text);
|
||||||
@ -60,7 +59,7 @@ export default {
|
|||||||
const title = fragments[2];
|
const title = fragments[2];
|
||||||
const view = fragments[3];
|
const view = fragments[3];
|
||||||
const childItems = SubmenuItemsArray.filter(
|
const childItems = SubmenuItemsArray.filter(
|
||||||
link => link.parent === parentFor
|
(link) => link.parent === parentFor
|
||||||
);
|
);
|
||||||
|
|
||||||
const menuItem = {
|
const menuItem = {
|
||||||
@ -69,7 +68,7 @@ export default {
|
|||||||
icon,
|
icon,
|
||||||
title,
|
title,
|
||||||
view,
|
view,
|
||||||
childItems
|
childItems,
|
||||||
};
|
};
|
||||||
menuItemsArray.push(menuItem);
|
menuItemsArray.push(menuItem);
|
||||||
});
|
});
|
||||||
@ -78,7 +77,7 @@ export default {
|
|||||||
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
menuItems: menuItemsArray,
|
menuItems: menuItemsArray,
|
||||||
showCaret
|
showCaret,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
@ -87,5 +86,5 @@ export default {
|
|||||||
"There's an issue in the Header Submenus Component. Check if your settings are entered correctly"
|
"There's an issue in the Header Submenus Component. Check if your settings are entered correctly"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user