Start a new discussion

To start a new discussion please visit the discussions section of the GitHub home page of the project.

Discussions on GitHub

You can also search our old self-hosted forums for any useful information below but please note that posting new content here is not possible any more.

Re: Smartmenus will not work when Jquery is loaded by Requirejs

Home Forums Older releases 0.9.x Smartmenus will not work when Jquery is loaded by Requirejs Re: Smartmenus will not work when Jquery is loaded by Requirejs

#1496
admin
Keymaster

The paths in requirePathsConfig.js seem to be wrong – you don’t include “lib/” at all. Then your “copy” function does funky but incorrect stuff and also produces a JS error.

Here is my suggestion how to fix the issues:

1) Assuming you use any of these on your pages (not very sure from your explanation which exactly you use):

<script type="text/javascript" data-main="js/lib/requirePathsConfig" src="js/lib/requirejs-2.1.2.js"/></script>

or:

<script type="text/javascript" src="js/lib/requirejs-2.1.2.js"/></script>
<script type="text/javascript" src="js/lib/requirePathsConfig.js"/></script>

2) Replace the content of your current requirePathsConfig.js with the following:

/* js/lib/requirePathsConfig.js */

(function(require) {

    if (!require) {
        return;
    }

    var context = "/" + location.pathname.split("/")[1] + "/";
    var web = context + "web/js/";
    var bl = context;

    require.config({
        baseUrl: web,
        paths : {
            /*
             * Paths lists the locations of particular scripts in web.
             * These will be used with the shim config option to setup dependencies for
             * each library.
             */

            jquery : "lib/jquery/jquery-1.7.2",
            // ** not using jquery.jqGrid-4.5.2 until fully tested with all Web features **
            jqGrid : "lib/jquery/plugins/webvisGridView/jquery.jqGrid-4.4.1/jquery.jqGrid.src", 
            jqGridLocale : "lib/jquery/plugins/webvisGridView/jquery.jqGrid-4.4.1/grid.locale-en",

            // Smartmenu stuff note, the different format
            "jquery.smartmenus" : "lib/jquery/jquery.smartmenus.min"
        },
        shim: {
            /* Hold the dependencies needed for each script. Designed to for 
             * RequireJS v2.0 or higher. Array holds the dependency requirements for each script    above. */

            "jquery.smartmenus": {
                deps: [ "jquery" ],
                exports: "jQuery.fn.smartmenus"
            },
            jqGridLocale: ["jquery", "jqUI"],
            jqGrid: ["jqGridLocale"]
        }
    });

    // load main.js
    require([web + "lib/jquery/main.js"]);

})(window.require);

and it should work assuming:

– you use the exact folder structure you mentioned;
main.js has the exact content I mentioned in my previous post;
– you keep the main RequireJS code in js/lib/requirejs-2.1.2.js.

Hope this helps. Let me know if you still have any troubles.