Whatever ClearWindow needs to be in json
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 42s
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 42s
This commit is contained in:
87
frontend/app/services/Tooltip.js
Normal file
87
frontend/app/services/Tooltip.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import { ref } from 'vue';
|
||||
import { animate } from 'motion';
|
||||
|
||||
let content = ref("");
|
||||
let margin = 14;
|
||||
|
||||
let cursorX = 0;
|
||||
let cursorY = 0;
|
||||
|
||||
let showed = false;
|
||||
let hided = false;
|
||||
|
||||
function ShowTooltip(){
|
||||
let tooltip = document.getElementById('mouse-tooltip');
|
||||
|
||||
tooltip.style.display = "block";
|
||||
|
||||
if(!showed){
|
||||
animate(tooltip, {
|
||||
opacity: [0, 1],
|
||||
translateY: [20, 0]
|
||||
}, {duration: 0.1, ease: 'ease-out'});
|
||||
showed = true;
|
||||
hided = false;
|
||||
}
|
||||
}
|
||||
|
||||
function HideTooltip(){
|
||||
let tooltip = document.getElementById('mouse-tooltip');
|
||||
|
||||
|
||||
if(!hided){
|
||||
animate(tooltip, {
|
||||
opacity: [1, 0],
|
||||
translateY: [0, 20]
|
||||
}, {duration: 0.1, ease: 'ease-in'}).finished.then(() => tooltip.style.display = "none")
|
||||
hided = true;
|
||||
showed = false;
|
||||
}
|
||||
}
|
||||
|
||||
function AddTooltip(element, val, data = {}){
|
||||
element._dr_tooltip = {value: val, ...data};
|
||||
}
|
||||
|
||||
function UpdateVisibilityThread(){
|
||||
let tooltip = document.getElementById('mouse-tooltip');
|
||||
let elements = document.elementsFromPoint(cursorX, cursorY);
|
||||
|
||||
let visible = false;
|
||||
for(let i = 0; i < elements.length; i++){
|
||||
let element = elements[i];
|
||||
if(element._dr_tooltip){
|
||||
ShowTooltip();
|
||||
content.value = element._dr_tooltip.value;
|
||||
if(element._dr_tooltip.max_width) tooltip.style.maxWidth = element._dr_tooltip.max_width + "px";
|
||||
else tooltip.style.maxWidth = "none";
|
||||
visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!visible) HideTooltip();
|
||||
|
||||
setTimeout(UpdateVisibilityThread, 0);
|
||||
}
|
||||
|
||||
function SetupTooltip(){
|
||||
let tooltip = document.getElementById('mouse-tooltip');
|
||||
|
||||
document.addEventListener("mousemove", (event) => {
|
||||
cursorX = event.clientX;
|
||||
cursorY = event.clientY;
|
||||
|
||||
tooltip.style.top = (cursorY + margin) + "px";
|
||||
tooltip.style.left = (cursorX + margin) + "px";
|
||||
});
|
||||
|
||||
UpdateVisibilityThread();
|
||||
}
|
||||
|
||||
let GetContentRef = () => content;
|
||||
|
||||
export {
|
||||
SetupTooltip,
|
||||
GetContentRef,
|
||||
AddTooltip,
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ClearWindowsWithType, GetFirstWindowId } from './Windows'
|
||||
|
||||
/*
|
||||
Put here all dragonroll windows
|
||||
*/
|
||||
|
||||
const defWindows = {
|
||||
login: {
|
||||
title: 'windows.login',
|
||||
@@ -20,7 +21,13 @@ const defWindows = {
|
||||
example: {
|
||||
title: 'windows.example',
|
||||
component: () => import('~/components/windows/ExampleWindow.vue'),
|
||||
}
|
||||
},
|
||||
edit_profile: {
|
||||
title: "windows.edit-profile",
|
||||
component: () => import('~/components/windows/EditProfileWindow.vue'),
|
||||
close: () => ClearWindowsWithType(GetFirstWindowId('edit_profile')),
|
||||
movable: true
|
||||
},
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import { ref } from 'vue'
|
||||
import { defWindows } from './WindowDefinitions';
|
||||
import { defineAsyncComponent } from 'vue'
|
||||
|
||||
const componentCache = {}
|
||||
|
||||
const getComponent = (type) => {
|
||||
if (!componentCache[type]) {
|
||||
componentCache[type] = defineAsyncComponent(
|
||||
defWindows[type].component
|
||||
)
|
||||
}
|
||||
|
||||
return componentCache[type]
|
||||
}
|
||||
|
||||
const windows = ref([]);
|
||||
|
||||
const getComponent = (type) => defineAsyncComponent(defWindows[type]?.component)
|
||||
|
||||
const reload = ref(0);
|
||||
|
||||
let ReloadRef = () => { return reload };
|
||||
let Windows = () => { return windows };
|
||||
let WindowMap = () => { return windowMap };
|
||||
|
||||
let currentIndex = 10;
|
||||
@@ -107,8 +113,9 @@ function SetupHandle(id, handle) {
|
||||
|
||||
// Should move eventually?
|
||||
window.addEventListener('resize', (event) => {
|
||||
if(!win.movable){
|
||||
ResetPosition(id, "center");
|
||||
for(const w of windows.value){
|
||||
if(w.movable) continue;
|
||||
ResetPosition(w.id, "center");
|
||||
}
|
||||
})
|
||||
|
||||
@@ -182,6 +189,7 @@ function GetPosition(id) {
|
||||
}
|
||||
|
||||
function ResetPosition(id, pos) {
|
||||
console.log("The id: ", id)
|
||||
let win = GetWindowWithId(id);
|
||||
let data = { x: win.x, y: win.y };
|
||||
|
||||
@@ -194,42 +202,48 @@ function ResetPosition(id, pos) {
|
||||
|
||||
|
||||
function CreateWindow(type, data = {}) {
|
||||
console.log("Creating window")
|
||||
console.log(windows.value);
|
||||
|
||||
let finalData = { ...{ type, id: currentId }, ...defWindows[type], ...data }
|
||||
console.log(finalData);
|
||||
|
||||
currentId++;
|
||||
|
||||
let contains = false;
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == finalData.type) {
|
||||
contains = true;
|
||||
console.log("It contains")
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) {
|
||||
windows.value.push(finalData);
|
||||
currentId++;
|
||||
console.log(finalData);
|
||||
console.log("Pushed ", finalData.type);
|
||||
// reload.value += 1;
|
||||
|
||||
console.log(windows.value);
|
||||
|
||||
console.log(windows.value)
|
||||
setTimeout(() => {
|
||||
SetOnTop(finalData.type);
|
||||
SetOnTop(finalData.id);
|
||||
if (finalData.create) finalData.create();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function CreateChildWindow(parentId, type, data = {}) {
|
||||
console.log("Creating child window")
|
||||
console.log(parentId, type, data);
|
||||
let finalData = { ...{ type }, ...defWindows[type], ...data }
|
||||
|
||||
let parent = GetWindowWithId(parentId);
|
||||
console.log(parent);
|
||||
if (parent.children) parent.children.push(finalData.type);
|
||||
else parent.children = [finalData.type];
|
||||
CreateWindow(type, data);
|
||||
}
|
||||
|
||||
function GetFirstWindowId(type) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == type) return windows.value[i].id;
|
||||
}
|
||||
}
|
||||
|
||||
function ClearAll() {
|
||||
Object.keys(windows).forEach((key) => {
|
||||
windows.value = [];
|
||||
@@ -243,21 +257,25 @@ function ClearWindows(data) {
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function ClearWindowsWithType(type) {
|
||||
const index = windows.value.findIndex(w => w.type === type);
|
||||
if (index !== -1) ClearWindow(windows.value[index].id)
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function ClearWindow(id) {
|
||||
let win = GetWindowWithId(id);
|
||||
console.log(win);
|
||||
if (!win) return;
|
||||
if (win.children) for (let i = 0; i < win.children.length; i++) ClearWindow(win.children[i]);
|
||||
windows.value = windows.value.filter((e) => { return e.type !== id });
|
||||
if (win.children) for (let i = 0; i < win.children.length; i++) ClearWindow(win.children[i].id);
|
||||
const index = windows.value.findIndex(w => w.type === id)
|
||||
if (index !== -1) windows.value.splice(index, 1)
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function GetWindowWithId(id) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == id) {
|
||||
return windows.value[i];
|
||||
}
|
||||
}
|
||||
const index = windows.value.findIndex(w => w.id === id);
|
||||
if (index !== -1) return windows.value[index];
|
||||
}
|
||||
|
||||
function CallWindow(id, callableName, arg) {
|
||||
@@ -283,6 +301,7 @@ function SetOnTop(id) {
|
||||
}
|
||||
|
||||
export {
|
||||
windows,
|
||||
SetupHandle,
|
||||
SetSize,
|
||||
SetResizable,
|
||||
@@ -291,17 +310,17 @@ export {
|
||||
SetPosition,
|
||||
SetMovable,
|
||||
ResetPosition,
|
||||
Windows,
|
||||
WindowMap,
|
||||
ReloadRef,
|
||||
ClearWindows,
|
||||
CreateWindow,
|
||||
CreateChildWindow,
|
||||
GetFirstWindowId,
|
||||
CallWindow,
|
||||
GetWindowWithId,
|
||||
SaveWindowPos,
|
||||
GetPosition,
|
||||
ClearWindow,
|
||||
ClearWindowsWithType,
|
||||
ClearAll,
|
||||
getComponent
|
||||
}
|
||||
Reference in New Issue
Block a user