Module:TabsHeader

local util_args = require('Module:ArgsUtil') local util_title = require('Module:TitleUtil')

local classes = { header = { tab = 'tabheader-tab', active = 'tabheader-active', outer = 'tabheader-top' },	title = { tab = 'titletabs-tab', active = 'titletabs-active', outer = 'titletabs-tabs' } }

local p = {}

function p.fromArgs(frame) local args = util_args.merge(true)

local output = {} local this = tonumber(args.This) local title = mw.title.getCurrentTitle.prefixedText local sep = '%s*' .. (args.sep or ',') .. '%s*' local basepage = args.basepage if args.links then names = args.names and mw.text.split(args.names,sep) or {} links = args.links:gsub('_',' ') for k, v in ipairs(mw.text.split(links,sep)) do			local curPage = util_title.concatSubpage(basepage, v)			local defaultDisplay = v ~= '' and v or k			output[k] = string.format('%s',				curPage,				args['name' .. k] or names[k] or defaultDisplay			) if curPage == title then this = k			end end else local i = 1 while args['link' .. i] do			output[i] = string.format('%s',				args['link' .. i],				args['name'.. i] or args['link' .. i]			) i = i + 1 end 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',			v,			names[k] or v		) end return p.main(output, this, settings) end

function p.main(links, this, settings) if not settings then settings = {} end local class = settings.tabstype or 'header' local tbl = p.initialize(settings, class) for k, v in ipairs(links) do		p.makeTab(tbl, class, v, k == this) end local f = mw.getCurrentFrame f:callParserFunction('#vardefine:tabThis',this) return tostring(tbl) end

function p.initialize(settings, class) return mw.html.create('div') :addClass(classes[class].outer) :css({ ['background-color'] = settings.backgroundcolor }) end

function p.makeTab(tbl, class, v, isthis) tbl:tag('div') :addClass(classes[class].tab) :addClass(isthis and classes[class].active or '') :wikitext(v) return end

return p