Documentation for this module may be created at Module:Nav/doc

--This module is invoked by Template:Nav
--<nowiki>
local p = {}
local getArgs = require('Module:Arguments').getArgs
local common = require('Module:Common')
 
function p.main(frame)
    args = getArgs(frame)
    if(pcall(p._main, args)) then
        return p._main(args)
    else
        return '[[Category:Pages with script errors]]<span style="color: red">Error. See [[Template:Nav]] for more info.</span>'
    end
end
 
function p._main(args)
    local border, templink, class, style, styleFE, headerFE, header, style1
    local nav, toggle, head, top, content, sections
    local frame = mw.getCurrentFrame()
    local L1, L2, L3 = 15, 15, 5 -- numbers for iteration
 
    -- Initialize args
    border =    common.setDefault(args.border, '#999')
    templink =  common.setDefault(args.templink, 'Nav')
    class =     common.setDefault(args.class)
    style =     common.setDefault(args.style)
    styleFE =   common.setDefault(args.styleFE)
    header =    common.setDefault(args.header, 'Header')
    style1 =    common.setDefault(args['style 1'])
 
    toggle = mw.html.create('div'):addClass('mw-collapsible-toggle '..class)
 
    -- Navbox outer
    nav = mw.html.create('div')
        :addClass('navbox mw-collapsible mw-collapsed')
        :cssText('border: 2px solid '..border)
 
    -- Navhead
    head = mw.html.create('div')
        :addClass('navhead')
        :cssText(style)
        :wikitext(frame:expandTemplate {
            title = 'Tnav',
            args = { 'Template:'..templink, class = 'navlink '..class }})
        :wikitext('<b>'..header..'</b>')
 
    -- Top row
    if(args.headerFE ~= nil) then 
        top = mw.html.create('div')
            :addClass(class)
            :addClass('top-row')
            :cssText(styleFE)
            :wikitext(args.headerFE)
    end
 
    -- Content
    content = mw.html.create('div')
        :addClass('mw-collapsible-content')
        :node(top)
 
    -- Sections level 1
    for i = 1, L1 do
        --------------------- Header ------------------------
        if(args['header '..i] ~= nil) then
            sections = mw.html.create('div')
                :addClass('section mw-collapsible mw-collapsed')
 
            sectionHead = mw.html.create('div')
                :cssText(common.setDefault(args['style '..i], style1))
                :wikitext('<b>'..args['header '..i]..'</b>')
 
            sectionContent = mw.html.create('div')
                :addClass('mw-collapsible-content')
 
            --------------------- Content ------------------------
            if(args['content '..i] ~= nil) then
                sectionContent:wikitext(args['content '..i])
            else
                subSections = sectionContent:tag('table')
                    :attr('width', '100%')
                    :attr('cellpadding', 0)
                    :attr('cellspacing', 0)
 
                -------------------- Sections level 2 ------------------------
                for j = 1, L2 do
                    if(args['header '..i..'-'..j] ~= nil) then
                        tr = subSections:tag('tr')
                        th = tr:tag('th')
                            :css('width', '15%')
                            :cssText(common.setDefault(args['style '..i..'-'..j], style1))
                            :wikitext(args['header '..i..'-'..j])
                        
                        if(args['content '..i..'-'..j] ~= nil) then
                            tr:tag('td')
                                :attr('colspan', 2)
                                :css({padding = '.5em .4em', ['text-align'] = 'left'})
                                :wikitext(common.setDefault(args['content '..i..'-'..j]))
                        else
                            -------------------- Sections level 3 ------------------------
                            for k = 1, L3 do
                                if(args['content '..i..'-'..j..'-'..k] ~= nil) then
                                    th:attr('rowspan', k)
                                    tr = (k ~= 1) and subSections:tag('tr') or tr
                                    tr:tag('th')
                                        :addClass('h3')
                                        :css('width', '15%')
                                        :cssText(common.setDefault(args['style '..i..'-'..j..'-'..k], style1))
                                        :wikitext(args['header '..i..'-'..j..'-'..k])
                                    tr:tag('td')
                                        :css({padding = '.5em .4em', ['text-align'] = 'left'})
                                        :wikitext(common.setDefault(args['content '..i..'-'..j..'-'..k]))
                                else break
                                end
                            end
                        end
                    else break end
                end
 
                ---------------------- Section Note --------------------------
                if(args['note '..i] ~= nil) then
                    sectionContent:tag('div')
                        :addClass('note')
                        :wikitext(args['note '..i])
                end
            end
 
            sections
                :node(toggle)
                :node(sectionHead)
                :node(sectionContent)
 
            content:node(sections)
            
        end
    end
 
    -- Final output
    nav :node(toggle)
        :node(head)
        :node(content)
 
    return tostring(nav)
end
 
return p
--</nowiki>
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.