src/cm/media/js/client/c_scopes.js
changeset 504 b2e0186daa5b
parent 373 f6fe14eb51bc
child 519 e89c25780e6e
equal deleted inserted replaced
502:8ec189cc214d 504:b2e0186daa5b
   264 },
   264 },
   265 
   265 
   266 //elt is supposed to be c-c classed
   266 //elt is supposed to be c-c classed
   267 _addIdClass = function (elt, commentId) {
   267 _addIdClass = function (elt, commentId) {
   268   CY.DOM.addClass(elt, 'c-id-' + commentId) ;
   268   CY.DOM.addClass(elt, 'c-id-' + commentId) ;
       
   269   var block_elt = _findParentBlockElt(elt);
       
   270   if (block_elt != null) {
       
   271     _unpaintCategories(block_elt);
       
   272     _repaintCategories(elt, block_elt);
       
   273   }
   269   _updateCommentCounter(elt) ;
   274   _updateCommentCounter(elt) ;
   270 } ;
   275 } ;
   271 
   276 
   272 //elt is supposed to be c-c classed
   277 //elt is supposed to be c-c classed
   273 _removeIdClass = function (elt, commentId) {
   278 _removeIdClass = function (elt, commentId) {
   274   CY.DOM.removeClass(elt, 'c-id-' + commentId) ;
   279   CY.DOM.removeClass(elt, 'c-id-' + commentId) ;
       
   280   var block_elt = _findParentBlockElt(elt);
       
   281   if (block_elt != null) {
       
   282     _unpaintCategories(block_elt);
       
   283     _repaintCategories(elt, block_elt, commentId);
       
   284   }
   275   _updateCommentCounter(elt) ;
   285   _updateCommentCounter(elt) ;
   276 } ;
   286 } ;
   277 
   287 
   278 //elt is supposed to be c-c classed
   288 //elt is supposed to be c-c classed
   279 _removeIdClasses = function (elt) {
   289 _removeIdClasses = function (elt) {
   280   var re = _cgetRegExp('(?:^|\\s+)c-id-(?:\\d+)', 'g');
   290   var re = _cgetRegExp('(?:^|\\s+)c-id-(?:\\d+)', 'g');
   281   elt['className'] = elt['className'].replace(re, " ") ;
   291   elt['className'] = elt['className'].replace(re, " ") ;
   282   _updateCommentCounter(elt) ;
   292   _updateCommentCounter(elt) ;
   283 } ;
   293   var block_elt = _findParentBlockElt(elt);
       
   294   if (block_elt != null) {
       
   295     _unpaintCategories(block_elt);
       
   296   }
       
   297 } ;
       
   298 
       
   299 // Finds the closest parent of an element which is a block.
       
   300 _findParentBlockElt = function(elt) {
       
   301   var block_elt = elt;
       
   302   var block_elt_style = block_elt.currentStyle || window.getComputedStyle(block_elt, ""); 
       
   303   var block_elt_display = block_elt_style.display;
       
   304   while (block_elt != null && block_elt_display != 'block') {
       
   305     block_elt = block_elt.parentElement;
       
   306     block_elt_style = block_elt.currentStyle || window.getComputedStyle(block_elt, ""); 
       
   307     block_elt_display = block_elt_style.display;
       
   308   }
       
   309   return block_elt;
       
   310 };
       
   311 
       
   312 // Removes all vertical bars from a block element.
       
   313 _unpaintCategories = function(block_elt) {
       
   314   CY.DOM.removeClass(block_elt, 'cat1');
       
   315   CY.DOM.removeClass(block_elt, 'cat2');
       
   316   CY.DOM.removeClass(block_elt, 'cat3');
       
   317   CY.DOM.removeClass(block_elt, 'cat4');
       
   318   CY.DOM.removeClass(block_elt, 'cat5');
       
   319 }
       
   320 
       
   321 // Paints all vertical bars of a block element but the one for commentId if not null.
       
   322 _repaintCategories = function(elt, block_elt, commentId) {
       
   323   // Loop through all comments in this wrapper id
       
   324   var wrapper_id = parseInt(getWrapperAncestor(elt).id.substr(3));
       
   325   var len = gDb.comments.length;
       
   326   for (var i=0; i<len; i++) {
       
   327     if (i in gDb.comments) {
       
   328       var comment = gDb.comments[i];
       
   329       if ((commentId == null || comment.id != commentId) && comment.start_wrapper <= wrapper_id && comment.end_wrapper >= wrapper_id) {
       
   330         if (comment.category) {
       
   331           CY.DOM.addClass(block_elt, 'cat' + comment.category);
       
   332         }
       
   333       }
       
   334     }
       
   335   }
       
   336 }
   284 
   337 
   285 _recAddComment = function (elt, commentId) {
   338 _recAddComment = function (elt, commentId) {
   286   if (CY.DOM.hasClass(elt, 'c-c')) {
   339   if (CY.DOM.hasClass(elt, 'c-c')) {
   287     _addIdClass(elt, commentId) ;
   340     _addIdClass(elt, commentId) ;
   288   }
   341   }