aframe-href-component
Advanced tools
Comparing version 0.5.0 to 0.5.1
58
index.js
@@ -0,3 +1,5 @@ | ||
/* globals AFRAME */ | ||
if (typeof AFRAME === 'undefined') { | ||
throw new Error('Component attempted to register before AFRAME was available.'); | ||
throw new Error('Component attempted to register before AFRAME' + | ||
' was available.'); | ||
} | ||
@@ -15,3 +17,3 @@ | ||
clickHandler: function href_clickHandler() { | ||
clickHandler: function hrefClickHandler() { | ||
var url = this.data; | ||
@@ -22,3 +24,3 @@ var target = this.el.getAttribute('target'); | ||
var ele = document.querySelector(url); | ||
var cams = document.querySelectorAll('a-camera') | ||
var cams = document.querySelectorAll('a-camera'); | ||
if (ele && cams) { | ||
@@ -37,3 +39,2 @@ var targetPosition = ele.getAttribute('position'); | ||
var exitAnimation = null; | ||
var animationendHandler = null; | ||
console.log('target to ' + target); | ||
@@ -47,28 +48,31 @@ if (target.indexOf('#') >= 0) { | ||
switch(target) { | ||
case '_blank': | ||
if (animation) { | ||
exitAnimation = document.getElementById(animation); | ||
exitAnimation.addEventListener('animationend', function animationendHandler() { | ||
exitAnimation.removeEventListener('animationend', animationendHandler); | ||
case '_blank': | ||
if (animation) { | ||
exitAnimation = document.getElementById(animation); | ||
exitAnimation.addEventListener('animationend', | ||
function animationendHandler() { | ||
exitAnimation.removeEventListener('animationend', | ||
animationendHandler); | ||
window.open(url); | ||
}); | ||
this.el.emit('href'); | ||
} else { | ||
window.open(url); | ||
} | ||
break; | ||
case 'window': | ||
default: | ||
if (animation) { | ||
exitAnimation = document.getElementById(animation); | ||
exitAnimation.addEventListener('animationend', function animationendHandler() { | ||
exitAnimation.removeEventListener('animationend', animationendHandler); | ||
console.log() | ||
this.el.emit('href'); | ||
} else { | ||
window.open(url); | ||
} | ||
break; | ||
case 'window': | ||
default: | ||
if (animation) { | ||
exitAnimation = document.getElementById(animation); | ||
exitAnimation.addEventListener('animationend', | ||
function animationendHandler() { | ||
exitAnimation.removeEventListener('animationend', | ||
animationendHandler); | ||
window.location.href = url; | ||
}); | ||
this.el.emit('href'); | ||
} else { | ||
window.location.href = url; | ||
} | ||
break; | ||
this.el.emit('href'); | ||
} else { | ||
window.location.href = url; | ||
} | ||
break; | ||
} | ||
@@ -93,5 +97,5 @@ } else { | ||
*/ | ||
remove: function () { | ||
remove: function() { | ||
this.el.removeEventListener('click', this.boundClickHandler); | ||
} | ||
}); |
{ | ||
"name": "aframe-href-component", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Hyper Link component for A-Frame.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "npm run eslint", | ||
"eslint": "eslint index.js examples/main.js", | ||
"build": "browserify examples/main.js -o examples/build.js", | ||
@@ -37,2 +39,4 @@ "dev": "budo examples/main.js:build.js --dir examples --port 8000 --live --open", | ||
"budo": "^8.2.2", | ||
"eslint": "^2.11.1", | ||
"eslint-config-defaults": "^9.0.0", | ||
"ghpages": "^0.0.8", | ||
@@ -39,0 +43,0 @@ "shx": "^0.1.1", |
@@ -16,2 +16,3 @@ ## aframe-href-component | ||
When link is clicked, the href-component will emit a `href` event within this object. You can append the animation id in `target` attribute, such as `target="#out-animation"` (a shortcut of `target="window#out-animation"`) or `target="_blank#out-animation"` to trigger the animation directly. If your animation is not defined within this object, you should emit the event manually. | ||
[demo](https://gasolin.github.io/aframe-href-component/basic/animation.html) | ||
@@ -18,0 +19,0 @@ ### Anchor support (experimental) |
20863
15
187
69
9