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') |
|||
-- return frame:preprocess(tostring(p._main(frame:getParent().args))) |
|||
local hc = require('Module:Paramtest').has_content |
|||
-- end |
|||
-- function p._main(args) |
|||
-- Module access point for infobox switch |
|||
-- local contents = {} |
|||
p._infobox_switch = function(args) |
|||
-- Prepare content list from arguments |
|||
-- local i = 1 |
|||
-- while args['item'..i] do |
|||
local i = 1 |
|||
-- table.insert(contents, { text = args['text'..i] or ('Item '..i), |
|||
while args['item'..i] do |
|||
-- 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 |
|||
end |
|||
-- local ret = mw.html.create('div') |
|||
-- :addClass('Gadget-switch-infobox') |
|||
-- Create the main table structure for the infobox switch |
|||
-- :addClass('loading') |
|||
local structure = mw.html.create('table') |
|||
: |
-- :tag('span') |
||
: |
-- :addClass('loading-button') |
||
-- :addClass('button') |
|||
:done(); |
|||
-- :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) |
|||
-- Create the div for the buttons inside the caption |
|||
-- if isSelect then |
|||
local buttons = structure:tag('div') |
|||
-- mah_triggers:addClass('infobox-triggers-select') |
|||
:attr('data-default-index', 1) |
|||
-- elseif i > 6 and isSelect ~= false then |
|||
-- mah_triggers:addClass('infobox-triggers-select') |
|||
-- end |
|||
-- for i, v in ipairs(contents) do |
|||
-- mah_triggers :tag('span') |
|||
for i, v in ipairs(contents) do |
|||
-- :addClass('trigger') |
|||
buttons:tag('button') |
|||
:addClass('button') |
-- :addClass('button') |
||
-- :addClass(i==1 and 'button-selected' or '') |
|||
:attr('data-switch-index', i) |
|||
:attr('data- |
-- :attr('data-id',v.id) |
||
:wikitext(v.text) |
-- :wikitext(v.text) |
||
:done() |
-- :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') |
|||
-- ret :tag('div') |
|||
-- Add each content section to the resources div |
|||
-- :addClass('item') |
|||
for i, v in ipairs(contents) do |
|||
-- :addClass(i==1 and 'showing' or '') |
|||
local param_div = resources_div:tag('div') |
|||
-- :attr('data-id',v.id) |
|||
-- :wikitext(v.content) |
|||
-- :done() |
|||
-- end |
|||
-- return ret |
|||
param_div:tag('div') |
|||
-- end |
|||
:attr('data-attr-index', i) |
|||
:wikitext(v.content) |
|||
:done() |
|||
-- return p |
|||
param_div:done() |
|||
end |
|||
local p = {} |
|||
mw.logObject(structure) |
|||
-- Return the complete HTML structure |
|||
return tostring(structure) |
|||
end |
|||
p. |
function p.infobox(frame) |
||
return |
return [[ |
||
<div class="infobox-switch" data-default-index="1"> |
|||
<table> |
|||
<caption> |
|||
<div> |
|||
<button data-switch-index="1" data-switch-anchor="#view1">Overview</button> |
|||
<button data-switch-index="2" data-switch-anchor="#view2">Details</button> |
|||
<button data-switch-index="3" data-switch-anchor="#view3">Stats</button> |
|||
</div> |
|||
</caption> |
|||
<tbody> |
|||
<tr><td>Name</td><td data-attr-param="name">Default Name</td></tr> |
|||
<tr><td>Description</td><td data-attr-param="description">Default Description</td></tr> |
|||
<tr><td>Attributes</td><td data-attr-param="attributes">Default Attributes</td></tr> |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
<div class="infobox-switch-resources"> |
|||
<div data-attr-param="name"> |
|||
<div data-attr-index="1">View 1 Name</div> |
|||
<div data-attr-index="2">View 2 Name</div> |
|||
<div data-attr-index="3">View 3 Name</div> |
|||
</div> |
|||
<div data-attr-param="description"> |
|||
<div data-attr-index="1">View 1 Description</div> |
|||
<div data-attr-index="2">View 2 Description</div> |
|||
<div data-attr-index="3">View 3 Description</div> |
|||
</div> |
|||
<div data-attr-param="attributes"> |
|||
<div data-attr-index="1"><ul><li>Attribute A (View 1)</li><li>Attribute B (View 1)</li></ul></div> |
|||
<div data-attr-index="2"><ul><li>Attribute A (View 2)</li><li>Attribute B (View 2)</li><li>Attribute C (View 2)</li></ul></div> |
|||
<div data-attr-index="3"><ul><li>Attribute A (View 3)</li><li>Attribute C (View 3)</li><li>Attribute D (View 3)</li></ul></div> |
|||
</div> |
|||
</div> |
|||
]] |
|||
end |
end |
||