Module:CompaniesNav

From TwogPedia
Revision as of 21:58, 13 March 2024 by Couchor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local tabArgs = {}
local i = 1
local currentTitle = mw.title.getCurrentTitle().text
function p.main(frame)
	local empty = true

    local tableContainer = mw.html.create('div'):addClass('news-nav')

    tab('Companies', '')
    tab("Organizations", 'Companies/')
    tab('Locations', 'Companies/')
    tab('Sponsors', 'Companies/')
    tab('Organizers', 'Companies/')
    tab('More', 'Companies/')
    tab('Search', 'Companies/')
    
	for j = 1, #tabArgs do
        local text
        if tabArgs[j].active then 
            text = tabArgs[j].name
        else
            text = '[[' .. tabArgs[j].link .. '|' .. tabArgs[j].name .. ']]'
        end
        tableContainer:node(mw.html.create('div'):addClass((tabArgs[j].active and 'active-nav ' or '') .. 'news-nav-item'):wikitext(text))
    end

    return tableContainer
end

function tab(title, prefix)
    local newObj = {
        name = title,
        link = prefix .. title
    }
    if prefix .. title == currentTitle then newObj.active = true end
    table.insert (tabArgs, newObj )
    i = i + 1
end

return p