Skip to content

Commit

Permalink
create scene-title component
Browse files Browse the repository at this point in the history
add 'newTitle' event emitter to metadata component
  • Loading branch information
Algorush committed Oct 6, 2023
1 parent 845b9f6 commit 492cd30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
inspector="url: //3dstreet.app/dist/3dstreet-editor.js"
notify
metadata
scene-title
>
<a-assets>
<!-- uncomment the line below to load assets from local github submodule -->
Expand Down
20 changes: 18 additions & 2 deletions src/json-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,24 @@ AFRAME.registerComponent('metadata', {
sceneTitle: { default: '' },
sceneId: { default: '' }
},
init: function () { },
update: function (oldData) {
const sceneTitle = this.data.sceneTitle;
if (sceneTitle !== oldData.sceneTitle) {
this.el.emit('newTitle', {sceneTitle: sceneTitle});
}
}
});

AFRAME.registerComponent('scene-title', {
schema: {
titleText: { default: '' }
},
init: function () {
this.titleElement = undefined;
this.el.addEventListener('newTitle', (evt) => {
this.el.setAttribute('scene-title', 'titleText', evt.detail.sceneTitle);
});
},
createTitleElement: function (titleText) {
const titleDiv = this.titleElement = document.createElement('div');
Expand All @@ -428,10 +444,10 @@ AFRAME.registerComponent('metadata', {
// No need to update.
if (Object.keys(oldData).length === 0) { return; }

const titleText = this.data.sceneTitle;
const titleText = this.data.titleText;
const titleElement = this.titleElement;

if (titleText !== oldData.sceneTitle) {
if (titleText !== oldData.titleText) {
if (!titleElement) {
this.createTitleElement(titleText);
} else {
Expand Down

0 comments on commit 492cd30

Please sign in to comment.