Module:Navbox

-- -- -- Module based on the following: --  https://en.wikipedia.org/wiki/Module:Navbox --  https://runescape.wiki/w/Module:Navbox -- local p = {} local yesno = require( 'Module:Yesno' )

local function insertRow( tbl ) return tbl:tag( 'tr' ) end

local function createTbl( args ) local tbl = mw.html.create( 'table' )

tbl :addClass( 'nowraplinks' ) :addClass( 'wikitable' ) -- remove once an own style can be applied :addClass( 'mw-collapsible' ) if args.style then tbl:cssText( args.style ) end return tbl end

local function header( tbl, args ) local div = insertRow( tbl ) :tag( 'th' ) :attr( 'colspan', '2' ) :addClass( 'navbox-title' ) :attr( 'id', 'navbox-title' ) :tag( 'div' ) if args.name then div :css( 'padding-left', args.state == 'plain' and '0' or '6em' ) :wikitext( args.title ) end return div:allDone end

local function row( tbl, gtitle, group, gtype, style, _name, subgroup ) local tr = insertRow( tbl ) local td

if gtitle then td = tr			:addClass( 'navbox-group' ) :tag( 'td' ) :addClass( 'navbox-group-title' ) :wikitext( gtitle ) :done :tag( 'td' ) else td = tr			:addClass( 'navbox-group' ) :addClass( 'navbox-group-split' ) :tag( 'td' ) :addClass( 'navbox-group-title-hidden' ) :attr( 'colspan', '0' ) :css( 'display', 'none' ) :done :tag( 'td' ) :attr( 'colspan', '2' ) end

if mw.ustring.match( group, '^%s*%*' ) then td:newline

-- trim whitespace on bullets local spl = mw.text.split( group, '\n' )

for i = 1, #spl do			spl[i] = mw.text.trim( spl[i] ) end

group = '\n' .. table.concat( spl, '\n' ) end local subgroups if gtype and mw.ustring.lower( gtype ) == 'subgroup' then td :addClass( 'navbox-parent' ) :css( {				padding = '0',				['border-bottom'] = '0'			} ) subgroups = mw.ustring.match(group, '@@JSON@@(.-)@@NOSJ@@') group = mw.ustring.gsub(group, '@@JSON@@.-@@NOSJ@@', '') end td :addClass( 'navbox-list' ) :wikitext( group )

if style then td:cssText( style ) end --	if yesno(subgroup) then --		td --				:wikitext('@@JSON@@') --				:wikitext(_dumpGroup(gtitle, gtype, group, subgroups)) --				:wikitext('@@NOSJ@@') --	end

return td:allDone end

function p._navbox( _args ) local args = {} for k, v in pairs( _args ) do		if v ~= '' then args[k] = v		end end local tbl = createTbl( args )

if not yesno( args.subgroup ) then tbl = header( tbl, args ) end for i = 1, 20 do		j = tostring( i ) if args['group' .. j] then tbl = row( tbl, args['gtitle' .. j], args['group' .. j], args['gtype' .. j], args['style' .. j], args.name, args.subgroup) else break end end return tostring( tbl ) end

function p.navbox( frame ) local args = frame:getParent.args return p._navbox( args ) end

return p --