blob: 58ab6af2a61f7f6edc4826e475a781aacf14ce34 [file] [log] [blame]
Davit Tabidze207ce082024-04-09 19:15:25 +04001document.addEventListener("DOMContentLoaded", function () {
Davit Tabidze00077272024-06-11 20:19:36 +04002 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.");
gio18d5c682024-05-02 10:30:57 +04003
Davit Tabidze00077272024-06-11 20:19:36 +04004 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 Tabidze207ce082024-04-09 19:15:25 +040064 [
Davit Tabidze00077272024-06-11 20:19:36 +040065 ['mouseenter', () => showTooltip(tooltip)],
66 ['mouseleave', () => hideTooltip(tooltip)],
67 ['focus', () => showTooltip(tooltip)],
68 ['blur', () => hideTooltip(tooltip)],
Davit Tabidze207ce082024-04-09 19:15:25 +040069 ].forEach(([event, listener]) => {
Davit Tabidze00077272024-06-11 20:19:36 +040070 icon.addEventListener(event, listener);
Davit Tabidze207ce082024-04-09 19:15:25 +040071 });
Davit Tabidze00077272024-06-11 20:19:36 +040072 });
73
gio92d86862024-05-21 12:51:31 +040074 let visibleModal = undefined;
Davit Tabidze00077272024-06-11 20:19:36 +040075 const openModal = function (modal) {
gio92d86862024-05-21 12:51:31 +040076 modal.removeAttribute("close");
77 modal.setAttribute("open", true);
Davit Tabidze00077272024-06-11 20:19:36 +040078 visibleModal = modal;
gio92d86862024-05-21 12:51:31 +040079 };
Davit Tabidze00077272024-06-11 20:19:36 +040080 const closeModal = function (modal) {
gio92d86862024-05-21 12:51:31 +040081 modal.removeAttribute("open");
82 modal.setAttribute("close", true);
Davit Tabidze00077272024-06-11 20:19:36 +040083 visibleModal = undefined;
gio92d86862024-05-21 12:51:31 +040084 };
Davit Tabidze00077272024-06-11 20:19:36 +040085
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 Tabidze207ce082024-04-09 19:15:25 +0400100 });
gio92d86862024-05-21 12:51:31 +0400101 });
Davit Tabidze00077272024-06-11 20:19:36 +0400102
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
gio92d86862024-05-21 12:51:31 +0400128 document.addEventListener("click", (event) => {
Davit Tabidze00077272024-06-11 20:19:36 +0400129 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 }
gio92d86862024-05-21 12:51:31 +0400135 });
Davit Tabidze207ce082024-04-09 19:15:25 +0400136});