NBA 2K Esports Wiki
[checked revision][checked revision]
Donut (talk | contribs)
m (Syncing content across wikis)
Esen (talk | contribs)
No edit summary
Line 1: Line 1:
  +
local m_team = require('Module:Team')
  +
local i18n = require('Module:i18nUtil')
 
local p = {}
 
local p = {}
   
 
function p.makeFootnoteN(n)
 
function p.makeFootnoteN(n)
 
if n and n ~= "" then
 
if n and n ~= "" then
return string.format('<span class="sup">%s</span>', n)
+
return string.format('<sup>%s</sup>', n)
 
end
 
end
 
return ""
 
return ""
 
end
 
end
   
function p.vsAlign(team1, team2)
+
function p.vsAlign(team1, team2, vs, tbl)
 
if not tbl then
local tbl = mw.html.create("div")
 
  +
tbl = mw.html.create("div")
tbl:css({ width = "100%", display = "table", ["table-layout"] = "fixed" })
 
  +
end
  +
tbl:addClass('vs-align-outer')
 
tbl:tag("div")
 
tbl:tag("div")
  +
:addClass('vs-align-left')
:css({ ["text-align"] = "right", display = "table-cell" })
 
 
:wikitext(team1)
 
:wikitext(team1)
 
:done()
 
:done()
 
:tag("div")
 
:tag("div")
  +
:addClass('vs-align-vs')
:css({ display = "table-cell", width = "20px", ["text-align"] = "center" })
 
:wikitext(" vs ")
+
:wikitext(vs or " vs ")
 
:done()
 
:done()
 
:tag("div")
 
:tag("div")
  +
:addClass('vs-align-right')
:css({ ["text-align"] = "left", display = "table-cell" })
 
 
:wikitext(team2)
 
:wikitext(team2)
 
:done()
 
:done()
 
 
 
return tbl
 
return tbl
  +
end
  +
  +
function p.teamsVsAlign(team1, team2)
  +
return p.vsAlign(m_team.leftshortlinked(team1), m_team.rightshortlinked(team2))
  +
end
  +
  +
function p.vsAlignStr(team1, team2)
  +
return tostring(p.vsAlign(team1, team2))
  +
end
  +
  +
function p.teamsVsAlignStr(team1, team2)
  +
return tostring(p.teamsVsAlign(team1, team2))
 
end
 
end
   
Line 61: Line 77:
 
end
 
end
   
function p.makeEmptySortRow(tbl, n)
+
function p.printEmptySortRow(tbl, n)
 
local tr = tbl:tag('tr'):css('font-size','60%')
 
local tr = tbl:tag('tr'):css('font-size','60%')
 
for i = 1, n do
 
for i = 1, n do
Line 70: Line 86:
 
end
 
end
   
function p.makeEmptyWidthRow(tbl, widths)
+
function p.printEmptyWidthRow(tbl, widths)
local tr = tbl:tag('tr'):css({
+
local tr = tbl:tag('tr'):addClass('empty-width-row')
  +
for _, v in ipairs(widths) do
background = 'none',
 
  +
tr:tag('td'):css('width', v):wikitext('&nbsp;')
['white-space'] = 'nowrap',
 
  +
end
visibility = 'collapse'
 
 
return
})
 
  +
end
  +
  +
function p.printEmptyWidthRowPX(tbl, widths)
  +
local tr = tbl:tag('tr'):addClass('empty-width-row')
 
for _, v in ipairs(widths) do
 
for _, v in ipairs(widths) do
 
tr:tag('td'):css('width', v .. 'px'):wikitext('&nbsp;')
 
tr:tag('td'):css('width', v .. 'px'):wikitext('&nbsp;')
Line 82: Line 102:
 
end
 
end
   
function p.imageHTML(image, args)
+
function p.printColspanHeader(tbl, display, colspan, class, width)
  +
local tr = tbl:tag('tr'):addClass(class)
local text = string.format('<img src="%s/Special:Filepath/%s" width="%s" height="%s" title="%s" alt="%s">',
 
  +
local th = tr:tag('th'):attr('colspan', colspan):wikitext(display)
mw.site.server,
 
  +
if width then
image,
 
  +
th:cssText(('width:%spx'):format(width))
args.width or '',
 
args.height or '',
 
args.title or '',
 
args.alt or args.title or ''
 
)
 
if args.link then
 
return string.format('<a href="%s" title="%s">%s</a>', args.link, args.alt or args.title, text)
 
 
end
 
end
return text
 
 
end
 
end
  +
  +
function p.printColspanCell(tbl, display, colspan, class, width)
  +
