Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
fix error when hopscotch is included in the head, instead of end of body
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed Mar 28, 2013
1 parent a377b2b commit ed78265
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
33 changes: 31 additions & 2 deletions js/hopscotch-0.0.5.js
Expand Up @@ -27,7 +27,7 @@
},
hasJquery = (typeof window.jQuery !== undefinedStr),
hasSessionStorage = (typeof window.sessionStorage !== undefinedStr),
docStyle = document.body.style,
docStyle = document.head.style,
hasCssTransitions = (typeof docStyle.MozTransition !== undefinedStr ||
typeof docStyle.MsTransition !== undefinedStr ||
typeof docStyle.webkitTransition !== undefinedStr ||
Expand Down Expand Up @@ -962,6 +962,7 @@
resizeCooldown = false, // for updating after window resize
onWinResize,
winResizeTimeout,
appendToBody,
opt;

this.element = el;
Expand Down Expand Up @@ -1039,7 +1040,35 @@
}

this.hide();
document.body.appendChild(el);

/**
* Append to body once the DOM is ready.
*/
if ( document.readyState === 'complete' ) {
document.body.appendChild(el);
}
else {
// Moz, webkit, Opera
if (document.addEventListener) {
appendToBody = function() {
document.removeEventListener('DOMContentLoaded', appendToBody);
document.body.appendChild(el);
};

document.addEventListener('DOMContentLoaded', appendToBody);
}
// IE
else {
appendToBody = function() {
if (document.readyState === 'complete') {
document.detachEvent('onreadystatechange', appendToBody);
document.body.appendChild(el);
}
};

document.attachEvent('onreadystatechange', appendToBody);
}
}
}
};

Expand Down

0 comments on commit ed78265

Please sign in to comment.