Jump to content

Module:Navigation header: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
adding tab type, which sets li ID
color parameter to provide color override
Tag: Reverted
Line 22: Line 22:
i = i + 1
i = i + 1
end
end

local color = parentFrame.args["color"]


local output = {}
local output = {}
Line 31: Line 33:
if leadtabLabel then
if leadtabLabel then
local leadtabIcon = parentFrame.args["leadtab-icon"]
local leadtabIcon = parentFrame.args["leadtab-icon"]
local leadtabColorStyle = color and (' style="background-color:' .. color .. ';"') or ""
if leadtabIcon then
if leadtabIcon then
output[#output + 1] = string.format(
output[#output + 1] = string.format(
'<li id="leadtab"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
'<li id="leadtab"%s><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
leadtabColorStyle,
leadtabIcon,
leadtabIcon,
leadtabLabel
leadtabLabel
Line 39: Line 43:
else
else
output[#output + 1] = string.format(
output[#output + 1] = string.format(
'<li id="leadtab">%s</li>',
'<li id="leadtab"%s>%s</li>',
leadtabColorStyle,
leadtabLabel
leadtabLabel
)
)
Line 46: Line 51:


for j = 1, #icon do
for j = 1, #icon do
local itemColorStyle = color and (' style="border-top-color:' .. color .. ';"') or ""
output[#output + 1] = string.format(
output[#output + 1] = string.format(
'<li id="%s"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
'<li id="%s"%s><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
itemType[j],
itemType[j],
itemColorStyle,
icon[j],
icon[j],
label[j]
label[j]

Revision as of 04:13, 7 May 2023

local p = {}

-- Import the standard icons module
local standardIcons = require('Module:Standard icons')

function p.getIcon(key)
    local iconTable = standardIcons.getIconTable()
    return iconTable[key] or key
end

function p.navigationHeader(frame)
    local parentFrame = frame:getParent()
    local icon = {}
    local label = {}
    local itemType = {}
    local i = 1

    while parentFrame.args["icon" .. i] or parentFrame.args["type" .. i] or parentFrame.args["label" .. i] do
        icon[i] = parentFrame.args["icon" .. i] or p.getIcon(parentFrame.args["type" .. i])
        label[i] = parentFrame.args["label" .. i] or ""
        itemType[i] = parentFrame.args["type" .. i] or ""
        i = i + 1
    end

    local color = parentFrame.args["color"]

    local output = {}
    output[#output + 1] = '<div class="navigation-header"><div role="navigation" class="navigation-header-tabs">'
    output[#output + 1] = '<ul>'

    -- Add leadtab if leadtab-label is defined
    local leadtabLabel = parentFrame.args["leadtab-label"]
    if leadtabLabel then
        local leadtabIcon = parentFrame.args["leadtab-icon"]
        local leadtabColorStyle = color and (' style="background-color:' .. color .. ';"') or ""
        if leadtabIcon then
            output[#output + 1] = string.format(
                '<li id="leadtab"%s><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
                leadtabColorStyle,
                leadtabIcon,
                leadtabLabel
            )
        else
            output[#output + 1] = string.format(
                '<li id="leadtab"%s>%s</li>',
                leadtabColorStyle,
                leadtabLabel
            )
        end
    end

    for j = 1, #icon do
        local itemColorStyle = color and (' style="border-top-color:' .. color .. ';"') or ""
        output[#output + 1] = string.format(
            '<li id="%s"%s><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div>&nbsp;%s</li>',
            itemType[j],
            itemColorStyle,
            icon[j],
            label[j]
        )
    end

    output[#output + 1] = '</ul>'
    output[#output + 1] = '</div></div>'

    return table.concat(output, '\n')
end

return p