[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yui/src/popuphelp/js/ -> popuphelp.js (source)

   1  /**
   2   * A popup help dialogue for Moodle.
   3   *
   4   * @module moodle-core-popuphelp
   5   */
   6  
   7  /**
   8   * A popup help dialogue for Moodle.
   9   *
  10   * @class M.core.popuphelp
  11   * @constructor
  12   */
  13  
  14  function POPUPHELP() {
  15      POPUPHELP.superclass.constructor.apply(this, arguments);
  16  }
  17  
  18  var SELECTORS = {
  19          CLICKABLELINKS: 'span.helptooltip > a',
  20          FOOTER: 'div.moodle-dialogue-ft'
  21      },
  22  
  23      CSS = {
  24          ICON: 'icon',
  25          ICONPRE: 'icon-pre'
  26      },
  27      ATTRS = {};
  28  
  29  // Set the modules base properties.
  30  POPUPHELP.NAME = 'moodle-core-popuphelp';
  31  POPUPHELP.ATTRS = ATTRS;
  32  
  33  Y.extend(POPUPHELP, Y.Base, {
  34      panel: null,
  35  
  36      /**
  37       * Setup the popuphelp.
  38       *
  39       * @method initializer
  40       */
  41      initializer: function() {
  42          Y.one('body').delegate('click', this.display_panel, SELECTORS.CLICKABLELINKS, this);
  43      },
  44  
  45      /**
  46       * Display the help tooltip.
  47       *
  48       * @method display_panel
  49       * @param {EventFacade} e
  50       */
  51      display_panel: function(e) {
  52          if (!this.panel) {
  53              this.panel = new M.core.tooltip({
  54                  bodyhandler: this.set_body_content,
  55                  footerhandler: this.set_footer,
  56                  initialheadertext: M.util.get_string('loadinghelp', 'moodle'),
  57                  initialfootertext: ''
  58              });
  59          }
  60  
  61          // Call the tooltip setup.
  62          this.panel.display_panel(e);
  63      },
  64  
  65      /**
  66       * Override the footer handler to add a 'More help' link where relevant.
  67       *
  68       * @method set_footer
  69       * @param {Object} helpobject The object returned from the AJAX call.
  70       */
  71      set_footer: function(helpobject) {
  72          // Check for an optional link to documentation on moodle.org.
  73          if (helpobject.doclink) {
  74              // Wrap a help icon and the morehelp text in an anchor. The class of the anchor should
  75              // determine whether it's opened in a new window or not.
  76              var doclink = Y.Node.create('<a />')
  77                  .setAttrs({
  78                      'href': helpobject.doclink.link
  79                  })
  80                  .addClass(helpobject.doclink['class']);
  81              var helpicon = Y.Node.create('<img />')
  82                  .setAttrs({
  83                      'src': M.util.image_url('docs', 'core')
  84                  })
  85                  .addClass(CSS.ICON)
  86                  .addClass(CSS.ICONPRE);
  87              doclink.appendChild(helpicon);
  88              doclink.appendChild(helpobject.doclink.linktext);
  89  
  90              // Set the footerContent to the contents of the doclink.
  91              this.set('footerContent', doclink);
  92              this.bb.one(SELECTORS.FOOTER).show();
  93          } else {
  94              this.bb.one(SELECTORS.FOOTER).hide();
  95          }
  96      }
  97  });
  98  M.core = M.core || {};
  99  M.core.popuphelp = M.core.popuphelp || null;
 100  M.core.init_popuphelp = M.core.init_popuphelp || function(config) {
 101      // Only set up a single instance of the popuphelp.
 102      if (!M.core.popuphelp) {
 103          M.core.popuphelp = new POPUPHELP(config);
 104      }
 105      return M.core.popuphelp;
 106  };


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