Skip to content
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

add div with title to metadata component code #359

Merged
merged 2 commits into from
Oct 16, 2023
Merged
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
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
46 changes: 45 additions & 1 deletion src/json-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,51 @@ AFRAME.registerComponent('metadata', {
sceneTitle: { default: '' },
sceneId: { default: '' }
},
init: function () {}
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');
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.titleText;
const titleElement = this.titleElement;

if (titleText !== oldData.titleText) {
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;
}
Loading