Skip to content

Commit bee65a9

Browse files
committed
keep the window global for verisons <=1.0.0; throw error if window is undefined in init()
1 parent a75afdf commit bee65a9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/libs/ParallaxController.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,25 @@ function ParallaxController() {
390390

391391
/**
392392
* Static method to instantiate the ParallaxController.
393-
* Returns a new instance of the ParallaxController.
393+
* Returns a new or existing instance of the ParallaxController.
394394
* @returns {Object} ParallaxController
395395
*/
396396
ParallaxController.init = function() {
397-
return new ParallaxController();
397+
const hasWindow = typeof window !== 'undefined';
398+
399+
if (!hasWindow) {
400+
throw new Error(
401+
'Looks like ParallaxController.init() was called on the server. This method must be called on the client.'
402+
);
403+
}
404+
405+
// Keep global reference for legacy versions >= 1.0.0
406+
407+
if (hasWindow && !window.ParallaxController) {
408+
window.ParallaxController = new ParallaxController();
409+
}
410+
411+
return window.ParallaxController;
398412
};
399413

400414
export default ParallaxController;

0 commit comments

Comments
 (0)