Skip to content

Commit

Permalink
fix(view-slot): add firstChild null checks
Browse files Browse the repository at this point in the history
add null checks for case when firstChild is null.  this occurs when the aurelia-app attribute is in a child element of body instead of on the body element, for example

Fixes #34
  • Loading branch information
cmichaelgraham committed Mar 19, 2015
1 parent d87a404 commit a49411d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/view-slot.js
Expand Up @@ -71,8 +71,10 @@ export class ViewSlot {
if(this.isAttached){
view.attached();
// Animate page itself
var element = view.firstChild.nextElementSibling;
if(view.firstChild.nodeType === 8 &&
var element = view.firstChild ? view.firstChild.nextElementSibling : null;
if(view.firstChild !== undefined &&
view.firstChild !== null &&
view.firstChild.nodeType === 8 &&
element !== null &&
element.nodeType === 1 &&
element.classList.contains('au-animate')) {
Expand Down Expand Up @@ -118,8 +120,10 @@ export class ViewSlot {
return view;
};

var element = view.firstChild.nextElementSibling;
if(view.firstChild.nodeType === 8 &&
var element = view.firstChild ? view.firstChild.nextElementSibling : null;
if(view.firstChild !== undefined &&
view.firstChild !== null &&
view.firstChild.nodeType === 8 &&
element !== null &&
element.nodeType === 1 &&
element.classList.contains('au-animate')) {
Expand All @@ -139,8 +143,9 @@ export class ViewSlot {
var rmPromises = [];

children.forEach( (child) => {
var element = child.firstChild.nextElementSibling;
var element = child.firstChild ? child.firstChild.nextElementSibling : null;
if(child.firstChild !== undefined &&
child.firstChild !== null &&
child.firstChild.nodeType === 8 &&
element !== null &&
element.nodeType === 1 &&
Expand Down Expand Up @@ -196,8 +201,10 @@ export class ViewSlot {
for(i = 0, ii = children.length; i < ii; ++i){
children[i].attached();

var element = children[i].firstChild.nextElementSibling;
if(children[i].firstChild.nodeType === 8 &&
var element = children[i].firstChild ? children[i].firstChild.nextElementSibling : null;
if(children[i].firstChild !== undefined &&
children[i].firstChild !== null &&
children[i].firstChild.nodeType === 8 &&
element !== null &&
element.nodeType === 1 &&
element.classList.contains('au-animate')) {
Expand Down

0 comments on commit a49411d

Please sign in to comment.