Module:Legend

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')
local util_text = require('Module:TextUtil')

local ORDER = {
	'upwith3bye', 'upwith2bye', 'semifinals', 'upwithbye', 'proceed', 'up', 'stayup', 'stay', 'staydown', 'down', 'drop', 'autorelegate', 'clinch-up', 'clinch-down', 'boldtext', 'incomplete', 'specialqualify'
}

local p = {}
local h = {}
function p.main(frame)
	local args = util_args.merge(true)
	local th = mw.html.create()
	p._main(th, args)
	return th
end

function p._main(th, args)
	local outerdiv = th:tag('div')
		:wikitext(args.display or 'Standings')
		:css({position = 'relative'})
	local div = outerdiv:tag('div')
		:addClass('table-header-rightcontent')
		:addClass('popup-button')
		:addClass('legend-icon')
		:addClass('popup-content-outer')
			
	local tbl = div:tag('div')
		:addClass('popup-content-inner popup-content-inner-pretty legend-table toggle-section-hidden')
		:css({
			['margin-left'] = (((args.legendwidth or 8) - 250) / 2) .. 'px',
			width = '250px'
		 })
		:tag('table')
			:addClass('legend-table')
	
	h.printLegendTable(tbl, args, util_text.splitOrNil(args.legendorder) or ORDER)
	return outerdiv
end

function h.printLegendTable(tbl, args, order)
	h.printTableHeader(tbl)
	for _, v in ipairs(order) do
		h.printLegendRow(tbl, v, args[v], args[v .. 'css'])
	end
end

function h.printTableHeader(tbl)
	local tr = tbl:tag('tr')
	tr:tag('th')
		:addClass('legend-header')
		:wikitext('Legend')
end

function h.printLegendRow(tbl, class, display, css)
	if not display then return end
	local tr = tbl:tag('tr')
	tr:tag('td')
		:addClass('standings-' .. class)
		:cssText(css)
		:wikitext(display)
end

return p