Useful core Javascript modules
From MoodleDocs
Moodle 2.9
Configuration settings (core/config)
Example of using config module:
require(['core/config’], function(mdlcfg) {
cosole.log(mdlcfg.wwwroot); // outputs the wwwroot of moodle to console
});
Language strings (core/str)
Example of using language strings module (retrieved via ajax, if the string is not yet loaded)
require([‘core/str’], function(str) {
str.get_string('edita', 'core', stringargument).done(function(s) {
console.log(s);
}).fail(console.log(e));
});
The string will be retrieved via AJAX request on the first use. To avoid ajax call you may preload strings in PHP:
global $PAGE;
$PAGE->requires->string_for_js('edita', 'core');