[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/community/yui/comments/ -> comments.js (source)

   1  YUI.add('moodle-block_community-comments', function(Y) {
   2  
   3      var COMMENTSNAME = 'blocks_community_comments';
   4  
   5      var COMMENTS = function() {
   6          COMMENTS.superclass.constructor.apply(this, arguments);
   7      };
   8  
   9      Y.extend(COMMENTS, Y.Base, {
  10  
  11          event:null,
  12          panelevent: null,
  13          panels: [], //all the comment boxes
  14  
  15          initializer : function(params) {
  16  
  17              //attach a show event on the div with id = comments
  18              for (var i=0;i<this.get('commentids').length;i++)
  19              {
  20                  var commentid = this.get('commentids')[i];
  21                  this.panels[commentid] = new M.core.dialogue({
  22                      headerContent:Y.Node.create('<h1>')
  23                          .append(Y.one('#commentoverlay-'+commentid+' .commenttitle').get('innerHTML')),
  24                      bodyContent:Y.one('#commentoverlay-'+commentid).get('innerHTML'),
  25                      visible: false, //by default it is not displayed
  26                      modal: false,
  27                      zIndex:100,
  28                      closeButtonTitle: this.get('closeButtonTitle')
  29                  });
  30  
  31                  this.panels[commentid].get('contentBox').one('.commenttitle').remove();
  32                  this.panels[commentid].render();
  33                  this.panels[commentid].hide();
  34  
  35                  Y.one('#comments-'+commentid).on('click', this.show, this, commentid);
  36              }
  37  
  38          },
  39  
  40          show : function (e, commentid) {
  41  
  42              // Hide all panels.
  43              for (var i=0;i<this.get('commentids').length;i++)
  44              {
  45                  this.hide(e, this.get('commentids')[i]);
  46              }
  47  
  48              this.panels[commentid].show(); //show the panel
  49  
  50              e.halt(); // we are going to attach a new 'hide panel' event to the body,
  51              // because javascript always propagate event to parent tag,
  52              // we need to tell Yahoo to stop to call the event on parent tag
  53              // otherwise the hide event will be call right away.
  54  
  55              // We add a new event on the body in order to hide the panel for the next click.
  56              this.event = Y.one(document.body).on('click', this.hide, this, commentid);
  57              // We add a new event on the panel in order to hide the panel for the next click (touch device).
  58              this.panelevent = Y.one("#commentoverlay-"+commentid).on('click', this.hide, this, commentid);
  59  
  60              // Focus on the close button
  61              this.panels[commentid].get('buttons').header[0].focus();
  62          },
  63  
  64          hide : function (e, commentid) {
  65              this.panels[commentid].hide(); //hide the panel
  66              if (this.event != null) {
  67                  this.event.detach(); //we need to detach the body hide event
  68              //Note: it would work without but create js warning everytime
  69              //we click on the body
  70              }
  71              if (this.panelevent != null) {
  72                  this.panelevent.detach(); //we need to detach the panel hide event
  73              //Note: it would work without but create js warning everytime
  74              //we click on the body
  75              }
  76  
  77          }
  78  
  79      }, {
  80          NAME : COMMENTSNAME,
  81          ATTRS : {
  82              commentids: {},
  83              closeButtonTitle : {
  84                  validator : Y.Lang.isString,
  85                  value : 'Close'
  86              }
  87          }
  88      });
  89  
  90      M.blocks_community = M.blocks_community || {};
  91      M.blocks_community.init_comments = function(params) {
  92          return new COMMENTS(params);
  93      }
  94  
  95  }, '@VERSION@', {
  96      requires:['base', 'moodle-core-notification']
  97  });


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