diff --git a/addon/components/async-image.js b/addon/components/async-image.js index f47489f..8fc4085 100644 --- a/addon/components/async-image.js +++ b/addon/components/async-image.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import isBrowser from 'ember-async-image/utils/is-browser'; const { Component, @@ -132,7 +133,7 @@ export default Component.extend({ init() { this._super(); - this._loadImage(); + if (isBrowser) { this._loadImage(); } } }); diff --git a/addon/utils/is-browser.js b/addon/utils/is-browser.js new file mode 100644 index 0000000..897b6dc --- /dev/null +++ b/addon/utils/is-browser.js @@ -0,0 +1,13 @@ +/* +Ye' ol annoying isBrower function to allow use of this library with fastboot. + +Use this within init() within components +*/ + +export default (function isBrowser() { + return typeof window !== 'undefined' && + typeof document !== 'undefined' && + typeof process === 'undefined' && + !!window.document && + !!window.document.createElement; +}()); diff --git a/app/utils/is-browser.js b/app/utils/is-browser.js new file mode 100644 index 0000000..0a4e32f --- /dev/null +++ b/app/utils/is-browser.js @@ -0,0 +1 @@ +export { default } from 'ember-async-image/utils/is-browser'; \ No newline at end of file diff --git a/tests/unit/utils/is-browser-test.js b/tests/unit/utils/is-browser-test.js new file mode 100644 index 0000000..026d2b9 --- /dev/null +++ b/tests/unit/utils/is-browser-test.js @@ -0,0 +1,10 @@ +import isBrowser from '../../../utils/is-browser'; +import { module, test } from 'qunit'; + +module('Unit | Utility | is browser'); + +// Replace this with your real tests. +test('it works', function(assert) { + var result = isBrowser(); + assert.ok(result); +});