local tr = tbl:tag('tr'):addClass(class)
  +
local td = tr:tag('td'):attr('colspan', colspan):wikitext(display)
  +
if width then
  +
td:cssText(('width:%spx'):format(width))
  +
end
  +
end
  +
  +
function p.printHeader(tbl, data, classes)
  +
if not classes then classes = {} end
  +
local class = type(classes) == 'string' and classes
  +
local tr = tbl:tag('tr'):addClass(classes.row)
  +
for i, v in ipairs(data) do
  +
tr:tag('th'):addClass(class or classes[i] or ''):wikitext(v)
  +
end
  +
return
  +
end
  +
  +
function p.printHeaderFromI18n(tbl, data)
  +
if not tbl.classes then tbl.classes = {} end
  +
local class = type(tbl.classes) == 'string' and tbl.classes
  +
local tr = tbl:tag('tr')
  +
:addClass(tbl.classes.row)
  +
for i, v in ipairs(data) do
  +
tr:tag('th')
  +
:addClass(class or tbl.classes[i] or '')
  +
:wikitext(i18n.print(v))
  +
end
  +
end
  +
  +
function p.printRowsByList(tbl, data, list)
  +
-- data is an array of tables
  +
for _, row in ipairs(data) do
  +
p.printRowByList(tbl, row, list)
  +
end
  +
return
  +
end
  +
  +
function p.printRowByList(tbl, row, list)
  +
tbl:tag('tr')
  +
for _, item in ipairs(list) do
  +
tbl:tag('td')
  +
:wikitext(row[item])
  +
:addClass(list.classes and list.classes[item] or '')
  +
end
  +
end
  +
  +
function p.printRowsByListInDict(tbl, data, list)
  +
-- data is an ordered dictionary
  +
for _, v in ipairs(data) do
  +
tbl:tag('tr')
  +
for _, item in ipairs(list) do
  +
tbl:tag('td'):wikitext(data[v][item])
  +
end
  +
end
  +
return
  +
end
  +
  +
function p.printHelpText(div, text)
  +
local questionmark = div:tag('div')
  +
:addClass('helptext-questionmark')
  +
questionmark:tag('div')
  +
:addClass('helptext')
  +
:wikitext(text)
  +
end
  +
  +
function p.clear(tbl)
  +
if not tbl then tbl = mw.html.create() end
  +
tbl:tag('div'):addClass('clear')
  +
return tbl
  +
end
  +
  +
function p.innerColspanTable(tbl, colspan)
  +
local th = p.innerColspanCellOnly(tbl, colspan)
  +
local tblNew = th:tag('table'):addClass('nested-table wikitable')
  +
return tblNew
  +
end
  +
  +
function p.innerColspanCellOnly(tbl, colspan)
  +
local th = tbl:tag('tr'):tag('th')
  +
:attr('colspan', colspan)
  +
:addClass('nested-table-outer')
  +
return th
  +
end
  +
  +
function p.makeFlatlist(tbl)
 
local div = mw.html.create('div')
  +
:addClass('hlist')
  +
local ul = div:tag('ul')
  +
for _, v in ipairs(tbl) do
  +
ul:tag('li'):wikitext(v)
  +
end
  +
return div
  +
end
  +
 
return p
 
return p

Revision as of 19:46, 17 September 2019

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


local m_team = require('Module:Team')
local i18n = require('Module:i18nUtil')
local p = {}

function p.makeFootnoteN(n)
	if n and n ~= "" then
		return string.format('<sup>%s</sup>', n)
	end
	return ""
end

function p.vsAlign(team1, team2, vs, tbl)
	if not tbl then
		tbl = mw.html.create("div")
	end
	tbl:addClass('vs-align-outer')
	tbl:tag("div")
		:addClass('vs-align-left')
		:wikitext(team1)
	:done()
	:tag("div")
		:addClass('vs-align-vs')
		:wikitext(vs or " vs ")
	:done()
	:tag("div")
		:addClass('vs-align-right')
		:wikitext(team2)
	:done()
		
	return tbl
end

function p.teamsVsAlign(team1, team2)
	return p.vsAlign(m_team.leftshortlinked(team1), m_team.rightshortlinked(team2))
end

function p.vsAlignStr(team1, team2)
	return tostring(p.vsAlign(team1, team2))
end

function p.teamsVsAlignStr(team1, team2)
	return tostring(p.teamsVsAlign(team1, team2))
end

function p.makeNodeFromWikitext(text)
	local tbl = mw.html.create()
		:wikitext(text)
	return tbl
end

