diff --git a/.gitignore b/.gitignore index 79eb93b09b6e26d831a4c8fad8592c6af42c8146..d88fa7776dab98ac8f8e2e2fda97f7eaf19b1193 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.htaccess \ No newline at end of file +.htaccess +.idea diff --git a/lib/scripts.js b/lib/scripts.js index 76dc09a284c869599c8f03bfbffb2a29fc21dc32..06b09770b895c2b0e1edc2e6b6bc3976688f4bc4 100644 --- a/lib/scripts.js +++ b/lib/scripts.js @@ -1,20 +1,45 @@ + +/** + * Open the menu, when click on the menu header button + */ function openMenu() { - + var menu = document.querySelector("header nav ul"); - var maxHeight = (menu.childElementCount * 2 + 1) + "rem"; - + if (menu.style.height != maxHeight) { - menu.style.height = maxHeight; - + } else { - menu.style.height = "0rem"; - } - } - document.querySelector("header nav button").addEventListener("click", openMenu); +/** + * Detect if URL has a Cesium pattern (like '#/app/xxx'), then redirect to https://demo.cesium.app. + * (Useful for OLD links http://g1.duniter.fr/#/app/xxx ) + */ +function detectCesiumHash() { + // Workaround to add String.startsWith() if not present + if (typeof String.prototype.startsWith !== 'function') { + console.debug("Adding String.prototype.startsWith() -> was missing on this platform"); + String.prototype.startsWith = function (prefix, position) { + return this.indexOf(prefix, position) === 0; + }; + } + + console.debug("[app] Trying to detect Cesium hash in '#/app/' in URL..."); + try { + var hash = window.location.hash; + if (hash && hash.startsWith('#/app/')) { + var demoUrl = "https://demo.cesium.app/" + hash; + console.debug("[app] Cesium hash detected! Redirect to: " + demoUrl); + window.location = demoUrl; + } + } catch (err) { + console.error(err); + } +} + +window.addEventListener("load", detectCesiumHash);