Jump to content

Module:Page tabs: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
or nil
Tag: Reverted
m Reverted edits by Izno (talk) to last version by GKFX
Line 6: Line 6:
local p = {}
local p = {}


local function makeTab(root, link, args, i)
function p.main(frame)
local thisPage = (args.This == 'auto' and
local args = getArgs(frame)
return p._main(args)
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 or nil)
:wikitext(link)
:done()
end
end


function p._main(args)
function p._main(args)
local makeTab = p.makeTab
local root = mw.html.create()
local root = mw.html.create()
root:wikitext(yesno(args.NOTOC) and '__NOTOC__' or nil)
root:wikitext(yesno(args.NOTOC) and '__NOTOC__' or nil)
local row = root:tag('div')
local row = root:tag('div')
:css('background-color', args.Background)
:css('background', args.Background or '#f8fcff')
:addClass('page-tabs')
:addClass('template-page-tabs')
if not args[1] then
if not args[1] then
args[1] = '{{{1}}}'
args[1] = '{{{1}}}'
Line 32: Line 25:
end
end
return mw.getCurrentFrame():extensionTag{
return tostring(root)
name = 'templatestyles', args = { src = 'Module:Page tabs/styles.css' }
} .. tostring(root)
end
end


function p.main(frame)
function p.makeTab(root, link, args, i)
local thisPage = (args.This == 'auto' and link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or tonumber(args.This) == i
local args = getArgs(frame)
root:tag('span')
return p._main(args)
: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
end



Revision as of 13:58, 30 July 2021

-- 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, args, i)
	end
		
	return tostring(root)
end

function p.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')
		: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