File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff 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 */
396396ParallaxController . 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
400414export default ParallaxController ;
You can’t perform that action at this time.
0 commit comments