From 7ef7d68eea1bb059d4dffff6528882e85c33e508 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 17 Dec 2024 15:19:01 +0000 Subject: [PATCH] added windows 'close' event --- com/isoterminal.js | 5 ++--- com/window.js | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/com/isoterminal.js b/com/isoterminal.js index c6285f4..b8ee961 100644 --- a/com/isoterminal.js +++ b/com/isoterminal.js @@ -229,9 +229,6 @@ if( typeof AFRAME != 'undefined '){ instance.addEventListener('DOMready', () => { this.setupVT100(instance) - setTimeout( () => { - instance.setAttribute("html-as-texture-in-xr", `domid: #term; faceuser: true`) - },100) //instance.winbox.resize(720,380) let size = `width: ${this.data.width}; height: ${this.data.height}` instance.setAttribute("window", `title: xrsh.iso; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}; ${size}; min: ${this.data.minimized}; max: ${this.data.maximized}; class: no-full, no-resize, no-move`) @@ -239,6 +236,8 @@ if( typeof AFRAME != 'undefined '){ instance.addEventListener('window.oncreate', (e) => { instance.dom.classList.add('blink') + // canvas to texture texture + instance.setAttribute("html-as-texture-in-xr", `domid: .winbox#${instance.uid}; faceuser: true`) // run iso let opts = {dom:instance.dom} diff --git a/com/window.js b/com/window.js index 8395e6b..7015de2 100644 --- a/com/window.js +++ b/com/window.js @@ -27,6 +27,20 @@ AFRAME.registerComponent('window', { await AFRAME.utils.require(this.dependencies) if( !this.el.dom ) return console.error('window element requires dom-component as dependency') + const close = () => { + let e = {halt:false} + this.el.emit('window.onclose',e) + if( e.halt ) return true + this.data.dom.style.display = 'none'; + if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el ) + this.data.dom.parentElement.remove() + return false + } + this.el.addEventListener('close', () => { + close() + this.el.winbox.close() + }) + this.el.dom.style.display = 'none' let winbox = this.el.winbox = new WinBox( this.data.title, { class: this.data.class, @@ -51,15 +65,8 @@ AFRAME.registerComponent('window', { this.el.components['obb-collider'].update() },1000) }, - onclose: () => { - let e = {halt:false} - this.el.emit('window.onclose',e) - if( e.halt ) return true - this.data.dom.style.display = 'none'; - if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el ) - this.data.dom.parentElement.remove() - return false - }, + onclose: close + }); this.data.dom.style.display = '' // show