[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/assign/yui/src/history/js/ -> history.js (source)

   1  // Define a function that will run in the context of a
   2  // Node instance:
   3  var CSS = {
   4          LINK: 'mod-assign-history-link',
   5          OPEN: 'mod-assign-history-link-open',
   6          CLOSED: 'mod-assign-history-link-closed',
   7          PANEL: 'mod-assign-history-panel'
   8      },
   9      COUNT = 0,
  10      TOGGLE = function() {
  11          var id = this.get('for'),
  12              panel = Y.one('#' + id);
  13          if (this.hasClass(CSS.OPEN)) {
  14              this.removeClass(CSS.OPEN);
  15              this.addClass(CSS.CLOSED);
  16              this.setStyle('overflow', 'hidden');
  17              panel.hide();
  18          } else {
  19              this.removeClass(CSS.CLOSED);
  20              this.addClass(CSS.OPEN);
  21              panel.show();
  22          }
  23      },
  24      HISTORY = function() {
  25          var link = null,
  26              panel = null,
  27              wrapper = null,
  28              container = this;
  29  
  30          // Loop through all the children of this container and turn
  31          // every odd node to a link to open/close the following panel.
  32          this.get('children').each(function () {
  33              if (link) {
  34                  COUNT++;
  35                  // First convert the link to an anchor.
  36                  wrapper = Y.Node.create('<a/>');
  37                  panel = this;
  38                  container.insertBefore(wrapper, link);
  39                  link.remove(false);
  40                  wrapper.appendChild(link);
  41  
  42                  // Add a for attribute to the link to link to the id of the panel.
  43                  if (!panel.get('id')) {
  44                      panel.set('id', CSS.PANEL + COUNT);
  45                  }
  46                  wrapper.set('for', panel.get('id'));
  47                  // Add an aria attribute for the live region.
  48                  panel.set('aria-live', 'polite');
  49  
  50                  wrapper.addClass(CSS.LINK);
  51                  wrapper.addClass(CSS.CLOSED);
  52                  panel.addClass(CSS.PANEL);
  53                  panel.hide();
  54                  link = null;
  55              } else {
  56                  link = this;
  57              }
  58          });
  59  
  60          // Setup event listeners.
  61          this.delegate('click', TOGGLE, '.' + CSS.LINK);
  62      };
  63  
  64  // Use addMethod to add history to the Node prototype:
  65  Y.Node.addMethod("history", HISTORY);
  66  
  67  // Extend this functionality to NodeLists.
  68  Y.NodeList.importMethod(Y.Node.prototype, "history");


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