Wiki.tree in Columns

    Table of contents
    1. 1. Code
    2. 2. Result

     

    Previous: Poll
    Next: feedtable

    Show children of wiki.tree("Some Page") in two columns.

    Paste the code below on to a wiki page, then click inside it and select "style=Dekiscript" from the Style pulldown, and adjust the wiki.tree() statement at the beginning to whatever path you want.

    It splits the list at a first-level bullet item only. It would be possible to optimize this behavior a bit. The example below uses the dekiscript page as the parent and reveals the limitations of splitting only on first-level bullets (you can't guarantee two columns that are nearly equal in length).

    Code

    var tree = wiki.tree("Dekiscript");
    var total = #xml.list(tree, ".//li");
    var half = total/2;

    <table><tbody><tr>
    // First column
    var start = -1;
    var col1 = 0;
    <td width="50%" valign="top"><ul>
    foreach (var li in xml.select(tree, "/html/body/div/ul/li")) {
        var size = 1 + #xml.list(li, ".//li");
        if (col1+size > half && (num.abs(col1-half) < num.abs(col1+size-half))) {
            let start = __index;
            break;
    }
        let col1 += size;
        li;
    }
    </ul></td>
    // Second column
    if (start >= 0) {
        <td valign="top"><ul>
            foreach (var li in xml.select(tree, "/html/body/div/ul/li"))
                if (__index >= start) li;
        </ul></td>;
    }
    </tr></tbody></table>;

    Result

    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by