Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix disabling link visual aspect, disable link visual aspect by default
  • Loading branch information
ngokevin committed Sep 4, 2018
commit e070ec9214ae8d314bf1a3cc3a91c592dbfa34c5
13 changes: 9 additions & 4 deletions src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports.Component = registerComponent('link', {
peekMode: {default: false},
title: {default: ''},
titleColor: {default: 'white', type: 'color'},
visualAspectEnabled: {default: true}
visualAspectEnabled: {default: false}
},

init: function () {
Expand All @@ -28,7 +28,6 @@ module.exports.Component = registerComponent('link', {
this.quaternionClone = new THREE.Quaternion();
// Store hidden elements during peek mode so we can show them again later.
this.hiddenEls = [];
this.initVisualAspect();
},

update: function (oldData) {
Expand All @@ -37,14 +36,18 @@ module.exports.Component = registerComponent('link', {
var backgroundColor;
var strokeColor;

if (!data.visualAspectEnabled) { return; }

this.initVisualAspect();

backgroundColor = data.highlighted ? data.highlightedColor : data.backgroundColor;
strokeColor = data.highlighted ? data.highlightedColor : data.borderColor;
el.setAttribute('material', 'backgroundColor', backgroundColor);
el.setAttribute('material', 'strokeColor', strokeColor);

if (data.on !== oldData.on) { this.updateEventListener(); }

if (data.visualAspectEnabled && oldData.peekMode !== undefined &&
if (oldData.peekMode !== undefined &&
data.peekMode !== oldData.peekMode) { this.updatePeekMode(); }

if (!data.image || oldData.image === data.image) { return; }
Expand Down Expand Up @@ -97,7 +100,7 @@ module.exports.Component = registerComponent('link', {
var sphereEl;
var textEl;

if (!this.data.visualAspectEnabled) { return; }
if (!this.data.visualAspectEnabled || this.visualAspectInitialized) { return; }

textEl = this.textEl = this.textEl || document.createElement('a-entity');
sphereEl = this.sphereEl = this.sphereEl || document.createElement('a-entity');
Expand Down Expand Up @@ -155,6 +158,8 @@ module.exports.Component = registerComponent('link', {
});
sphereEl.setAttribute('visible', false);
el.appendChild(sphereEl);

this.visualAspectInitialized = true;
},

navigate: function () {
Expand Down
22 changes: 14 additions & 8 deletions tests/components/link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
var entityFactory = require('../helpers').entityFactory;

suite('link', function () {
var el;

setup(function (done) {
var el = this.el = entityFactory();
el = entityFactory();
el.setAttribute('link', '');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
});

suite('init', function () {
test('initialize visual aspect', function () {
var el = this.el;
assert.ok(el.components.link.textEl);
assert.ok(el.components.link.sphereEl);
assert.ok(el.components.link.semiSphereEl);
});
test('does not initialize visual aspect by default', function () {
assert.notOk(el.components.link.textEl);
assert.notOk(el.components.link.sphereEl);
assert.notOk(el.components.link.semiSphereEl);
});

test('initializes visual aspect if set', function () {
el.setAttribute('link', 'visualAspectEnabled', true);
assert.ok(el.components.link.textEl);
assert.ok(el.components.link.sphereEl);
assert.ok(el.components.link.semiSphereEl);
});
});