Module:NavboxUpgraded: Difference between revisions
EnWikiAdmin (talk | contribs) Created page with "-- Module:NavboxUpgraded local p = {} local getArgs = require('Module:Arguments').getArgs -- Function to generate the desktop navbox function p._navboxDesktop(args) local navbox = mw.html.create('table') navbox :addClass('navbox') :css('width', '100%') :css('margin', 'auto') :css('clear', 'both') :css('border', '1px solid #a2a9b1') :css('padding', '1px') :css('font-size', '88%') :css('text-align',..." |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
-- Module:NavboxUpgraded | -- Module:NavboxUpgraded | ||
local p = {} | local p = {} | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
-- Recursive function to process subgroups | |||
local function renderSubgroups(args, groupPrefix) | |||
local html = mw.html.create() | |||
for i = 1, 10 do | |||
local subgroup = args[groupPrefix .. '_group' .. i] | |||
local sublist = args[groupPrefix .. '_list' .. i] | |||
if subgroup or sublist then | |||
local container = html:tag('div') | |||
:addClass('navbox-subgroup') | |||
:css('margin', '0.5em 0') | |||
:css('padding', '0.25em') | |||
-- Subgroup heading | |||
if subgroup then | |||
container:tag('div') | |||
:addClass('navbox-subgroup-heading') | |||
:css('background-color', '#e6e6ff') -- Light shade | |||
:css('padding', '0.25em 1em') | |||
:css('font-weight', 'bold') | |||
:wikitext(subgroup) | |||
end | |||
-- Subgroup list | |||
if sublist then | |||
container:tag('ul') | |||
:addClass('navbox-list') | |||
:css('padding-left', '1.5em') | |||
:css('list-style', 'disc') -- Bullet points | |||
:wikitext(sublist) | |||
end | |||
end | |||
end | |||
return tostring(html) | |||
end | |||
-- Function to generate the desktop navbox | -- Function to generate the desktop navbox | ||
Line 43: | Line 77: | ||
-- Handle groups and lists | -- Handle groups and lists | ||
for i = 1, | for i = 1, 10 do | ||
local group = args['group' .. i] | local group = args['group' .. i] | ||
local list = args['list' .. i] | local list = args['list' .. i] | ||
if group or list then | if group or list then | ||
local row = navbox:tag('tr') | local row = navbox:tag('tr') | ||
-- Group heading | |||
if group then | if group then | ||
local groupCell = row:tag('th') | local groupCell = row:tag('th') | ||
Line 53: | Line 89: | ||
:addClass('navbox-group') | :addClass('navbox-group') | ||
:css('text-align', 'right') | :css('text-align', 'right') | ||
:css('background-color', '#ddf') | :css('background-color', '#ddf') -- Parent shade | ||
:css('padding', '0.25em 1em') | :css('padding', '0.25em 1em') | ||
:wikitext(group) | :wikitext(group) | ||
end | end | ||
-- Group content | |||
if list then | if list then | ||
local listCell = row:tag('td') | local listCell = row:tag('td') | ||
Line 62: | Line 100: | ||
:addClass('navbox-list') | :addClass('navbox-list') | ||
:css('text-align', 'left') | :css('text-align', 'left') | ||
:css('background-color', '#f7f7f7') | :css('background-color', '#f7f7f7') -- Neutral list background | ||
:css('padding', '0.25em 1em') | :css('padding', '0.25em 1em') | ||
:wikitext(list) | |||
-- Render subgroups if present | |||
local subgroups = renderSubgroups(args, 'list' .. i) | |||
if subgroups ~= '' then | |||
listCell:wikitext(subgroups) | |||
else | |||
listCell:tag('ul') | |||
:addClass('navbox-list') | |||
:css('list-style', 'disc') -- Bullet points | |||
:css('padding-left', '1.5em') | |||
:wikitext(list) | |||
end | |||
end | end | ||
end | end | ||
Line 99: | Line 148: | ||
-- Handle title | -- Handle title | ||
if args.title then | if args.title then | ||
navbox:tag('div') | |||
:addClass('navbox-title-mobile') | :addClass('navbox-title-mobile') | ||
:css('background-color', '#ccf') | :css('background-color', '#ccf') | ||
Line 109: | Line 157: | ||
-- Handle above | -- Handle above | ||
if args.above then | if args.above then | ||
navbox:tag('div') | |||
:addClass('navbox-abovebelow-mobile') | :addClass('navbox-abovebelow-mobile') | ||
:css('background-color', '#ddf') | :css('background-color', '#ddf') | ||
Line 118: | Line 165: | ||
-- Handle groups and lists | -- Handle groups and lists | ||
for i = 1, | for i = 1, 10 do | ||
local group = args['group' .. i] | local group = args['group' .. i] | ||
local list = args['list' .. i] | local list = args['list' .. i] | ||
if group or list then | if group or list then | ||
if group then | if group then | ||
navbox:tag('div') | |||
:addClass('navbox-group-mobile') | :addClass('navbox-group-mobile') | ||
:css('background-color', '#ddf') | :css('background-color', '#ddf') -- Parent shade | ||
:css('padding', '0.25em 1em') | :css('padding', '0.25em 1em') | ||
:css('font-weight', 'bold') | :css('font-weight', 'bold') | ||
Line 132: | Line 178: | ||
end | end | ||
if list then | if list then | ||
navbox:tag('div') | |||
:addClass('navbox-list-mobile') | :addClass('navbox-list-mobile') | ||
:css('background-color', '#f7f7f7') | :css('background-color', '#f7f7f7') | ||
:css('padding', '0.25em 1em') | :css('padding', '0.25em 1em') | ||
:wikitext(list) | :tag('ul') | ||
:css('list-style', 'disc') -- Bullets | |||
:css('padding-left', '1.5em') | |||
:wikitext(list) | |||
end | end | ||
end | end | ||
Line 144: | Line 192: | ||
-- Handle below | -- Handle below | ||
if args.below then | if args.below then | ||
navbox:tag('div') | |||
:addClass('navbox-abovebelow-mobile') | :addClass('navbox-abovebelow-mobile') | ||
:css('background-color', '#ddf') | :css('background-color', '#ddf') | ||
Line 155: | Line 202: | ||
end | end | ||
-- Main function | -- Main function | ||
function p.navbox(frame) | function p.navbox(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
Line 163: | Line 210: | ||
local res = mw.html.create() | local res = mw.html.create() | ||
res | res | ||
:tag('div') | :tag('div') | ||
:addClass('nomobile') | :addClass('nomobile') |
Revision as of 05:51, 22 November 2024
Documentation for this module may be created at Module:NavboxUpgraded/doc
-- Module:NavboxUpgraded
local p = {}
local getArgs = require('Module:Arguments').getArgs
-- Recursive function to process subgroups
local function renderSubgroups(args, groupPrefix)
local html = mw.html.create()
for i = 1, 10 do
local subgroup = args[groupPrefix .. '_group' .. i]
local sublist = args[groupPrefix .. '_list' .. i]
if subgroup or sublist then
local container = html:tag('div')
:addClass('navbox-subgroup')
:css('margin', '0.5em 0')
:css('padding', '0.25em')
-- Subgroup heading
if subgroup then
container:tag('div')
:addClass('navbox-subgroup-heading')
:css('background-color', '#e6e6ff') -- Light shade
:css('padding', '0.25em 1em')
:css('font-weight', 'bold')
:wikitext(subgroup)
end
-- Subgroup list
if sublist then
container:tag('ul')
:addClass('navbox-list')
:css('padding-left', '1.5em')
:css('list-style', 'disc') -- Bullet points
:wikitext(sublist)
end
end
end
return tostring(html)
end
-- Function to generate the desktop navbox
function p._navboxDesktop(args)
local navbox = mw.html.create('table')
navbox
:addClass('navbox')
:css('width', '100%')
:css('margin', 'auto')
:css('clear', 'both')
:css('border', '1px solid #a2a9b1')
:css('padding', '1px')
:css('font-size', '88%')
:css('text-align', 'center')
-- Handle title
if args.title then
local titleRow = navbox:tag('tr')
local titleCell = titleRow:tag('th')
titleCell
:attr('colspan', '2')
:addClass('navbox-title')
:css('background-color', '#ccf')
:css('padding', '0.25em 1em')
:wikitext(args.title)
end
-- Handle above
if args.above then
local aboveRow = navbox:tag('tr')
local aboveCell = aboveRow:tag('td')
aboveCell
:attr('colspan', '2')
:addClass('navbox-abovebelow')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.above)
end
-- Handle groups and lists
for i = 1, 10 do
local group = args['group' .. i]
local list = args['list' .. i]
if group or list then
local row = navbox:tag('tr')
-- Group heading
if group then
local groupCell = row:tag('th')
groupCell
:addClass('navbox-group')
:css('text-align', 'right')
:css('background-color', '#ddf') -- Parent shade
:css('padding', '0.25em 1em')
:wikitext(group)
end
-- Group content
if list then
local listCell = row:tag('td')
listCell
:addClass('navbox-list')
:css('text-align', 'left')
:css('background-color', '#f7f7f7') -- Neutral list background
:css('padding', '0.25em 1em')
-- Render subgroups if present
local subgroups = renderSubgroups(args, 'list' .. i)
if subgroups ~= '' then
listCell:wikitext(subgroups)
else
listCell:tag('ul')
:addClass('navbox-list')
:css('list-style', 'disc') -- Bullet points
:css('padding-left', '1.5em')
:wikitext(list)
end
end
end
end
-- Handle below
if args.below then
local belowRow = navbox:tag('tr')
local belowCell = belowRow:tag('td')
belowCell
:attr('colspan', '2')
:addClass('navbox-abovebelow')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.below)
end
return tostring(navbox)
end
-- Function to generate the mobile navbox
function p._navboxMobile(args)
local navbox = mw.html.create('div')
navbox
:addClass('navbox-mobile')
:css('width', '100%')
:css('margin', 'auto')
:css('clear', 'both')
:css('border', '1px solid #a2a9b1')
:css('padding', '1px')
:css('font-size', '88%')
:css('text-align', 'center')
-- Handle title
if args.title then
navbox:tag('div')
:addClass('navbox-title-mobile')
:css('background-color', '#ccf')
:css('padding', '0.25em 1em')
:wikitext(args.title)
end
-- Handle above
if args.above then
navbox:tag('div')
:addClass('navbox-abovebelow-mobile')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.above)
end
-- Handle groups and lists
for i = 1, 10 do
local group = args['group' .. i]
local list = args['list' .. i]
if group or list then
if group then
navbox:tag('div')
:addClass('navbox-group-mobile')
:css('background-color', '#ddf') -- Parent shade
:css('padding', '0.25em 1em')
:css('font-weight', 'bold')
:wikitext(group)
end
if list then
navbox:tag('div')
:addClass('navbox-list-mobile')
:css('background-color', '#f7f7f7')
:css('padding', '0.25em 1em')
:tag('ul')
:css('list-style', 'disc') -- Bullets
:css('padding-left', '1.5em')
:wikitext(list)
end
end
end
-- Handle below
if args.below then
navbox:tag('div')
:addClass('navbox-abovebelow-mobile')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.below)
end
return tostring(navbox)
end
-- Main function
function p.navbox(frame)
local args = getArgs(frame)
local desktopNavbox = p._navboxDesktop(args)
local mobileNavbox = p._navboxMobile(args)
local res = mw.html.create()
res
:tag('div')
:addClass('nomobile')
:wikitext(desktopNavbox)
:done()
:tag('div')
:addClass('onlymobile')
:wikitext(mobileNavbox)
:done()
return tostring(res)
end
return p