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 1: | Line 1: | ||
--Attribution: This module was taken from the Runescape wiki - https://runescape.wiki/w/Module:Switch_infobox - See changes there for a list of contributors |
|||
local p = {} |
local p = {} |
||
⚫ | |||
function p.main(frame) |
|||
⚫ | |||
⚫ | |||
local hc = require('Module:Paramtest').has_content |
|||
⚫ | |||
function p._main(args) |
|||
-- Module access point for infobox switch |
|||
p._infobox_switch = function(args) |
|||
-- 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 |
||
Line 15: | Line 17: | ||
i = i + 1 |
i = i + 1 |
||
end |
end |
||
-- Create the main table structure for the infobox switch |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- Create the div for the buttons inside the caption |
|||
⚫ | |||
⚫ | |||
⚫ | |||
-- Add buttons for each item in contents |
|||
⚫ | |||
⚫ | |||
:addClass('loading') |
|||
: |
:tag('span') |
||
: |
:addClass('loading-button') |
||
:addClass('button') |
|||
:attr('data-switch-anchor', '#section' ..i) |
|||
:wikitext( |
:wikitext('Loading...') |
||
:done() |
:done() |
||
if args.float then |
|||
if args.float == 'left' then |
|||
ret:addClass('tleft') |
|||
:addClass('thumb') |
|||
elseif args.float == 'right' then |
|||
ret:addClass('tright') |
|||
:addClass('thumb') |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local isSelect = yesno(args.select) |
|||
if isSelect then |
|||
mah_triggers:addClass('infobox-triggers-select') |
|||
elseif i > 6 and isSelect ~= false then |
|||
mah_triggers:addClass('infobox-triggers-select') |
|||
end |
end |
||
local content_body = structure:tag('tbody') |
|||
local default_content = contents[1] -- Assuming default index is 1 |
|||
if default_content then |
|||
local row = content_body:tag('tr') |
|||
row:tag('td') |
|||
:attr('data-attr-param', 'param1') |
|||
⚫ | |||
:done() |
|||
row:done() |
|||
⚫ | |||
-- Create the hidden resources section that contains all switchable content |
|||
local resources_div = structure:tag('div') |
|||
⚫ | |||
⚫ | |||
-- Add each content section to the resources div |
|||
mah_triggers :tag('span') |
|||
for i, v in ipairs(contents) do |
|||
:addClass('trigger') |
|||
local param_div = resources_div:tag('div') |
|||
:addClass('button') |
|||
:attr('data-attr-param', 'param1') |
|||
:addClass(i==1 and 'button-selected' or '') |
|||
:attr('data-id',v.id) |
|||
param_div:tag('div') |
|||
⚫ | |||
:attr('data-attr-index', i) |
|||
:done() |
|||
⚫ | |||
:done() |
|||
⚫ | |||
param_div:done() |
|||
:addClass('item') |
|||
⚫ | |||
:addClass(i==1 and 'showing' or '') |
|||
⚫ | |||
mw.logObject(structure) |
|||
⚫ | |||
-- Return the complete HTML structure |
|||
⚫ | |||
return tostring(structure) |
|||
end |
end |
||
return ret |
|||
p.infobox_switch = function(frame) |
|||
⚫ | |||
end |
end |
||