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:33, 25 January 2026 by Esportsamaze (talk | contribs) (Created page with "local p = {} local html = mw.html function p.main(frame) local args = frame:getParent().args -- 1. Determine Base Page -- If 'base' is provided, use it. Otherwise, assume the first 3 parts of the current title are the "Root". -- (Matches your old logic: {{#titleparts:{{PAGENAME}}|3}}) local currentTitle = mw.title.getCurrentTitle() local basePage = args.base or currentTitle.baseText -- Fallback for complicated URLs if .baseText isn't eno...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local html = mw.html

function p.main(frame)
    local args = frame:getParent().args
    
    -- 1. Determine Base Page
    -- If 'base' is provided, use it. Otherwise, assume the first 3 parts of the current title are the "Root".
    -- (Matches your old logic: {{#titleparts:{{PAGENAME}}|3}})
    local currentTitle = mw.title.getCurrentTitle()
    local basePage = args.base or currentTitle.baseText
    -- Fallback for complicated URLs if .baseText isn't enough:
    if not args.base and currentTitle.text:find('/') then
        -- Grab the first 3 parts (e.g., Game/Tournaments/Event)
        local parts = mw.text.split(currentTitle.text, '/')
        if #parts >= 3 then
            basePage = table.concat(parts, '/', 1, 3)
        end
    end

    -- 2. Determine Style (Main vs Sub)
    local isSub = (args.type == 'sub')
    local containerClass = isSub and 'pastel-bar' or 'chrome-tabs-container'
    local tabClass = isSub and 'pastel-pill' or 'chrome-tab'

    -- 3. Build the Container
    local root = html.create('div'):addClass(containerClass)
    
    -- 4. Iterate through numbered args (1, 2, 3...)
    local i = 1
    while args[i] do
        local tabName = args[i]
        local target = ""
        
        -- Logic: "Overview" usually links to the Base Page itself.
        -- All other tabs link to BasePage/TabName
        if tabName == "Overview" then
            target = basePage
        else
            target = basePage .. '/' .. tabName
        end
        
        -- Active State Check
        local isActive = (currentTitle.text == target)
        
        -- Build the Tab
        local tabDiv = root:tag('div')
            :addClass(tabClass)
        
        if isActive then
            tabDiv:addClass('active')
        end
        
        tabDiv:wikitext('[[' .. target .. '|' .. tabName .. ']]')
        
        i = i + 1
    end
    
    return tostring(root)
end

return p