menu: use native Lampa.Menu.addButton (reliable, no manual DOM insert); drop makeButton

This commit is contained in:
Hermes committed 2026-08-09 13:19:29 +02:00
1 parent 24ac13cf88
commit 0e6cc6f025
1 file changed
+17 -30
+17 -30
View File
@@ -389,37 +389,25 @@
}
// ---------- Menu item ----------
// Lampa builds the main menu on the 'menu:start' event, e.body is the jQuery menu root.
// Remove ALL old copies from the DOM first, then add exactly one button.
function makeButton() {
var button = $(
'<li class="menu__item selector" data-action="' + PLUGIN.menu_action + '">' +
'<div class="menu__ico">' +
'<svg class="sprite-folder"><use xlink:href="#sprite-folder"></use></svg>' +
'</div>' +
'<div class="menu__text">' + t(PLUGIN.title) + '</div>' +
'</li>'
);
button.on('hover:enter', function () {
Lampa.Activity.push({
url: '',
component: PLUGIN.name,
title: t(PLUGIN.title),
page: t(PLUGIN.title)
});
});
return button;
}
var menuSubscribed = false;
function addMenuButton() {
// remove ALL copies everywhere in DOM, then add exactly one
$('[data-action="' + PLUGIN.menu_action + '"]').remove();
$('.menu .menu__list').eq(0).append(makeButton());
if (Lampa.Selector) Lampa.Selector.update();
}
// Lampa builds the main menu on the 'menu:start' event. We add our item via the
// native Lampa.Menu.addButton() API (adds to .menu__list and wires hover:enter).
var menuSubscribed = false;
var menuInterval = null;
function addMenuButton() {
// Use Lampa's native menu API (adds to .menu__list:eq(0) and wires hover:enter).
Lampa.Menu.addButton(
'<svg class="sprite-folder"><use xlink:href="#sprite-folder"></use></svg>',
t(PLUGIN.title),
function () {
Lampa.Activity.push({
url: '',
component: PLUGIN.name,
title: t(PLUGIN.title),
page: t(PLUGIN.title)
});
}
);
}
function start() {
if (menuSubscribed) return;
menuSubscribed = true;
@@ -449,7 +437,6 @@
// The main menu may already be built (or built later) by the time this plugin
// loads. Poll briefly (every 500ms) until it appears, then add the item once.
// This keeps it from showing "late and shoving items" while still being reliable.
if (!tryAdd()) {
menuInterval = setInterval(tryAdd, 500);
// safety: stop polling after 30s regardless