blob: bcc16e04181cf18dada1d55c03c883be6d4655d2 [file] [log] [blame]
Davit Tabidze207ce082024-04-09 19:15:25 +04001document.addEventListener("DOMContentLoaded", function () {
gio18d5c682024-05-02 10:30:57 +04002 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 Tabidze207ce082024-04-09 19:15:25 +04004 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");
giocf6c7142024-05-21 13:26:42 +040027 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 Tabidze207ce082024-04-09 19:15:25 +040035 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 });
gio92d86862024-05-21 12:51:31 +040056 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 Tabidze207ce082024-04-09 19:15:25 +040067 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);
gio92d86862024-05-21 12:51:31 +040075 openModal(modal);
Davit Tabidze207ce082024-04-09 19:15:25 +040076 const closeHelpButton = document.getElementById(closeHelpId);
77 closeHelpButton.addEventListener('click', function (event) {
gio92d86862024-05-21 12:51:31 +040078 event.stopPropagation();
79 closeModal(modal);
Davit Tabidze207ce082024-04-09 19:15:25 +040080 });
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) {
gio106b0242024-05-21 12:17:03 +040092 contentElement.style.display = "none";
Davit Tabidze207ce082024-04-09 19:15:25 +040093 });
gio106b0242024-05-21 12:17:03 +040094 modalHelpButtons.forEach(function (button) {
95 button.removeAttribute("aria-current");
96 });
97 document.getElementById(helpContentId).style.display = 'block';
98 button.setAttribute("aria-current", "page");
Davit Tabidze207ce082024-04-09 19:15:25 +040099 });
100 });
gio92d86862024-05-21 12:51:31 +0400101 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 Tabidze207ce082024-04-09 19:15:25 +0400114});