src/cm/media/js/client/c_scopes.js
author gibus
Wed, 11 Sep 2013 23:13:01 +0200
changeset 532 0bad3613f59d
parent 525 89ef5ed3c48b
child 600 fda73ac53450
permissions -rw-r--r--
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
// DOM MANIPULATION TO DYNAMICALLY RENDER COMMENTS SCOPES IN TEXT 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
// cf. http://www.quirksmode.org/dom/w3c_core.html#nodemanipulation (informative!)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
// classes :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
// c-s is for 'textnode wrapper span'
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
// c-c is a comment marker
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     8
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     9
paintCommentScope = function(comment) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    10
  if (comment.reply_to_id == null && comment['start_wrapper'] != -1) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    11
    var selection = {   'start' : { 'elt' : document.getElementById("sv_"+comment['start_wrapper']), 'offset' : comment['start_offset'] },
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    12
              'end' : { 'elt' : document.getElementById("sv_"+comment['end_wrapper']), 'offset' : comment['end_offset'] }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    13
            } ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    14
    if (document.getElementById("sv_"+comment['start_wrapper'])== null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    15
      warn_server({'from':'paintCommentScope', 'start_wrapper':comment['start_wrapper']}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    16
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    17
    else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    18
      if (document.getElementById("sv_"+comment['end_wrapper'])== null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    19
        warn_server({'from':'paintCommentScope', 'end_wrapper':comment['end_wrapper']}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    20
      else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    21
          selection['start'] = _convertSelectionFromCSToCC(selection['start']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    22
          selection['end'] = _convertSelectionFromCSToCC(selection['end']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    23
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    24
          renderComment(selection, comment['id']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    25
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    26
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    27
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    28
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    29
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    30
getCommentIdsFromClasses = function (elt) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    31
  var commentIds = [] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    32
  var classes = elt['className'].split(" ") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    33
  for (var i = 0, ilen = classes.length ; i < ilen ; i++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    34
    if (classes[i].indexOf('c-id-') == 0) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    35
      commentIds.push(parseInt(classes[i].substring('c-id-'.length))) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    36
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    37
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    38
  return commentIds ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    39
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    40
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    41
renderComment = function (selection, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    42
  var startOffset = selection['start']['offset'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    43
  var endOffset = selection['end']['offset'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    44
  var startElt = selection['start']['elt'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    45
  var endElt = selection['end']['elt'] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    46
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    47
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    48
    if ((startElt != null) && (endElt != null) && _getTextNodeContent(startElt) != '' && _getTextNodeContent(endElt) != ''){
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    49
// log('startElt.id : ' + startElt.id) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    50
// log('endElt.id : ' + endElt.id) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    51
//      log('startElt.innerHTML : ' + startElt.innerHTML) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    52
//      log('endElt.innerHTML : ' + endElt.innerHTML) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    53
      markWholeNodesAsComments(startElt, endElt, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    54
      markEndsAsComments(startElt, startOffset, endElt, endOffset, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    55
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    56
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    57
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    58
markWholeNodesAsComments = function (startElt, endElt, commentId) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    59
    var commonAncestor = _findCommonAncestor(startElt, endElt) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    60
    _dynSpanToAnc(startElt, commonAncestor, commentId, false) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    61
    
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    62
    _dynSpanToAnc(endElt, commonAncestor, commentId, true) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    63
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    64
    _dynSpanInBetween(commonAncestor, startElt, endElt, commentId) ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    65
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    66
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    67
_setTextNodeContent = function(txtNodeParent, contentString) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
    CY.DOM.setText(txtNodeParent, contentString);
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    69
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
_getTextNodeContent = function(txtNodeParent) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
    return CY.DOM.getText(txtNodeParent);
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
    73
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
markEndsAsComments = function(startElt, startOffset, endElt, endOffset, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    76
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    77
//  alert('starting with: ' + startElt.childNodes.length + 'and a length of : ' + startElt.firstChild.data.length) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    78
//  alert('2 and a length of : ' + CY.DOM.getText(startElt).length) ; 
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    79
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    80
  var beforeStart = _getTextNodeContent(startElt).substring(0, startOffset) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    81
  var afterStart = _getTextNodeContent(startElt).substring(startOffset) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    82
  var beforeEnd = _getTextNodeContent(endElt).substring(0, endOffset) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    83
  var afterEnd = _getTextNodeContent(endElt).substring(endOffset) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    85
    var sameNode = (startElt === endElt) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
    
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    87
//    log('beforeStart : ' + beforeStart + ' , afterStart : ' + afterStart + ' , beforeEnd : ' + beforeEnd + ' , afterEnd : ' + afterEnd + ' , sameNode : ' + sameNode) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    89
    // taking care of start node : (and 'sameNode' case when start and end lie
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    90
  // on same node)
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    91
    if (afterStart != "") { // otherwise nothing to do on the start node
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    92
      if (CY.DOM.hasClass(startElt, 'c-c')) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    93
        var lastElt = null, afterStartElt = null, afterEndElt = null, beforeStartElt = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    94
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    95
          var btw = (sameNode) ? _getTextNodeContent(startElt).substring(startOffset, endOffset) : afterStart ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    96
                    
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    97
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    98
          if (sameNode && (afterEnd != "")) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
    99
        afterEndElt = startElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   100
        lastElt = afterEndElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   101
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   102
        if (btw != "") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   103
          if (lastElt == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   104
            afterStartElt = startElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   105
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   106
          else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   107
            afterStartElt = _yuiCloneNode(startElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   108
            lastElt.parentNode.insertBefore(afterStartElt, lastElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   109
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   110
        lastElt = afterStartElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   111
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   112
        if (beforeStart != "") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   113
          if (lastElt == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   114
            beforeStartElt = startElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   115
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   116
          else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   117
            beforeStartElt = _yuiCloneNode(startElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   118
            lastElt.parentNode.insertBefore(beforeStartElt, lastElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   119
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   120
        lastElt = beforeStartElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   121
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   122
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   123
      if (afterEndElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   124
        _setTextNodeContent(afterEndElt, afterEnd) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   125
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   126
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   127
        if (afterStartElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   128
        _setTextNodeContent(afterStartElt, btw) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   129
          _addIdClass(afterStartElt, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   130
        }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   131
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   132
//        alert('beforeStartElt.firstChild.data.length: ' + beforeStartElt.firstChild.data.length);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   133
//        alert('beforeStartElt.childNodes.length: ' + beforeStartElt.childNodes.length);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   134
        if (beforeStartElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   135
        _setTextNodeContent(beforeStartElt, beforeStart) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   136
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   137
//        alert('beforeStartElt.childNodes.length: ' + beforeStartElt.childNodes.length);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   138
        //alert('typeof beforeStartElt: ' + typeof beforeStartElt);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   139
//        alert('beforeStartElt.lastChild ==  beforeStartElt.firstChild : ' + (beforeStartElt.lastChild == beforeStartElt.firstChild));
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   140
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   141
//        alert('beforeStartElt.firstChild.id : ' + beforeStartElt.firstChild.id);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   142
//        alert('beforeStartElt.lastChild.data : ' + beforeStartElt.lastChild.data);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   143
//        alert('beforeStartElt.firstChild.data : ' + beforeStartElt.firstChild.data);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   144
//        alert('afterStartElt.firstChild.data : ' + afterStartElt.firstChild.data);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   145
//        alert('afterEndElt.firstChild.data : ' + afterEndElt.firstChild.data);
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   146
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   147
        }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   148
    }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   149
    if ( ( !sameNode ) && ( beforeEnd != "" ) ) { // otherwise nothing to do
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   150
                          // on the end node
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   151
      if (CY.DOM.hasClass(endElt, 'c-c')) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   152
        var lastElt = null, beforeEndElt = null, afterEndElt = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   153
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   154
        if (afterEnd != "") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   155
          afterEndElt = endElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   156
        lastElt = endElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   157
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   158
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   159
        if (beforeEnd != "") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   160
          if (lastElt == null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   161
            beforeEndElt = endElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   162
          else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   163
            beforeEndElt = _yuiCloneNode(endElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   164
            lastElt.parentNode.insertBefore(beforeEndElt, lastElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   165
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   166
        lastElt = beforeEndElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   167
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   168
        if (afterEndElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   169
          _setTextNodeContent(afterEndElt, afterEnd) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   170
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   171
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   172
        if (beforeEndElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   173
          _addIdClass(beforeEndElt, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   174
          _setTextNodeContent(beforeEndElt, beforeEnd) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   175
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   176
      }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   177
    }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   178
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   179
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   180
// WARNING (200891108): had to use YUI cloneNode instead of the native cloneNode
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   181
// (because of the _yuid that is cloned under IE, cf tests made in textYUIcloneNode.html)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   182
// so code like :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   183
// afterStartElt = startElt.cloneNode(true) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   184
// afterStartElt.id = CY.guid() ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   185
// was replaced with :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   186
// afterStartElt = _yuiCloneNode(startElt) ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   187
_yuiCloneNode = function (srcElt) {
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
   188
  var ret = CY.Node.getDOMNode(CY.get('#'+srcElt.id).cloneNode(true)) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   189
  ret.id = CY.guid();
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   190
  return ret ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   191
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   192
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   193
// will wrap textNodes into c-c spans going up the DOM tree from elt to ancestor
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   194
// textNodes impacted here will be those that are :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   195
// the same generation or older than elt (but elt is excluded)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   196
// AND not older than grand children of to
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   197
// assumption :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   198
// 1 ancestor is an ancestor of elt (we'll be going up the DOM tree)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   199
// 2 elt is a textNode.
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   200
// argumentss :
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   201
// prev : will spannify previous siblings if true, next siblings otherwise
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   202
_dynSpanToAnc = function (elt, ancestor, commentId, prev) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   203
// log('in : _dynSpanToAnc, elt : ' + elt.id) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   204
  var c = elt ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   205
    while ((c != null) && (c !== ancestor) && (c.parentNode !== ancestor)) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   206
    var c_sib = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   207
    if (prev) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   208
      c_sib = c.previousSibling ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   209
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   210
    else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   211
      c_sib = c.nextSibling ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   212
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   213
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   214
    if (c_sib == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   215
      c = c.parentNode ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   216
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   217
    else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   218
      c = c_sib ;     
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   219
      _recAddComment(c, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   220
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   221
  } ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   222
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   223
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   224
// between elt1 and elt2 (which are excluded)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   225
_dynSpanInBetween = function (anc, elt1, elt2, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   226
  var a = elt1 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   227
  var elt1Anc = null ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   228
    while (a) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   229
        if (a.parentNode === anc) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   230
          elt1Anc = a ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   231
          break;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   232
        }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   233
        a = a.parentNode;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   234
    }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   235
  if (elt1Anc != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   236
    a = elt2 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   237
    var elt2Anc = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   238
      while (a) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   239
          if (a.parentNode === anc) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   240
            elt2Anc = a ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   241
            break;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   242
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   243
          a = a.parentNode;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   244
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   245
    if (elt2Anc != null) { // found both ancestor, now doing the work
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   246
      a = elt1Anc.nextSibling ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   247
      while ((a != null) && (a !== elt2Anc)) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   248
        _recAddComment(a, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   249
        a = a.nextSibling ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   250
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   251
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   252
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   253
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   254
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   255
// (copied from YUI dom-base)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   256
_bruteContains = function(element, needle) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   257
    while (needle) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   258
        if (element === needle) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   259
            return true;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   260
        }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   261
        needle = needle.parentNode;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   262
    }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   263
    return false;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   264
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   265
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   266
//elt is supposed to be c-c classed
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   267
_addIdClass = function (elt, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   268
  CY.DOM.addClass(elt, 'c-id-' + commentId) ;
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   269
  var block_elt = _findParentBlockElt(elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   270
  if (block_elt != null) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   271
    _unpaintCategories(block_elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   272
    _repaintCategories(elt, block_elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   273
  }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   274
  _updateCommentCounter(elt) ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   275
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   276
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   277
//elt is supposed to be c-c classed
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   278
_removeIdClass = function (elt, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   279
  CY.DOM.removeClass(elt, 'c-id-' + commentId) ;
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   280
  var block_elt = _findParentBlockElt(elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   281
  if (block_elt != null) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   282
    _unpaintCategories(block_elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   283
    _repaintCategories(elt, block_elt, commentId);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   284
  }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   285
  _updateCommentCounter(elt) ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   286
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   287
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   288
//elt is supposed to be c-c classed
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   289
_removeIdClasses = function (elt) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   290
  var re = _cgetRegExp('(?:^|\\s+)c-id-(?:\\d+)', 'g');
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   291
  elt['className'] = elt['className'].replace(re, " ") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   292
  _updateCommentCounter(elt) ;
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   293
  var block_elt = _findParentBlockElt(elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   294
  if (block_elt != null) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   295
    _unpaintCategories(block_elt);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   296
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   297
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   298
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   299
// Finds the closest parent of an element which is a block.
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   300
_findParentBlockElt = function(elt) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   301
  var block_elt = elt;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   302
  var block_elt_style = block_elt.currentStyle || window.getComputedStyle(block_elt, ""); 
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   303
  var block_elt_display = block_elt_style.display;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   304
  while (block_elt != null && block_elt_display != 'block') {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   305
    block_elt = block_elt.parentElement;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   306
    block_elt_style = block_elt.currentStyle || window.getComputedStyle(block_elt, ""); 
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   307
    block_elt_display = block_elt_style.display;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   308
  }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   309
  return block_elt;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   310
};
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   311
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   312
// Removes all vertical bars from a block element.
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   313
_unpaintCategories = function(block_elt) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   314
  CY.DOM.removeClass(block_elt, 'cat1');
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   315
  CY.DOM.removeClass(block_elt, 'cat2');
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   316
  CY.DOM.removeClass(block_elt, 'cat3');
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   317
  CY.DOM.removeClass(block_elt, 'cat4');
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   318
  CY.DOM.removeClass(block_elt, 'cat5');
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   319
};
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   320
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   321
// Paints all vertical bars of a block element but the one for commentId if not null.
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   322
_repaintCategories = function(elt, block_elt, commentId) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   323
  // Loop through all comments in this wrapper id
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   324
  var wrapper_id = parseInt(getWrapperAncestor(elt).id.substr(3));
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   325
  var len = gDb.comments.length;
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   326
  for (var i=0; i<len; i++) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   327
    if (i in gDb.comments) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   328
      var comment = gDb.comments[i];
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   329
      if ((commentId == null || comment.id != commentId) && comment.start_wrapper <= wrapper_id && comment.end_wrapper >= wrapper_id) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   330
        if (comment.category) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   331
          CY.DOM.addClass(block_elt, 'cat' + comment.category);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   332
        }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   333
      }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   334
    }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   335
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   336
};
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 373
diff changeset
   337
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   338
_recAddComment = function (elt, commentId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   339
  if (CY.DOM.hasClass(elt, 'c-c')) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   340
    _addIdClass(elt, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   341
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   342
  else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   343
    var c = elt.firstChild ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   344
        while (c != null) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   345
          _recAddComment(c, commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   346
      c = c.nextSibling ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   347
        }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   348
    }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   349
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   350
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   351
// might be expensive ... (? maybe should use contains when available, instead
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   352
// of custom _bruteContains)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   353
_findCommonAncestor = function (elt1, elt2) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   354
  if (_bruteContains(elt1, elt2))
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   355
    return elt1 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   356
  else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   357
    var e = elt2 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   358
    while ((e != null) && !_bruteContains(e, elt1)) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   359
      e = e.parentNode ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   360
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   361
    return e ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   362
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   363
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   364
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   365
_cregexCache = {};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   366
// inspired (copied) from dom-base-debug in yui
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   367
_cgetRegExp = function(str, flags) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   368
    flags = flags || '';
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   369
    if (!_cregexCache[str + flags]) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   370
        _cregexCache[str + flags] = new RegExp(str, flags);
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   371
    }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   372
    return _cregexCache[str + flags];
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   373
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   374
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   375
//c-c should be classed with a c-count-x where x is a number for color graduation
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   376
//c-c should be classed with many c-id-xid where xid is the comment db id of comment that apply to it
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   377
_updateCommentCounter = function (elt) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   378
  var re = _cgetRegExp('(?:^|\\s+)c-id-(?:\\d+)', 'g');
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   379
  var matches = elt['className'].match(re);
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   380
  var countIds = (matches == null) ? 0 : gDb.getThreads(CY.Array.map(matches, function(item) {return gDb.getComment(parseInt(item.replace(/\D/g, '')));})).length
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   381
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   382
  re = _cgetRegExp('(?:^|\\s+)c-count-(?:\\d+)', 'g');
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   383
  elt['className'] = elt['className'].replace(re, " ") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   384
  CY.DOM.addClass(elt, 'c-count-'+countIds+' ') ;
373
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   385
  if (countIds > 0) {
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   386
    elt.setAttribute ('title', countIds + ngettext(' comment', ' comments', countIds));
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   387
    if (countIds > 25) {
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   388
      // ensure that we have the last color even if there are too many comments on the same place
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   389
      CY.DOM.addClass(elt, 'c-count-25') ;
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   390
    }
f6fe14eb51bc Add a title attribute on comment scopes to indicate the number of comments in the scope.
Simon Descarpentries <sid1@sopinspace.com>
parents: 341
diff changeset
   391
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   392
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   393
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   394
_convertSelectionFromCCToCS = function (sel) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   395
  var offset = sel['offset'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   396
  var elt = sel['elt'].parentNode ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   397
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   398
  var e = sel['elt'].previousSibling ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   399
  while (e != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   400
    offset += _getTextNodeContent(e).length ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   401
    e = e.previousSibling ; // will be a c-c !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   402
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   403
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   404
  return  {'elt':elt, 'offset':offset} ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   405
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   406
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   407
_convertSelectionFromCSToCC = function (sel) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   408
  var ret = {'elt':null, 'offset':-1} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   409
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   410
  var cc = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   411
  var ccElt = sel['elt'].firstChild ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   412
  var length = 0 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   413
  while (ccElt != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   414
    var prevLength = length ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   415
    length += _getTextNodeContent(ccElt).length ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   416
    if (length >= sel['offset']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   417
      ret['elt'] = ccElt ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   418
      ret['offset'] = sel['offset'] - prevLength ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   419
      break ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   420
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   421
    ccElt = ccElt.nextSibling ; // will be a c-c !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   422
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   423
  return ret ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   424
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   425
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   426
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   427
/*******************************************************************************/
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   428
/* SCOPE REMOVAL */
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   429
/*******************************************************************************/
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   430
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   431
unpaintCommentScope = function(comment) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   432
    var dbId = comment.id;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   433
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   434
  var classeId = 'c-id-' + dbId ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   435
  var toBeRemovedElts = [] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   436
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   437
  var cNodeList = CY.all("."+classeId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   438
  if (cNodeList != null) { // null in case of a reply ...
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   439
    for (var i = 0, ilen = cNodeList.size() ; i < ilen ; i++)  {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   440
      var c = cNodeList.item(i) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   441
      if (c.hasClass('c-c')) { // always will !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   442
        var cElt = CY.Node.getDOMNode(c) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   443
        _removeIdClass(cElt, dbId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   444
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   445
        var cIds = getCommentIdsFromClasses(cElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   446
        quicksort(cIds) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   447
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   448
        var p = c.get('previousSibling') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   449
        if (p != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   450
          var pElt = CY.Node.getDOMNode(p) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   451
          var pIds = getCommentIdsFromClasses(pElt) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   452
          quicksort(pIds) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   453
          if (areSortedArraysEqual(cIds, pIds)) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   454
            _setTextNodeContent(cElt, _getTextNodeContent(pElt) + _getTextNodeContent(cElt)) ;            
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   455
            toBeRemovedElts.push(pElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   456
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   457
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   458
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   459
        var n = c.get('nextSibling') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   460
        if (n != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   461
          var nElt = CY.Node.getDOMNode(n) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   462
          var nIds = getCommentIdsFromClasses(nElt) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   463
          quicksort(nIds) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   464
          if (areSortedArraysEqual(cIds, nIds)) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   465
            cElt.firstChild.data = cElt.firstChild.data + nElt.firstChild.data; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   466
            toBeRemovedElts.push(nElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   467
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   468
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   469
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   470
      else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   471
        alert('HAS NO c-c ? : ' + commentNode.get('id') + " , innerHTML :" + commentNode.get('innerHTML')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   472
        return ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   473
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   474
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   475
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   476
  for (var i = 0, ilen = toBeRemovedElts.length ; i < ilen ; i++)  {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   477
    toBeRemovedElts[i].parentNode.removeChild(toBeRemovedElts[i]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   478
  }
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   479
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   480
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   481
// not related to the unpaintCommentScope function (faster)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   482
unpaintAllComments = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   483
  var cNodeList= CY.all(".c-s") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   484
  var toBeRemovedElts = [] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   485
  for (var i = 0, ilen = cNodeList.size() ; i < ilen ; i++)  {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   486
    var c = cNodeList.item(i) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   487
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   488
    // remove Classes
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   489
    var fc = c.get('firstChild') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   490
    var fcElt = CY.Node.getDOMNode(c.get('firstChild')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   491
    _removeIdClasses(fcElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   492
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   493
    // merge nodes
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   494
    var n = fc.get('nextSibling') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   495
    while (n != null)  {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   496
      var nElt = CY.Node.getDOMNode(n) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   497
      fcElt.firstChild.data = fcElt.firstChild.data + nElt.firstChild.data; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   498
      toBeRemovedElts.push(nElt) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   499
      n = n.get('nextSibling') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   500
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   501
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   502
  for (var i = 0, ilen = toBeRemovedElts.length ; i < ilen ; i++)  {
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   503
    toBeRemovedElts[i].parentNode.removeChild(toBeRemovedElts[i]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   504
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   505
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   506
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   507
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   508
showScope = function(commentDbId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   509
  var s = CY.all('.c-id-' + commentDbId); 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   510
  if (s != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   511
    s.addClass('c-scope') ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   512
};
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   513
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   514
hideScopeAnyway = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   515
  var s = CY.all('.c-scope'); 
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   516
  if (s != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 103
diff changeset
   517
    s.removeClass('c-scope') ;
519
e89c25780e6e Gradient of colors for commented text depends on number of comments including replies, instead of depending only on number of threads.
gibus
parents: 504
diff changeset
   518
};