mozilla

Revision 647067 of Template:test

  • Revision slug: Template:test
  • Revision title: Template:test
  • Revision id: 647067
  • 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; if (len) { var items = text.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;

if (len) {
    var items = text.split("<dt ");
    log.debug(items.length + " items in the list");
    var sum = 0;
    var lengths = items.map(function(v) {
        sum += v.length;
        return v.length;
    });
    
    var n = 0;
    var ts = 0;
    
    while (ts < sum/2) {
        ts += lengths[n++];
    }
    log.debug("ts = " + ts);
    
    var col1 = items.slice(0, n-1).join("<dt ");
    var col2 = items.slice(n, items.length).join("<dt ");
    
    %>
    <div class="row topicpage-table">
    <div class="section"><%-col1%></div>
    <div class="section"><%-col2%></div>
    </div>
    <%
} else {
    %><p><strong>There are no subpages at this time.</strong></p><%
}
%>