Skip to content
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
16 changes: 13 additions & 3 deletions docs/components/vr-mode-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ to the [`<a-scene>` element][scene].

## Properties

| Property | Description | Default Value |
|----------|------------------------------------------------------|---------------|
| enabled | Whether or not to display UI related to entering VR. | true |
| Property | Description | Default Value |
|---------------|---------------------------------------------------------------------|---------------|
| enabled | Whether or not to display UI related to entering VR. | true |
| enterVRButton | Selector to a custom VR button. On click, the button will enter VR. | '' |

### Specifying a Custom Enter VR Button

```html
<a-scene vr-mode-ui="enterVRButton: #myEnterVRButton">
<!-- Style the button with images or whatever. -->
<a id="myEnterVRButton" href="#"></a>
</a-scene>
```

[scene]: ../core/scene.md
20 changes: 15 additions & 5 deletions src/components/scene/vr-mode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports.Component = registerComponent('vr-mode-ui', {
dependencies: ['canvas'],

schema: {
enabled: {default: true}
enabled: {default: true},
enterVRButton: {default: ''}
},

init: function () {
Expand Down Expand Up @@ -66,16 +67,23 @@ module.exports.Component = registerComponent('vr-mode-ui', {
},

update: function () {
var data = this.data;
var sceneEl = this.el;

if (!this.data.enabled || this.insideLoader || utils.getUrlParameter('ui') === 'false') {
if (!data.enabled || this.insideLoader || utils.getUrlParameter('ui') === 'false') {
return this.remove();
}
if (this.enterVREl || this.orientationModalEl) { return; }

// Add UI if enabled and not already present.
this.enterVREl = createEnterVRButton(this.onEnterVRButtonClick);
sceneEl.appendChild(this.enterVREl);
if (data.enterVRButton) {
// Custom button.
this.enterVREl = document.querySelector(data.enterVRButton);
this.enterVREl.addEventListener('click', this.onEnterVRButtonClick);
} else {
this.enterVREl = createEnterVRButton(this.onEnterVRButtonClick);
sceneEl.appendChild(this.enterVREl);
}

this.orientationModalEl = createOrientationModal(this.onModalClick);
sceneEl.appendChild(this.orientationModalEl);
Expand Down Expand Up @@ -137,7 +145,9 @@ function createEnterVRButton (onClick) {
wrapper.setAttribute(constants.AFRAME_INJECTED, '');
vrButton = document.createElement('button');
vrButton.className = ENTER_VR_BTN_CLASS;
vrButton.setAttribute('title', 'Enter VR mode with a headset or fullscreen mode on a desktop. Visit https://webvr.rocks or https://webvr.info for more information.');
vrButton.setAttribute('title',
'Enter VR mode with a headset or fullscreen mode on a desktop. ' +
'Visit https://webvr.rocks or https://webvr.info for more information.');
vrButton.setAttribute(constants.AFRAME_INJECTED, '');

// Insert elements.
Expand Down