| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 1 | document.addEventListener("DOMContentLoaded", function () { |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 2 | document.getElementById('appFrame-default').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."); |
| gio | 18d5c68 | 2024-05-02 10:30:57 +0400 | [diff] [blame] | 3 | |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 4 | function showTooltip(obj) { |
| 5 | obj.style.visibility = 'visible'; |
| 6 | obj.style.opacity = '1'; |
| 7 | } |
| 8 | function hideTooltip(obj) { |
| 9 | obj.style.visibility = 'hidden'; |
| 10 | obj.style.opacity = '0'; |
| 11 | } |
| 12 | |
| 13 | const circle = document.querySelector(".user-circle"); |
| 14 | const tooltipUser = document.querySelector("#tooltip-user"); |
| 15 | [ |
| 16 | ['mouseenter', () => showTooltip(tooltipUser)], |
| 17 | ['mouseleave', () => hideTooltip(tooltipUser)], |
| 18 | ].forEach(([event, listener]) => { |
| 19 | circle.addEventListener(event, listener); |
| 20 | }); |
| 21 | |
| 22 | const iframes = {}; |
| 23 | const rightPanel = document.getElementById('right-panel'); |
| 24 | |
| 25 | function showIframe(appId) { |
| 26 | document.querySelectorAll('.appFrame').forEach(iframe => { |
| 27 | iframe.style.display = iframe.id === `appFrame-${appId}` ? 'block' : 'none'; |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | function createIframe(appId, appUrl) { |
| 32 | const iframe = document.createElement('iframe'); |
| 33 | iframe.id = `appFrame-${appId}`; |
| 34 | iframe.className = 'appFrame'; |
| 35 | iframe.src = appUrl; |
| 36 | iframe.style.display = 'none'; |
| 37 | rightPanel.appendChild(iframe); |
| 38 | iframes[appId] = iframe; |
| 39 | } |
| 40 | |
| 41 | const icons = document.querySelectorAll(".app-icon-tooltip"); |
| 42 | icons.forEach(function (icon) { |
| 43 | icon.addEventListener("click", function (event) { |
| 44 | event.stopPropagation(); |
| 45 | const appUrl = this.getAttribute("data-app-url"); |
| 46 | const appId = this.getAttribute("data-app-id"); |
| 47 | if (!appUrl) { |
| 48 | const modalId = `modal-${this.querySelector('.help-button').id.replace('help-button-', '')}`; |
| 49 | openModal(document.getElementById(modalId)); |
| 50 | } else { |
| 51 | if (!iframes[appId]) createIframe(appId, appUrl); |
| 52 | showIframe(appId); |
| 53 | } |
| 54 | document.querySelectorAll(".app-icon-tooltip .background-glow").forEach((e) => e.remove()); |
| 55 | const glow = document.createElement('div'); |
| 56 | glow.classList.add("background-glow"); |
| 57 | glow.setAttribute("style", "transform: none; transform-origin: 50% 50% 0px;") |
| 58 | this.appendChild(glow); |
| 59 | }); |
| 60 | const tooltip = icon.querySelector('.tooltip'); |
| 61 | tooltip.addEventListener("click", function (event) { |
| 62 | event.stopPropagation(); |
| 63 | }); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 64 | [ |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 65 | ['mouseenter', () => showTooltip(tooltip)], |
| 66 | ['mouseleave', () => hideTooltip(tooltip)], |
| 67 | ['focus', () => showTooltip(tooltip)], |
| 68 | ['blur', () => hideTooltip(tooltip)], |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 69 | ].forEach(([event, listener]) => { |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 70 | icon.addEventListener(event, listener); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 71 | }); |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 72 | }); |
| 73 | |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 74 | let visibleModal = undefined; |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 75 | const openModal = function (modal) { |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 76 | modal.removeAttribute("close"); |
| 77 | modal.setAttribute("open", true); |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 78 | visibleModal = modal; |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 79 | }; |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 80 | const closeModal = function (modal) { |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 81 | modal.removeAttribute("open"); |
| 82 | modal.setAttribute("close", true); |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 83 | visibleModal = undefined; |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 84 | }; |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 85 | |
| 86 | const helpButtons = document.querySelectorAll('.help-button'); |
| 87 | helpButtons.forEach(function (button) { |
| 88 | button.addEventListener('click', function (event) { |
| 89 | event.stopPropagation(); |
| 90 | const buttonId = button.getAttribute('id'); |
| 91 | const modalId = 'modal-' + buttonId.substring("help-button-".length); |
| 92 | const closeHelpId = "close-help-" + buttonId.substring("help-button-".length); |
| 93 | const modal = document.getElementById(modalId); |
| 94 | openModal(modal); |
| 95 | const closeHelpButton = document.getElementById(closeHelpId); |
| 96 | closeHelpButton.addEventListener('click', function (event) { |
| 97 | event.stopPropagation(); |
| 98 | closeModal(modal); |
| 99 | }); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 100 | }); |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 101 | }); |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 102 | |
| 103 | const modalHelpButtons = document.querySelectorAll('.title-menu'); |
| 104 | modalHelpButtons.forEach(function (button) { |
| 105 | button.addEventListener('click', function (event) { |
| 106 | event.stopPropagation(); |
| 107 | const helpTitle = button.getAttribute('id'); |
| 108 | const helpTitleId = helpTitle.substring('title-'.length); |
| 109 | const helpContentId = 'help-content-' + helpTitleId; |
| 110 | const allContentElements = document.querySelectorAll('.help-content'); |
| 111 | allContentElements.forEach(function (contentElement) { |
| 112 | contentElement.style.display = "none"; |
| 113 | }); |
| 114 | modalHelpButtons.forEach(function (button) { |
| 115 | button.removeAttribute("aria-current"); |
| 116 | }); |
| 117 | document.getElementById(helpContentId).style.display = 'block'; |
| 118 | button.setAttribute("aria-current", "page"); |
| 119 | }); |
| 120 | }); |
| 121 | |
| 122 | document.addEventListener("keydown", (event) => { |
| 123 | if (event.key === "Escape" && visibleModal) { |
| 124 | closeModal(visibleModal); |
| 125 | } |
| 126 | }); |
| 127 | |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 128 | document.addEventListener("click", (event) => { |
| Davit Tabidze | 0007727 | 2024-06-11 20:19:36 +0400 | [diff] [blame^] | 129 | if (visibleModal === null) return; |
| 130 | const modalContent = visibleModal.querySelector("article"); |
| 131 | const closeButton = visibleModal.querySelector(".close-button"); |
| 132 | if (!modalContent.contains(event.target) || closeButton.contains(event.target)) { |
| 133 | closeModal(visibleModal); |
| 134 | } |
| gio | 92d8686 | 2024-05-21 12:51:31 +0400 | [diff] [blame] | 135 | }); |
| Davit Tabidze | 207ce08 | 2024-04-09 19:15:25 +0400 | [diff] [blame] | 136 | }); |