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
2 changes: 1 addition & 1 deletion src/components/look-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports.Component = registerComponent('look-controls', {
},

removeEventListeners: function () {
var sceneEl = document.querySelector('a-scene');
var sceneEl = this.el.sceneEl;
var canvasEl = sceneEl && sceneEl.canvas;
if (!canvasEl) { return; }

Expand Down
2 changes: 1 addition & 1 deletion src/components/raycaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports.Component = registerComponent('raycaster', {

// Push meshes onto list of objects to intersect.
if (data.objects) {
objectEls = this.el.closest('a-scene').querySelectorAll(data.objects);
objectEls = this.el.sceneEl.querySelectorAll(data.objects);
this.objects = [];
for (i = 0; i < objectEls.length; i++) {
this.objects.push(objectEls[i].object3D);
Expand Down
2 changes: 1 addition & 1 deletion src/core/a-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = registerElement('a-assets', {
var timeout = parseInt(this.getAttribute('timeout'), 10) || 3000;
var videos = this.querySelectorAll('video');

if (this.parentNode.tagName !== 'A-SCENE') {
if (!this.parentNode.isScene) {
throw new Error('<a-assets> must be a child of a <a-scene>.');
}

Expand Down
17 changes: 16 additions & 1 deletion src/core/a-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = registerElement('a-node', {
attachedCallback: {
value: function () {
var mixins = this.getAttribute('mixin');
this.sceneEl = this.tagName === 'A-SCENE' ? this : this.closest('a-scene');
this.sceneEl = this.isScene ? this : this.closestScene();
this.emit('nodeready', {}, false);
if (mixins) { this.updateMixins(mixins); }
}
Expand All @@ -34,6 +34,21 @@ module.exports = registerElement('a-node', {
}
},

/**
* Returns the first scene by traversing up the tree starting from and
* including receiver element.
*/
closestScene: {
value: function closest () {
var element = this;
while (element) {
if (element.isScene) { break; }
element = element.parentElement;
}
return element;
}
},

/**
* Returns first element matching a selector by traversing up the tree starting
* from and including receiver element.
Expand Down
2 changes: 1 addition & 1 deletion src/core/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports.registerSystem = function (name, definition) {
var i;
var NewSystem;
var proto = {};
var scenes = document.querySelectorAll('a-scene');
var scenes = utils.findAllScenes(document);

// Format definition object to prototype object.
Object.keys(definition).forEach(function (key) {
Expand Down
2 changes: 1 addition & 1 deletion src/extras/declarative-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = registerElement('a-event', {
'Use https://github.com/ngokevin/aframe-event-set-component instead.');

if (targetSelector) {
this.targetEls = this.closest('a-scene').querySelectorAll(targetSelector);
this.targetEls = this.el.sceneEl.querySelectorAll(targetSelector);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably leave this one since it's deprecated, just to make sure we don't break it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, probably fine.

} else {
this.targetEls = [this.el];
}
Expand Down
16 changes: 16 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,21 @@ module.exports.isIframed = function () {
return window.top !== window.self;
};

/**
* Finds all elements under the element that have the isScene
* property set to true
*/
module.exports.findAllScenes = function (el) {
var matchingElements = [];
var allElements = el.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++) {
if (allElements[i].isScene) {
// Element exists with isScene set.
matchingElements.push(allElements[i]);
}
}
return matchingElements;
};

// Must be at bottom to avoid circular dependency.
module.exports.srcLoader = require('./src-loader');