mozilla

Revision 647127 of Template:test

  • Revision slug: Template:test
  • Revision title: Template:test
  • Revision id: 647127
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment

Revision Content

<% // TESTING REPLACEMENT FOR MakeColumnsForDL! // // Outputs a two-column view for the input HTML, which must be a
// list. // // Parameters: // // $0 The HTML containing a
to turn into a two column menu. var html = $0; var len = html.length; // Remove the surrounding
- we will do our own in each column. html = html.replace(/]*>|<\/dl>$/g, ""); log.debug("HTML: " + html); if (len) { var items = html.split("
<%-col1%>
<%-col2%>
<% } else { %>

There are no subpages at this time.

<% } %>

Revision Source

<%
// TESTING REPLACEMENT FOR MakeColumnsForDL!
//
// Outputs a two-column view for the input HTML, which must be a <dl>
// list.
//
// Parameters:
//
//  $0  The HTML containing a <dl> to turn into a two column menu.

var html = $0;
var len = html.length;

// Remove the surrounding <dl> - we will do our own in each column.

html = html.replace(/<dl[^>]*>|<\/dl>$/g, "");
log.debug("HTML: " + html);

if (len) {
    var items = html.split("<dt ");
    items.shift();  // The first item is empty here since the string should start with "<dt"
    var sum = 0;
    var lengths = items.map(function(v) {
        sum += v.length;
        return v.length;
    });
    
    log.debug("Item lengths: " + lengths);
    
    var n = 0;
    var ts = 0;
    
    while (ts < sum/2) {
        ts += lengths[n++];
    }
    log.debug("Total length of all items in first column = " + ts);
    log.debug("Number of items in first column: " + n);
    
    var col1 = "<dt " + items.slice(0, n-1).join("<dt ");
    var col2 = "<dt " + items.slice(n, items.length).join("<dt ");
    
    log.debug("Column 1: " + col1);
    log.debug("Column 2: " + col2);
    
    %>
    <div class="row topicpage-table">
    <div class="section"><dl><%-col1%></dl></div>
    <div class="section"><dl><%-col2%></dl></div>
    </div>
    <%
} else {
    %><p><strong>There are no subpages at this time.</strong></p><%
}
%>