Module:Sandbox/User:The Gaffer/Modules/Infobox Switch: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
The Gaffer (talk | contribs) No edit summary |
The Gaffer (talk | contribs) No edit summary |
||
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 |
|||
local contents = {} |
|||
local i = 1 |
|||
while args['item' .. i] do |
|||
table.insert(contents, { |
|||
table.insert(contents, { text = args['text'..i] or ('Item '..i), |
|||
text = args['text' .. i] or ('Item ' .. i), |
|||
content = '\n' .. args['item' .. i], |
|||
id = args['switch_id' .. i] or i |
|||
⚫ | |||
}) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
:addClass('infobox-buttons') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
:done() |
|||
⚫ | |||
-- Create the tbody for the main content area of the infobox |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
:done() |
|||
end |
|||
⚫ | |||
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 46: | Line 50: | ||
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 64: | Line 68: | ||
end |
end |
||
-- Return the complete HTML structure |
-- Return the complete HTML structure as a string |
||
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) |
||
-- Directly return the raw HTML output |
|||
return p._infobox_switch(frame:getParent().args) |
|||
return frame:callParserFunction('tag', { 'div', html_output, content = 'html' }) |
|||
end |
end |
||
return p |
return p |