// Miscellaneous core Javascript functions for Moodle // Global M object is initilised in inline javascript // Global Y instance, inilialised much later in page footer, // it is usually better to initialise own Y by: "YUI(M.yui.loader).use('......', function(Y) { .... }); var Y = null; /** * Add module to list of available modules that can be laoded from YUI. */ M.yui.add_module = function(modules) { for (modname in modules) { M.yui.loader.modules[modname] = modules[modname]; } }; /** * Various utility functions */ M.util = { /** * Returns url for images. */ image_url: function(imagename, component) { var url = M.cfg.wwwroot + '/theme/image.php?theme=' + M.cfg.theme + '&image=' + imagename; if (M.cfg.themerev > 0) { url = url + '&rev=' + M.cfg.themerev; } if (component != '' && component != 'moodle' && component != 'core') { url = url + '&component=' + component; } return url; } } function launch_filemanager(options) { Y.use('core_filemanager', function() { var client_id = options.client_id; // filemangers defined in lib/form/filemanager.js if (!filemanagers[client_id]) { filemanagers[client_id] = new M.core_filemanager(options); } }); } // === old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code === function popupchecker(msg) { var testwindow = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no'); if (!testwindow) { alert(msg); } else { testwindow.close(); } } function checkall() { var inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == 'checkbox') { inputs[i].checked = true; } } } function checknone() { var inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == 'checkbox') { inputs[i].checked = false; } } } function lockoptions(formid, master, subitems) { // Subitems is an array of names of sub items. // Optionally, each item in subitems may have a // companion hidden item in the form with the // same name but prefixed by "h". var form = document.forms[formid]; if (eval("form."+master+".checked")) { for (i=0; i