mozilla
Your Search Results

    Template:SidebarTOC

    <%
    /*
     * UNDER DEVELOPMENT, DO NOT USE!!!!
     * $0 - SidebarTOC sub template
     *      [{"url":"url1","title":"title1"},{"url":"url2","title":"title2"}]
     *      [{"url":"url1","title":"title1","subpages":[{"url":"urlA","title":"titleA"},{"url":"urlB","title":"titleB"}]},{"url":"url2","title":"title2"}]
     *      To add a main heading (it should be first and only one)
     *          [{"title":"TOC Heading","head":"main"},{"url":"url1","title":"title1"},{"url":"url2","title":"title2"}]
     *      To add sub headings (sub headings are treated as headings of the following items although subpages can be used if desired)
     *          [{"url":"url1","title":"title1"},{"title":"Sub Heading","head":"sub"},{"url":"url2","title":"title2"}]
     *          [{"url":"url1","title":"title1","subpages":[{"url":"urlA","title":"titleA"},{"url":"urlB","title":"titleB"}]},{"title":"Sub Heading","head":"sub"},{"url":"url2","title":"title2"}]
    */
        var path_page = env.path;
        var toc = '';
          
        if ($0 != undefined && $0 != '') {
            var source = template("SidebarTOC:" + $0, [ ]);
            if (source != '') {
                var list = JSON.parse(source);
                toc = process_array(list);
                 
                function process_array(arr) {
                    var result = '';
                    if(arr.length) {
                        if (arr[0].head == 'main') {
                            item = arr.shift();
                            result += '<div style="font-size:large;">';
                            if (item.url) {
                                result += '<a href="' + item.url + '">' + item.title + '</a>';
                            } else {
                                result += item.title;
                            }
                            result += '</div>';
                        }
                        var itemCount = 0;
                        result += '<dl>';
                        arr.forEach(function(item) {
                            if (item.head) {
                                if (itemCount != 0) {
                                    result += '</ul></dd>';
                                    itemCount = 0;
                                }
                                result += '<dt>';
                                if (item.url) {
                                    result += '<a href="' + item.url + '">' + item.title + '</a>';
                                } else {
                                    result += item.title;
                                }
                                result += '</dt>';
                                result += process_array(item.subpages || []);
                            } else {
                                if (itemCount == 0) {
                                    result += '<dd><ul style="padding:0">';
                                }
                                result += '<li>';
                                if (item.url != path_page) {
                                    result += '<a href="' + item.url + '">' + item.title + '</a>';
                                } else {
                                    result += item.title;
                                }
                                result += process_array(item.subpages || []);
                                result += '</li>';
                                itemCount++;
                            }
                        });
                        if (itemCount > 0) {
                            result += '</ul></dd>';
                        }
                        result += '</dl>';
                    }
                    return result;
                }
            }
        }
    %>
    <%- toc %>
    Search for pages that use Template:SidebarTOC to see example use cases and how many pages use this macro.

    Document Tags and Contributors

    Contributors to this page: trevorh
    Last updated by: trevorh,