Skip to content

added support for loading external html #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ To use the component you just add the component to the A-Frame entity containing
</a-scene>
```

> NOTE: `src:` lets you reference a local file using `<a-entity htmlembed="src: content.html" position="0 0 -5">`

## Interactivity

### Using CSS
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<a-entity id="mouseCursor" cursor="rayOrigin: mouse" raycaster="objects: .screen"></a-entity>
<a-entity laser-controls raycaster="objects: .screen;"></a-entity>
</a-entity>
<a-entity id="menu" class="screen menu dark" htmlembed="ppu:256" position="-2.712 2.5 -4.476" rotation="0 45 0">
<a-entity id="menu" class="screen menu dark" htmlembed="ppu:256;" position="-2.712 2.5 -4.476" rotation="0 45 0">
<h2>Menu</h2>
<ul>
<li><a href="#" class="button">Home</a></li>
Expand Down
4 changes: 4 additions & 0 deletions examples/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<b>Lorem ipsum</b>
<br>
<br>
This is a test
14 changes: 12 additions & 2 deletions src/aframe-htmlembed-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ AFRAME.registerComponent('htmlembed', {
ppu: {
type: 'number',
default: 256
}
},
src:{
type: 'string'
}
},
init: function() {
init: function(html) {
if( html ) this.el.innerHTML = html
if( !html && this.data.src){
fetch(this.data.src )
.then( (res) => res.text() )
.then( (html) => this.init(html) )
this.el.innerHTML = this.data.loaderhtml || 'loading..'
}
var htmlcanvas = new HTMLCanvas(this.el, () => {
if (texture) texture.needsUpdate = true;
}, (event, data) => {
Expand Down