// JavaScript source code //20200818B var standard1 = function () { var enter_key = function (id, fn) { document.getElementById(id).addEventListener('keydown', function (e) { var key = e.which || e.keyCode; if (key === 13) { e.preventDefault(); fn(); document.getElementById(id).value = ""; } }); }; var title_case = function titleCase(string_name) { if (string_name !== null && typeof (string_name) === "string") { var string_name_array = string_name.split(' '); for (var i = 0; i < string_name_array.length; i++) { string_name_array[i] = string_name_array[i].charAt(0).toUpperCase() + string_name_array[i].substr(1); var hyphen_case_split = string_name_array[i].split("-"); if (hyphen_case_split.length > 1) { for (var j = 0; j < hyphen_case_split.length; j++) { hyphen_case_split[j] = hyphen_case_split[j].charAt(0).toUpperCase() + hyphen_case_split[j].substr(1); } string_name_array[i] = hyphen_case_split.join("-"); } } var titleCase_string = string_name_array.join(' '); return titleCase_string; } else { console.log("Only string can be processed"); } }; var toast_env = function () { var initialize = function (msg, duration) { durationActive = duration; var body_elem = document.getElementsByTagName('body')[0]; var toastDiv = document.createElement('DIV'); toastDiv.setAttribute('id', 'mirToastDiv'); toastDiv.setAttribute('style', 'transition: all 0.2s linear;z-index:2147483647;background-color: #000000 ;width : 100px;font-size:1rem;padding:5px;text-align: center;color: #ffffff;position: fixed; top:15%; right: 2%;opacity: 0;transition: opacity 0.3s, top 0.4s;'); var toastMessage = document.createTextNode(msg); toastDiv.appendChild(toastMessage); body_elem.insertBefore(toastDiv, body_elem.lastElementChild); in_transition_duration = 200; out_transition_duration = 400; durationActive += in_transition_duration + out_transition_duration; setTimeout(function () { toastDiv.style.top = '10%'; toastDiv.style.opacity = '1'; setTimeout(function () { toastDiv.style.top = '5%'; toastDiv.style.opacity = '0'; setTimeout(function () { body_elem.removeChild(toastDiv); }, durationActive + 1800); }, durationActive); }, in_transition_duration); }; return { initialize: initialize } }(); var toast_avp = function () { var initialize = function (msg, duration) { var soundFile = document.createElement("audio"); soundFile.src = "/sounds/notification_ping.mp3"; soundFile.currentTime = 0.01; soundFile.volume = 0.5; durationActive = duration; var body_elem = document.getElementsByTagName('body')[0]; var toastDiv = document.createElement('DIV'); toastDiv.setAttribute('id', 'mirToastDiv'); toastDiv.setAttribute('style', 'transition: all 0.2s linear;z-index:2147483647;background-color: #000000 ;width : 350px;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; top:95%; right: 2%;opacity: 0;transition: opacity 0.3s, top 0.4s;'); var toastMessage = document.createTextNode(msg); toastDiv.appendChild(toastMessage); body_elem.insertBefore(toastDiv, body_elem.lastElementChild); in_transition_duration = 200; out_transition_duration = 400; durationActive += in_transition_duration + out_transition_duration; setTimeout(function () { soundFile.play(); toastDiv.style.top = '90%'; toastDiv.style.opacity = '1'; setTimeout(function () { toastDiv.style.top = '85%'; toastDiv.style.opacity = '0'; setTimeout(function () { body_elem.removeChild(toastDiv); }, durationActive + 1800); }, durationActive); }, in_transition_duration); }; return { initialize: initialize } }(); var test = function () { console.log("Standard works"); }; var toast = function (msg, duration, position = "bottom_right") { console.log("triggering toast"); var durationActive = duration; var toastDiv = document.createElement('DIV'); toastDiv.setAttribute('id', 'mirToastDiv'); if (position == "bottom_right") { toastDiv.setAttribute('style', 'transition: all 0.2s linear;background-color: #000000 ;z-index:2147483647;width : 350px;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; bottom:5%; right: 2%;opacity: 0;transition: opacity 0.3s, bottom 0.4s;'); } else if (position == "bottom_left") { toastDiv.setAttribute('style', 'transition: all 0.2s linear;background-color: #000000 ;z-index:2147483647;width : 350px;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; bottom:5%; left: 2%;opacity: 0;transition: opacity 0.3s, bottom 0.4s;'); } else if (position == "top_left") { toastDiv.setAttribute('style', 'transition: all 0.2s linear;background-color: #000000 ;z-index:2147483647;width : 350px;height: fit-content;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; top:5%; left: 2%;opacity: 0;transition: opacity 0.3s, top 0.4s;'); } else if (position == "top_right") { toastDiv.setAttribute('style', 'transition: all 0.2s linear;background-color: #000000 ;z-index:2147483647;width : 350px;height: fit-content;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; top:5%; right: 2%;opacity: 0;transition: opacity 0.3s, top 0.4s;'); } else { toastDiv.setAttribute('style', 'transition: all 0.2s linear;background-color: #000000 ;z-index:2147483647;width : 350px;font-size:1.2rem;padding:8px;text-align: center;color: #ffffff;position: fixed; bottom:5%; right: 2%;opacity: 0;transition: opacity 0.3s, bottom 0.4s;'); } var toastMessage = document.createTextNode(msg.toString()); toastDiv.appendChild(toastMessage); document.getElementsByTagName('body')[0].appendChild(toastDiv); var in_transition_duration = 200; var out_transition_duration = 400; durationActive += in_transition_duration + out_transition_duration; if(position == "bottom_right" || position == "bottom_left"){ setTimeout(function () { toastDiv.style.bottom = '10%'; toastDiv.style.opacity = '1'; setTimeout(function () { toastDiv.style.bottom = '15%'; toastDiv.style.opacity = '0'; setTimeout(function () { document.getElementsByTagName('body')[0].removeChild(toastDiv); }, durationActive + 1800); }, durationActive); }, in_transition_duration); } else if(position == "top_left" || position == "top_right"){ setTimeout(function () { toastDiv.style.top = '10%'; toastDiv.style.opacity = '1'; setTimeout(function () { toastDiv.style.top = '15%'; toastDiv.style.opacity = '0'; setTimeout(function () { document.getElementsByTagName('body')[0].removeChild(toastDiv); }, durationActive + 1800); }, durationActive); }, in_transition_duration); } }; var add_mouse_over_effect = function (elem) { elem.addEventListener("mouseover", function () { elem.style.opacity = "0.8"; }); elem.addEventListener("mouseout", function () { elem.style.opacity = "1"; }); }; var deep_copy = function (a) { var keys = Object.keys(a); var b = {}; for (var i = 0; i < keys.length; i++) { b[keys[i]] = a[keys[i]]; } return b; }; var insert_html = function (s, list_of_vals) { var slot_count = s.match(/%s/g).length; var val_count = list_of_vals.length; if (slot_count != val_count) { console.log('WARNING: Slot count does not match val count'); } for (var i = 0; i < list_of_vals.length; i++) { s = s.replace('%s', list_of_vals[i]); } return s; }; var input_title = function (parent_elem, input_type, span_title) { var input_elem = parent_elem.querySelector(input_type); var span_elem = parent_elem.querySelector("span"); input_elem.addEventListener("keyup", function () { if (input_elem.value.length > 0) { span_elem.classList.add("span_normal"); span_elem.textContent = span_title; } else { span_elem.classList.remove("span_normal"); span_elem.textContent = ""; } }) input_elem.addEventListener("change", function () { if (input_elem.value.length > 0) { span_elem.classList.add("span_normal"); span_elem.textContent = span_title; } else { span_elem.classList.remove("span_normal"); span_elem.textContent = ""; } }); }; var sanitized_string = ""; var sanitize_innerhtml = function (html_string) { sanitized_string = html_string; if (html_string.indexOf("