We've Moved! Just as Gamepedia has joined forces with Fandom, this wiki had joined forces with our Fandom equivalent. The wiki has been archived and we ask that readers and editors move to the now combined wiki on Fandom. Click to go to the new wiki.

Module:TabsHeader

From The Vault - Fallout Wiki
Jump to: navigation, search

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


local p = {}

function p.fromArgs(frame)
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end

	local output = {}
	local this = tonumber(args.This)
	
	local i = 1
	while args['link' .. i] do
		output[i] = string.format('[[%s|%s]]',
			args['link' .. i],
			args['name'.. i] or args['link' .. i]
		)
		i = i + 1
	end
	
	return p.main(output, this, args)
end

function p.fromTables(names, links, this, settings)
	local output = {}
	for k, v in ipairs(links) do
		output[k] = string.format('[[%s|%s]]',
			v,
			names[k] or v
		)
	end
	return p.main(output, this, settings)
end

function p.makeTab(tbl, v, isthis)
	class = isthis and 'tabheader-active' or ''
	tbl:tag('div')
		:addClass('tabheader-tab')
		:addClass(class)
		:wikitext(v)
	return
end

function p.main(links, this, settings)
	frame = mw.getCurrentFrame()
	frame:callParserFunction{ name = '#vardefine:hastabs', args = 'true' }
	tbl = mw.html.create('div')
		:css({ ['background-color'] = settings.backgroundcolor })
		:addClass('tabheader-top')
	for k, v in ipairs(links) do
		p.makeTab(tbl, v, k == this)
	end
	return tostring(tbl)
end

return p