"use strict"; function save_thumbnail_to_dom(win_id, win_html) { var new_id = null; var div_container = null; var thumbnails_container = null; var thumbnail_is_cached = null; var cached_thumb = null; var cached_thumb_child_array = null; var i = null; var thumbnail_elem = null; //create the DOM containers to hold cached thumbnails and the thumbnails' top parent container. //if you create the thumbnail's container, then the top parent container is automatically created as well. //if either of these DOM containers already exist, they will not be recreated. //instead, the existing objects are returned by the function. thumbnails_container = make_thumbnails_container(); //returns the thumbnail cache container in the DOM //create a string which will serve as a unique ID value for the div container holding the thumbnail HTML. //make a div object to serve as the thumbnail's parent container. //modify its ID attribute to make it unique. //store the thumbnail's ID, and the ID the of the thumbnails web window as custom attributes. //set the container so that its not displayed. //place the thumbnail's HTML into the container new_id = win_id + "_in_DOM"; div_container = document.createElement("div"); div_container.setAttribute("id", new_id + "_container"); div_container.setAttribute("name", "cached_DOM_thumbnails"); div_container.setAttribute("data-thumbnail_id_", win_id + "_is_cached"); div_container.setAttribute("data-win_id", win_id.replace("copied_node_", "")); div_container.style.display = "none"; div_container.style.position = "fixed"; div_container.style.border = "2px none rgb(0, 0, 255)"; div_container.innerHTML = win_html; //2023-09-19: //tried chanding every child id attribute. It caused errors. //Reset the code back to as it was from a backup file. //Will try again later.... //2023-09-19: //Set the child node of the div_container which is the stored web window thumbnail HTML. //change its ID attribute to be unique. A thumbnail located elsewhere in the //DOM(inside the 'single_thumbnail_contaier' object), may already exist. if (div_container.hasChildNodes() === true) { cached_thumb = div_container.childNodes[0]; if (cached_thumb !== null) { cached_thumb_child_array = cached_thumb.getElementsByTagName("*"); for (i = 0; i < cached_thumb_child_array.length; i++) { thumbnail_elem = cached_thumb_child_array[i]; thumbnail_elem.setAttribute("id", (thumbnail_elem.id + "_is_cached")); //change the cached thumbnail's ID attribute to be unique } } } //set the child node of the div_container which is the stored web window thumbnail HTML. //change its ID attribute to be unique. A thumbnail located elsewhere in the //DOM(inside the 'single_thumbnail_contaier' object), may already exist. /* if (div_container.hasChildNodes() === true) { cached_thumb = div_container.childNodes[0]; if (cached_thumb !== null) { cached_thumb.setAttribute("id", (cached_thumb.id + "_is_cached")); //change the cached thumbnail's ID attribute to be unique } } */ //check to see if the cached thumbnail's parent container object exists in the DOM. //If the thumbnail's container exists, then so does the thumbnail's HTML -- we don't need to check //for the actual cached thumbnail specifically. thumbnail_is_cached = thumbnail_exists_in_dom_cache(win_id + "_in_DOM_container"); //the argument is the ID attribute of the thumbnail's container object //console.log("thumbnail_is_cached"); if (thumbnail_is_cached === false) { if (thumbnails_container !== null) { thumbnails_container.appendChild(div_container); //add the container object and its thumbnail HTML into the cached thumbnails collection } } //get the cached thumbnail object via its parent container ID. //if the thumbnail object is not null (it exists), then //set the expiration date to 1.5 days. Time given until //expiration date is input as a number of days. The expiration //date provides the date as a number of seconds. if (div_container.hasChildNodes() === true) { cached_thumb = div_container.childNodes[0]; //get the thumbnail object in cache if (cached_thumb !== null) { //2023-06-24: Don't remove this. It may be used later. //store the expiration date in the thumbnail as an HTML attribute. //In this case, the expiration date expires in 1.5 days.The stored //expiration date is a numeric value representing a date in seconds. set_thumbnail_cache_expiration_date(cached_thumb.id, 0); } } } //This function creates the immediate parent container for cached thumbnails. //the immediate parent container is stored within the thumbnails' top parent //node container. If that top parent doesn't exist, create it. function make_thumbnails_container() { var div_id = null; var div_id_2 = null; var thumbnails_container = null; var thumbnails_top_container = null; var top_container = null; var single_thumbnail_container = null; div_id = "thumbnail_top_container"; thumbnails_top_container = document.getElementById(div_id); div_id_2 = "cached_thumbnails"; thumbnails_container = document.getElementById(div_id_2); if (thumbnails_top_container !== null) { if (thumbnails_container !== null) { thumbnails_top_container.appendChild(thumbnails_container); } else { single_thumbnail_container = document.createElement("div"); single_thumbnail_container.setAttribute("id", "cached_thumbnails"); thumbnails_top_container.appendChild(single_thumbnail_container); } } else { top_container = document.createElement("div"); top_container.setAttribute("id", "thumbnail_top_container"); document.body.appendChild(top_container); } return thumbnails_container; } //this function returns a boolean value of true if the thumbnail already exists in the DOM. //otherwise, it returns false. This prevents duplicate cached thumbnails from being //added to the DOM function thumbnail_exists_in_dom_cache(thumbnail_id) { var cached_thumbnails = null; var thumbnail = null; var thumb_id = null; var i = null; var exists = null; exists = false; cached_thumbnails = document.getElementById("cached_thumbnails"); if (cached_thumbnails !== null) { //alert("cached_thumbnails elem exists"); if (cached_thumbnails.hasChildNodes() === true) { //alert("has child nodes"); for (i = 0; i < cached_thumbnails.childElementCount; i++) { thumbnail = cached_thumbnails.childNodes[i]; //alert(thumbnail.id); //alert(thumbnail_id); if (thumbnail !== null) { //alert(thumbnail.hasAttribute("id")); if (thumbnail.hasAttribute("id") === true) { thumb_id = thumbnail.getAttribute("id"); if (thumb_id === thumbnail_id) { exists = true; //alert("test"); return exists; } } } } } } return exists; } function set_thumbnail_cache_expiration_date(thumbnail_id, num_of_days) { var thumbnail = null; var expire_date = null; var num_days_until_expiration = null; var days_until_expiration = null; var date_in_seconds = null; var default_expiration_days = null; var grace_period = null; var seconds_per_day = null; var seconds_until_expiration = null; //if the expiration time length in days is invalid, or not specified, default to 2.0 days. default_expiration_days = 2.0; //get the time until expiration in days. //if the number of days is not a valid number //that is equal to or greater than 0, then //then the number of days defaults to 2.0. num_days_until_expiration = num_of_days; if (typeof num_days_until_expiration === "number") { if (num_days_until_expiration >= 0) { days_until_expiration = num_days_until_expiration; //number of days passed in as an argument is a valid numver greater or equal to 0. } else { days_until_expiration = default_expiration_days; //number of days specified is less than 0. } } else { days_until_expiration = default_expiration_days; //the number of days specified is not a number } thumbnail = document.getElementById(thumbnail_id); if (thumbnail !== null) { expire_date = calculate_expiration_date(days_until_expiration); //today's date in seconds + number of days until expiration. grace_period = 10.0; //provide a 10 second grace period before the thumbnail expires. Used mostly for testing. date_in_seconds = parseFloat(get_date_in_seconds()); seconds_per_day = 60 * 60 * 24; seconds_until_expiration = (seconds_per_day * days_until_expiration); //this sets exiration date to 2 days from now (in seconds) expire_date = parseFloat(date_in_seconds) + parseFloat(grace_period) + parseFloat(seconds_until_expiration); //add today's date in seconds to the seconds until expiration to get the expiration date. thumbnail.setAttribute("data-thumbnail_cache_expiration_date", expire_date); //set expiration date in an html attribute of the thumbnail. } else { expire_date = calculate_expiration_date(days_until_expiration); //today's date in seconds + number of days until expiration. grace_period = 10.0; //provide a 10 second grace period before the thumbnail expires. Used mostly for testing. date_in_seconds = parseFloat(get_date_in_seconds()); seconds_per_day = 60 * 60 * 24; seconds_until_expiration = (seconds_per_day * days_until_expiration); //this sets exiration date to 2 days from now (in seconds) expire_date = parseFloat(date_in_seconds) + parseFloat(grace_period) + parseFloat(seconds_until_expiration); //add today's date in seconds to the seconds until expiration to get the expiration date. } //alert("Time till expiration: " + (expire_date - date_in_seconds)); return expire_date; } //2023-06-24: get the expiration date stored in a thumbnail object's HTML attribute. //if the attribute exists and is numeric return that date (in seconds). Otherwise, return null. function get_thumbnail_cache_expiration_date(thumbnail_id) { var thumbnail = null; var expires = null; thumbnail = document.getElementById(thumbnail_id); if (thumbnail !== null) { if (thumbnail.hasAttribute("data-expiration_date") === true) { expires = thumbnail.getAttribute("data-expiration_date"); if (expires !== null && !isNaN(expires) === true && expires !== undefined && expires !== "") { return expires; } else { //in this conditional, the 'expires' variable is either non-existent, or //does not have a numerical value, or has the value of null. So, //set the expiration date into a new HTML attribute of "data-expiration_date". expires = set_thumbnail_cache_expiration_date(thumbnail_id, 2.0); return expires; } } else { //the HTML attribute doesn't exist in this object. Add it. expires = set_thumbnail_cache_expiration_date(thumbnail_id, 2.0); return expires; } } return expires; } //2023-06-24: depending on the number of days //specified in this function's argument, this function //returns the expiration date in seconds. //Defaults to 2 days if the argument isn't a number above -1.0 function calculate_expiration_date(num_days_until_expiration) { var date_in_seconds = null; var seconds_per_day = null; var seconds_until_expiration = null; var expiration_date_in_seconds = null; var days_until_expiration = null; if (typeof num_days_until_expiration === "number") { if (num_days_until_expiration >= 0) { days_until_expiration = num_days_until_expiration; } else { days_until_expiration = 2.0; } } else { days_until_expiration = 2.0; } date_in_seconds = parseFloat(get_date_in_seconds()); seconds_per_day = 60 * 60 * 24; seconds_until_expiration = seconds_per_day * days_until_expiration; //this sets exiration date to 2 days from now (in seconds) expiration_date_in_seconds = parseFloat(date_in_seconds) + parseFloat(seconds_until_expiration); //add today's date in seconds to the seconds until expiration to get the expiration date. return expiration_date_in_seconds; } //gets the date in milliseconds by default. Divide by 1,000 to get seconds. function get_date_in_seconds() { var d = null; var d_now = null; d = new Date(Date.now()); d_now = parseFloat(d.getTime()); d_now = Math.round(d_now / 1000); ////console.log(d_now); return d_now; } function is_cached_thumbnail_in_DOM_expired(thumbnail_id) { var thumbnail = null; var todays_date = null; var attribute_name = null; var expire_date = null; var is_expired = null; todays_date = parseFloat(get_date_in_seconds()); is_expired = null; //get thumbnail object by its ID thumbnail = document.getElementById(thumbnail_id); if (thumbnail !== null) { attribute_name = "data-thumbnail_cache_expiration_date"; //When expiration dates are stored in HTML //attributes, they may be retrieved by accessing this //thumbnail's attribute value. if (thumbnail.hasAttribute(attribute_name) === true) { expire_date = thumbnail.getAttribute(attribute_name); if (!isNaN(expire_date) === true) { expire_date = parseFloat(expire_date); if (!isNaN(todays_date) === true) { if (todays_date >= expire_date) { //the thumbnail is expired by: console.log("Thumbnail expired by " + (todays_date - expire_date) + " seconds."); is_expired = true; return is_expired; } else if (todays_date < expire_date) { //the thumbnail is valid for: console.log("Thumbnail is valid for " + (expire_date - todays_date) + " seconds."); is_expired = false; return is_expired; } } } } } return is_expired; } function position_cached_thumbnail_to_web_window(win_id) { var win = null; var thumbnail = null; var thumbnail_parent_container_id = null; var thumbnail_parent = null; win = document.getElementById(win_id); if (win !== null) { thumbnail = document.getElementById("copied_node_" + win_id + "_is_cached"); thumbnail_parent_container_id = "copied_node_" + win_id + "_in_DOM_container"; thumbnail_parent = document.getElementById(thumbnail_parent_container_id); if (thumbnail_parent !== null) { if (thumbnail !== null) { remove_elem_animations(thumbnail.id); thumbnail_parent.style.top = (parseFloat(win.offsetTop) + 29) + "px"; thumbnail_parent.style.left = (parseFloat(win.offsetLeft) + 28) + "px"; thumbnail_parent.style.width = ((parseFloat(thumbnail.style.width) * 0.5) + 3) + "px"; thumbnail_parent.style.height = ((parseFloat(thumbnail.style.height) * 0.5) + 3) + "px"; thumbnail.style.top = (parseFloat(win.scrollTop)) + "px"; thumbnail.style.left = (parseFloat(win.offsetLeft)) + "px"; //2023-06-26: If window icons still have a blue background from user interaction, //these two lines remove those backgrounds if they exist on a thumbnail object. remove_bg_color("copied_node_" + win_id + "_tbl_0000_tr_0000_td_0002"); remove_bg_color("copied_node_" + win_id + "_tbl_0000_tr_0000_td_0000"); } } } } /* function is_object_thumbnail_window(win_id) { var win = null; var is_thumbnail = null; var attr = null var r_value = null; win = document.getElementById(win_id); if (win !== null) { if (win.hasAttribute("data-is_thumbnail_object") === true) { is_thumbnail = win.getAttribute("data-is_thumbnail_object"); if (is_thumbnail !== null) { if (is_thumbnail === "true" || is_thumbnail === true) { r_value = true; } else if (r_value === "false" || r_value === false) { r_value = false; } else { r_value = null; } } } else { win.setAttribute("data-is_thumbnail_object", "false"); r_value = false; } } return r_value; } function set_object_thumbnail_true(win_id) { var win = null; win = document.getElementById(win_id); if (win !== null) { win.setAttribute("data-is_thumbnail_object", "true"); } } function set_object_thumbnail_false(win_id) { var win = null; win = document.getElementById(win_id); if (win !== null) { win.setAttribute("data-is_thumbnail_object", "false"); } } */