MDL-30857 block_community Removing comments hardcoded height
[moodle.git] / blocks / community / yui / comments / comments.js
CommitLineData
1ce282c8 1YUI.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);
f7af9f2e 7 };
1ce282c8 8
9 Y.extend(COMMENTS, Y.Base, {
10
11 event:null,
12 overlayevent:null,
13 overlays: [], //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++)
f7af9f2e 19 {
1ce282c8 20 var commentid = this.get('commentids')[i];
21 this.overlays[commentid] = new M.core.dialogue({
22 headerContent:Y.one('#commentoverlay-'+commentid+' .commenttitle').get('innerHTML'),
23 bodyContent:Y.one('#commentoverlay-'+commentid).get('innerHTML'),
24 visible: false, //by default it is not displayed
25 lightbox : false,
0e0f3beb 26 zIndex:100
1ce282c8 27 });
28
29 this.overlays[commentid].get('contentBox').one('.commenttitle').remove();
30 this.overlays[commentid].render();
31 this.overlays[commentid].hide();
32
1ce282c8 33 Y.one('#comments-'+commentid).on('click', this.show, this, commentid);
34 }
35
36 },
37
38 show : function (e, commentid) {
39
40 //hide all overlays
41 for (var i=0;i<this.get('commentids').length;i++)
42 {
43 this.hide(e, this.get('commentids')[i]);
44 }
45
46 this.overlays[commentid].show(); //show the overlay
47
48 e.halt(); // we are going to attach a new 'hide overlay' event to the body,
49 // because javascript always propagate event to parent tag,
50 // we need to tell Yahoo to stop to call the event on parent tag
51 // otherwise the hide event will be call right away.
52
53 //we add a new event on the body in order to hide the overlay for the next click
54 this.event = Y.one(document.body).on('click', this.hide, this, commentid);
55 //we add a new event on the overlay in order to hide the overlay for the next click (touch device)
56 this.overlayevent = Y.one("#commentoverlay-"+commentid).on('click', this.hide, this, commentid);
57 },
58
59 hide : function (e, commentid) {
60 this.overlays[commentid].hide(); //hide the overlay
61 if (this.event != null) {
62 this.event.detach(); //we need to detach the body hide event
63 //Note: it would work without but create js warning everytime
64 //we click on the body
65 }
66 if (this.overlayevent != null) {
67 this.overlayevent.detach(); //we need to detach the overlay hide event
68 //Note: it would work without but create js warning everytime
69 //we click on the body
70 }
f7af9f2e 71
1ce282c8 72 }
73
74 }, {
75 NAME : COMMENTSNAME,
76 ATTRS : {
77 commentids: {}
78 }
79 });
80
81 M.blocks_community = M.blocks_community || {};
82 M.blocks_community.init_comments = function(params) {
83 return new COMMENTS(params);
84 }
85
86}, '@VERSION@', {
d2a27ab0
ARN
87 requires:['base','overlay', 'moodle-core-notification']
88});