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 = {} |
||
local yesno = require('Module:Yesno') |
|||
function p.main(frame) |
|||
local yn = require('Module:Yesno') |
|||
mw.loader.load('ext.gadget.switch-infobox') |
|||
local hc = require('Module:Paramtest').has_content |
|||
return '<div class="infobox infobox-switch">This content will be switchable.</div>' |
|||
--return frame:preprocess(tostring(p._main(frame:getParent().args))) |
|||
end |
|||
-- function p._main(args) |
|||
-- Module access point for infobox switch |
|||
-- local contents = {} |
|||
p._infobox_switch = function(args) |
|||
-- Prepare content list from arguments |
|||
local contents = {} |
|||
local i = 1 |
|||
while args['item'..i] do |
|||
table.insert(contents, { text = args['text'..i] or ('Item '..i), |
|||
content = '\n' .. args['item'..i], |
|||
id = args['switch_id'..i] or i}) |
|||
i = i + 1 |
|||
end |
|||
-- Create the main table structure for the infobox switch |
|||
local structure = mw.html.create('table') |
|||
:addClass('infobox-switch') |
|||
:tag('caption') |
|||
:done(); |
|||
-- Create the div for the buttons inside the caption |
|||
local buttons = structure:tag('div') |
|||
:attr('data-default-index', 1) |
|||
-- local i = 1 |
|||
-- Add buttons for each item in contents |
|||
-- while args['item'..i] do |
|||
for i, v in ipairs(contents) do |
|||
-- table.insert(contents, { text = args['text'..i] or ('Item '..i), |
|||
buttons:tag('button') |
|||
-- content = '\n' .. args['item'..i], |
|||
:addClass('button') |
|||
-- id = args['switch_id'..i] or i}) |
|||
:attr('data-switch-index', i) |
|||
-- i = i + 1 |
|||
:attr('data-switch-anchor', '#section' ..i) |
|||
-- end |
|||
:wikitext(v.text) |
|||
:done() |
|||
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') |
|||
:wikitext(default_content.content) |
|||
:done() |
|||
row:done() |
|||
end |
|||
-- Create the hidden resources section that contains all switchable content |
|||
local resources_div = structure:tag('div') |
|||
:addClass('infobox-switch-resources') |
|||
-- local ret = mw.html.create('div') |
|||
-- Add each content section to the resources div |
|||
-- :addClass('Gadget-switch-infobox') |
|||
for i, v in ipairs(contents) do |
|||
-- :addClass('loading') |
|||
local param_div = resources_div:tag('div') |
|||
-- :tag('span') |
|||
:attr('data-attr-param', 'param1') |
|||
-- :addClass('loading-button') |
|||
-- :addClass('button') |
|||
-- :wikitext('Loading...') |
|||
-- :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 |
|||
-- end |
|||
-- local mah_triggers = ret:tag('div') |
|||
-- :addClass('switch-infobox-triggers') |
|||
-- 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 |
|||
-- for i, v in ipairs(contents) do |
|||
param_div:tag('div') |
|||
-- mah_triggers :tag('span') |
|||
:attr('data-attr-index', i) |
|||
-- :addClass('trigger') |
|||
:wikitext(v.content) |
|||
-- :addClass('button') |
|||
:done() |
|||
-- :addClass(i==1 and 'button-selected' or '') |
|||
-- :attr('data-id',v.id) |
|||
-- :wikitext(v.text) |
|||
-- :done() |
|||
-- ret :tag('div') |
|||
param_div:done() |
|||
-- :addClass('item') |
|||
end |
|||
-- :addClass(i==1 and 'showing' or '') |
|||
-- :attr('data-id',v.id) |
|||
-- :wikitext(v.content) |
|||
-- :done() |
|||
-- end |
|||
-- return ret |
|||
mw.logObject(structure) |
|||
-- end |
|||
-- Return the complete HTML structure |
|||
return tostring(structure) |
|||
end |
|||
p.infobox_switch = function(frame) |
|||
return p._infobox_switch(frame:getParent().args) |
|||
end |
|||
return p |
return p |