Sizerboard/Public/ecma/Sizerboard.Base.ecma.js

103 lines
3.4 KiB
JavaScript
Raw Permalink Normal View History

Sizerboard.Base = function(sizerboard, inputs){
const self = this,
screen_cache = {x : 0, y : 0},
texts_cache = {}
let started = false,
thread = null;
const construct = () => {
sizerboard.print("info", "sizerboard_base_building");
sizerboard.print("ok", "sizerboard_base_built");
};
const changes_thread_method = () => {
if(screen_cache.x != sizerboard.item_self.offsetWidth || screen_cache.y != sizerboard.item_self.offsetHeight){
screen_cache.x = sizerboard.item_self.offsetWidth;
screen_cache.y = sizerboard.item_self.offsetHeight;
sizerboard.item_self.style.fontSize = (screen_cache[screen_cache.x < screen_cache.y ? "x" : "y"] / Number(sizerboard.item_self.getAttribute("data-cells"))) + "px";
};
["projects_menu", "draw_box"].forEach(key => {
const text_box = sizerboard.item_self.querySelector("p[data-i18n=" + key + "_text]");
let y;
if(text_box && (
!texts_cache[key] ||
text_box.innerText != texts_cache[key].text ||
(y = text_box.offsetHeight / Number(sizerboard.item_self.style.fontSize.slice(0, -2))) != texts_cache[key].y
)){
(texts_cache[key] || (texts_cache[key] = {})).text = text_box.innerText;
texts_cache[key].y = y;
text_box.parentNode.querySelector("p+ul").style.top = y + "em";
text_box.parentNode.querySelector("p+ul+*").style.top = (1.4 + y) + "em";
};
});
};
this.start = callback => {
const end = status => typeof callback == "function" && callback(status);
sizerboard.print("info", "sizerboard_base_starting");
if(started){
sizerboard.print("warn", "sizerboard_base_already_started");
end(false);
return false;
};
started = true;
sizerboard.preload(sizerboard.settings("position"), (position, error, asynchronous) => {
if(error)
return;
const classes = sizerboard.settings("class"),
hash = sizerboard.hash();
position.innerHTML = sizerboard.views.get("base_view", {
application : sizerboard.settings(["application_name", "application"]),
git : sizerboard.settings(["application_git", "git"]),
url : sizerboard.settings(["application_url", "url"]),
hash : hash,
classes : classes ? " " + classes : "",
cells : sizerboard.settings("cells"),
main_menu_items : sizerboard.views.get_multiple_items("main_menu_item", sizerboard.settings("main_menu_items"))[0],
preloader : sizerboard.build_preloader((view, error, asynchronous) => {
if(error)
return;
const self_error = sizerboard.set_self(view, hash);
if(self_error)
return;
thread = sizerboard.thread_add(changes_thread_method);
sizerboard.print("ok", "sizerboard_base_started");
end(true);
}),
projects : sizerboard.views.get_multiple_items("project_option", [])[0]
})[0];
});
return true;
};
construct();
};