Module:IconNav: Difference between revisions

From MENACE Official Wiki
No edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 5: Line 5:
     local icons = {}
     local icons = {}
     local links = {}
     local links = {}
   
 
     -- Collect all icon/link pairs
     -- Collect icon/link pairs
     local i = 1
     local i = 1
     while args['icon' .. i] do
     while args['icon' .. i] do
Line 13: Line 13:
         i = i + 1
         i = i + 1
     end
     end
   
 
     -- Get header parameters
     -- Header parameters
     local headerText = args['header'] or 'Buildings'
     local headerText = args['header']
     local leftImage = args['leftImage'] or 'laurels left.png'
    local leftImage  = args['leftImage']
     local rightImage = args['rightImage'] or 'laurels right.png'
    local rightImage = args['rightImage']
   
 
     -- Build icon row
    -- size parameters
    local iconSize = args['iconSize'] or '124px'
     local iconHeaderSize = args['iconHeaderSize'] or '15px'
     local tableWidth = args['width'] or '95%'
 
     -- Build icon row (no auto File:, no auto .png)
     local iconRow = '| '
     local iconRow = '| '
     for j, icon in ipairs(icons) do
     for j, icon in ipairs(icons) do
         if j > 1 then iconRow = iconRow .. ' || ' end
         if j > 1 then iconRow = iconRow .. ' || ' end
         iconRow = iconRow .. '[[File:' .. icon .. '.png|link=' .. links[j] .. '|124px]]'
         iconRow = iconRow .. '[[' .. icon .. '|link=' .. (links[j] or '') .. '|' .. iconSize .. ']]'
     end
     end
   
 
     -- Build link row
     -- Build link row
     local linkRow = '| '
     local linkRow = '| '
Line 32: Line 37:
         linkRow = linkRow .. '[[' .. link .. ']]'
         linkRow = linkRow .. '[[' .. link .. ']]'
     end
     end
      
 
     -- Build table
     local result = ''
     local result = '{| class="gridBG" align="center" style="background-color:#; width: 95%; height: 50px; border: 1px solid white; color: white; border-left: none; border-right: none; border-top: none;"\n'
 
    result = result .. '| class="hides hidem" style="font-size: 125%; text-align: center;" | <center><big>[[File:' .. leftImage .. '|15px|link=]]&numsp;\'\'\'' .. headerText .. '\'\'\'&numsp;[[File:' .. rightImage .. '|15px|link=]]</big></center>\n'
     -- Determine if header should be shown
    result = result .. '|}\n'
    local hasHeader =
     result = result .. '<center>\n'
        (headerText and headerText ~= '') or
     result = result .. '{| style="width: 95%; text-align: center;"\n'
        (leftImage and leftImage ~= '') or
        (rightImage and rightImage ~= '')
 
     if hasHeader then
        local headerLine = ''
 
        if leftImage and leftImage ~= '' then
            headerLine = headerLine .. '[[' .. leftImage .. '|' .. iconHeaderSize .. '|link=]]&numsp;'
        end
        if headerText and headerText ~= '' then
            headerLine = headerLine .. "'''" .. headerText .. "'''"
        end
        if rightImage and rightImage ~= '' then
            headerLine = headerLine .. '&numsp;[[' .. rightImage .. '|' .. iconHeaderSize .. '|link=]]'
        end
 
        result = result .. '{| class="gridBG" align="center" style="background-color:#; width: ' .. tableWidth .. '; height: 50px; border: 1px solid white; color: white; border-left: none; border-right: none; border-top: none;"\n'
        result = result .. '| class="hides hidem" style="font-size: 125%; text-align: center;" | <center><big>' .. headerLine .. '</big></center>\n'
        result = result .. '|}\n'
    end
 
    -- Lower table
     result = result .. '<div style="overflow-x:auto; width:100%;"><center>\n'
     result = result .. '{| style="width: ' .. tableWidth .. '; text-align: center;"\n'
     result = result .. '|-\n'
     result = result .. '|-\n'
     result = result .. '| style="height: 20px;" |\n'
     result = result .. '| style="height: 20px;" |\n'
Line 46: Line 74:
     result = result .. linkRow .. '\n'
     result = result .. linkRow .. '\n'
     result = result .. '|}\n'
     result = result .. '|}\n'
     result = result .. '</center>'
     result = result .. '</center></div>'
   
 
     return result
     return result
end
end


return p
return p

Latest revision as of 15:38, 27 February 2026

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

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local icons = {}
    local links = {}

    -- Collect icon/link pairs
    local i = 1
    while args['icon' .. i] do
        table.insert(icons, args['icon' .. i])
        table.insert(links, args['link' .. i])
        i = i + 1
    end

    -- Header parameters
    local headerText = args['header']
    local leftImage  = args['leftImage']
    local rightImage = args['rightImage']

    -- size parameters
    local iconSize = args['iconSize'] or '124px'
    local iconHeaderSize = args['iconHeaderSize'] or '15px'
    local tableWidth = args['width'] or '95%'

    -- Build icon row (no auto File:, no auto .png)
    local iconRow = '| '
    for j, icon in ipairs(icons) do
        if j > 1 then iconRow = iconRow .. ' || ' end
        iconRow = iconRow .. '[[' .. icon .. '|link=' .. (links[j] or '') .. '|' .. iconSize .. ']]'
    end

    -- Build link row
    local linkRow = '| '
    for j, link in ipairs(links) do
        if j > 1 then linkRow = linkRow .. ' || ' end
        linkRow = linkRow .. '[[' .. link .. ']]'
    end

    local result = ''

    -- Determine if header should be shown
    local hasHeader =
        (headerText and headerText ~= '') or
        (leftImage and leftImage ~= '') or
        (rightImage and rightImage ~= '')

    if hasHeader then
        local headerLine = ''

        if leftImage and leftImage ~= '' then
            headerLine = headerLine .. '[[' .. leftImage .. '|' .. iconHeaderSize .. '|link=]]&numsp;'
        end
        if headerText and headerText ~= '' then
            headerLine = headerLine .. "'''" .. headerText .. "'''"
        end
        if rightImage and rightImage ~= '' then
            headerLine = headerLine .. '&numsp;[[' .. rightImage .. '|' .. iconHeaderSize .. '|link=]]'
        end

        result = result .. '{| class="gridBG" align="center" style="background-color:#; width: ' .. tableWidth .. '; height: 50px; border: 1px solid white; color: white; border-left: none; border-right: none; border-top: none;"\n'
        result = result .. '| class="hides hidem" style="font-size: 125%; text-align: center;" | <center><big>' .. headerLine .. '</big></center>\n'
        result = result .. '|}\n'
    end

    -- Lower table
    result = result .. '<div style="overflow-x:auto; width:100%;"><center>\n'
    result = result .. '{| style="width: ' .. tableWidth .. '; text-align: center;"\n'
    result = result .. '|-\n'
    result = result .. '| style="height: 20px;" |\n'
    result = result .. '|-\n'
    result = result .. iconRow .. '\n'
    result = result .. '|-\n'
    result = result .. linkRow .. '\n'
    result = result .. '|}\n'
    result = result .. '</center></div>'

    return result
end

return p