Jump to content

Module:Page tabs: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
make "class1", "class2", etc. add styling to each individual tab, as well as "style1", "style2", etc. and "class" and "style" control overall styling of the tabs
make default background color lighter to meet MOS:CONTRAST, see Template talk:Page tabs#Tab background color
Line 34: Line 34:
root:tag('span')
root:tag('span')
:addClass(class)
:addClass(class)
:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#cee0f2'))
:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#e0edf6'))
:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%')
:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%')
:cssText(css)
:cssText(css)

Revision as of 06:23, 26 April 2024

-- 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')
		:cssText(args.style or nil)
		:addClass('template-page-tabs')
		:addClass(args.class or nil)
	if not args[1] then
		args[1] = '{{{1}}}'
	end
	for i, link in ipairs(args) do
		makeTab(row, link, args, i, args["class" .. i] or nil, args["style" .. i] or nil)
	end
		
	return tostring(root)
end

function p.makeTab(root, link, args, i, class, css)
	local thisPage = (args.This == 'auto' and link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or tonumber(args.This) == i
	root:tag('span')
		:addClass(class)
		:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#e0edf6'))
		:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%')
		:cssText(css)
		:wikitext(link)
		:done()
		:wikitext('<span class="spacer ' .. (class or "") .. '">&#32;</span>')
end

return p