mozilla
Your Search Results

    Template: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 = 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;
        });
            
        var n = 0;
        var ts = 0;
        
        // Figure out how many items go in the first column. If there are only
        // two items in the list, this is always 1, to be sure both columns
        // have content.
        
        if (items.length == 2) {
            n = 1;
        } else {
            while (ts < sum/2) {
                ts += lengths[n++];
            }
        }
        
        //var col1 = ""; //items[0];
        var col1 = items[0] + "<dt " + items.slice(1, n).join("<dt ");
        var col2 = "<dt " + items.slice(n, items.length).join("<dt ");
        
        %>
        <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><%
    }
    %>
    Search for pages that use Template:MakeColumnsForDL to see example use cases and how many pages use this macro.

    Document Tags and Contributors

    Contributors to this page: groovecoder, Sheppy, DavidWalsh
    Last updated by: Sheppy,