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

Module:Hidden

From Vault Hunters Official Wiki
Revision as of 00:13, 22 July 2025 by Mnooseman (talk | contribs) (Created page with "local p = {} function p.main(frame) -- Get arguments from the template local args = frame:getParent().args -- First parameter is the header local header = args[1] or "Hidden content" -- Everything from parameter 2 onwards is content local contentParts = {} local i = 2 while args[i] do table.insert(contentParts, args[i]) i = i + 1 end local content = table.concat(contentParts, "|") -- Named parame...")
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)

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

local p = {}

function p.main(frame)
    -- Get arguments from the template
    local args = frame:getParent().args
    
    -- First parameter is the header
    local header = args[1] or "Hidden content"
    
    -- Everything from parameter 2 onwards is content
    local contentParts = {}
    local i = 2
    while args[i] do
        table.insert(contentParts, args[i])
        i = i + 1
    end
    local content = table.concat(contentParts, "|")
    
    -- Named parameters for additional options
    local id = args.id or ""
    local class = args.class or ""
    local style = args.style or ""
    local collapsed = args.collapsed or "yes"
    
    -- Sanitize and prepare the header
    header = mw.text.trim(header)
    if header == "" then
        header = "Hidden content"
    end
    
    -- Build CSS classes
    local cssClasses = {"mw-collapsible"}
    
    -- Add collapsed class if needed
    if collapsed == "yes" or collapsed == "true" or collapsed == "1" then
        table.insert(cssClasses, "mw-collapsed")
    end
    
    -- Add custom class if provided
    if class ~= "" then
        table.insert(cssClasses, mw.text.trim(class))
    end
    
    local classAttr = table.concat(cssClasses, " ")
    
    -- Build the HTML structure
    local html = mw.html.create()
    
    local table = html:tag('table')
        :addClass(classAttr)
    
    -- Add custom ID if provided
    if id ~= "" then
        table:attr('id', mw.text.trim(id))
    end
    
    -- Add custom style if provided
    if style ~= "" then
        table:attr('style', style)
    end
    
    -- Create the header row
    local headerRow = table:tag('tr')
    local headerCell = headerRow:tag('th')
        :addClass('mw-collapsible-toggle')
        :wikitext(header)
    
    -- Create the content row
    local contentRow = table:tag('tr')
    local contentCell = contentRow:tag('td')
        :addClass('mw-collapsible-content')
    
    -- Handle the content - preserve it as-is to avoid parser interference
    if content ~= "" then
        -- Use newline to help with formatting
        contentCell:wikitext('\n' .. content .. '\n')
    end
    
    return tostring(html)
end

-- Alternative function for direct invocation with parameters
function p.create(frame)
    local args = frame.args
    
    local header = args.header or args[1] or "Hidden content"
    local content = args.content or args[2] or ""
    local id = args.id or ""
    local class = args.class or ""
    local style = args.style or ""
    local collapsed = args.collapsed or "yes"
    
    -- Build CSS classes
    local cssClasses = {"mw-collapsible"}
    
    if collapsed == "yes" or collapsed == "true" or collapsed == "1" then
        table.insert(cssClasses, "mw-collapsed")
    end
    
    if class ~= "" then
        table.insert(cssClasses, mw.text.trim(class))
    end
    
    local classAttr = table.concat(cssClasses, " ")
    
    -- Build HTML
    local html = mw.html.create()
    local table = html:tag('table'):addClass(classAttr)
    
    if id ~= "" then
        table:attr('id', mw.text.trim(id))
    end
    
    if style ~= "" then
        table:attr('style', style)
    end
    
    -- Header
    table:tag('tr'):tag('th')
        :addClass('mw-collapsible-toggle')
        :wikitext(mw.text.trim(header))
    
    -- Content
    table:tag('tr'):tag('td')
        :addClass('mw-collapsible-content')
        :wikitext('\n' .. content .. '\n')
    
    return tostring(html)
end

return p