Changes
rewrite with htmlbuilder
-- This module will implement {{Navbox}}
--
local p = {}
local HtmlBuilder = require('Module:Sandbox/Toohool/HtmlBuilder')
local gutterRow argslocal tableRowAdded = '<tr style="height:2px;"><td></td></tr>'false
local border
local listnums = {}
function trim(s)
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
end
function addTableRow(tbl)
-- If any other rows have already been added, then we add a 2px gutter row.
if tableRowAdded then
tbl
.tag('tr')
.css('height', '2px')
.tag('td')
end
tableRowAdded = true
return tbl.tag('tr')
end
---- Title row--function renderTitleRow(argstbl)
if not args.title then return end
local titleRow = addTableRow(tbl)
if args.titlegroup then
titleRow
.tag('th')
.attr('scope', 'row')
.addClass('navbox-group')
.addClass(args.titlegroupclass)
.cssText(args.basestyle)
.cssText(args.groupstyle)
.cssText(args.titlegroupstyle)
.wikitext(args.titlegroup)
end
if args.titlegroup then
end
local colspan titleColspan = 2 if args.imageleft then colspan titleColspan = colspan titleColspan + 1 end if args.image then colspan titleColspan = colspan titleColspan + 1 end if args.titlegroup then colspan titleColspan = colspan titleColspan - 1 end add titleCell .cssText(args.basestyle, ';', ) .cssText(args.titlestyle, ) .addClass('" class="navbox-title" ') .attr('colspan=', colspantitleColspan) renderNavBar(titleCell) titleCell .tag('div') .addClass(args.titleclass) .css('font-size', '>110%') .newline() .wikitext(args.title)end function renderNavBar(titleCell) local stateLinkPlaceholder addStateLinkPlaceholder = '<span style="float:right;width:6em;"> </span>'false
if args.navbar == 'plain' or args.navbar == 'off' or (not args.name and (border == 'subgroup' or border == 'child' or border == 'none')) then
if args.navbar == 'off' then
else
end
else
if args.name then
args.name,
mini = 1,
}})
else
end
end
if addStateLinkPlaceholder then
titleCell
.tag('span')
.css('float', 'right')
.css('width', '6em')
.wikitext(' ')
end
end
---- Above/Below rows--function renderAboveRow(argstbl)
if not args.above then return end
end
function renderBelowRow(argstbl) if not args.below thenreturn end if args addTableRow(tbl) .title or args.above or #listnums > 0 then addtag(gutterRow'td') end add .addClass('<tr><td class="navbox-abovebelow ', ) .addClass(args.belowclass, '" style="', ) .cssText(args.basestyle, ';', ) .cssText(args.belowstyle, ) .attr('" colspan="', getAboveBelowColspan(args), '">') add .tag('<div>\n', ) .newline() .wikitext(args.below, '</div></td></tr>') end
end
function getAboveBelowColspan(args)
local ret = 2
if args.imageleft then ret = ret + 1 end
return ret
end
---- List rows--function renderFirstListRow(argstbl)
if not args.list1 then return end
if args.imageleft then
end
if args.group1 then
local groupCell = row.tag('th')
groupCell
.attr('scope', 'row')
.addClass('navbox-group')
.addClass(args.groupclass)
.cssText(args.basestyle)
if args.groupwidth then
groupCell.css('width', args.groupwidth)
end
groupCell
.cssText(args.groupstyle)
.cssText(args.group1style)
.wikitext(args.group1)
end
local listCell = row.tag('td')
if args.group1 then
else
end
if not args.groupwidth then add listCell.css('width:100%;') end add('padding:0px;', args.liststyle, ';', args.oddstyle, ';', args.list1style, '" class="navbox-list navbox-') if args.evenodd == 'swap' then add('even') else add(args.evenodd or 'odd100%')
end
local evenOdd = args.evenodd or 'odd' addif args.evenodd == 'swap' then evenOdd = 'even' end listCell .css(' padding', '0px') .cssText(args.liststyle) .cssText(args.oddstyle) .cssText(args.list1style) .addClass('navbox-list') .addClass('navbox-' .. evenOdd) .addClass(args.listclass, ) .tag('">div') add .css('<div style="padding:', args.list1padding or args.listpadding or '0em 0.25em', '">\n') add .newline() .wikitext(args.list1) add('</div></td>')
if args.image then
end
if args['group' .. listnum] then
else
end
local isOdd = (listnum % 2) == 1
local rowstyle = args.evenstyle
if isOdd then rowstyle = args.oddstyle end
end
---- Main navbox tables--function p._navbox(args) for k, v in pairsrenderMainTable(args) do local listnum tbl = ('' HtmlBuilder.. k):matchcreate('^list(%d+)$table') if listnum then table .insertattr(listnums'cellspacing', tonumber(listnum0)) end end table .sortaddClass(listnums) border = trim(args.border or args[1] or 'nowraplinks') if border == 'subgroup' or border == 'child' then add('</div>') elseif border ~= 'none' then add('<table cellspacing="0" class="navbox" style="border-spacing:0;', args .bodystyle, ';', args.style, '"><tr><td style="padding:2px;">') end addaddClass('<table cellspacing="0" class="nowraplinks ', args.bodyclass, ' ')
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
end
if border == 'subgroup' or border == 'child' or border == 'none' then
end
-- render lists 2 through N
for i, listnum in ipairs(listnums) do
if listnum > 1 then
renderNthListRow(argstbl, listnum)
end
end
renderBelowRow(tbl)
return tbl
end
function p._navbox(navboxArgs)
args = navboxArgs
for k, v in pairs(args) do
local listnum = ('' .. k):match('^list(%d+)$')
if listnum then table.insert(listnums, tonumber(listnum)) end
end
table.sort(listnums)
border = trim(args.border or args[1] or '')
if border == 'subgroup' or border == 'child' then
elseif border ~= 'none' then
end
-- TODO: add tracking categories
end
function p.navbox(frame)
return p._navbox(frame:getParent().args)
end
return p