Sizerboard.Projects = function(sizerboard, inputs){ const self = this; let started = false, cache = "", autosearch_thread; const construct = () => { sizerboard.print("info", "sizerboard_projects_building"); sizerboard.print("ok", "sizerboard_projects_built"); }; this.start = callback => { const end = status => typeof callback == "function" && callback(status); sizerboard.print("info", "sizerboard_projects_starting"); if(started){ sizerboard.print("warn", "sizerboard_projects_already_started"); end(false); return false; }; started = true; sizerboard.preload("#projects_menu_search", (item, error, asynchronous) => ( error || (autosearch_thread = sizerboard.thread_add(autosearch_thread_method)) )); sizerboard.print("ok", "sizerboard_projects_started"); end(true); return true; }; const autosearch_thread_method = () => { const text = sizerboard.item_self.querySelector(".projects-menu .search-box [name=search]").value; if(text != cache){ cache = text; sizerboard.item_self.querySelectorAll(".projects-menu nav li").forEach(item => item.setAttribute("data-visible", !cache || item.innerText.includes(cache))); }; }; this.search = (item, event) => {}; this.add = (item, event) => { let name = item.parentNode.parentNode.querySelector("[type=text]").value, error = ( name === undefined ? 1 << 0 : name === null ? 1 << 1 : typeof name != "string" ? 1 << 2 : !name ? 1 << 3 : !(name = name.trim()) ? 1 << 4 : /[^a-z0-9_\- ]/i.test(name) ? 1 << 5 : sizerboard.item_self.querySelector(".projects-menu nav li[data-name=" + name + "]") ? 1 << 6 : ["null"].includes(name) ? 1 << 7 : 0) << 1; error || (sizerboard.item_self.querySelector(".projects-menu nav>ul").innerHTML += sizerboard.views.get("project_option", { name : name, i : sizerboard.item_self.querySelectorAll(".projects-menu nav li").length })[0]); }; this.get_in_gui = (item, event) => { sizerboard.item_self.querySelectorAll(".projects-menu nav li[data-selected=true]").forEach(item => { item.hasAttribute("disabled") && item.removeAttribute("disabled"); item.setAttribute("data-selected", false); }); sizerboard.item_self.querySelector(".draw-box").setAttribute("data-selected", item.getAttribute("data-name")); item.setAttribute("data-selected", true); item.setAttribute("disabled", true); }; construct(); };