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: Difference between revisions

From Vault Hunters Official Wiki
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..."
 
No edit summary
 
Line 29: Line 29:
     end
     end
      
      
     -- Build CSS classes
     -- Build CSS classes - match the original format
     local cssClasses = {"mw-collapsible"}
     local cssClasses = {"mw-collapsible", "mw-collapsed", "wikitable"}
      
      
     -- Add collapsed class if needed
     -- Override collapsed state if explicitly set to no
     if collapsed == "yes" or collapsed == "true" or collapsed == "1" then
     if collapsed == "no" or collapsed == "false" or collapsed == "0" then
         table.insert(cssClasses, "mw-collapsed")
         cssClasses = {"mw-collapsible", "wikitable"}
     end
     end
      
      
Line 43: Line 43:
      
      
     local classAttr = table.concat(cssClasses, " ")
     local classAttr = table.concat(cssClasses, " ")
   
    -- Build the default style to match original
    local defaultStyle = "width: 100%; table-layout: fixed; display: table"
    local finalStyle = defaultStyle
    if style ~= "" then
        finalStyle = defaultStyle .. "; " .. style
    end
      
      
     -- Build the HTML structure
     -- Build the HTML structure
Line 48: Line 55:
      
      
     local table = html:tag('table')
     local table = html:tag('table')
         :addClass(classAttr)
         :attr('class', classAttr)
        :attr('style', finalStyle)
      
      
     -- Add custom ID if provided
     -- Add custom ID if provided
Line 55: Line 63:
     end
     end
      
      
    -- Add custom style if provided
     -- Create the header row (th automatically becomes the collapsible toggle)
    if style ~= "" then
        table:attr('style', style)
    end
   
     -- Create the header row
     local headerRow = table:tag('tr')
     local headerRow = table:tag('tr')
     local headerCell = headerRow:tag('th')
     local headerCell = headerRow:tag('th')
        :addClass('mw-collapsible-toggle')
         :wikitext(header)
         :wikitext(header)
      
      
     -- Create the content row
     -- Create the content row - single td containing everything
     local contentRow = table:tag('tr')
     local contentRow = table:tag('tr')
     local contentCell = contentRow:tag('td')
     local contentCell = contentRow:tag('td')
        :addClass('mw-collapsible-content')
      
      
     -- Handle the content - preserve it as-is to avoid parser interference
     -- Handle the content - preserve it as-is to avoid parser interference
     if content ~= "" then
     if content ~= "" then
        -- Use newline to help with formatting
         contentCell:wikitext(content)
         contentCell:wikitext('\n' .. content .. '\n')
     end
     end
      
      
Line 91: Line 91:
     local collapsed = args.collapsed or "yes"
     local collapsed = args.collapsed or "yes"
      
      
     -- Build CSS classes
     -- Build CSS classes to match original
     local cssClasses = {"mw-collapsible"}
     local cssClasses = {"mw-collapsible", "mw-collapsed", "wikitable"}
      
      
     if collapsed == "yes" or collapsed == "true" or collapsed == "1" then
     if collapsed == "no" or collapsed == "false" or collapsed == "0" then
         table.insert(cssClasses, "mw-collapsed")
         cssClasses = {"mw-collapsible", "wikitable"}
     end
     end
      
      
Line 103: Line 103:
      
      
     local classAttr = table.concat(cssClasses, " ")
     local classAttr = table.concat(cssClasses, " ")
   
    -- Default style matching original
    local defaultStyle = "width: 100%; table-layout: fixed; display: table"
    local finalStyle = defaultStyle
    if style ~= "" then
        finalStyle = defaultStyle .. "; " .. style
    end
      
      
     -- Build HTML
     -- Build HTML
     local html = mw.html.create()
     local html = mw.html.create()
     local table = html:tag('table'):addClass(classAttr)
     local table = html:tag('table')
        :attr('class', classAttr)
        :attr('style', finalStyle)
      
      
     if id ~= "" then
     if id ~= "" then
Line 112: Line 121:
     end
     end
      
      
    if style ~= "" then
     -- Header row - th becomes collapsible toggle automatically
        table:attr('style', style)
     table:tag('tr'):tag('th'):wikitext(mw.text.trim(header))
    end
   
     -- Header
     table:tag('tr'):tag('th')
        :addClass('mw-collapsible-toggle')
        :wikitext(mw.text.trim(header))
      
      
     -- Content
     -- Content row - single td
     table:tag('tr'):tag('td')
     table:tag('tr'):tag('td'):wikitext(content)
        :addClass('mw-collapsible-content')
        :wikitext('\n' .. content .. '\n')
      
      
     return tostring(html)
     return tostring(html)

Latest revision as of 00:23, 22 July 2025

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 - match the original format
    local cssClasses = {"mw-collapsible", "mw-collapsed", "wikitable"}
    
    -- Override collapsed state if explicitly set to no
    if collapsed == "no" or collapsed == "false" or collapsed == "0" then
        cssClasses = {"mw-collapsible", "wikitable"}
    end
    
    -- Add custom class if provided
    if class ~= "" then
        table.insert(cssClasses, mw.text.trim(class))
    end
    
    local classAttr = table.concat(cssClasses, " ")
    
    -- Build the default style to match original
    local defaultStyle = "width: 100%; table-layout: fixed; display: table"
    local finalStyle = defaultStyle
    if style ~= "" then
        finalStyle = defaultStyle .. "; " .. style
    end
    
    -- Build the HTML structure
    local html = mw.html.create()
    
    local table = html:tag('table')
        :attr('class', classAttr)
        :attr('style', finalStyle)
    
    -- Add custom ID if provided
    if id ~= "" then
        table:attr('id', mw.text.trim(id))
    end
    
    -- Create the header row (th automatically becomes the collapsible toggle)
    local headerRow = table:tag('tr')
    local headerCell = headerRow:tag('th')
        :wikitext(header)
    
    -- Create the content row - single td containing everything
    local contentRow = table:tag('tr')
    local contentCell = contentRow:tag('td')
    
    -- Handle the content - preserve it as-is to avoid parser interference
    if content ~= "" then
        contentCell:wikitext(content)
    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 to match original
    local cssClasses = {"mw-collapsible", "mw-collapsed", "wikitable"}
    
    if collapsed == "no" or collapsed == "false" or collapsed == "0" then
        cssClasses = {"mw-collapsible", "wikitable"}
    end
    
    if class ~= "" then
        table.insert(cssClasses, mw.text.trim(class))
    end
    
    local classAttr = table.concat(cssClasses, " ")
    
    -- Default style matching original
    local defaultStyle = "width: 100%; table-layout: fixed; display: table"
    local finalStyle = defaultStyle
    if style ~= "" then
        finalStyle = defaultStyle .. "; " .. style
    end
    
    -- Build HTML
    local html = mw.html.create()
    local table = html:tag('table')
        :attr('class', classAttr)
        :attr('style', finalStyle)
    
    if id ~= "" then
        table:attr('id', mw.text.trim(id))
    end
    
    -- Header row - th becomes collapsible toggle automatically
    table:tag('tr'):tag('th'):wikitext(mw.text.trim(header))
    
    -- Content row - single td
    table:tag('tr'):tag('td'):wikitext(content)
    
    return tostring(html)
end

return p