[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/course/format/weeks/ -> format.js (source)

   1  // Javascript functions for Weeks course format
   2  
   3  M.course = M.course || {};
   4  
   5  M.course.format = M.course.format || {};
   6  
   7  /**
   8   * Get sections config for this format
   9   *
  10   * The section structure is:
  11   * <ul class="weeks">
  12   *  <li class="section">...</li>
  13   *  <li class="section">...</li>
  14   *   ...
  15   * </ul>
  16   *
  17   * @return {object} section list configuration
  18   */
  19  M.course.format.get_config = function() {
  20      return {
  21          container_node : 'ul',
  22          container_class : 'weeks',
  23          section_node : 'li',
  24          section_class : 'section'
  25      };
  26  }
  27  
  28  /**
  29   * Swap section
  30   *
  31   * @param {YUI} Y YUI3 instance
  32   * @param {string} node1 node to swap to
  33   * @param {string} node2 node to swap with
  34   * @return {NodeList} section list
  35   */
  36  M.course.format.swap_sections = function(Y, node1, node2) {
  37      var CSS = {
  38          COURSECONTENT : 'course-content',
  39          SECTIONADDMENUS : 'section_add_menus'
  40      };
  41  
  42      var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.course.format.get_section_selector(Y));
  43      // Swap menus.
  44      sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS));
  45  }
  46  
  47  /**
  48   * Process sections after ajax response
  49   *
  50   * @param {YUI} Y YUI3 instance
  51   * @param {array} response ajax response
  52   * @param {string} sectionfrom first affected section
  53   * @param {string} sectionto last affected section
  54   * @return void
  55   */
  56  M.course.format.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) {
  57      var CSS = {
  58          SECTIONNAME : 'sectionname'
  59      },
  60      SELECTORS = {
  61          SECTIONLEFTSIDE : '.left .section-handle img'
  62      };
  63  
  64      if (response.action == 'move') {
  65          // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates.
  66          if (sectionfrom > sectionto) {
  67              var temp = sectionto;
  68              sectionto = sectionfrom;
  69              sectionfrom = temp;
  70          }
  71  
  72          // Update titles and move icons in all affected sections.
  73          var ele, str, stridx, newstr;
  74  
  75          for (var i = sectionfrom; i <= sectionto; i++) {
  76              // Update section title.
  77              var content = Y.Node.create('<span>' + response.sectiontitles[i] + '</span>');
  78              sectionlist.item(i).all('.'+CSS.SECTIONNAME).setHTML(content);
  79  
  80              // Update move icon.
  81              ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
  82              str = ele.getAttribute('alt');
  83              stridx = str.lastIndexOf(' ');
  84              newstr = str.substr(0, stridx +1) + i;
  85              ele.setAttribute('alt', newstr);
  86              ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed.
  87  
  88              // Remove the current class as section has been moved.
  89              sectionlist.item(i).removeClass('current');
  90          }
  91          // If there is a current section, apply corresponding class in order to highlight it.
  92          if (response.current !== -1) {
  93              // Add current class to the required section.
  94              sectionlist.item(response.current).addClass('current');
  95          }
  96      }
  97  }


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