Module:Sandbox/User:The Gaffer/Modules/Infobox Switch: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
(Undo revision 18699 by The Gaffer (talk))
Tag: Undo
Line 6: Line 6:
-- Module access point for infobox switch
-- Module access point for infobox switch
p._infobox_switch = function(args)
p._infobox_switch = function(args)
-- Prepare content list from arguments
-- Prepare content list from arguments
local contents = {}
local contents = {}
local i = 1
local i = 1
while args['item' .. i] do
while args['item'..i] do
table.insert(contents, { text = args['text'..i] or ('Item '..i),
table.insert(contents, {
text = args['text' .. i] or ('Item ' .. i),
content = '\n' .. args['item'..i],
content = '\n' .. args['item' .. i],
id = args['switch_id'..i] or i})
i = i + 1
id = args['switch_id' .. i] or i
end
})
i = i + 1
-- Create the main table structure for the infobox switch
end
local structure = mw.html.create('table')

:addClass('infobox-switch')
-- Create the main table structure for the infobox switch
:tag('caption')
local structure = mw.html.create('table')
:done();
:addClass('infobox-switch')
:tag('caption')
-- Create the div for the buttons inside the caption
:done()
local buttons = structure:tag('div')

:attr('data-default-index', 1)
-- Create the div for the buttons inside the caption
local buttons = structure:tag('div')
:addClass('infobox-buttons')
:attr('data-default-index', 1)

-- Add buttons for each item in contents
for i, v in ipairs(contents) do
buttons:tag('button')
:addClass('button')
:attr('data-switch-index', i)
:attr('data-switch-anchor', '#section' .. i)
:wikitext(v.text)
:done()
end


-- Add buttons for each item in contents
-- Create the tbody for the main content area of the infobox
for i, v in ipairs(contents) do
local content_body = structure:tag('tbody')
buttons:tag('button')
:addClass('button')
:attr('data-switch-index', i)
:attr('data-switch-anchor', '#section' ..i)
:wikitext(v.text)
:done()
end
local content_body = structure:tag('tbody')
local default_content = contents[1] -- Assuming default index is 1
local default_content = contents[1] -- Assuming default index is 1
if default_content then
if default_content then
Line 50: Line 46:
row:done()
row:done()
end
end

-- Create the hidden resources section that contains all switchable content
-- Create the hidden resources section that contains all switchable content
local resources_div = structure:tag('div')
local resources_div = structure:tag('div')
Line 68: Line 64:
end
end


-- Return the complete HTML structure as a string
-- Return the complete HTML structure
return tostring(structure)
return tostring(structure)
end
end


-- Public function to be called by templates
p.infobox_switch = function(frame)
p.infobox_switch = function(frame)
local html_output = p._infobox_switch(frame:getParent().args)
-- Directly return the raw HTML output
return frame:callParserFunction('tag', { 'div', html_output, content = 'html' })
return p._infobox_switch(frame:getParent().args)
end
end



return p
return p