Module:InfoboxProto: Difference between revisions
From Elwiki
No edit summary |
No edit summary Tag: Manual revert |
||
(25 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
local args = getArgs(frame); | local args = getArgs(frame); | ||
if args. | if args.color == nil then | ||
args. | if args['Color'] ~= nil then | ||
args.color = args['Color']; | |||
args. | else | ||
args.color = '{{ColorSel|Misc}}'; | |||
end | |||
end | |||
if title == nil then | |||
title = args.name | |||
end | |||
if title == nil then | |||
title = args['Name'] | |||
end | end | ||
local infobox = mw.html.create('div'):addClass('infobox-new'); | local infobox = mw.html.create('div'):addClass('infobox-new'); | ||
infobox:tag('div'):addClass('infobox-new-header'):css('background-color', args.color:gsub("%#", "#")): | infobox:tag('div'):addClass('infobox-new-header'):css('background-color', args.color:gsub("%#", "#")):wikitext(title); | ||
' | local img = args.image; | ||
infobox:tag('div'):addClass('infobox-new-image'):wikitext( | if args.image == nil then | ||
img = args['Image']; | |||
end | |||
infobox:tag('div'):addClass('infobox-new-image'):wikitext(img); | |||
-- Adds a normal row | -- Adds a normal row | ||
function addField(param, field_name, double) | function addField(param, field_name, double, field_value, collapsed) | ||
if args[param] ~= nil then | if args[param] ~= nil or field_value ~= nil then | ||
local row = infobox:tag('div'):addClass('infobox-row'); | local row = infobox:tag('div'):addClass('infobox-row'); | ||
if field_name == nil then | if field_name == nil then | ||
field_name = titleCase(param); | field_name = titleCase(param); | ||
end | end | ||
row:tag('div'):addClass('infobox-row-title'):wikitext(field_name); | if field_value == nil then | ||
if (param == 'video' or param == 'tree' or param == ' | field_value = args[param]; | ||
end | |||
row:tag('div'):addClass('infobox-row-title'):tag('span'):wikitext(field_name); | |||
local content = row:tag('div'):addClass('infobox-row-content'); | |||
if (param == 'video' or param == 'tree' or param == 'stat') then | |||
content:wikitext(field_value); | |||
if param == 'video' then | |||
content:addClass('infobox-video-row') | |||
end | |||
else | else | ||
local inner = content:tag('div') | |||
if collapsed then | |||
inner:addClass('mw-collapsible mw-collapsed') | |||
end | |||
inner:wikitext(field_value); | |||
end | end | ||
end | end | ||
if double == true then addField2(param, field_name) end | if double == true then | ||
addField2(param, field_name, collapsed) | |||
end | |||
end | end | ||
-- Adds a row with 2 columns | -- Adds a row with 2 columns | ||
function addField2(param, field_name) | function addField2(param, field_name, collapsed) | ||
if args[param .. '1'] ~= nil and args[param .. '2'] ~= nil then | if args[param .. '1'] ~= nil and args[param .. '2'] ~= nil then | ||
local row = infobox:tag('div'):addClass('infobox-row'):addClass('infobox-double-row'); | local row = infobox:tag('div'):addClass('infobox-row'):addClass('infobox-double-row'); | ||
Line 43: | Line 68: | ||
end | end | ||
row:tag('div'):addClass('infobox-row-title'):wikitext(field_name); | row:tag('div'):addClass('infobox-row-title'):wikitext(field_name); | ||
row:tag('div'):addClass('infobox-row-content'):tag(' | for i=1, 2, 1 do | ||
local inner = row:tag('div'):addClass('infobox-row-content'):tag('div') | |||
if collapsed then | |||
inner:addClass('mw-collapsible mw-collapsed') | |||
end | |||
inner:wikitext(args[param .. i]); | |||
end | |||
end | |||
end | |||
-- For adding multiple fields. | |||
function addFields(fields) | |||
for k, v in ipairs(fields) do | |||
if v.special then | |||
addField2(v.id, v.localize) | |||
else | |||
addField(v.id, v.localize, v.dual, v.value, v.collapsed) | |||
end | |||
end | end | ||
end | end |
Latest revision as of 15:25, 8 September 2023
Documentation for this module may be created at Module:InfoboxProto/doc
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame, title)
local args = getArgs(frame);
if args.color == nil then
if args['Color'] ~= nil then
args.color = args['Color'];
else
args.color = '{{ColorSel|Misc}}';
end
end
if title == nil then
title = args.name
end
if title == nil then
title = args['Name']
end
local infobox = mw.html.create('div'):addClass('infobox-new');
infobox:tag('div'):addClass('infobox-new-header'):css('background-color', args.color:gsub("%#", "#")):wikitext(title);
local img = args.image;
if args.image == nil then
img = args['Image'];
end
infobox:tag('div'):addClass('infobox-new-image'):wikitext(img);
-- Adds a normal row
function addField(param, field_name, double, field_value, collapsed)
if args[param] ~= nil or field_value ~= nil then
local row = infobox:tag('div'):addClass('infobox-row');
if field_name == nil then
field_name = titleCase(param);
end
if field_value == nil then
field_value = args[param];
end
row:tag('div'):addClass('infobox-row-title'):tag('span'):wikitext(field_name);
local content = row:tag('div'):addClass('infobox-row-content');
if (param == 'video' or param == 'tree' or param == 'stat') then
content:wikitext(field_value);
if param == 'video' then
content:addClass('infobox-video-row')
end
else
local inner = content:tag('div')
if collapsed then
inner:addClass('mw-collapsible mw-collapsed')
end
inner:wikitext(field_value);
end
end
if double == true then
addField2(param, field_name, collapsed)
end
end
-- Adds a row with 2 columns
function addField2(param, field_name, collapsed)
if args[param .. '1'] ~= nil and args[param .. '2'] ~= nil then
local row = infobox:tag('div'):addClass('infobox-row'):addClass('infobox-double-row');
if field_name == nil then
field_name = titleCase(param):gsub("%d+", '');
end
row:tag('div'):addClass('infobox-row-title'):wikitext(field_name);
for i=1, 2, 1 do
local inner = row:tag('div'):addClass('infobox-row-content'):tag('div')
if collapsed then
inner:addClass('mw-collapsible mw-collapsed')
end
inner:wikitext(args[param .. i]);
end
end
end
-- For adding multiple fields.
function addFields(fields)
for k, v in ipairs(fields) do
if v.special then
addField2(v.id, v.localize)
else
addField(v.id, v.localize, v.dual, v.value, v.collapsed)
end
end
end
return infobox;
end
return p