• Resolved wiekafe

    (@wiekafe)


    Hey,
    I was following this guide: https://www.youtube.com/watch?v=wwxYvxsknmM and I got it working earlier.
    After updating to a theme that support full site editing, I can’t directly edit the footer.php file to setup mapster hook, and I can’t get it to work anymore.
    In order to add the javascript mapster hooks needed, I installed the ‘Insert Headers and Footers’-plugin and tried to add the scripts with that. However, I get the error ‘mwm is not defined’. How could I get a reference to mwm, or where is it defined? The video doesn’t really explain it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter wiekafe

    (@wiekafe)

    I figured that mwm is defined after my script runs, and that’s why my script can’t find it. I made the script wait until mwm is defined, but maybe there is a better solution?

    Plugin Author mapster

    (@mapster)

    Hello! First off thanks for using the plugin, hope it’s working nicely for you.

    The “mwm” is defined when the Mapster scripts start up, which is basically once they are loaded onto the page (they have a dependency on jQuery and then some internal dependencies, such as loading the Mapbox library and so on). WordPress can be tough in terms of knowing exactly which scripts are loading before which other scripts, especially when you’re using plugins like you described that are inserting scripts at different places.

    You’re probably safe if you wait for the jQuery loading event before calling mwm. If you’re not sure, safest to call window.mwm since it’s defined globally. However, your solution also works great — basically using some kind of setInterval to check if window.mwm is defined before doing your custom scripts. I think you probably have it figured out!

    Let me know if you need any more help.

    Thread Starter wiekafe

    (@wiekafe)

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating javascript hook when using new full site editing’ is closed to new replies.