2019-04-20 10:22:09 -06:00
|
|
|
"use strict";
|
2020-05-19 14:03:05 -06:00
|
|
|
/////////////////////// BlueCore 1.8.3 \\\\\\\\\\\\\\\\\\\\\\\\\\
|
2019-04-20 10:22:09 -06:00
|
|
|
|
|
|
|
function getData(url,dothis,tothis,type,body) {
|
|
|
|
var DataRequest = new XMLHttpRequest();
|
|
|
|
if (undefined == type) { type = "GET"; }
|
|
|
|
if (undefined == body) { body = ""; }
|
|
|
|
DataRequest.open(type, url, true);
|
|
|
|
DataRequest.onreadystatechange = function () {
|
|
|
|
if ( (DataRequest.readyState === XMLHttpRequest.DONE) && (DataRequest.status === 200) ) {
|
|
|
|
dothis(DataRequest.responseText,tothis);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DataRequest.send(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEmpty(object) {
|
|
|
|
console.log(object);
|
|
|
|
console.log(typeof object);
|
|
|
|
if ( "object" == typeof object ) {
|
|
|
|
for ( var propery in object ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addJavascript(string,action) {
|
|
|
|
try {
|
|
|
|
window.eval(string);
|
|
|
|
if ("function" == typeof action) { action(); }
|
|
|
|
}
|
|
|
|
catch (e) { console.log("Error with external script: "+e); }
|
|
|
|
}
|
|
|
|
|
|
|
|
function getJavascript(url,action) {
|
|
|
|
getData(url,addJavascript,action);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addHTMLfrag(string,target) {
|
|
|
|
target.innerHTML = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHTMLfrag(url,targetNode) {
|
|
|
|
var target = document.querySelector(targetNode);
|
|
|
|
target.innerHTML = "Loading...";
|
|
|
|
getData(url,addHTMLfrag,target);
|
|
|
|
}
|
|
|
|
|
|
|
|
function elementMake (ID,Class,element) { //new and improved, I can use more than just divs for things now.
|
2019-04-20 10:30:10 -06:00
|
|
|
ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID;
|
2019-04-20 10:22:09 -06:00
|
|
|
return (function (myElement) {
|
|
|
|
if ("string" == typeof ID) { myElement.id = ID; }
|
|
|
|
if ("string" == typeof Class) { myElement.className = Class; }
|
|
|
|
return myElement;
|
|
|
|
})(document.createElement(element));
|
|
|
|
}
|
|
|
|
|
|
|
|
function elementPlace (parentID, ID, Class, element, position) {
|
2019-04-20 10:30:10 -06:00
|
|
|
parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID;
|
|
|
|
ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID;
|
2019-04-20 10:22:09 -06:00
|
|
|
var newElement = elementMake(ID,Class,element);
|
|
|
|
if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant?
|
|
|
|
if ("before" == position) {
|
|
|
|
document.querySelector(parentID).prepend(newElement);
|
|
|
|
} else {
|
|
|
|
document.querySelector(parentID).append(newElement);
|
|
|
|
}
|
|
|
|
} else { //No? Ok we will use the old way.
|
|
|
|
if ("before" == position) {
|
|
|
|
var p = document.querySelector(parentID);
|
|
|
|
p.insertBefore(newElement,p.firstChild);
|
|
|
|
} else {
|
|
|
|
document.querySelector(parentID).appendChild(newElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
2019-04-20 10:30:10 -06:00
|
|
|
function titledContainer (ParentID,ID,Class,Element,Position,Title) {
|
|
|
|
var outer = elementPlace(ParentID,"outer_"+ID,"outer "+Class,"div",Position);
|
|
|
|
outer.innerHTML = '<p class="title">'+Title+'</p>';
|
|
|
|
return elementPlace("#outer_"+ID,ID,Class,Element);
|
|
|
|
}
|
|
|
|
|
2021-06-18 13:13:53 -06:00
|
|
|
function numberShorten (Value,Accuricy) {
|
2019-04-20 10:30:10 -06:00
|
|
|
var level = 0;
|
2021-06-18 13:13:53 -06:00
|
|
|
var number = "number" == Value ? Value : 0;
|
|
|
|
var places = "number" == Accuricy ? Accuricy : 3;
|
2019-04-20 10:30:10 -06:00
|
|
|
var unit = ["","k","M","B","T","q","Q","s","S","O","N","d","Ud","Dd","Td","qd","Qd","sd","Sd","Od","Nd","v","Uv","Dv","Tv","qv","Qv","sv","Sv","Ov","Nv","t","Ut","Dt","Tt","qt","Qt","st","St","Ot","Nv","c","uc","dc","Tc","Dc","Uc","vc","Sc","Oc","Nc","STOP"];
|
|
|
|
while (999<number) {
|
|
|
|
level++;
|
|
|
|
number = Math.round(number)/1000;
|
|
|
|
}
|
2021-06-18 13:13:53 -06:00
|
|
|
return (Math.floor(number*(places*10))/(places*10))+unit[level];
|
2019-04-20 10:30:10 -06:00
|
|
|
}
|
|
|
|
|
2019-04-20 10:22:09 -06:00
|
|
|
function buttonAdd (ParentID,ID,Label,Action,Class,Element) {
|
|
|
|
if ( "undefined" == typeof Class ) { Class = ""; }
|
|
|
|
if ( "undefined" == typeof Element) { Element = "div"; }
|
2021-06-17 15:35:38 -06:00
|
|
|
var me = (function (button) {
|
2019-04-20 10:22:09 -06:00
|
|
|
button.innerHTML = Label;
|
|
|
|
button.onclick = function () { Action(); }
|
2021-06-17 15:35:38 -06:00
|
|
|
return button;
|
2019-04-20 10:22:09 -06:00
|
|
|
})(elementPlace(ParentID,ID,"button "+Class,Element));
|
2021-06-17 15:35:38 -06:00
|
|
|
return me;
|
2019-04-20 10:22:09 -06:00
|
|
|
}
|
|
|
|
|
2019-04-20 10:30:10 -06:00
|
|
|
function inputDialog (dialogRoot,container,args,callback) {
|
|
|
|
args = "object" == typeof args ? args : {"content":""};
|
|
|
|
args.content = "string" == typeof args.content ? args.content : "";
|
|
|
|
container.innerText += args.content;
|
|
|
|
var inputArea = elementPlace("#"+container.id,null,"formInput","input");
|
|
|
|
if ("string" == typeof args.inputType) { inputArea.type = args.inputType; }
|
|
|
|
buttonAdd("#"+container.id,null,"Submit",function () {
|
2020-05-19 14:03:05 -06:00
|
|
|
if ("file" == inputArea.type ) {
|
|
|
|
callback(inputArea.files);
|
|
|
|
} else {
|
|
|
|
callback(inputArea.value);
|
|
|
|
}
|
2019-04-20 10:30:10 -06:00
|
|
|
dialogRoot.parentNode.removeChild(dialogRoot);
|
|
|
|
},"dialog_submit");
|
2019-04-20 10:22:09 -06:00
|
|
|
}
|
|
|
|
|
2019-04-20 10:30:10 -06:00
|
|
|
function messageDialog (dialogRoot,container,args) {
|
|
|
|
args = "object" == typeof args ? args : {"content":""};
|
|
|
|
args.content = "string" == typeof args.content ? args.content : "";
|
|
|
|
container.innerText += args.content;
|
|
|
|
buttonAdd("#"+container.id,null,"Ok",function () {
|
|
|
|
dialogRoot.parentNode.removeChild(dialogRoot);
|
|
|
|
},"dialog_submit");
|
|
|
|
}
|
|
|
|
|
|
|
|
function popupDialog (ID, title, closeable, contentGen, genArgs, callback) {
|
|
|
|
if ("function" != typeof callback) { callback = function () { return 0; }; }
|
|
|
|
var dialogBack = elementPlace("body",ID+"_back","dialog_back","div");
|
|
|
|
var dialogWindow = elementPlace("#"+ID+"_back",ID,"dialog_window","div");
|
|
|
|
var dialogTitle = elementPlace("#"+ID,ID+"_title","dialog_title","div");
|
|
|
|
if ("string" == typeof title) { dialogTitle.innerText = title; }
|
|
|
|
if (true == closeable) {buttonAdd("#"+ID+"_title",null,"X",function () {dialogBack.parentNode.removeChild(dialogBack);},"dialog_close");}
|
|
|
|
var dialogContent = elementPlace("#"+ID,ID+"_content","dialog_content","div");
|
|
|
|
if ("function" == typeof contentGen) {
|
|
|
|
contentGen(dialogBack,dialogContent,genArgs,callback);
|
|
|
|
} else {
|
|
|
|
dialogContent.innerText = "string" == typeof contentGen ? contentGen : "Empty Dialog";
|
|
|
|
buttonAdd("#"+ID+"_content",null,"Close",callback);
|
|
|
|
}
|
2019-04-20 10:22:09 -06:00
|
|
|
}
|