/* Cblock cares about storing info and comments for given block */ /* Commentable handles all other routines such as creating list of blocks */ Commentable = function(){ /* private variables */ var cb, blocks, tpl, cn, tabs, wait, list, vlist, error, submit, postBtn; var cmResize, viewResize; var posting = false; var currentIndex, lastIndex; /* private functions */ var isOnCommentBar = function(e){ var x = cb.getX(); return(e.getPageX() >= x && e.getPageX() <= (x+30)); }; var setActiveIndex = function(index){ index = index || 0; if(typeof currentIndex != 'undefined'){ blocks[currentIndex].el.removeClass('active-content'); } currentIndex = index; blocks[currentIndex].el.addClass('active-content'); }; var onClick = function(e){ if(isOnCommentBar(e)){ var p = Ext.get(e.getTarget()); var p = Ext.get(e.getTarget()); if(p.contentIndex >= 0){ e.stopEvent(); setActiveIndex(p.contentIndex); Commentable.addComment(); } } }; var cancelSelection = function(e){ if(isOnCommentBar(e)){ e.preventDefault(); } }; var afterSuccess = function(el){ blocks[currentIndex].addComment(el); } var commentSuccess = function(o){ posting = false; var text = o.responseText; // if we got a comment block back if(text.substr(0, 3) == ' containerBottom){ container.scrollTop = childBottom-container.clientHeight; } } }; }(); CBlock = function(el, index){ this.el = el; el.contentIndex = index; el.set({contentIndex : index}); this.index = index; this.count = 0; }; CBlock.prototype = { addComment : function(commentItem){ if(!this.comments){ this.comments = []; } this.comments.push(commentItem); this.count++; this.updateMark(); }, updateMark : function(){ if(this.mark == null){ this.markTpl = new Ext.Template( '' + '{commentsNo}'); this.mark = Ext.get(this.markTpl.append(this.el, {contentIndex: this.index, commentsNo: this.count, markTitle: (this.count == 1 ? '1 comment' : this.count + ' comments')})); this.mark.on('click', this.onClick, this, {stopEvent: true}); } else { this.mark.dom.firstChild.innerHTML = this.count; this.mark.dom.title = this.count == 1 ? '1 comment' : this.count + ' comments'; } }, getXY : function(){ return this.el.getXY(); }, onClick : function(e){ this.mark.setOpacity(.5); Commentable.commentMarkClick(this); } };