aframe-href-component
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -66,3 +66,17 @@ /******/ (function(modules) { // webpackBootstrap | ||
console.log('link to ' + url); | ||
window.location.href = url; | ||
if (url && url[0] === '#') { // in-page anchor | ||
var ele = document.querySelector(url); | ||
var cams = document.querySelectorAll('a-camera') | ||
if (ele && cams) { | ||
var targetPosition = ele.getAttribute('position'); | ||
console.log('focus camera to position:' + | ||
JSON.stringify(targetPosition)); | ||
cams[0].setAttribute('position', targetPosition); | ||
window.location.hash = url; | ||
} else { | ||
console.log('#id or a-camera is not defined'); | ||
} | ||
} else { // normal hyper link | ||
window.location.href = url; | ||
} | ||
}); | ||
@@ -69,0 +83,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("href",{schema:{"default":""},init:function(){var e=this.data;this.el.addEventListener("click",function(){console.log("link to "+e),window.location.href=e})}})}]); | ||
!function(e){function o(n){if(t[n])return t[n].exports;var r=t[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,o),r.loaded=!0,r.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("href",{schema:{"default":""},init:function(){var e=this.data;this.el.addEventListener("click",function(){if(console.log("link to "+e),e&&"#"===e[0]){var o=document.querySelector(e),t=document.querySelectorAll("a-camera");if(o&&t){var n=o.getAttribute("position");console.log("focus camera to position:"+JSON.stringify(n)),t[0].setAttribute("position",n),window.location.hash=e}else console.log("#id or a-camera is not defined")}else window.location.href=e})}})}]); |
16
index.js
@@ -20,5 +20,19 @@ if (typeof AFRAME === 'undefined') { | ||
console.log('link to ' + url); | ||
window.location.href = url; | ||
if (url && url[0] === '#') { // in-page anchor | ||
var ele = document.querySelector(url); | ||
var cams = document.querySelectorAll('a-camera') | ||
if (ele && cams) { | ||
var targetPosition = ele.getAttribute('position'); | ||
console.log('focus camera to position:' + | ||
JSON.stringify(targetPosition)); | ||
cams[0].setAttribute('position', targetPosition); | ||
window.location.hash = url; | ||
} else { | ||
console.log('#id or a-camera is not defined'); | ||
} | ||
} else { // normal hyper link | ||
window.location.href = url; | ||
} | ||
}); | ||
} | ||
}); |
{ | ||
"name": "aframe-href-component", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Hyper Link component for A-Frame.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,4 +5,6 @@ ## aframe-href-component | ||
Add `href="url"` attribute to any a-frame tag, turn the object as a normal web link. | ||
Add `href="www.sample.com"` attribute to any a-frame tag, turn the object as a normal web link. | ||
Add `href="#id"` attribute to any a-frame tag will move `a-camera` focus to the target object. (experimental) | ||
### Properties | ||
@@ -39,3 +41,3 @@ | ||
width="2" depth="2" height="2" color="#F16745" | ||
href="http://aframe.io/"></a-box> | ||
href="https://github.com/gasolin/aframe-href-component"></a-box> | ||
</a-scene> | ||
@@ -42,0 +44,0 @@ </body> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14146
13
107
59