mami/src/mami.js/ui/toggles.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-01-18 19:50:37 +00:00
#include utility.js
#include ui/elems.js
Umi.UI.Toggles = (function() {
const ids = [];
return {
Add: function(baseId, eventHandlers, title) {
if(ids.indexOf(baseId) < 0) {
ids.push(baseId);
const toggle = $e({
attrs: {
id: Umi.UI.Elements.Toggles.id + '-' + baseId,
classList: ['sidebar__selector-mode', 'sidebar__selector-mode--' + baseId],
title: title,
},
});
for(const i in eventHandlers)
toggle.addEventListener(i, eventHandlers[i]);
Umi.UI.Elements.Toggles.insertBefore(toggle, Umi.UI.Elements.Toggles.firstChild);
}
},
Get: function(baseId, icon) {
const id = Umi.UI.Elements.Toggles.id + '-' + baseId;
if(ids.indexOf(baseId) >= 0)
return $i(id);
return null;
},
Remove: function(baseId) {
$ri(Umi.UI.Elements.Toggles.id + '-' + baseId);
},
};
})();