if(!CU) var CU = { }; if(!CU.widget) CU.widget = { }; /** * Allows you to add little comment count icons * to margins of blocks */ CU.widget.BlockComments = function() { } CU.widget.BlockComments.prototype = { _comments: [], /** * Set the comments for each block. */ setComments: function(comments) { this._comments = comments; }, /** * Applies comment functionality to nodes found with a query * @param {String} query dojo.query style query, ie. #foo p */ applyTo: function(query) { var index = 0; var self = this; var props = {}; props[query] = { found: function(n) { var commentsEl = document.createElement('div'); commentsEl.className = 'commentsBubble'; if(index < self._comments.length) commentsEl.innerHTML = self._comments[index].length; else commentsEl.innerHTML = '0'; n.appendChild(commentsEl); var i = index; dojo.connect(commentsEl, 'click', function() { self.onCommentsCountClicked(i, self._comments[i]); }); index++; }, onmouseenter: function() { dojo.addClass(this, 'showcomments'); }, onmouseleave: function() { dojo.removeClass(this, 'showcomments'); } }; dojo.behavior.add(props); dojo.behavior.apply(); }, /** * Called when a comments count el is clicked * @param {Number} index block index * @param {Array} comments comments for the block */ onCommentsCountClicked: function(index, comments) { } };