Module:Page tabs

From Zoophilia Wiki
Revision as of 03:13, 11 June 2021 by Quantumhusky (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:Page tabs/doc

-- This module implements {{Page tabs}}.

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local makeTab = p.makeTab
	local root = mw.html.create()
	root:wikitext(yesno(args.NOTOC) and '__NOTOC__' or nil)
	local row = root:tag('div')
		:css('background', args.Background or '#f8fcff')
		:addClass('template-page-tabs')
	if not args[1] then
		args[1] = '{{{1}}}'
	end
	for i, link in ipairs(args) do
		makeTab(row, link, tonumber(args.This) == i)
	end
		
	return tostring(root)
end

function p.makeTab(root, link, thisPage)
	local args = mw.getCurrentFrame():getParent().args
	root:tag('span')
		:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#cee0f2'))
		:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%')
		:wikitext(link)
		:done()
		:wikitext('<span class="spacer">&#32;</span>')
end

return p