2024-06-28 18:01:24 +02:00
|
|
|
AFRAME.registerComponent('window', {
|
|
|
|
schema:{
|
2024-09-16 13:28:28 +02:00
|
|
|
title: {type:'string',"default":"title"},
|
|
|
|
width: {type:'string'}, // wrap
|
|
|
|
height: {type:'string',"default":'260px'},
|
|
|
|
uid: {type:'string'},
|
|
|
|
attach: {type:'selector'},
|
|
|
|
dom: {type:'selector'},
|
|
|
|
max: {type:'boolean',"default":false},
|
2024-09-17 18:59:38 +02:00
|
|
|
min: {type:'boolean',"default":false},
|
2024-09-16 13:28:28 +02:00
|
|
|
x: {type:'string',"default":"center"},
|
2024-11-20 12:03:44 +01:00
|
|
|
y: {type:'string',"default":"center"},
|
|
|
|
"class": {type:'array',"default":[]},
|
2024-06-28 18:01:24 +02:00
|
|
|
},
|
|
|
|
|
2024-07-04 23:00:44 +02:00
|
|
|
dependencies:{
|
|
|
|
dom: "com/dom.js",
|
2024-08-13 18:08:03 +02:00
|
|
|
winboxjs: "https://unpkg.com/winbox@0.2.82/dist/winbox.bundle.min.js", // deadsimple windows: https://nextapps-de.github.io/winbox
|
2024-08-26 12:02:35 +02:00
|
|
|
//winboxcss: "https://unpkg.com/winbox@0.2.82/dist/css/winbox.min.css", // main theme
|
2024-07-04 23:00:44 +02:00
|
|
|
},
|
2024-06-28 18:01:24 +02:00
|
|
|
|
|
|
|
init: function(){
|
|
|
|
setTimeout( () => this.setupWindow(), 10 ) // init after other components
|
|
|
|
},
|
|
|
|
|
2024-07-04 23:00:44 +02:00
|
|
|
setupWindow: async function(){
|
|
|
|
await AFRAME.utils.require(this.dependencies)
|
2024-06-28 18:01:24 +02:00
|
|
|
if( !this.el.dom ) return console.error('window element requires dom-component as dependency')
|
|
|
|
|
|
|
|
this.el.dom.style.display = 'none'
|
2024-07-04 23:00:44 +02:00
|
|
|
let winbox = this.el.winbox = new WinBox( this.data.title, {
|
2024-11-20 12:03:44 +01:00
|
|
|
class: this.data.class,
|
2024-06-28 18:01:24 +02:00
|
|
|
height:this.data.height,
|
2024-07-04 23:00:44 +02:00
|
|
|
width:this.data.width,
|
2024-06-28 18:01:24 +02:00
|
|
|
x: this.data.x,
|
|
|
|
y: this.data.y,
|
|
|
|
id: this.data.uid || String(Math.random()).substr(4), // important hint for html-mesh
|
|
|
|
root: this.data.attach || document.body,
|
|
|
|
mount: this.data.dom,
|
2024-09-16 13:28:28 +02:00
|
|
|
max: this.data.max,
|
2024-09-17 18:59:38 +02:00
|
|
|
min: this.data.min,
|
2024-08-13 18:08:03 +02:00
|
|
|
onresize: () => this.el.emit('window.onresize',{}),
|
|
|
|
onmaximize: () => this.el.emit('window.onmaximize',{}),
|
2024-09-16 13:28:28 +02:00
|
|
|
oncreate: (e) => {
|
2024-06-28 18:01:24 +02:00
|
|
|
this.el.emit('window.oncreate',{})
|
|
|
|
// resize after the dom content has been rendered & updated
|
|
|
|
setTimeout( () => {
|
2024-09-16 13:28:28 +02:00
|
|
|
if( !this.data.max ) winbox.resize( this.el.dom.offsetWidth+'px', this.el.dom.offsetHeight+'px' )
|
2024-08-13 18:08:03 +02:00
|
|
|
// hint grabbable's obb-collider to track the window-object
|
|
|
|
this.el.components['obb-collider'].data.trackedObject3D = 'components.html.el.object3D.children.0'
|
|
|
|
this.el.components['obb-collider'].update()
|
2024-06-28 18:01:24 +02:00
|
|
|
},1000)
|
|
|
|
},
|
|
|
|
onclose: () => {
|
|
|
|
let e = {halt:false}
|
|
|
|
this.el.emit('window.onclose',e)
|
|
|
|
if( e.halt ) return true
|
|
|
|
this.data.dom.style.display = 'none';
|
2024-09-23 16:58:48 +02:00
|
|
|
if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el )
|
2024-08-26 12:02:35 +02:00
|
|
|
this.data.dom.parentElement.remove()
|
2024-06-28 18:01:24 +02:00
|
|
|
return false
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.data.dom.style.display = '' // show
|
|
|
|
|
2024-08-13 18:08:03 +02:00
|
|
|
this.el.setAttribute("grabbable","")
|
2024-06-28 18:01:24 +02:00
|
|
|
|
2024-10-21 14:03:16 +02:00
|
|
|
if( this.el.object3D.position.x == 0 &&
|
|
|
|
this.el.object3D.position.y == 0 &&
|
|
|
|
this.el.object3D.position.z == 0 ){ // position next to previous window
|
|
|
|
var els = [...document.querySelectorAll('[window]')]
|
|
|
|
if( els.length < 2 ) return
|
|
|
|
let current = els[ els.length-1 ]
|
|
|
|
let last = els[ els.length-2 ]
|
2024-10-28 13:25:14 +01:00
|
|
|
AFRAME.utils.positionObjectNextToNeighbor( current.object3D , last.object3D, 0.02 )
|
2024-10-21 14:03:16 +02:00
|
|
|
}
|
2024-10-03 12:41:53 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
show: function(state){
|
|
|
|
this.el.dom.closest('.winbox').style.display = state ? '' : 'none'
|
2024-06-28 18:01:24 +02:00
|
|
|
}
|
|
|
|
})
|
2024-10-21 14:03:16 +02:00
|
|
|
|
2024-10-28 13:25:14 +01:00
|
|
|
AFRAME.utils.positionObjectNextToNeighbor = function positionObjectNextToNeighbor(object, lastNeighbor = null, margin ){
|
2024-10-21 14:03:16 +02:00
|
|
|
// *FIXME* this could be more sophisticated :)
|
2024-10-28 13:25:14 +01:00
|
|
|
object.position.x = lastNeighbor.position.x + margin
|
|
|
|
object.position.y = lastNeighbor.position.y - margin
|
|
|
|
object.position.z = lastNeighbor.position.z + margin
|
2024-10-21 14:03:16 +02:00
|
|
|
|
|
|
|
}
|