Module:Navbox

From Workers & Resources: Soviet Republic Official Wiki
Revision as of 02:07, 6 July 2022 by workers-resources-fandom>Abominação (Created page with "-- ==================== -- This module exist to add some extra functionalities for navboxes -- Credits: This module was taken from Nukapedia -- ==================== local p = {} local collapseOptions = { ["collapsed"] = "mw-collapsible mw-collapsed", ["collapsedgroups"] = "mw-collapsible mw-collapsed", ["uncollapsed"] = "mw-collapsible", ["uncollapsedgroups"] = "mw-collapsible", } function p.collapse(frame) local optionGroups = mw...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Lua error: callParserFunction: function "#translation" was not found.

See Template:Navbox


-- ====================
-- This module exist to add some extra functionalities for navboxes
--		Credits: This module was taken from Nukapedia
-- ====================

local p = {}

local collapseOptions = {
    ["collapsed"]         = "mw-collapsible mw-collapsed",
    ["collapsedgroups"]   = "mw-collapsible mw-collapsed",
    ["uncollapsed"]       = "mw-collapsible",
    ["uncollapsedgroups"] = "mw-collapsible", 
}

function p.collapse(frame)
    local optionGroups = mw.text.split(frame.args[1], ",")
    local optionCount = table.getn(optionGroups)
    if optionCount > 0 then
        n = 1
        while n <= optionCount do
            if collapseOptions[optionGroups[n]] ~= nil then
                result = collapseOptions[optionGroups[n]]
            end
            n = n + 1
        end
    end
    
    if result == nil then
        result = "mw-collapsible mw-collapsed"
    end
    
    return result
end

function p.toggle(frame)
    local toggleGroups = mw.text.split(frame.args[1], ",")
    local toggleCount = table.getn(toggleGroups)
    local toggleResult = 0
    if toggleCount > 0 then
        n = 1
        while n <= toggleCount do
            if collapseOptions[toggleGroups[n]] ~= nil then
                toggleResult = toggleResult +1
            end
            n = n + 1
        end
    end
    
    if toggleResult > 0 then
        result = '<td class="np-navbox-header-side mw-customtoggle-myDivision" data-expandtext="Show" data-collapsetext="Hide"></td>'
    else
        result = '<td class="np-navbox-header-side>&nbsp;</td>'
    end
    
    return result
end

function p.columns(frame)
    local columnGroups = mw.text.split(frame.args[1], ",")
    local groupCount = table.getn(columnGroups)
    local columnResult = 0
    
    if groupCount > 0 then
        n = 1
        while n <= table do
            if columnGroups[n] == "columns" then
                groupCount = groupCount + 1
            end
        end
    end
    
    if columnResult > 0 then
        columnResult = "columns"
    end
    
    return columnResult
end

return p