-- this function only makes the inner divs; it does not put the content into a table to restrict width, that's up to the parent function
-- as such, this adds to an existing html object and does not create its own
-- while content is a table, padding is a constant because why would you want variable padding
-- the name of this function is inherited from the template BlockBox
function p.blockBoxContent(content, padding, tbl)
	for k, v in ipairs(content) do
		div = tbl:tag('div')
		div:css({
			display = "inline-block",
			['vertical-align'] = 'top',
		})
		if padding and k ~= #content then
			div:css('padding-right',padding)
		end
		div:wikitext(v)
	end
	return
end

function p.blockBox(content, padding)
	local tbl = mw.html.create('table')
		:addClass('blockbox')
	local tr = tbl:tag('tr')
	local td = tr:tag('td')
	p.blockBoxContent(content, padding, td)
	return tbl
end

function p.printEmptySortRow(tbl, n)
	local tr = tbl:tag('tr'):css('font-size','60%')
	for i = 1, n do
		tr:tag('th')
		:wikitext('&nbsp;')
	end
	return
end

function p.printEmptyWidthRow(tbl, widths)
	local tr = tbl:tag('tr'):addClass('empty-width-row')
	for _, v in ipairs(widths) do
		tr:tag('td'):css('width', v):wikitext('&nbsp;')
	end
	return
end

function p.printEmptyWidthRowPX(tbl, widths)
	local tr = tbl:tag('tr'):addClass('empty-width-row')
	for _, v in ipairs(widths) do
		tr:tag('td'):css('width', v .. 'px'):wikitext('&nbsp;')
	end
	return
end

function p.printColspanHeader(tbl, display, colspan, class, width)
	local tr = tbl:tag('tr'):addClass(class)
	local th = tr:tag('th'):attr('colspan', colspan):wikitext(display)
	if width then
		th:cssText(('width:%spx'):format(width))
	end
end

function p.printColspanCell(tbl, display, colspan, class, width)
	local tr = tbl:tag('tr'):addClass(class)
	local td = tr:tag('td'):attr('colspan', colspan):wikitext(display)
	if width then
		td:cssText(('width:%spx'):format(width))
	end
end

function p.printHeader(tbl, data, classes)
	if not classes then classes = {} end
	local class = type(classes) == 'string' and classes
	local tr = tbl:tag('tr'):addClass(classes.row)
	for i, v in  ipairs(data) do
		tr:tag('th'):addClass(class or classes[i] or ''):wikitext(v)
	end
	return
end

function p.printHeaderFromI18n(tbl, data)
	if not tbl.classes then tbl.classes = {} end
	local class = type(tbl.classes) == 'string' and tbl.classes
	local tr = tbl:tag('tr')
		:addClass(tbl.classes.row)
	for i, v in  ipairs(data) do
		tr:tag('th')
			:addClass(class or tbl.classes[i] or '')
			:wikitext(i18n.print(v))
	end
end

function p.printRowsByList(tbl, data, list)
	-- data is an array of tables
	for _, row in ipairs(data) do
		p.printRowByList(tbl, row, list)
	end
	return
end

function p.printRowByList(tbl, row, list)
	tbl:tag('tr')
	for _, item in ipairs(list) do
		tbl:tag('td')
			:wikitext(row[item])
			:addClass(list.classes and list.classes[item] or '')
	end
end

function p.printRowsByListInDict(tbl, data, list)
	-- data is an ordered dictionary
	for _, v in ipairs(data) do
		tbl:tag('tr')
		for _, item in ipairs(list) do
			tbl:tag('td'):wikitext(data[v][item])
		end
	end
	return
end

function p.printHelpText(div, text)
	local questionmark = div:tag('div')
		:addClass('helptext-questionmark')
	questionmark:tag('div')
		:addClass('helptext')
		:wikitext(text)
end

function p.clear(tbl)
	if not tbl then tbl = mw.html.create() end
	tbl:tag('div'):addClass('clear')
	return tbl
end

function p.innerColspanTable(tbl, colspan)
	local th = p.innerColspanCellOnly(tbl, colspan)
	local tblNew = th:tag('table'):addClass('nested-table wikitable')
	return tblNew
end

function p.innerColspanCellOnly(tbl, colspan)
	local th = tbl:tag('tr'):tag('th')
		:attr('colspan', colspan)
		:addClass('nested-table-outer')
	return th
end

function p.makeFlatlist(tbl)
	local div = mw.html.create('div')
		:addClass('hlist')
	local ul = div:tag('ul')
	for _, v in ipairs(tbl) do
		ul:tag('li'):wikitext(v)
	end
	return div
end

return p