Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Navpills: Difference between revisions

From Aeronautica Official Wiki
Pyrenol (talk | contribs)
m changed thumbnail size for better resolution
Pyrenol (talk | contribs)
Added Category page redirecting capability
Line 1: Line 1:
-- Navpills taken from the Star Citizen Wiki, 25 Apr 2025.
local mArguments = require('Module:Arguments')
local mArguments --initialize lazily
local p = {}
local p = {}


-- Returns a table containing the numbers of the arguments that exist
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- for the specified prefix.
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local function getArgNums(prefix, args)
local function getArgNums(prefix, args)
local nums = {}
    local nums = {}
for k, v in pairs(args) do
    for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
        if num then
end
            table.insert(nums, tonumber(num))
table.sort(nums)
        end
return nums
    end
    table.sort(nums)
    return nums
end
end


-- Function to determine if a page is a category
local function isCategoryPage(pageName)
    local title = mw.title.new(pageName)
    return title and title.namespace == 14 -- Namespace 14 is "Category"
end


--Implements {{Navpills}} from the frame
--Implements {{Navpills}} from the frame
function p.navpills( frame )
function p.navpills(frame)
mArguments = require( 'Module:Arguments' )
    mArguments = require('Module:Arguments')
return p._navpills( mArguments.getArgs( frame ) )
    return p._navpills(mArguments.getArgs(frame, { trim = true, removeBlanks = false }))
end
end


function p._navpills( args )
function p._navpills(args)
if not args then
    if not args then
return 'Missing arguments'
        return 'Missing arguments'
end
    end
 
    local html = mw.html.create('div'):addClass('template-navpills'):attr('role', 'navigation')
 
    if args['cols'] then
        local num = tostring(args['cols'])
        html:addClass(string.format('template-navpills--col%s', num))
    end
 
    if args['rows'] then
        local num = tostring(args['rows'])
        html:addClass(string.format('template-navpills--row%s', num))
    end
 
    for i, _ in ipairs(getArgNums('page', args)) do
        if not args['page' .. i] then
            return
        end
        local num = tostring(i)
        local pageName = args['page' .. num]
        local text = args['text' .. num] or pageName
        local navpill = mw.html.create('div'):addClass('template-navpill')


local html = mw.html.create( 'div' ):addClass( 'template-navpills' ):attr( 'role', 'navigation' )
        if args['image' .. i] then
            navpill:tag('div'):addClass('template-navpill-background')
if args['cols'] then
                :wikitext(string.format('[[File:%s|x128px|link=]]', args['image' .. num]))
local num = tostring( args['cols'] )
        end
html:addClass( string.format( 'template-navpills--col%s', num ) )
end
if args['rows'] then
local num = tostring( args['rows'] )
html:addClass( string.format( 'template-navpills--row%s', num ) )
end
for i, _ in ipairs( getArgNums( 'page', args ) ) do
if not args[ 'page' .. i ] then return end
local num = tostring( i )
local navpill = mw.html.create('div'):addClass('template-navpill')


if args[ 'image' .. i ] then
        local linkTarget = pageName
navpill:tag('div'):addClass('template-navpill-background')
        if isCategoryPage(pageName) then
:wikitext( string.format( '[[File:%s|x128px|link=]]', args[ 'image' .. num ] ) )
            linkTarget = 'Category:' .. pageName  -- Ensure "Category:" prefix
end
        end


navpill:wikitext( string.format( '[[%s|%s]]', args[ 'page' .. num ], args[ 'text' .. num ] or args[ 'page' .. num ] ) )
        navpill:wikitext(string.format('[[%s|%s]]', linkTarget, text))
html:node(navpill)
        html:node(navpill)
end
    end


return mw.getCurrentFrame():extensionTag{
    return mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Module:Navpills/styles.css' }
        name = 'templatestyles',
} .. tostring( html )
        args = { src = 'Module:Navpills/styles.css' }
    } .. tostring(html)
end
end


return p
return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.