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