William Toohey 9 years ago
parent 252a03942e
commit a3eb7e4195
  1. 40
      src/js/ResourceManager.js

@ -22,6 +22,15 @@
(function(window, document) { (function(window, document) {
"use strict"; "use strict";
let TAB_SONGS = 0;
let TAB_IMAGES = 1;
// For multiple Hues on one page
let unique = 0;
let getAndIncrementUnique = function() {
return unique++;
}
// NOTE: Any packs referenced need CORS enabled or loads fail // NOTE: Any packs referenced need CORS enabled or loads fail
let packsURL = "https://cdn.0x40hu.es/getRespacks.php"; let packsURL = "https://cdn.0x40hu.es/getRespacks.php";
@ -67,6 +76,8 @@ function Resources(core, huesWin) {
progressTop: null, progressTop: null,
progressPercent: null progressPercent: null
}; };
this.currentTab = TAB_SONGS;
this.unique = getAndIncrementUnique();
this.remotes = null; this.remotes = null;
this.fileInput = null; this.fileInput = null;
this.fileParseQueue = []; this.fileParseQueue = [];
@ -424,6 +435,8 @@ Resources.prototype.initUI = function() {
songList.classList.add("respack-tab__content--checked"); songList.classList.add("respack-tab__content--checked");
imageList.classList.remove("respack-tab__content--checked"); imageList.classList.remove("respack-tab__content--checked");
this.currentTab = TAB_SONGS;
}; };
imageCount.onclick = () => { imageCount.onclick = () => {
@ -432,6 +445,8 @@ Resources.prototype.initUI = function() {
imageList.classList.add("respack-tab__content--checked"); imageList.classList.add("respack-tab__content--checked");
songList.classList.remove("respack-tab__content--checked"); songList.classList.remove("respack-tab__content--checked");
this.currentTab = TAB_IMAGES;
}; };
let packButtons = document.createElement("div"); let packButtons = document.createElement("div");
@ -626,13 +641,13 @@ Resources.prototype.getEnabledTabContents = function() {
if(!pack) { if(!pack) {
return null; return null;
} }
let ret = {arr: pack.images, if(this.currentTab == TAB_SONGS) {
elName: "image"}; return {arr: pack.songs,
if(document.getElementById("res-songtab").checked) { elName: "song"};
ret.arr = pack.songs; } else {
ret.elName = "song"; return {arr: pack.images,
elName: "image"};
} }
return ret;
}; };
Resources.prototype.enableAll = function() { Resources.prototype.enableAll = function() {
@ -641,7 +656,7 @@ Resources.prototype.enableAll = function() {
return; return;
for(let i = 0; i < tab.arr.length; i++) { for(let i = 0; i < tab.arr.length; i++) {
tab.arr[i].enabled = true; tab.arr[i].enabled = true;
document.getElementById(tab.elName + i).checked = true; document.getElementById(tab.elName + i + "-" + this.unique).checked = true;
} }
this.rebuildEnabled(); this.rebuildEnabled();
}; };
@ -652,7 +667,7 @@ Resources.prototype.disableAll = function() {
return; return;
for(let i = 0; i < tab.arr.length; i++) { for(let i = 0; i < tab.arr.length; i++) {
tab.arr[i].enabled = false; tab.arr[i].enabled = false;
document.getElementById(tab.elName + i).checked = false; document.getElementById(tab.elName + i + "-" + this.unique).checked = false;
} }
this.rebuildEnabled(); this.rebuildEnabled();
}; };
@ -663,7 +678,7 @@ Resources.prototype.invert = function() {
return; return;
for(let i = 0; i < tab.arr.length; i++) { for(let i = 0; i < tab.arr.length; i++) {
tab.arr[i].enabled = !tab.arr[i].enabled; tab.arr[i].enabled = !tab.arr[i].enabled;
document.getElementById(tab.elName + i).checked = tab.arr[i].enabled; document.getElementById(tab.elName + i + "-" + this.unique).checked = tab.arr[i].enabled;
} }
this.rebuildEnabled(); this.rebuildEnabled();
}; };
@ -673,18 +688,13 @@ Resources.prototype.appendListItem = function(name, value, id, root, oncheck, on
if(checked === undefined) { if(checked === undefined) {
checked = true; checked = true;
} }
// For multiple hues on one page
let unique = 0;
while(document.getElementById(id + "-" + unique)) {
unique++;
}
let div = document.createElement("div"); let div = document.createElement("div");
div.className = "respacks-listitem"; div.className = "respacks-listitem";
let checkbox = document.createElement("input"); let checkbox = document.createElement("input");
checkbox.type = "checkbox"; checkbox.type = "checkbox";
checkbox.name = name; checkbox.name = name;
checkbox.value = value; checkbox.value = value;
checkbox.id = id + "-" + unique; checkbox.id = id + "-" + this.unique;
checkbox.checked = checked; checkbox.checked = checked;
checkbox.onclick = oncheck; checkbox.onclick = oncheck;
let checkStyler = document.createElement("label"); let checkStyler = document.createElement("label");

Loading…
Cancel
Save