[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 /** 2 * The quizbase class to provide shared functionality to Modules within Moodle. 3 * 4 * @module moodle-mod_quiz-quizbase 5 */ 6 var QUIZBASENAME = 'mod_quiz-quizbase'; 7 8 var QUIZBASE = function() { 9 QUIZBASE.superclass.constructor.apply(this, arguments); 10 }; 11 12 /** 13 * The coursebase class to provide shared functionality to Modules within 14 * Moodle. 15 * 16 * @class M.course.coursebase 17 * @constructor 18 */ 19 Y.extend(QUIZBASE, Y.Base, { 20 // Registered Modules 21 registermodules : [], 22 23 /** 24 * Register a new Javascript Module 25 * 26 * @method register_module 27 * @param {Object} The instantiated module to call functions on 28 * @chainable 29 */ 30 register_module : function(object) { 31 this.registermodules.push(object); 32 33 return this; 34 }, 35 36 /** 37 * Invoke the specified function in all registered modules with the given arguments 38 * 39 * @method invoke_function 40 * @param {String} functionname The name of the function to call 41 * @param {mixed} args The argument supplied to the function 42 * @chainable 43 */ 44 invoke_function : function(functionname, args) { 45 var module; 46 for (module in this.registermodules) { 47 if (functionname in this.registermodules[module]) { 48 this.registermodules[module][functionname](args); 49 } 50 } 51 52 return this; 53 } 54 }, { 55 NAME : QUIZBASENAME, 56 ATTRS : {} 57 }); 58 59 // Ensure that M.course exists and that coursebase is initialised correctly 60 M.mod_quiz = M.mod_quiz || {}; 61 M.mod_quiz.quizbase = M.mod_quiz.quizbase || new QUIZBASE(); 62 63 // Abstract functions that needs to be defined per format (course/format/somename/format.js) 64 M.mod_quiz.edit = M.mod_quiz.edit || {}; 65 66 /** 67 * Swap section (should be defined in format.js if requred) 68 * 69 * @param {YUI} Y YUI3 instance 70 * @param {string} node1 node to swap to 71 * @param {string} node2 node to swap with 72 * @return {NodeList} section list 73 */ 74 M.mod_quiz.edit.swap_sections = function(Y, node1, node2) { 75 var CSS = { 76 COURSECONTENT : 'mod-quiz-edit-content', 77 SECTIONADDMENUS : 'section_add_menus' 78 }; 79 80 var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' ' + M.mod_quiz.edit.get_section_selector(Y)); 81 // Swap menus. 82 sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS)); 83 }; 84 85 /** 86 * Process sections after ajax response (should be defined in format.js) 87 * If some response is expected, we pass it over to format, as it knows better 88 * hot to process it. 89 * 90 * @param {YUI} Y YUI3 instance 91 * @param {NodeList} list of sections 92 * @param {array} response ajax response 93 * @param {string} sectionfrom first affected section 94 * @param {string} sectionto last affected section 95 * @return void 96 */ 97 M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) { 98 var CSS = { 99 SECTIONNAME : 'sectionname' 100 }, 101 SELECTORS = { 102 SECTIONLEFTSIDE : '.left .section-handle img' 103 }; 104 105 if (response.action === 'move') { 106 // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates. 107 if (sectionfrom > sectionto) { 108 var temp = sectionto; 109 sectionto = sectionfrom; 110 sectionfrom = temp; 111 } 112 113 // Update titles and move icons in all affected sections. 114 var ele, str, stridx, newstr; 115 116 for (var i = sectionfrom; i <= sectionto; i++) { 117 // Update section title. 118 sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]); 119 120 // Update move icon. 121 ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); 122 str = ele.getAttribute('alt'); 123 stridx = str.lastIndexOf(' '); 124 newstr = str.substr(0, stridx + 1) + i; 125 ele.setAttribute('alt', newstr); 126 ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed. 127 128 // Remove the current class as section has been moved. 129 sectionlist.item(i).removeClass('current'); 130 } 131 // If there is a current section, apply corresponding class in order to highlight it. 132 if (response.current !== -1) { 133 // Add current class to the required section. 134 sectionlist.item(response.current).addClass('current'); 135 } 136 } 137 }; 138 139 /** 140 * Get sections config for this format, for examples see function definition 141 * in the formats. 142 * 143 * @return {object} section list configuration 144 */ 145 M.mod_quiz.edit.get_config = function() { 146 return { 147 container_node : 'ul', 148 container_class : 'slots', 149 section_node : 'li', 150 section_class : 'section' 151 }; 152 }; 153 154 /** 155 * Get section list for this format (usually items inside container_node.container_class selector) 156 * 157 * @param {YUI} Y YUI3 instance 158 * @return {string} section selector 159 */ 160 M.mod_quiz.edit.get_section_selector = function() { 161 var config = M.mod_quiz.edit.get_config(); 162 if (config.section_node && config.section_class) { 163 return config.section_node + '.' + config.section_class; 164 } 165 Y.log('section_node and section_class are not defined in M.mod_quiz.edit.get_config', 'warn', 'moodle-mod_quiz-quizbase'); 166 return null; 167 }; 168 169 /** 170 * Get section wraper for this format (only used in case when each 171 * container_node.container_class node is wrapped in some other element). 172 * 173 * @param {YUI} Y YUI3 instance 174 * @return {string} section wrapper selector or M.mod_quiz.format.get_section_selector 175 * if section_wrapper_node and section_wrapper_class are not defined in the format config. 176 */ 177 M.mod_quiz.edit.get_section_wrapper = function(Y) { 178 var config = M.mod_quiz.edit.get_config(); 179 if (config.section_wrapper_node && config.section_wrapper_class) { 180 return config.section_wrapper_node + '.' + config.section_wrapper_class; 181 } 182 return M.mod_quiz.edit.get_section_selector(Y); 183 }; 184 185 /** 186 * Get the tag of container node 187 * 188 * @return {string} tag of container node. 189 */ 190 M.mod_quiz.edit.get_containernode = function() { 191 var config = M.mod_quiz.edit.get_config(); 192 if (config.container_node) { 193 return config.container_node; 194 } else { 195 Y.log('container_node is not defined in M.mod_quiz.edit.get_config', 'warn', 'moodle-mod_quiz-quizbase'); 196 } 197 }; 198 199 /** 200 * Get the class of container node 201 * 202 * @return {string} class of the container node. 203 */ 204 M.mod_quiz.edit.get_containerclass = function() { 205 var config = M.mod_quiz.edit.get_config(); 206 if (config.container_class) { 207 return config.container_class; 208 } else { 209 Y.log('container_class is not defined in M.mod_quiz.edit.get_config', 'warn', 'moodle-mod_quiz-quizbase'); 210 } 211 }; 212 213 /** 214 * Get the tag of draggable node (section wrapper if exists, otherwise section) 215 * 216 * @return {string} tag of the draggable node. 217 */ 218 M.mod_quiz.edit.get_sectionwrappernode = function() { 219 var config = M.mod_quiz.edit.get_config(); 220 if (config.section_wrapper_node) { 221 return config.section_wrapper_node; 222 } else { 223 return config.section_node; 224 } 225 }; 226 227 /** 228 * Get the class of draggable node (section wrapper if exists, otherwise section) 229 * 230 * @return {string} class of the draggable node. 231 */ 232 M.mod_quiz.edit.get_sectionwrapperclass = function() { 233 var config = M.mod_quiz.edit.get_config(); 234 if (config.section_wrapper_class) { 235 return config.section_wrapper_class; 236 } else { 237 return config.section_class; 238 } 239 }; 240 241 /** 242 * Get the tag of section node 243 * 244 * @return {string} tag of section node. 245 */ 246 M.mod_quiz.edit.get_sectionnode = function() { 247 var config = M.mod_quiz.edit.get_config(); 248 if (config.section_node) { 249 return config.section_node; 250 } else { 251 Y.log('section_node is not defined in M.mod_quiz.edit.get_config', 'warn', 'moodle-mod_quiz-quizbase'); 252 } 253 }; 254 255 /** 256 * Get the class of section node 257 * 258 * @return {string} class of the section node. 259 */ 260 M.mod_quiz.edit.get_sectionclass = function() { 261 var config = M.mod_quiz.edit.get_config(); 262 if (config.section_class) { 263 return config.section_class; 264 } else { 265 Y.log('section_class is not defined in M.mod_quiz.edit.get_config', 'warn', 'moodle-mod_quiz-quizbase'); 266 } 267 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |