Jump to content

Module:Page tabs

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Izno (talk | contribs) at 13:35, 30 July 2021 (templatestyles instead). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- 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-color', args.Background)
		:addClass('page-tabs')
	if not args[1] then
		args[1] = '{{{1}}}'
	end
	for i, link in ipairs(args) do
		makeTab(row, link, args, i)
	end
		
	return mw.getCurrentFrame():extensionTag{
		name = 'templatestyles', args = { src = 'Module:Page tabs/styles.css' }
	} .. tostring(root)
end

local function makeTab(root, link, args, i)
	local thisPage = (args.This == 'auto' and
		link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or
		tonumber(args.This) == i
	root
		:tag('span')
			:addClass()
			:addClass(thisPage and 'page-tabs-page-tab' or 'page-tabs-tab')
			:css('background-color', thisPage and args.tab-bg or args.tab1-bg)
			:wikitext(link)
			:done()
end

return p