[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/yui/src/coursebase/js/ -> coursebase.js (source)

   1  /**
   2   * The coursebase class to provide shared functionality to Modules within
   3   * Moodle.
   4   *
   5   * @module moodle-course-coursebase
   6   */
   7  var COURSEBASENAME = 'course-coursebase';
   8  
   9  var COURSEBASE = function() {
  10      COURSEBASE.superclass.constructor.apply(this, arguments);
  11  };
  12  
  13  /**
  14   * The coursebase class to provide shared functionality to Modules within
  15   * Moodle.
  16   *
  17   * @class M.course.coursebase
  18   * @constructor
  19   */
  20  Y.extend(COURSEBASE, Y.Base, {
  21      // Registered Modules
  22      registermodules: [],
  23  
  24      /**
  25       * Register a new Javascript Module
  26       *
  27       * @method register_module
  28       * @param {Object} The instantiated module to call functions on
  29       * @chainable
  30       */
  31      register_module: function(object) {
  32          this.registermodules.push(object);
  33  
  34          return this;
  35      },
  36  
  37      /**
  38       * Invoke the specified function in all registered modules with the given arguments
  39       *
  40       * @method invoke_function
  41       * @param {String} functionname The name of the function to call
  42       * @param {mixed} args The argument supplied to the function
  43       * @chainable
  44       */
  45      invoke_function: function(functionname, args) {
  46          var module;
  47          for (module in this.registermodules) {
  48              if (functionname in this.registermodules[module]) {
  49                  this.registermodules[module][functionname](args);
  50              }
  51          }
  52  
  53          return this;
  54      }
  55  }, {
  56      NAME: COURSEBASENAME,
  57      ATTRS: {}
  58  });
  59  
  60  // Ensure that M.course exists and that coursebase is initialised correctly
  61  M.course = M.course || {};
  62  M.course.coursebase = M.course.coursebase || new COURSEBASE();
  63  
  64  // Abstract functions that needs to be defined per format (course/format/somename/format.js)
  65  M.course.format = M.course.format || {};
  66  
  67  /**
  68   * Swap section (should be defined in format.js if requred)
  69   *
  70   * @method M.course.format.swap_sections
  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.course.format.swap_sections = M.course.format.swap_sections || function() {
  77      return null;
  78  };
  79  
  80  /**
  81   * Process sections after ajax response (should be defined in format.js)
  82   * If some response is expected, we pass it over to format, as it knows better
  83   * hot to process it.
  84   *
  85   * @method M.course.format.process_sections
  86   * @param {YUI} Y YUI3 instance
  87   * @param {NodeList} list of sections
  88   * @param {array} response ajax response
  89   * @param {string} sectionfrom first affected section
  90   * @param {string} sectionto last affected section
  91   */
  92  M.course.format.process_sections = M.course.format.process_sections || function() {
  93      return null;
  94  };
  95  
  96  /**
  97  * Get sections config for this format, for examples see function definition
  98  * in the formats.
  99  *
 100  * @method M.course.format.get_config
 101  * @return {object} section list configuration
 102  */
 103  M.course.format.get_config = M.course.format.get_config || function() {
 104      return {
 105          container_node: null, // compulsory
 106          container_class: null, // compulsory
 107          section_wrapper_node: null, // optional
 108          section_wrapper_class: null, // optional
 109          section_node: null,  // compulsory
 110          section_class: null  // compulsory
 111      };
 112  };
 113  
 114  /**
 115   * Get section list for this format (usually items inside container_node.container_class selector)
 116   *
 117   * @method M.course.format.get_section_selector
 118   * @param {YUI} Y YUI3 instance
 119   * @return {string} section selector
 120   */
 121  M.course.format.get_section_selector = M.course.format.get_section_selector || function() {
 122      var config = M.course.format.get_config();
 123      if (config.section_node && config.section_class) {
 124          return config.section_node + '.' + config.section_class;
 125      }
 126      Y.log('section_node and section_class are not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
 127      return null;
 128  };
 129  
 130  /**
 131   * Get section wraper for this format (only used in case when each
 132   * container_node.container_class node is wrapped in some other element).
 133   *
 134   * @method M.course.format.get_section_wrapper
 135   * @param {YUI} Y YUI3 instance
 136   * @return {string} section wrapper selector or M.course.format.get_section_selector
 137   * if section_wrapper_node and section_wrapper_class are not defined in the format config.
 138   */
 139  M.course.format.get_section_wrapper = M.course.format.get_section_wrapper || function(Y) {
 140      var config = M.course.format.get_config();
 141      if (config.section_wrapper_node && config.section_wrapper_class) {
 142          return config.section_wrapper_node + '.' + config.section_wrapper_class;
 143      }
 144      return M.course.format.get_section_selector(Y);
 145  };
 146  
 147  /**
 148   * Get the tag of container node
 149   *
 150   * @method M.course.format.get_containernode
 151   * @return {string} tag of container node.
 152   */
 153  M.course.format.get_containernode = M.course.format.get_containernode || function() {
 154      var config = M.course.format.get_config();
 155      if (config.container_node) {
 156          return config.container_node;
 157      } else {
 158          Y.log('container_node is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
 159      }
 160  };
 161  
 162  /**
 163   * Get the class of container node
 164   *
 165   * @method M.course.format.get_containerclass
 166   * @return {string} class of the container node.
 167   */
 168  M.course.format.get_containerclass = M.course.format.get_containerclass || function() {
 169      var config = M.course.format.get_config();
 170      if (config.container_class) {
 171          return config.container_class;
 172      } else {
 173          Y.log('container_class is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
 174      }
 175  };
 176  
 177  /**
 178   * Get the tag of draggable node (section wrapper if exists, otherwise section)
 179   *
 180   * @method M.course.format.get_sectionwrappernode
 181   * @return {string} tag of the draggable node.
 182   */
 183  M.course.format.get_sectionwrappernode = M.course.format.get_sectionwrappernode || function() {
 184      var config = M.course.format.get_config();
 185      if (config.section_wrapper_node) {
 186          return config.section_wrapper_node;
 187      } else {
 188          return config.section_node;
 189      }
 190  };
 191  
 192  /**
 193   * Get the class of draggable node (section wrapper if exists, otherwise section)
 194   *
 195   * @method M.course.format.get_sectionwrapperclass
 196   * @return {string} class of the draggable node.
 197   */
 198  M.course.format.get_sectionwrapperclass = M.course.format.get_sectionwrapperclass || function() {
 199      var config = M.course.format.get_config();
 200      if (config.section_wrapper_class) {
 201          return config.section_wrapper_class;
 202      } else {
 203          return config.section_class;
 204      }
 205  };
 206  
 207  /**
 208   * Get the tag of section node
 209   *
 210   * @method M.course.format.get_sectionnode
 211   * @return {string} tag of section node.
 212   */
 213  M.course.format.get_sectionnode = M.course.format.get_sectionnode || function() {
 214      var config = M.course.format.get_config();
 215      if (config.section_node) {
 216          return config.section_node;
 217      } else {
 218          Y.log('section_node is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
 219      }
 220  };
 221  
 222  /**
 223   * Get the class of section node
 224   *
 225   * @method M.course.format.get_sectionclass
 226   * @return {string} class of the section node.
 227   */
 228  M.course.format.get_sectionclass = M.course.format.get_sectionclass || function() {
 229      var config = M.course.format.get_config();
 230      if (config.section_class) {
 231          return config.section_class;
 232      } else {
 233          Y.log('section_class is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
 234      }
 235  };


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1