Editing Module:Sandbox/User:The Gaffer/Modules/Infobox Switch
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
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 |
||
⚫ | |||
mw.logObject(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) |
||
-- Directly return the raw HTML output |
|||
return p._infobox_switch(frame:getParent().args) |
return p._infobox_switch(frame:getParent().args) |
||
end |
end |