xmodule.js 1.58 KB
Newer Older
1 2 3 4 5 6
## This file is designed to load all the XModule Javascript files in one wad
## using requirejs. It is passed through the Mako template system, which
## populates the `urls` variable with a list of paths to XModule JS files.
## These files assume that several libraries are available and bound to
## variables in the global context, so we load those libraries with requirejs
## and attach them to the global context manually.
7
define(["jquery", "underscore", "codemirror", "tinymce",
8 9 10
        "jquery.tinymce", "jquery.qtip", "jquery.scrollTo", "jquery.flot",
        "jquery.cookie",
        "utility"],
11
       function($, _, CodeMirror, tinymce) {
12 13
    window.$ = $;
    window._ = _;
14
    require(['mathjax']);
15 16 17 18 19 20
    window.CodeMirror = CodeMirror;
    window.RequireJS = {
        'requirejs': requirejs,
        'require': require,
        'define': define
    };
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    /**
     * Loads all modules one-by-one in exact order.
     * The module should be used until we'll use RequireJS for XModules.
     * @param {Array} modules A list of urls.
     * @return {jQuery Promise}
     **/
    var requireQueue = function(modules) {
        var deferred = $.Deferred();
        var loadScript = function (queue) {
            // Loads the next script if queue is not empty.
            if (queue.length) {
                require([queue.shift()], function() {
                    loadScript(queue);
                });
            } else {
                deferred.resolve();
37
            }
38
        };
39

40 41 42 43 44
        loadScript(modules.concat());
        return deferred.promise();
    };

    return requireQueue(${urls});
45
});