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

Module:Tabs: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
Line 5: Line 5:


function p.main(frame)
function p.main(frame)
    local args = frame:getParent().args
local args = frame:getParent().args
   
    -- 1. Collect Tab Names
    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
   
    -- 2. INTELLIGENT ROOT DETECTION
    local basePage = args.base
    if not basePage then
        basePage = title.prefixedText
       
        local parts = text.split(title.prefixedText, '/')
        local foundRoot = false -- Flag to track if we found the root
       
        for idx, part in ipairs(parts) do
            local cleanPart = part:gsub('_', ' ')
           
            for _, tab in ipairs(tabNames) do
                -- If we find a matching tab name in the URL (e.g. "The Grind")
                -- and it's not "Overview"
                if cleanPart == tab and tab:lower() ~= 'overview' then
                    -- The Root is the path up to this point
                    basePage = table.concat(parts, '/', 1, idx - 1)
                    foundRoot = true
                    break -- Break inner loop
                end
            end
           
            if foundRoot then
                break -- Break outer loop
            end
        end
    end


    -- 3. Build HTML
local tabNames = {}
    local isSub = (args.type == 'sub')
local i = 1
    local containerClass = isSub and 'pastel-bar' or 'chrome-tabs-container'
while args[i] do
    local tabClass = isSub and 'pastel-pill' or 'chrome-tab'
local t = text.trim(args[i])
   
if t ~= "" then table.insert(tabNames, t) end
    local root = html.create('div'):addClass(containerClass)
i = i + 1
   
end
    for _, name in ipairs(tabNames) do
 
        local target = ""
local basePage = args.base
        local cleanName = name:gsub(' ', '_')
if not basePage then
       
basePage = title.prefixedText
        if name:lower() == 'overview' then
 
            target = basePage
local parts = text.split(title.prefixedText, '/')
        else
local foundRoot = false
            target = basePage .. '/' .. cleanName
 
        end
for idx, part in ipairs(parts) do
       
for _, tab in ipairs(tabNames) do
        -- 4. ACTIVE STATE LOGIC
if part:lower() == tab:lower() and tab:lower() ~= 'overview' then
        local isActive = false
basePage = table.concat(parts, '/', 1, idx - 1)
       
foundRoot = true
        if title.prefixedText == target then
break
            -- Exact match? Always active.
end
            isActive = true
end
        elseif title.prefixedText:find(target .. '/', 1, true) == 1 then
if foundRoot then break end
            -- Are we on a sub-sub-page? (e.g. .../The_Grind/Group_A)
end
            -- YES, highlight this tab... UNLESS it is Overview.
end
            if name:lower() ~= 'overview' then
 
                isActive = true
local isSub = (args.type == 'sub')
            end
local containerClass = isSub and 'pastel-bar' or 'chrome-tabs-container'
        end
local tabClass = isSub and 'pastel-pill' or 'chrome-tab'
       
 
        local tabDiv = root:tag('div'):addClass(tabClass)
local root = html.create('div'):addClass(containerClass)
        if isActive then tabDiv:addClass('active') end
 
       
for _, name in ipairs(tabNames) do
        tabDiv:wikitext('[[' .. target .. '|' .. name .. ']]')
local target = ""
    end
 
   
if name:lower() == 'overview' then
    return tostring(root)
target = basePage
else
target = basePage .. '/' .. name
end
 
local isActive = false
 
if title.prefixedText == target then
isActive = true
elseif title.prefixedText:find(target .. '/', 1, true) == 1 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
end


return p
return p

Revision as of 08:16, 26 February 2026

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:find(target .. '/', 1, true) == 1 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