Fix unreliable window and document detection (#246)

* Fix unreliable DOM availability detection to more robust approach

Signed-off-by: Viktor Bezděk <viktor.bezdek@siteone.cz>

* Temporarily commit compiled files to repo before pull request #246 gets published to fix ssr issues

Signed-off-by: Viktor Bezděk <viktor.bezdek@siteone.cz>

* Revert "Temporarily commit compiled files to repo before pull request #246 gets published to fix ssr issues"

This reverts commit 7e19a8630c7e3e148803f0797cbf89567c7a8c45.
This commit is contained in:
Viktor Bezdek 2016-09-23 09:49:31 -05:00 committed by Ivan Starkov
parent 7ae63cb3d7
commit 94eac51b6e

View File

@ -9,9 +9,15 @@
* version: 0.5.3
**/
// Reliable `window` and `document` detection
var canUseDOM = !!(
(typeof window !== 'undefined' &&
window.document && window.document.createElement)
);
// Check `document` and `window` in case of server-side rendering
var _window
if (typeof window !== 'undefined') {
if (canUseDOM) {
_window = window
} else if (typeof self !== 'undefined') {
_window = self
@ -22,7 +28,7 @@ if (typeof window !== 'undefined') {
var attachEvent = typeof document !== 'undefined' && document.attachEvent;
var stylesCreated = false;
if (typeof window !== 'undefined' && !attachEvent) {
if (canUseDOM && !attachEvent) {
var requestFrame = (function(){
var raf = _window.requestAnimationFrame || _window.mozRequestAnimationFrame || _window.webkitRequestAnimationFrame ||
function(fn){ return _window.setTimeout(fn, 20); };
@ -76,7 +82,8 @@ if (typeof window !== 'undefined' && !attachEvent) {
domPrefixes = 'Webkit Moz O ms'.split(' '),
startEvents = 'webkitAnimationStart animationstart oAnimationStart MSAnimationStart'.split(' '),
pfx = '';
{
if(canUseDOM) {
var elm = document.createElement('fakeelement');
if( elm.style.animationName !== undefined ) { animation = true; }