Skip to content

Commit 492cd30

Browse files
committed
create scene-title component
add 'newTitle' event emitter to metadata component
1 parent 845b9f6 commit 492cd30

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
inspector="url: //3dstreet.app/dist/3dstreet-editor.js"
4848
notify
4949
metadata
50+
scene-title
5051
>
5152
<a-assets>
5253
<!-- uncomment the line below to load assets from local github submodule -->

src/json-utils.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,24 @@ AFRAME.registerComponent('metadata', {
410410
sceneTitle: { default: '' },
411411
sceneId: { default: '' }
412412
},
413+
init: function () { },
414+
update: function (oldData) {
415+
const sceneTitle = this.data.sceneTitle;
416+
if (sceneTitle !== oldData.sceneTitle) {
417+
this.el.emit('newTitle', {sceneTitle: sceneTitle});
418+
}
419+
}
420+
});
421+
422+
AFRAME.registerComponent('scene-title', {
423+
schema: {
424+
titleText: { default: '' }
425+
},
413426
init: function () {
414427
this.titleElement = undefined;
428+
this.el.addEventListener('newTitle', (evt) => {
429+
this.el.setAttribute('scene-title', 'titleText', evt.detail.sceneTitle);
430+
});
415431
},
416432
createTitleElement: function (titleText) {
417433
const titleDiv = this.titleElement = document.createElement('div');
@@ -428,10 +444,10 @@ AFRAME.registerComponent('metadata', {
428444
// No need to update.
429445
if (Object.keys(oldData).length === 0) { return; }
430446

431-
const titleText = this.data.sceneTitle;
447+
const titleText = this.data.titleText;
432448
const titleElement = this.titleElement;
433449

434-
if (titleText !== oldData.sceneTitle) {
450+
if (titleText !== oldData.titleText) {
435451
if (!titleElement) {
436452
this.createTitleElement(titleText);
437453
} else {

0 commit comments

Comments
 (0)