brown-wall/main.js

41 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-07-04 17:00:23 +02:00
"using strict";
2023-11-01 17:45:00 +01:00
// const menus = [ { "name": "Fruit", "items": [ "Banana", "Orange", "Pineapple", "Apple" ], "description":"What it says on the tin." }, { "name": "Genre", "items": [ "FFP", "Jiminy Cockthroat", "しひろ Cockthroat", "Spunk Gargle Weewee" ], "description":"Overal genre of the thinky thing" } ];
2023-07-04 22:27:06 +02:00
2023-11-01 17:45:00 +01:00
function initLists (lists){
const menuContainer = document.getElementById('menu-container');
2023-07-04 22:27:06 +02:00
lists.forEach( menu =>{
2023-11-01 17:45:00 +01:00
const dropdownMenu = document.createElement('menu');
const menuTitle = Object.assign(document.createElement('h2'), {innerHTML:menu.name});
const description = Object.assign(document.createElement('p'), {innerHTML:menu.description});
const dropdownSelect = document.createElement('select');
2023-07-04 22:27:06 +02:00
2023-11-01 17:45:00 +01:00
dropdownMenu.id = menu.name.toLowerCase();
dropdownMenu.className = "dropdown-menu";
dropdownMenu.appendChild(menuTitle);
dropdownMenu.appendChild(description);
menuContainer.appendChild(dropdownMenu);
dropdownMenu.appendChild(dropdownSelect);
2023-07-04 22:27:06 +02:00
2023-11-01 17:45:00 +01:00
menu.items.forEach(item =>{
dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item}));
});
});
};
2023-11-01 17:13:20 +01:00
document.getElementById('import').onclick = function() {
const files = document.getElementById('selectFiles').files;
if (files.length <= 0) {
return false;
}
2023-11-01 17:45:00 +01:00
const fr = new FileReader();
2023-11-01 17:45:00 +01:00
fr.onload = function(e) {
initLists(JSON.parse(e.target.result));
}
2023-11-01 17:45:00 +01:00
fr.readAsText(files.item(0));
2023-11-01 17:13:20 +01:00
};