[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 + ' li.section'); 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 }, '@VERSION@', {"requires": ["base", "node"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |