"use strict"; /////////////////////// BlueCore 1.8.3 \\\\\\\\\\\\\\\\\\\\\\\\\\ 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); } /// Legacy functions for backwards compatibility, no reason for this abstraction function elementMake (ID,Class,element) { //new and improved, I can use more than just divs for things now. ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID; 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) { parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID; ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID; 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; } function titledContainer (ParentID,ID,Class,Element,Position,Title) { var outer = elementPlace(ParentID,"outer_"+ID,"outer "+Class,"div",Position); outer.innerHTML = '
'+Title+'
'; return elementPlace("#outer_"+ID,ID,Class,Element); } /// end of legacy function numberShorten (value=0, accuricy=3, factor=1000, notationArray=["","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"]) { value = !isNaN(value) ? value : 0; factor = !isNaN(factor) ? factor : 1000; accuricy = !isNaN(accuricy) ? accuricy : 3; if (value < factor) { return value.toPrecision(acc); } var mag = 0; while (value > factor) { value /= factor; mag++; } notationArray = Array.isArray(notationArray) ? notationArray : [""]; if (mag > notationArray.length) { return (Math.pow(factor,mag)*value).toExponential(accuricy); } return value.toPrecision(accuricy)+notationArray[mag]; } /// more legacy functions that are being kept purely for backwards compatability function buttonAdd (ParentID,ID,Label,Action,Class,Element) { if ( "undefined" == typeof Class ) { Class = ""; } if ( "undefined" == typeof Element) { Element = "div"; } var me = (function (button) { button.innerHTML = Label; button.onclick = function () { Action(); } return button; })(elementPlace(ParentID,ID,"button "+Class,Element)); return me; } 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 () { if ("file" == inputArea.type ) { callback(inputArea.files); } else { callback(inputArea.value); } dialogRoot.parentNode.removeChild(dialogRoot); },"dialog_submit"); } 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); } } /// end of legacy