Module:NavboxUpgraded
Documentation for this module may be created at Module:NavboxUpgraded/doc
-- 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', '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, 20 do
local group = args['group' .. i]
local list = args['list' .. i]
if group or list then
local row = navbox:tag('tr')
if group then
local groupCell = row:tag('th')
groupCell
:addClass('navbox-group')
:css('text-align', 'right')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(group)
end
if list then
local listCell = row:tag('td')
listCell
:addClass('navbox-list')
:css('text-align', 'left')
:css('background-color', '#f7f7f7')
:css('padding', '0.25em 1em')
:wikitext(list)
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
local titleDiv = navbox:tag('div')
titleDiv
:addClass('navbox-title-mobile')
:css('background-color', '#ccf')
:css('padding', '0.25em 1em')
:wikitext(args.title)
end
-- Handle above
if args.above then
local aboveDiv = navbox:tag('div')
aboveDiv
:addClass('navbox-abovebelow-mobile')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.above)
end
-- Handle groups and lists
for i = 1, 20 do
local group = args['group' .. i]
local list = args['list' .. i]
if group or list then
if group then
local groupDiv = navbox:tag('div')
groupDiv
:addClass('navbox-group-mobile')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:css('font-weight', 'bold')
:wikitext(group)
end
if list then
local listDiv = navbox:tag('div')
listDiv
:addClass('navbox-list-mobile')
:css('background-color', '#f7f7f7')
:css('padding', '0.25em 1em')
:wikitext(list)
end
end
end
-- Handle below
if args.below then
local belowDiv = navbox:tag('div')
belowDiv
:addClass('navbox-abovebelow-mobile')
:css('background-color', '#ddf')
:css('padding', '0.25em 1em')
:wikitext(args.below)
end
return tostring(navbox)
end
-- Main function to generate both versions and wrap them appropriately
function p.navbox(frame)
local args = getArgs(frame)
local desktopNavbox = p._navboxDesktop(args)
local mobileNavbox = p._navboxMobile(args)
local res = mw.html.create()
res
:wikitext(frame:extensionTag('templatestyles', '', {src = 'Module:NavboxUpgraded/styles.css'}))
:tag('div')
:addClass('nomobile')
:wikitext(desktopNavbox)
:done()
:tag('div')
:addClass('onlymobile')
:wikitext(mobileNavbox)
:done()
return tostring(res)
end
return p