From WikiTemp, the GBAtemp wiki
(Created page with "--- Simple infobox module local p = {} --- Main function function p.infobox( frame ) local args if frame == mw.getCurrentFrame() then args = frame:getParent().args else...")
 
 
Line 16: Line 16:
 
local title = args.title
 
local title = args.title
 
if not title or title == '' then title = mw.title.getCurrentTitle().text end
 
if not title or title == '' then title = mw.title.getCurrentTitle().text end
infobox:tag('tr'):addClass('infobox-title'):tag('th'):attr('scope','col'):attr('colspan',2):wikitext(title)
+
infobox:tag('tr'):tag('th'):addClass('infobox-title'):attr('scope','col'):attr('colspan',2):wikitext(title)
 
   
 
   
 
-- Image
 
-- Image
Line 27: Line 27:
 
image = '[[' .. image .. '|' .. (args.imagesize or '200px') .. ']]'
 
image = '[[' .. image .. '|' .. (args.imagesize or '200px') .. ']]'
 
end
 
end
local imgcell = infobox:tag('tr'):addClass('infobox-image'):tag('td')
+
local imgcell = infobox:tag('tr'):tag('td'):addClass('infobox-image')
 
:attr('colspan',2):wikitext(image)
 
:attr('colspan',2):wikitext(image)
 
local caption = args.imagecaption
 
local caption = args.imagecaption
Line 42: Line 42:
 
   
 
   
 
if header then
 
if header then
infobox:tag('tr'):addClass('infobox-header')
+
infobox:tag('tr')
:tag('th'):attr('scope','col'):attr('colspan',2):wikitext(header)
+
:tag('th'):addClass('infobox-header'):attr('scope','col'):attr('colspan',2):wikitext(header)
 
end
 
end
 
if data then
 
if data then
Line 61: Line 61:
 
local below = args.below
 
local below = args.below
 
if below and below ~= '' then
 
if below and below ~= '' then
infobox:tag('tr'):addClass('infobox-below'):tag('td'):attr('colspan',2):wikitext(below)
+
infobox:tag('tr'):tag('td'):addClass('infobox-below'):attr('colspan',2):wikitext(below)
 
end
 
end
 
   
 
   

Latest revision as of 11:55, 22 October 2016

↑ Module Documentation ↓ [CreateReload]

No documentation available.
Add new documentation.


The Module documentation will automatically appear in this box after the documentation page is created.
--- Simple infobox module
local p = {}
 
--- Main function
function p.infobox( frame )
	local args
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame
	end
 
	local infobox = mw.html.create('table'):addClass('infobox')
 
	-- Title
	local title = args.title
	if not title or title == '' then title = mw.title.getCurrentTitle().text end
	infobox:tag('tr'):tag('th'):addClass('infobox-title'):attr('scope','col'):attr('colspan',2):wikitext(title)
 
	-- Image
	local image = args.image
	if image and image ~= '' then
		if image:sub(1,2) ~= '[[' then
			if not image:find(':') then
				image = 'File:' .. image	
			end
			image = '[[' .. image .. '|' .. (args.imagesize or '200px') .. ']]'
		end
		local imgcell = infobox:tag('tr'):tag('td'):addClass('infobox-image')
			:attr('colspan',2):wikitext(image)
		local caption = args.imagecaption
		if caption and caption ~= '' then
			imgcell:wikitext("<br />''" .. caption .. "''")
		end
	end
 
	-- Rows
	for i = 1, 20 do
		local header = args['header' .. i]; if header == '' then header = nil end
		local label = args['label' .. i]; if label == '' then label = nil end
		local data = args['data' .. i]; if data == '' then data = nil end
 
		if header then
			infobox:tag('tr')
				:tag('th'):addClass('infobox-header'):attr('scope','col'):attr('colspan',2):wikitext(header)
		end
		if data then
			if label then
				infobox:tag('tr')
					:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label):done()
					:tag('td'):addClass('infobox-data'):wikitext(data)
			else
				infobox:tag('tr')
					:tag('td'):addClass('infobox-data'):attr('colspan',2)
						:css('text-align','center'):wikitext(data)
			end
		end
	end
 
	-- Below
	local below = args.below
	if below and below ~= '' then
		infobox:tag('tr'):tag('td'):addClass('infobox-below'):attr('colspan',2):wikitext(below)
	end
 
	return infobox
end
 
return p