1 YUI.add('moodle-mod_quiz-quizbase', function (Y, NAME) {
4 * The quizbase class to provide shared functionality to Modules within Moodle.
6 * @module moodle-mod_quiz-quizbase
8 var QUIZBASENAME = 'mod_quiz-quizbase';
10 var QUIZBASE = function() {
11 QUIZBASE.superclass.constructor.apply(this, arguments);
15 * The coursebase class to provide shared functionality to Modules within
18 * @class M.course.coursebase
21 Y.extend(QUIZBASE, Y.Base, {
26 * Register a new Javascript Module
28 * @method register_module
29 * @param {Object} The instantiated module to call functions on
32 register_module : function(object) {
33 this.registermodules.push(object);
39 * Invoke the specified function in all registered modules with the given arguments
41 * @method invoke_function
42 * @param {String} functionname The name of the function to call
43 * @param {mixed} args The argument supplied to the function
46 invoke_function : function(functionname, args) {
48 for (module in this.registermodules) {
49 if (functionname in this.registermodules[module]) {
50 this.registermodules[module][functionname](args);
61 // Ensure that M.course exists and that coursebase is initialised correctly
62 M.mod_quiz = M.mod_quiz || {};
63 M.mod_quiz.quizbase = M.mod_quiz.quizbase || new QUIZBASE();
65 // Abstract functions that needs to be defined per format (course/format/somename/format.js)
66 M.mod_quiz.edit = M.mod_quiz.edit || {};
69 * Swap section (should be defined in format.js if requred)
71 * @param {YUI} Y YUI3 instance
72 * @param {string} node1 node to swap to
73 * @param {string} node2 node to swap with
74 * @return {NodeList} section list
76 M.mod_quiz.edit.swap_sections = function(Y, node1, node2) {
78 COURSECONTENT : 'mod-quiz-edit-content',
79 SECTIONADDMENUS : 'section_add_menus'
82 var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' li.section');
84 sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS));
88 * Process sections after ajax response (should be defined in format.js)
89 * If some response is expected, we pass it over to format, as it knows better
92 * @param {YUI} Y YUI3 instance
93 * @param {NodeList} list of sections
94 * @param {array} response ajax response
95 * @param {string} sectionfrom first affected section
96 * @param {string} sectionto last affected section
99 M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) {
101 SECTIONNAME : 'sectionname'
104 SECTIONLEFTSIDE : '.left .section-handle img'
107 if (response.action === 'move') {
108 // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates.
109 if (sectionfrom > sectionto) {
110 var temp = sectionto;
111 sectionto = sectionfrom;
115 // Update titles and move icons in all affected sections.
116 var ele, str, stridx, newstr;
118 for (var i = sectionfrom; i <= sectionto; i++) {
119 // Update section title.
120 sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
123 ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
124 str = ele.getAttribute('alt');
125 stridx = str.lastIndexOf(' ');
126 newstr = str.substr(0, stridx + 1) + i;
127 ele.setAttribute('alt', newstr);
128 ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed.
130 // Remove the current class as section has been moved.
131 sectionlist.item(i).removeClass('current');
133 // If there is a current section, apply corresponding class in order to highlight it.
134 if (response.current !== -1) {
135 // Add current class to the required section.
136 sectionlist.item(response.current).addClass('current');
142 }, '@VERSION@', {"requires": ["base", "node"]});