-
Notifications
You must be signed in to change notification settings - Fork 1
/
aframe-teleport-extras.min.js
executable file
·1 lines (1 loc) · 1.96 KB
/
aframe-teleport-extras.min.js
1
if('undefined'==typeof AFRAME)throw new Error('Component attempted to register before AFRAME was available.');AFRAME.registerComponent('toggle-on-event',{schema:{hideOn:{type:'string',default:'raycaster-intersection-cleared'},showOn:{type:'string',default:'raycaster-intersection'},raycasterObject:{type:'selector'}},noIntersections:0,init:function(){this.data.raycasterObject||(this.data.raycasterObject=this.el),this.data.raycasterObject.addEventListener(this.data.showOn,function(){this.noIntersections++,this.toggle()}.bind(this)),this.data.raycasterObject.addEventListener(this.data.hideOn,function(){this.noIntersections--,this.toggle()}.bind(this))},toggle:function(){this.noIntersections=Math.max(this.noIntersections,0),this.el.setAttribute('visible',0<this.noIntersections)}}),AFRAME.registerComponent('teleport-extras',{schema:{cursor:{type:'selector',default:'[cursor]'}},active:!0,init:function(){document.querySelector('a-scene').addEventListener('touchstart',this.startTouch.bind(this)),document.querySelector('a-scene').addEventListener('mousedown',this.startTouch.bind(this)),document.body.addEventListener('keydown',function(a){32==a.keyCode&&this.startTouch()}.bind(this)),document.querySelector('a-scene').addEventListener('touchend',this.endTouch.bind(this)),document.querySelector('a-scene').addEventListener('mouseup',this.endTouch.bind(this)),document.body.addEventListener('keyup',function(a){32==a.keyCode&&this.endTouch()}.bind(this)),this.el.addEventListener('raycaster-intersection',this.onStartIntersection.bind(this)),this.el.addEventListener('raycaster-intersection-cleared',this.onEndIntersection.bind(this))},startTouch:function(){this.active&&this.el.emit('starttouch')},endTouch:function(){this.active&&this.el.emit('endtouch')},onStartIntersection:function(){this.active=!1;const a=this.el.components['teleport-controls'];a.active=!1,a.hitEntity.setAttribute('visible',!1),a.teleportEntity.setAttribute('visible',!1)},onEndIntersection:function(){this.active=!0}});