Plugin based on Google Maps not working on Elgg 2.x


I'm trying to develop a plugin that uses Google maps to show a map in a page, this part was working in Elgg 1.1X but no more in Elgg 2.x

, the error I got in Chrome console is: Uncaught ReferenceError: $ is not defined in a JS code like: 

<script type='text/javascript'>
    $(document).ready(function () { frn_initialize();  });

I use xampp in Windows 7 and windows 10 (same environment and same code in Elgg 1.11.0 works fine)

There is some change in the way JS / GoogleMaps are to be used in Elgg 2.x ?



  • Yes, all scripts in Elgg 2 are loaded asynchronously using requirejs.  It looks like you're calling this from an inline script so it tries to fire before jquery has been loaded.

    The proper solution is to convert your plugin js to AMD modules -

    A quick not-as-good-but-should-work solution is to wrap it in a require call

    require(['jquery'], function($) {

        $(document).ready(function () { frn_initialize(); });