跳转到内容

模組:Page tabs

维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2020年8月30日 (日) 12:19编辑。这可能和当前版本存在着巨大的差异。

-- 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 tab = mw.html.create():tag('table'):addClass('page_tab')
	if args.Background then
		tab = tab:css('background', args.Background or '#f8fcff')
	end
	tab = tab:tag('tr')
	if not args[1] then
		tab = tab:wikitext('{{{1}}}')
	else
		for i, link in ipairs(args) do
			local thisPage
			if tonumber(args.This) == i then
				thisPage = true
			end
			tab = tab:wikitext(makeTab(link, thisPage))
		end
	end
	
	tab = tab:tag('td')
		:css('border-bottom', '2px solid #a3b1bf')
		:css('width', '3000px')
		:wikitext(' ')
		
	return (yesno(args.NOTOC) and '__NOTOC__' or nil) .. tostring(tab)
end

function p.makeTab(link, thisPage)
	local tcell = mw.html.create()
	tcell:tag('td')
		:css('padding', '0.5em')
		:css('background-color', thisPage and 'white' or '#cee0f2')
		:cssText(not thisPage and 'font-size:95%' or nil)
		:css('line-height', '0.95em')
		:css('border', 'solid 2px #a3b1bf')
		:cssText(thisPage and 'border-bottom:0')
		:cssText(thisPage and 'font-weight:bold')
		:css('white-space', 'nowrap')
		:css('width', '20px')
		:wikitext(link)
		:done()
	:tag('td')
		:css('border-bottom', '2px solid #a3b1bf')
		:css('width', '3px')
		:css('padding', '0')
		:wikitext(' ')
	return tostring(tcell)
end

return p