[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/quiz/yui/build/moodle-mod_quiz-quizbase/ -> moodle-mod_quiz-quizbase.js (source)

   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      return null;
 168  };
 169  
 170  /**
 171   * Get section wraper for this format (only used in case when each
 172   * container_node.container_class node is wrapped in some other element).
 173   *
 174   * @param {YUI} Y YUI3 instance
 175   * @return {string} section wrapper selector or M.mod_quiz.format.get_section_selector
 176   * if section_wrapper_node and section_wrapper_class are not defined in the format config.
 177   */
 178  M.mod_quiz.edit.get_section_wrapper = function(Y) {
 179      var config = M.mod_quiz.edit.get_config();
 180      if (config.section_wrapper_node && config.section_wrapper_class) {
 181          return config.section_wrapper_node + '.' + config.section_wrapper_class;
 182      }
 183      return M.mod_quiz.edit.get_section_selector(Y);
 184  };
 185  
 186  /**
 187   * Get the tag of container node
 188   *
 189   * @return {string} tag of container node.
 190   */
 191  M.mod_quiz.edit.get_containernode = function() {
 192      var config = M.mod_quiz.edit.get_config();
 193      if (config.container_node) {
 194          return config.container_node;
 195      } else {
 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      }
 210  };
 211  
 212  /**
 213   * Get the tag of draggable node (section wrapper if exists, otherwise section)
 214   *
 215   * @return {string} tag of the draggable node.
 216   */
 217  M.mod_quiz.edit.get_sectionwrappernode = function() {
 218      var config = M.mod_quiz.edit.get_config();
 219      if (config.section_wrapper_node) {
 220          return config.section_wrapper_node;
 221      } else {
 222          return config.section_node;
 223      }
 224  };
 225  
 226  /**
 227   * Get the class of draggable node (section wrapper if exists, otherwise section)
 228   *
 229   * @return {string} class of the draggable node.
 230   */
 231  M.mod_quiz.edit.get_sectionwrapperclass = function() {
 232      var config = M.mod_quiz.edit.get_config();
 233      if (config.section_wrapper_class) {
 234          return config.section_wrapper_class;
 235      } else {
 236          return config.section_class;
 237      }
 238  };
 239  
 240  /**
 241   * Get the tag of section node
 242   *
 243   * @return {string} tag of section node.
 244   */
 245  M.mod_quiz.edit.get_sectionnode = function() {
 246      var config = M.mod_quiz.edit.get_config();
 247      if (config.section_node) {
 248          return config.section_node;
 249      } else {
 250      }
 251  };
 252  
 253  /**
 254   * Get the class of section node
 255   *
 256   * @return {string} class of the section node.
 257   */
 258  M.mod_quiz.edit.get_sectionclass = function() {
 259      var config = M.mod_quiz.edit.get_config();
 260      if (config.section_class) {
 261          return config.section_class;
 262      } else {
 263      }
 264  };
 265  
 266  
 267  }, '@VERSION@', {"requires": ["base", "node"]});


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1