v0.9 Release – Fix for the Line Break bug

In my previous blog post I explained the line break bug and how I would go about fixing it. I’ve managed to get the functionality up and running now. Lets have a look at the code:

// ellipsis for multi-line desc messages
$('.desc').each(function (i) {
  if($(this).html().indexOf("n") != -1) {
    $(this).html($(this).html().replace(/n/g, "
    $(this).html(createEllipsis($(this).html(), ($(this).attr("class")).match(/idd+/) + i));
$('.ellipsisexpand').click(function () {
  var pushid = $(this).attr("class");
  pushid = 'span.' + pushid.match(/idd+/);
  return false;
function createEllipsis(html, pushid) {
  return html.substring(0, html.indexOf(""))
    + "<a class="&quot;ellipsisexpand" href="">[...]</a><span class="&quot;hide">"
    + html.substring(html.indexOf(""), html.length)
    + "</span>";

The map file:

<strong class="desc id#id#">#author|person# — #desc|strip|escape|buglink#</strong>

When using jquery you want to keep all your functionality within the $(document).ready function, which is what I have done. So, in the map file I gave the strong tag that contains the commit message a new class, called desc (see above). Then, I loop through each tag containing a class called desc with the code on line 36. Within the loop I replace all occurances of ‘n’ with ‘<br/>’.  Next I call createEllipsis() (line  39). This function rewrites the html within the strong tag to include an ellipsis link and puts all the lines that will get expanded/collapsed in a different span tag. Lastly, line 40 hides everything that should be hidden.

Next I have a click handler that expands/collapses any span tag with the class name ‘hide’. Within this function, I also uniquely identify which span tag to toggle. This is needed because there are can be more than one span tag with the class name, ‘hide’ on any given page. I set the pushid as one of the class names to uniquely identify each span tag. Thus, each span tag that should be hidden will have two class names, hide and the pushid. See the results below:

Collapsed Example

Expanded Example

This entry was posted in DPS911, Mercurial Project, Open Source and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>