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

37 lines
1 KiB
JavaScript
Raw Normal View History

2024-01-18 19:50:37 +00:00
#include utility.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: {
2024-02-09 00:56:27 +00:00
id: 'umi-toggles-' + baseId,
2024-01-18 19:50:37 +00:00
classList: ['sidebar__selector-mode', 'sidebar__selector-mode--' + baseId],
title: title,
},
});
for(const i in eventHandlers)
toggle.addEventListener(i, eventHandlers[i]);
2024-02-09 00:56:27 +00:00
const toggles = $i('umi-toggles');
toggles.insertBefore(toggle, toggles.firstChild);
2024-01-18 19:50:37 +00:00
}
},
Get: function(baseId, icon) {
2024-02-09 00:56:27 +00:00
const id = 'umi-toggles-' + baseId;
2024-01-18 19:50:37 +00:00
if(ids.indexOf(baseId) >= 0)
return $i(id);
return null;
},
Remove: function(baseId) {
2024-02-09 00:56:27 +00:00
$ri('umi-toggles-' + baseId);
2024-01-18 19:50:37 +00:00
},
};
})();