/** * Function toggleHash toggles a specified location.hash value. * * @param {string} identifier ID to toggle. * * @return {void} */ function toggleHash(identifier) { if (window.location.hash == "#" + identifier) window.location.hash = ""; else window.location.hash = "#" + identifier; } document.addEventListener("DOMContentLoaded", function() { let translations = { "en" : { }, "de" : { }, "hu" : { } }; var debugging = false; /** * Function queryPage queries a web page and runs the specified function over the output. * * @param string url URL to query. * @param function func Callback function to run on the request after loading. * @param boolean debug Enable / disable debug mode. * * @return boolean */ function queryPage (url, func, debug = false) { let request = new XMLHttpRequest(); request.open('GET', url); request.setRequestHeader("Cache-Control", "no-cache"); request.responseType = 'htm'; request.send(); request.onload = function() { func(request, debug); }; } /** * Returns a requested translation from an array in the currently used language. * * @param mixed[] list Translation variable. * @param string specifier Specifies which translation to get. * * @return string */ function getTranslation (list, specifier) { let preferedLang = document.getElementsByTagName("html")[0].getAttribute("lang"); if (list[preferedLang] !== undefined && list[preferedLang][specifier] !== null) return list[preferedLang][specifier]; return list["en"][specifier]; } /** * Function to get all GET variables passed by user * Based on gion_13's answer at https://stackoverflow.com/questions/12049620/how-to-get-get-variables-value-in-javascript * * @return string[] */ function getGETvars () { var output = {}; if(document.location.toString().indexOf('?') !== -1) { var query = document.location .toString() // get the query string .replace(/^.*?\?/, '') // and remove any existing hash string (thanks, @vrijdenker) .replace(/#.*$/, '') .split('&'); for(var i = 0, l = query.length; i < l; i++) { var aux = decodeURIComponent(query[i]).split('='); output[aux[0]] = aux[1]; } } return (output); } /** * Open the URL given in the href attribute of the element with the given ID. * * @param {string} identifier ID of the element with whose href to replace location.href * * @return {void} */ function replaceWindowById(identifier) { var link = document.getElementById(identifier); if (link != null) { window.location.href = link.href; } } });