Skip to content

Commit

Permalink
add div with title to metadata component code
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed Sep 23, 2023
1 parent c2705b5 commit 845b9f6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/json-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,35 @@ AFRAME.registerComponent('metadata', {
sceneTitle: { default: '' },
sceneId: { default: '' }
},
init: function () {}
init: function () {
this.titleElement = undefined;
},
createTitleElement: function (titleText) {
const titleDiv = this.titleElement = document.createElement('div');
const newContent = document.createTextNode(titleText);
titleDiv.setAttribute('id', 'sceneTitle');
titleDiv.appendChild(newContent);
document.body.append(titleDiv);
},
updateTitleText: function (titleText) {
this.titleElement.textContent = titleText;
},
update: function (oldData) {
// If `oldData` is empty, then this means we're in the initialization process.
// No need to update.
if (Object.keys(oldData).length === 0) { return; }

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

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

AFRAME.registerComponent('set-loader-from-hash', {
Expand Down
19 changes: 19 additions & 0 deletions src/viewer-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,22 @@ body {
background: #6100FF;
z-index: 9999;
}

/********* scene title css *********/

#sceneTitle {
position: fixed;
color: white;
font-size: 20px;
font-family: Lato;
font-weight: 400;
word-wrap: break-word;
bottom: 43px;
pointer-events: none;
z-index: 2;
width: 100%;
text-align: center;
height: 26px;
overflow: hidden;
text-overflow: ellipsis;
}

0 comments on commit 845b9f6

Please sign in to comment.