Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 02:23, 3 March 2026 by Esportsamaze (talk | contribs)

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

local p = {}
local html = mw.html
local title = mw.title.getCurrentTitle()
local text = mw.text

function p.main(frame)
local args = frame:getParent().args

local tabNames = {}
local i = 1
while args[i] do
local t = text.trim(args[i])
if t ~= "" then table.insert(tabNames, t) end
i = i + 1
end

local basePage = args.base
if not basePage then
basePage = title.prefixedText 

local parts = text.split(title.prefixedText, '/')
local foundRoot = false

for idx, part in ipairs(parts) do
for _, tab in ipairs(tabNames) do
if part:lower() == tab:lower() and tab:lower() ~= 'overview' then
basePage = table.concat(parts, '/', 1, idx - 1)
foundRoot = true
break
end
end
if foundRoot then break end
end
end

local isSub = (args.type == 'sub')
local containerClass = isSub and 'pastel-bar' or 'chrome-tabs-container'
local tabClass = isSub and 'pastel-pill' or 'chrome-tab'

local root = html.create('div'):addClass(containerClass)

for _, name in ipairs(tabNames) do
local target = ""

if name:lower() == 'overview' then
target = basePage
else
target = basePage .. '/' .. name
end

local isActive = false

if title.prefixedText == target then
isActive = true
elseif title.prefixedText:sub(1, #target + 1) == target .. '/' then
if name:lower() ~= 'overview' then
isActive = true
end
end

local tabDiv = root:tag('div'):addClass(tabClass)
if isActive then tabDiv:addClass('active') end

tabDiv:wikitext('[[' .. target .. '|' .. name .. ']]')
end

return tostring(root)
end

return p