Short description

It could be quite puzzling to new users having always the menu item "comments" displayed in the editbar although there are no inline comments in the page at all. Clicking on the menu item triggers no action. So most users would ask themselves "What's that?" and in longer pages they start to search, where the inline comments are - but there are no comments. Displaying the menu item could also be misunderstood, see MoinMoinBugs/1.6BetaDiscussionPage. Therefore I think it is better to remove the "comments" button if no inline comments are available. Toggling the item is the only easy way to inform the user about the existance of inline comments without the need to search longer pages whether there are really comments in there or not.

(!) Implemented by http://hg.moinmo.in/moin/1.6/rev/c2981c625591 and http://hg.moinmo.in/moin/1.7/rev/d6057ed413e6. I didn't commit that "comments counting", that is rather superfluous IMHO.

Here's a patch for moin-1.6.0beta2 which allows to toggle toggleComments:

   1 diff -r 57536a4cb500 wiki/htdocs/common/js/common.js
   2 --- a/wiki/htdocs/common/js/common.js	Sun Dec 09 18:16:51 2007 +0100
   3 +++ b/wiki/htdocs/common/js/common.js	Sun Dec 09 19:46:26 2007 +0100
   4 @@ -168,6 +168,7 @@ function show_switch2gui() {
   5      }
   6  }
   7  
   8 +
   9  function toggleComments() {
  10      // Toggle visibility of every tag with class == *comment*
  11      var all = document.getElementsByTagName('*');
  12 @@ -183,6 +184,31 @@ function toggleComments() {
  13      }
  14  }
  15  
  16 +
  17 +function toggle_toggleComments() {
  18 +    // Disable menu item "ToggleComments" if no inline comments exist on a page
  19 +    var all = document.getElementsByTagName('*');
  20 +    var j = 0;
  21 +    for (i = 0; i < all.length; i++){
  22 +        el = all[i];
  23 +        if ( el.className.indexOf('comment') >= 0 ){
  24 +            j++;
  25 +        }
  26 +    }
  27 +    all = document.getElementsByTagName('*');
  28 +    for (i = 0; i < all.length; i++){
  29 +        el = all[i];
  30 +        if ( el.className.indexOf('toggleCommentsButton') >= 0 ){
  31 +            if ( j > 0 ) {
  32 +                el.parentNode.style.display = '';
  33 +            } else {
  34 +                el.parentNode.style.display = 'none';
  35 +            }
  36 +        }
  37 +    }
  38 +}
  39 +
  40 +
  41  function load() {
  42      // Do not name this "onload", it does not work with IE :-)
  43      // TODO: create separate onload for each type of view and set the
  44 @@ -200,6 +226,9 @@ function load() {
  45      
  46      // Editor stuff
  47      show_switch2gui();
  48 +
  49 +    // Disable menu item "ToggleComments" if no inline comments exist
  50 +    toggle_toggleComments();
  51  }
  52  
  53  

patch.diff


How about going one step further and showing the user the number of comments in the page and give an indication of the status of the toggle. So:

  Comments+2 -- means click to show the 2 comments in the page

  Comments-3 -- means click to hide the 3 comments in the page

             -- means there are no comments on the page

function toggleComments() {
    // Toggle visibility of every tag with class == *comment*
    var all = document.getElementsByTagName('*');
    for (i = 0; i < all.length; i++){
        el = all[i];
        if ( el.className.indexOf('comment') >= 0 ){
            if ( el.style.display != 'none' ) {
                el.style.display = 'none';
            } else {
                el.style.display = '';
            }
        }
    }
    toggle_toggleComments();
}

// add onload function to hide Comments hyperlink or show number of comments in page
addLoadEvent(toggle_toggleComments);
commentValue = '';
function toggle_toggleComments() {
    // count all comments in page -- there may be 0 comments
    var all = document.getElementsByTagName('*');
    var count = 0;
    var hidden = 0;
    for (i = 0; i < all.length; i++){
        el = all[i];
        if ( el.className.indexOf('comment') >= 0 ){
            count += 1;
            // remember if comments are currently hidden or not
            hidden = el.style.display;
        }
    }
    // find all the show/hide comments hyperlinks;  either hide the hyperlink or add the count -- there will be at least 1
    var a = document.getElementsByTagName('a');
    for (i = 0; i < a.length; i++){
        hlink = a[i];
        if ( hlink.className.indexOf('toggleCommentsButton') >= 0 ){
            // save the starting value of the first hyperlink we find 
            if (!commentValue) {
                commentValue = hlink.innerHTML;
            }
            if (count){
                // change the hyperlink to show +/- count of elements
                if ( hidden == 'none' ) {
                    hlink.innerHTML = commentValue + '+' + count;
                } else {
                    hlink.innerHTML = commentValue + '-' + count;
                }
            } else {
                // hide the hyperlink
                hlink.parentNode.style.display = 'none';
            }
        }
    }
}


CategoryFeatureRequest CategoryFeatureImplemented

MoinMoin: FeatureRequests/Toggle_ToggleComments_IfNoInlineCommentsExist (last edited 2008-03-23 12:40:02 by ReimarBauer)