"use strict";
//2023-11-18:
//takes an HTML string and converts it into a node object.
//Returns a node object.
function HTML_to_node(html = "") {
var new_node = null;
var dom_parser = null;
dom_parser = new DOMParser();
new_node = dom_parser.parseFromString(html, "text/html");
return new_node;
}
//2024-01-16:
//A function that designates an HTML element, and all of its
//child elements into a node collection. For the element, and
//every one of its child node elements it contains, iterate through
//the child nodes. For each attribute in each element, change its value
//to a new value by adding a suffix to the attribute's value. This function
//only changes the value of specific attributes, given the attribute's name.
function change_element_attribute_values(element, attr_name, new_suffix) {
//alert(element.id);
var elem = null;
var child_array = null;
var attr = null;
var suffix = null;
var child_attr = null;
var i = null;
var child = null;
attr = attr_name; //the name of the attribute as a string
elem = element; //the element in which we will change the attribute values
suffix = new_suffix; //the string of characters to add to the attribute value
//if the element and its parent node exist
if (elem !== null) {
//change the attribute value for the element itself.
if (elem.hasAttribute(attr) === true) {
elem.setAttribute(attr, elem.getAttribute(attr) + suffix);
}
//if the element has child nodes
if (elem.hasChildNodes() === true) {
//create a collection of all child nodes
child_array = elem.getElementsByTagName("*");
//for each child node in the child array
for (i = 0; i < child_array.length; i++) {
//get the child located at 'i' within the elements' collection
child = child_array[i];
//if the child element already contains the attribute
if (child.hasAttribute(attr) === true) {
//get the attribute value
child_attr = child.getAttribute(attr);
//set the child's attribute name to a new value
child.setAttribute(attr, (child_attr + suffix));
}
}
}
}
return elem;
}
//2023-11-18:
//this function goes through EVERY javascript tag in the page
//and if it has a 'src' attribute, it changes the attribute
//to point to a 'null.js' file (blank), and then changes
//the src attribute back to what it was originally.
function reload_all_javascripts_by_src_attributes() {
var scripts = null;
var script = null;
var i = null;
var script_src = null;
scripts = document.getElementsByTagName("script");
for (i = 0; i < scripts.length; i++) {
script = scripts[i];
script_src = script.getAttribute("src");
script.setAttribute("src", "/chromosphere/scripts/js/ui/null.js");
script.setAttribute("src", script_src);
}
}
//2023-08-22: This function removes an element's scrollbars,
//but still allows for scrolling functionality. This function
//relies on the file 'window.css'. Without this CSS file,
//or the classes within it, this function cannot work.
function hide_scrollbars(elem_id) {
var elem = null;
elem = document.getElementById(elem_id);
if (elem !== null) {
elem.classList.add("hide_scroll_bars");
}
}
//function set_window_contents_to_default(win_id, content_id, default_html) {
// var w = null;
// var content_container = null;
// w = document.getElementById(win_id);
// if (w !== null) {
// content_container = document.getElementById(win_id + "_inner_contents_container"); //win_id inner content scontainer
// if (content_container !== null) {
// content_container.innerHTML = "" + content_id + "
No Data
";
// }
// }
//}
//removes the innerHTML from a web window object
//function strip_web_window(win_id) {
// var w = null;
// var win_innerHTML = null;
// w = document.getElementById(win_id);
// if (w !== null) {
// win_innerHTML == w.innerHTML;
// w.innerHTML = "";
// }
//}
//I once read something that said if you make a copy of a node, that copied node loses its event listeners.
/* (Tried it -- doesn't seem to work) */
/*
function remove_eventlisteners(object) {
var obj_copy = null;
var obj = null;
var parent_node = null;
var node_HTML = null;
var output = null;
output = false; //set return value variable
obj = object; //place the argument and place it onto a local variable
obj_copy = obj.cloneNode(true); //create a copy of the object
obj = document.getElementById(obj.id); //get the existing object if it still exists
if (obj !== null) {
obj_parent = obj.parentNode; //store the parent node of the object -- provided the object has a parent node.
if (obj_parent !== null) {
obj.parentNode.removeChild(obj); //remove the object from the DOM
obj_parent.appendChild(obj_copy); //append the copied object to the parent node. Keep in mind, if multiple siblings exists under the parent, this function might change their order in the DOM
output = true; //it seems to have worked. Make the output of the function set to true. The default value is false.
}
else {
//if the object provided by the function's argument does not have a parent node.
node_HTML = obj.outerHTML.toString(); //place the HTML of the object into a variable as a string.
obj.outerHTML = node_HTML; //replace the object's HTML with the stored HTML string.
output = true; //I believe that this should work successfully in removing event listeners, but it's theoretical.
}
}
return output; //returns true or false
}
*/
//depreciated
//function move_elem_up_2(elem_id, end_at, pxls, delay, drag_rate) {
// var i = null;
// var elem_top = null;
// var elem = null;
// var drag_coefficient = null;
// var adjusted_delay = null;
// drag_coefficient = verify_drag_ratio(drag_rate); //must be a number greater than 0 and less than 2. If not, it defaults to 1.0, thus having no change in velocity
// console.log(drag_coefficient);
// elem = document.getElementById(elem_id);
// if (elem !== null) {
// elem_top = parseFloat(elem.style.top);
// if (elem_top >= end_at) {
// elem.style.top = (elem_top - pxls) + "px";
// elem_top = parseFloat(elem.style.top);
// if (elem_top >= end_at) {
// global_tId22 = setTimeout(function () {
// clearTimeout(global_tId22);
// adjusted_delay = parseFloat((delay * drag_coefficient));
// adjusted_delay = Math.round(adjusted_delay);
// if (adjusted_delay === "number") {
// if (adjusted_delay > 10) {
// move_elem_up_2(elem_id, end_at, pxls, adjusted_delay, drag_coefficient);
// }
// else {
// clearTimeout(global_tId22);
// elem.style.top = end_at + "px";
// }
// }
// else {
// clearTimeout(global_tId22);
// elem.style.top = end_at + "px";
// }
// });
// } else {
// clearTimeout(global_tId22);
// elem.style.top = end_at + "px";
// }
// }
// else {
// clearTimeout(global_tId22);
// elem.style.top = end_at + "px";
// }
// }
// else {
// clearTimeout(global_tId22);
// }
//}
function move_up(elem_id, end_at, pxls, delay, drag_quotient) {
var i = null;
var elem_top = null;
var elem = null;
var new_top = null;
var drag = null;
drag = drag_quotient;
elem = document.getElementById(elem_id);
if (elem !== null) {
elem_top = parseFloat(elem.style.top).toFixed(3);
if (elem_top >= end_at) {
new_top = parseFloat(elem_top - pxls).toFixed(3);
elem.style.top = new_top + "px";
console.log("TOP: " + elem_top);
if (elem_top > end_at) {
global_tId22 = setTimeout(function () {
move_up(elem_id, end_at, pxls, delay, drag_quotient);
});
}
else {
clearTimeout(global_tId22);
elem.style.top = end_at + "px";
return;
}
}
else {
clearTimeout(global_tId22);
elem.style.top = end_at + "px";
}
}
else {
clearTimeout(global_tId22);
}
}
function move_elem_down_2() {
}
function move_elem_left_2() {
}
function move_elem_right_2() {
}
function verify_drag_ratio(drag_rate) {
var drag_coefficient = null;
drag_coefficient = drag_rate;
if (typeof drag_coefficient === "number") {
if (drag_coefficient > 0) {
if (drag_coefficient < 2) {
//no changes... valid drag coefficient... continue
}
else {
drag_coefficient = 1.0;
}
}
else {
drag_coefficient = 1.0;
}
}
else {
drag_coefficient = 1.0;
}
return drag_coefficient;
}
function quick_fade_in(obj_id) {
var opacity = null;
var obj = null;
var i = null;
obj = document.getElementById(obj_id);
if (obj !== null) {
opacity = obj.style.opacity;
opacity = parseFloat(opacity);
if (opacity < 1) {
opacity = opacity + 0.1;
obj.style.opacity = opacity;
if (parseFloat(obj.style.opacity) < 1) {
setTimeout(function () { quick_fade_in(obj_id) }, 10);
}
}
else {
obj.style.opacity = 1.0;
return;
}
}
}
function quick_fade_out(obj_id) {
var opacity = null;
var obj = null;
var i = null;
obj = document.getElementById(obj_id);
if (obj !== null) {
opacity = obj.style.opacity;
opacity = parseFloat(opacity);
if (opacity > 0) {
opacity = opacity - 0.1;
obj.style.opacity = opacity;
if (parseFloat(obj.style.opacity) > 0) {
setTimeout(function () { quick_fade_out(obj_id) }, 10);
}
}
else {
obj.style.opacity = 0.0;
return;
}
}
}
//2023-08-23:
//check to see if an opened window already exists in the DOM.
function duplicate_window_exists(win_id) {
var wins = null;
var i = null;
var w = null;
var content_id = null;
var win_client_id = null;
var window_id = null;
var win_exists = null;
win_exists = false;
wins = document.getElementsByName("web_window");
if (wins !== null) {
if (wins.length >= 1) {
for (i = 0; i < wins.length; i++) {
w = wins[i];
if (w !== null) {
if (w.hasAttribute("id") === true) {
win_client_id = w.getAttribute("id");
if (win_client_id.indexOf("_") >= 0) {
if (win_id.indexOf("_") >= 0) {
content_id = win_client_id.split("_")[2];
window_id = win_id.split("_")[2];
if (content_id === window_id) {
win_exists = true;
break;
}
}
}
}
}
}
}
}
return win_exists;
}
//2023-08-25:
//this cleans up the UI. It hides any visible stack menus of the top
//menu.
function reset_ui() {
//Hide all submenus/stack menus of the top menu that may be visible.
hide_all_stack_menus();
//alert("c0W!");
}
function return_url_querystring(urlStr) {
var return_qStr_value = null;
if (typeof urlStr === "string") {
if (urlStr.indexOf("?") > -1.0) {
return_qStr_value = urlStr.split("?")[1];
}
else {
return_qStr_value = "";
}
}
return return_qStr_value;
}
//function return_value_by_name(qstr, str_name) {
// var value = null;
// var name = null;
// if (typeof qstr === "string") {
// if (qstr.length > 0) {
// if (qstr.indexOf("=") > -1.0) {
// if (qstr.indexOf("&") > -1.0) {
// //querystring contains both at least 1 "=" character,
// //and at least 1 "&" character.
// }
// else {
// //querystring contains an '=' character,
// //but not a '&' character.
// //name = qstr.split("=")[0];
// //value = qstr.split("=")[1];
// }
// }
// else {
// //querystring contains no '=' character.
// }
// }
// else {
// //querystring is a zero-length string.
// }
// }
// else {
// //querystring input does not qualify as a data type of "string"
// }
//}
function return_non_cached_url(url) {
var rand = null;
var i = null;
var r_value = null;
var new_r_qStr = null;
var urlStr = null;
var non_cached_url = null;
urlStr = url;
//random 10 digit number
rand = (Math.floor(Math.random() * 9000000000) + parseInt(1000000000)).toString();
if (typeof urlStr === "string") {
if (urlStr.length > 0) {
if (urlStr.indexOf("random=") > -1.0) {
r_value = get_querystring_value_by_name(urlStr, "random");
if (typeof r_value === "string") {
if (r_value.length > 0) {
//create the new name=value string, and
//replace the "random" querysting value
//with the new value, the 10 digit number
new_r_qStr = "random=" + rand;
non_cached_url = urlStr.replace(("random=" + r_value), (new_r_qStr));
}
else {
non_cached_url = urlStr.replace("random=", ""); //the "random" querystring value is a zero-length string. Set return output to input.
}
}
else {
non_cached_url = urlStr.replace("random=", ""); //the querystring value for "random" isn't a string data type. Set return output to input.
}
}
else {
if (urlStr.indexOf("?") > -1.0) {
urlStr = urlStr + "&random=" + rand; //append random querystring to url's existing querystring
}
else {
urlStr = urlStr + "?random=" + rand; //there is no querystring in the url string. Append it to the url as a new querystring
}
non_cached_url = urlStr; //set the output value to the newly modified url string
}
}
else {
non_cached_url = urlStr; //0 length string, set return value to input value
}
}
else {
non_cached_url = urlStr; //Not a string type object, set return value to input value
}
return non_cached_url;
}
/*
------------------------------------------------------------
BEGIN FUNCTIONS FOR REMOVING AN OBJECT'S ABILITY TO INTERACT.
------------------------------------------------------------
*/
//2023-09-19:
//A function that renders an element incapable of
//performing any event listeners, and comments out
//all inline HTML event handler attribute values. This renders
//the element incacpable of user interaction.
function remove_all_event_listeners_and_event_handlers(obj) {
////var delay = null;
//if testing this function using the entire document object,
//set the delay to 10000 ms. This lets all the document objects load before
//any changes are made.
////delay = 10000;
////delay = 10;
////setTimeout(function () {
remove_all_event_listeners(obj);
remove_all_event_handlers(obj);
//FYI: Testing this with the entire documentElement object.
//When testing set the timeout delay value to 10 seconds to be sure
//all elements on the page have loaded.
////remove_all_event_listeners(document.documentElement);
////remove_all_event_handlers(document.documentElement);
//// }, delay);
}
//this function comments out any inline HTML attributes
//that begin with "on", as in "onselect", or "onmouseup", etc.
//Example:
//'onmouseup="doSomething();"' is replaced with 'onmouseup="//doSomething();"'
function remove_all_event_handlers(elem) {
var obj = null;
var obj_nodes = [];
var obj_node_attributes = [];
var obj_node = null;
var obj_node_attribute = null;
var i = null;
var j = null;
var obj_nodes_length = null;
var obj_node_attributes_length = null;
var attribute_name = null;
var attribute_value = null;
var cloned_obj = null;
obj = elem;
if (obj !== null) {
obj_nodes = obj.getElementsByTagName("*");
if (obj_nodes.length > 0) {
obj_nodes_length = obj_nodes.length;
for (i = 0; i < obj_nodes_length; i++) {
obj_node = obj_nodes[i];
if (obj_node.hasAttributes() === true) {
obj_node_attributes = obj_node.attributes;
obj_node_attributes_length = obj_node_attributes.length;
for (j = 0; j < obj_node_attributes_length; j++) {
obj_node_attribute = obj_node_attributes.item(j);
attribute_name = obj_node_attribute.name;
attribute_value = obj_node_attribute.value;
if (attribute_name.substring(0, 2).toLowerCase() === "on" && attribute_name.indexOf("data-on") < 0) {
/*
//I put this here to prevent multiple comments from being placed
//in the value of the attribute. Uncomment if deemed necessary.
if (attribute_value.substring(0, 2) === "//") {
attribute_value = attribute_value.substring(2, attribute_value.length);
}
*/
//comment out any javascript event handlers, removing UI interaction
obj_node.setAttribute(attribute_name, "//" + attribute_value);
/*
//this was an attempt to remove the attribute itself,
//and place a 'data-' prefix onto inline event handler attributes.
if (obj_node.hasAttribute(attribute_name) === true) {
obj_node.removeAttribute(attribute_name);
}
obj_node.setAttribute("data-" + attribute_name, attribute_value);
console.log(obj_node.getAttribute("data-" + attribute_name));
*/
}
}
}
}
}
}
return obj;
}
//removes any existing event listeners from an element.
function remove_all_event_listeners(obj) {
obj.replaceWith(obj.cloneNode(true)); //remove any event listeners from the object by replacing it with a clone of itself.
}
/*
------------------------------------------------------------
END FUNCTIONS FOR REMOVING AN OBJECT'S ABILITY TO INTERACT.
------------------------------------------------------------
*/
/*
------------------------------------------------------------
BEGIN FUNCTIONS FOR GETTING WINDOW AND CONTENT TD SIZES.
------------------------------------------------------------
*/
//get the offset width value of a window.
function get_win_width(win_id) {
var win = null;
var win_width = null;
win = document.getElementById(win_id);
if (win !== null) {
win_width = parseFloat(win.offsetWidth);
// alert(win_width);
//win_width = win_width - (parseFloat(win.style.padding) * 2);
//win_width = win_width - (parseFloat(win.style.margin) * 2);
//win_width = win_width - (parseFloat(win.style.borderWidth) * 2);
}
return win_width;
}
//get the offset height value of a window.
function get_win_height(win_id) {
var win = null;
var win_height = null;
win = document.getElementById(win_id);
if (win !== null) {
win_height = parseFloat(win.offsetHeight);
// alert(win_height);
//win_height = win_height - (parseFloat(win.style.padding) * 2);
//win_height = win_height - (parseFloat(win.style.margin) * 2);
//win_height = win_height - (parseFloat(win.style.borderWidth) * 2);
}
return win_height;
}
//get the offset left value added to the scroll left value
//of a window.
function get_win_left(win_id) {
var win = null;
var win_left = null;
win = document.getElementById(win_id);
if (win !== null) {
win_left = parseFloat(win.offsetLeft) + parseFloat(win.scrollLeft);
//alert(win_left);
//win_left = win_left - (parseFloat(win.style.padding) * 2);
//win_left = win_left - (parseFloat(win.style.margin) * 2);
//win_left = win_left - (parseFloat(win.style.borderWidth) * 2);
}
return win_left;
}
//get the offset top value added to the scroll top value
//of a window.
function get_win_top(win_id) {
var win = null;
var win_top = null;
win = document.getElementById(win_id);
if (win !== null) {
win_top = parseFloat(win.offsetTop) + parseFloat(win.scrollTop);
//alert(win_top);
//win_top = win_top - (parseFloat(win.style.padding) * 2);
//win_top = win_top - (parseFloat(win.style.margin) * 2);
//win_top = win_top - (parseFloat(win.style.borderWidth) * 2);
}
return win_top;
}
function get_window_contents_td_width(win_id) {
var win = null;
var contents_td = null;
var td_width = null;
win = document.getElementById(win_id);
if (win !== null) {
contents_td = document.getElementById(win_id + "_tbl_0000_tr_0001_td_0000");
if (contents_td !== null) {
td_width = parseFloat(contents_td.offsetWidth);
//alert(td_width);
}
}
return td_width;
}
function get_window_contents_td_height(win_id) {
var win = null;
var contents_td = null;
var td_height = null;
win = document.getElementById(win_id);
if (win !== null) {
contents_td = document.getElementById(win_id + "_tbl_0000_tr_0001_td_0000");
if (contents_td !== null) {
td_height = parseFloat(contents_td.offsetHeight);
//alert(td_height);
}
}
return td_height;
}
function get_window_contents_td_left(win_id) {
var win = null;
var contents_td = null;
var td_left = null;
win = document.getElementById(win_id);
if (win !== null) {
contents_td = document.getElementById(win_id + "_tbl_0000_tr_0001_td_0000");
if (contents_td !== null) {
//td_left = parseFloat(win.clientLeft) + parseFloat(contents_td.offsetWidth); // + parseFloat(contents_td.scrollTop);
td_left = parseFloat(win.clientLeft); // + parseFloat(contents_td.offsetWidth); // + parseFloat(contents_td.scrollTop);
//alert(td_left);
}
}
return td_left;
}
function get_window_contents_td_top(win_id) {
var win = null;
var contents_td = null;
var td_top = null;
win = document.getElementById(win_id);
if (win !== null) {
contents_td = document.getElementById(win_id + "_tbl_0000_tr_0001_td_0000");
if (contents_td !== null) {
td_top = parseFloat(win.clientTop) + parseFloat(contents_td.offsetTop); // + parseFloat(contents_td.scrollTop);
//alert(td_top);
}
}
return td_top;
}
/*
------------------------------------------------------------
END FUNCTIONS FOR GETTING WINDOW AND CONTENT TD SIZES.
------------------------------------------------------------
*/
//Returns the date in milliseconds.
function get_time_milliseconds() {
var time_ms = null;
var d = null;
d = new Date();
time_ms = d.getMilliseconds();
return time_ms;
}
function get_top_window_zIndex() {
var web_windows = null;
var num_windows = null;
var i = null;
var top_zIndex = null;
var web_window = null;
var current_zIndex = null;
web_windows = document.getElementsByName("web_window");
num_windows = parseFloat(web_windows.length);
top_zIndex = 0;
for (i = 0; i < num_windows; i++) {
web_window = web_windows[i];
current_zIndex = web_window.style.zIndex;
if (current_zIndex > top_zIndex) {
top_zIndex = current_zIndex;
}
}
return top_zIndex;
}
function get_bottom_window_zIndex() {
var web_windows = null;
var num_windows = null;
var i = null;
var bottom_zIndex = null;
var web_window = null;
var current_zIndex = null;
web_windows = document.getElementsByName("web_window");
num_windows = parseFloat(web_windows.length);
bottom_zIndex = 0;
for (i = 0; i < num_windows; i++) {
web_window = web_windows[i];
current_zIndex = web_window.style.zIndex;
if (current_zIndex < bottom_zIndex) {
bottom_zIndex = current_zIndex;
}
}
return bottom_zIndex;
}