| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 1 | document.addEventListener("DOMContentLoaded", function () { |
| gio | 18d5c68 | 2024-05-02 10:30:57 +0400 | [diff] [blame] | 2 | document.querySelector('iframe').contentDocument.write("Welcome to the dodo: application launcher, think of it as your desktop environment. You can launch applications from left-hand side dock. You should setup VPN clients on your devices, so you can install applications from Application Manager and access your private network. Instructions on how to do that can be viewed by clicking <b>Help</b> button after hovering over <b>Headscale</b> icon in the dock."); |
| 3 | |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 4 | function showTooltip(obj) { |
| 5 | // obj.style.display = 'flex'; |
| 6 | obj.style.visibility = 'visible'; |
| 7 | obj.style.opacity = '1'; |
| 8 | } |
| 9 | function hideTooltip(obj) { |
| 10 | obj.style.visibility = 'hidden'; |
| 11 | obj.style.opacity = '0'; |
| 12 | // obj.style.display = ''; |
| 13 | } |
| 14 | const circle = document.querySelector(".user-circle"); |
| 15 | const tooltipUser = document.querySelector("#tooltip-user"); |
| 16 | [ |
| 17 | ['mouseenter', () => showTooltip(tooltipUser)], |
| 18 | ['mouseleave', () => hideTooltip(tooltipUser)], |
| 19 | ].forEach(([event, listener]) => { |
| 20 | circle.addEventListener(event, listener); |
| 21 | }); |
| 22 | const icons = document.querySelectorAll(".app-icon-tooltip"); |
| 23 | icons.forEach(function (icon) { |
| 24 | icon.addEventListener("click", function (event) { |
| 25 | event.stopPropagation(); |
| 26 | const appUrl = this.getAttribute("data-app-url"); |
| gio | cf6c714 | 2024-05-21 13:26:42 +0400 | [diff] [blame^] | 27 | if (!appUrl) { |
| 28 | const button = this.querySelector('.help-button'); |
| 29 | const buttonId = button.getAttribute('id'); |
| 30 | const modalId = 'modal-' + buttonId.substring("help-button-".length); |
| 31 | const modal = document.getElementById(modalId); |
| 32 | openModal(modal); |
| 33 | return; |
| 34 | } |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 35 | document.getElementById('appFrame').src = 'about:blank'; |
| 36 | document.getElementById('appFrame').src = appUrl; |
| 37 | document.querySelectorAll(".app-icon-tooltip .background-glow").forEach((e) => e.remove()); |
| 38 | const glow = document.createElement('div'); |
| 39 | glow.classList.add("background-glow"); |
| 40 | glow.setAttribute("style", "transform: none; transform-origin: 50% 50% 0px;") |
| 41 | this.appendChild(glow); |
| 42 | }); |
| 43 | const tooltip = icon.querySelector('.tooltip'); |
| 44 | tooltip.addEventListener("click", function (event) { |
| 45 | event.stopPropagation(); |
| 46 | }); |
| 47 | [ |
| 48 | ['mouseenter', () => showTooltip(tooltip)], |
| 49 | ['mouseleave', () => hideTooltip(tooltip)], |
| 50 | ['focus', () => showTooltip(tooltip)], |
| 51 | ['blur', () => hideTooltip(tooltip)], |
| 52 | ].forEach(([event, listener]) => { |
| 53 | icon.addEventListener(event, listener); |
| 54 | }); |
| 55 | }); |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 56 | let visibleModal = undefined; |
| 57 | const openModal = function(modal) { |
| 58 | modal.removeAttribute("close"); |
| 59 | modal.setAttribute("open", true); |
| 60 | visibleModal = modal; |
| 61 | }; |
| 62 | const closeModal = function(modal) { |
| 63 | modal.removeAttribute("open"); |
| 64 | modal.setAttribute("close", true); |
| 65 | visibleModal = undefined; |
| 66 | }; |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 67 | const helpButtons = document.querySelectorAll('.help-button'); |
| 68 | helpButtons.forEach(function (button) { |
| 69 | button.addEventListener('click', function (event) { |
| 70 | event.stopPropagation(); |
| 71 | const buttonId = button.getAttribute('id'); |
| 72 | const modalId = 'modal-' + buttonId.substring("help-button-".length); |
| 73 | const closeHelpId = "close-help-" + buttonId.substring("help-button-".length); |
| 74 | const modal = document.getElementById(modalId); |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 75 | openModal(modal); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 76 | const closeHelpButton = document.getElementById(closeHelpId); |
| 77 | closeHelpButton.addEventListener('click', function (event) { |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 78 | event.stopPropagation(); |
| 79 | closeModal(modal); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 80 | }); |
| 81 | }); |
| 82 | }); |
| 83 | const modalHelpButtons = document.querySelectorAll('.title-menu'); |
| 84 | modalHelpButtons.forEach(function (button) { |
| 85 | button.addEventListener('click', function (event) { |
| 86 | event.stopPropagation(); |
| 87 | const helpTitle = button.getAttribute('id'); |
| 88 | const helpTitleId = helpTitle.substring('title-'.length); |
| 89 | const helpContentId = 'help-content-' + helpTitleId; |
| 90 | const allContentElements = document.querySelectorAll('.help-content'); |
| 91 | allContentElements.forEach(function (contentElement) { |
| gio | 106b024 | 2024-05-21 12:17:03 +0400 | [diff] [blame] | 92 | contentElement.style.display = "none"; |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 93 | }); |
| gio | 106b024 | 2024-05-21 12:17:03 +0400 | [diff] [blame] | 94 | modalHelpButtons.forEach(function (button) { |
| 95 | button.removeAttribute("aria-current"); |
| 96 | }); |
| 97 | document.getElementById(helpContentId).style.display = 'block'; |
| 98 | button.setAttribute("aria-current", "page"); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 99 | }); |
| 100 | }); |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 101 | document.addEventListener("keydown", (event) => { |
| 102 | if (event.key === "Escape" && visibleModal) { |
| 103 | closeModal(visibleModal); |
| 104 | } |
| 105 | }); |
| 106 | document.addEventListener("click", (event) => { |
| 107 | if (visibleModal === null) return; |
| 108 | const modalContent = visibleModal.querySelector("article"); |
| 109 | const isClickInside = modalContent.contains(event.target); |
| 110 | if (!isClickInside) { |
| 111 | closeModal(visibleModal); |
| 112 | } |
| 113 | }); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 114 | }); |