Kontentke ótiw

Module:Sidebar

Wikipedia, erkin enciklopediya

Bul moduldiń hújjetin Module:Sidebar/doc betinde jarata alasız

--
-- This module implements {{Sidebar}}
--
require('Module:No globals')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local navbar = require('Module:Navbar')._navbar

local function trimAndAddAutomaticNewline(s)
	-- For compatibility with the original {{sidebar with collapsible lists}}
	-- implementation, which passed some parameters through {{#if}} to trim
	-- their whitespace. This also triggered the automatic newline behavior.
	-- ([[meta:Help:Newlines and spaces#Automatic newline]])
	s = mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1")
	if mw.ustring.find(s, '^[#*:;]') or mw.ustring.find(s, '^{|') then
		return '\n' .. s
	else
		return s
	end
end

local function hasSubgroup(s)
	if mw.ustring.find(s, 'vertical%-navbox%-subgroup') then
		return true
	else
		return false
	end
end

function p.sidebar(frame, args)
	if not args then
		args = getArgs(frame)
	end
	local root = mw.html.create()
	local child = args.child and mw.text.trim(args.child) == 'yes' or args.child and mw.text.trim(args.child) == 'sim' or args.filha and mw.text.trim(args.filha) == 'yes' or args.filha and mw.text.trim(args.filha) == 'sim'

	root = root:tag('table')
	if not child then
		root 
			:addClass('vertical-navbox')
			:addClass(args.wraplinks ~= 'true' and args.wraplinks ~= 'verdadeiro' and args.wraplinks ~= 'verdadeira' and 'nowraplinks' or nil)
			:addClass(args.bodyclass or args['classe-corpo'] or args.class or args.classe)
			:css('float', args.float or args['flutuar'] or args['lado'] or 'right')
			:css('clear', (args.float == 'none' and 'both') or (args['flutuar'] == 'none' and 'both') or (args['lado'] == 'none' and 'both') or args.float or 'right')
			:css('width', args.width or args.largura or '22.0em')
			:css('margin', args.float == 'left' and '0.5em 0.5em 0 1em' or '0.5em 0 0.5em 1em')
			:css('background', '#f9f9f9')
			:css('border', '1px solid #aaa')
			:css('padding', '0.2em')
			:css('border-spacing', '0.4em 0')
			:css('text-align', 'center')
			:css('line-height', '1.4em')
			:css('font-size', '88%')
			:cssText(args.bodystyle or args['usil-corpo'] or args.style or args.usil)

		if args.outertitle or args['bet-externo'] or args['bet-exterior'] then
			root
				:tag('caption')
					:addClass(args.outertitleclass or args['classe-bet-externo'] or args['classe-bet-exterior'])
					:css('padding-bottom', '0.2em')
					:css('font-size', '125%')
					:css('line-height', '1.2em')
					:css('font-weight', 'bold')
					:cssText(args.outertitlestyle or args['usil-bet-externo'] or args['usil-bet-exterior'])
					:wikitext(args.outertitle or args['bet-externo'] or args['bet-exterior'])
		end

		if args.topimage or args['imagem-joqarı'] or args['imagem2'] then
			local imageCell = root:tag('tr'):tag('td')

			imageCell
				:addClass(args.topimageclass or args['classe-imagem-joqarı'] or args['classe-imagem2'])
				:css('padding', '0.4em 0')
				:cssText(args.topimagestyle or args['usil-imagem-joqarı'] or args['usil-imagem2'])
				:wikitext(args.topimage or args['joqarı-imagem'] or args['imagem2'])

			if args.topcaption or args['legenda-joqarı'] or args['imagem_legenda2'] then
				imageCell
					:tag('div')
						:css('padding-top', '0.2em')
						:css('line-height', '1.2em')
						:cssText(args.topcaptionstyle or args['usil-legenda-joqarı'] or args['usil-imagem_legenda2'])
						:wikitext(args.topcaption or args['legenda-joqarı'] or arg['imagem_legenda2'])
			end
		end

		if args.pretitle or args['aldınǵı bet'] then
			root
				:tag('tr')
					:tag('td')
						:addClass(args.pretitleclass or args['classe-aldınǵı bet'])
						:cssText(args.basestyle or args['usil-base'])
						:css('padding-top', args.topimage and '0.2em' or args['imagem-joqarı'] and '0.2em' or args['imagem2'] and '0.2em' or '0.4em')
						:css('line-height', '1.2em')
						:cssText(args.pretitlestyle or args['bet usilı'])
						:wikitext(args.pretitle or args['aldınǵı bet'])
		end
	else
		root
			:addClass('vertical-navbox-subgroup')
			:css('width', '100%')
			:css('margin', '0px')
			:css('border-spacing', '0px')
			:addClass(args.bodyclass or args['classe-corpo'] or args.class or args.classe)
			:cssText(args.bodystyle or args['usil-corpo'] or args.style or args.usil)
	end

	if args.title or args['bet'] then
		if child then
			root
				:wikitext(args.title or args['bet'])
		else
			root
				:tag('tr')
					:tag('th')
						:addClass(args.titleclass or args['classe-bet'])
						:cssText(args.basestyle or args['usil-base'])
						:css('padding', '0.2em 0.4em 0.2em')
						:css('padding-top', args.pretitle and 0 or args['aldınǵı bet'] and 0)
						:css('font-size', '145%')
						:css('line-height', '1.2em')
						:cssText(args.titlestyle or args['usil-bet'])
						:wikitext(args.title or args['bet'])
		end
	end

	if args.image or args.imagem then
		local imageCell = root:tag('tr'):tag('td')

		imageCell
			:addClass(args.imageclass or args['classe-imagem'])
			:css('padding', '0.2em 0 0.4em')
			:cssText(args.imagestyle or args['usil-imagem'])
			:wikitext(args.image or args.imagem)

		if args.caption or args.legenda or args['imagem_legenda'] then
			imageCell
				:tag('div')
					:css('padding-top', '0.2em')
					:css('line-height', '1.2em')
					:cssText(args.captionstyle or args['usil-legenda'] or args['usil-imagem_legenda'])
					:wikitext(args.caption or args.legenda or args['imagem_legenda'])
		end
	end

	if args.above or args.acima then
		root
			:tag('tr')
				:tag('td')
					:addClass(args.aboveclass or args['classe-acima'])
					:css('padding', '0.3em 0.4em 0.3em')
					:css('font-weight', 'bold')
					:cssText(args.abovestyle or args['usil-acima'])
					:newline() -- newline required for bullet-points to work
					:wikitext(args.above or args.acima)
	end

	local rowNums = {}
	for k, v in pairs(args) do
		k = '' .. k
		local num = k:match('^heading(%d+)$') or k:match('^cabeçalho(%d+)$') or k:match('^content(%d+)$') or k:match('^conteúdo(%d+)$')
		if num then table.insert(rowNums, tonumber(num)) end
	end
	table.sort(rowNums)
	-- remove duplicates from the list (e.g. 3 will be duplicated if both heading3 and content3 are specified)
	for i = #rowNums, 1, -1 do
		if rowNums[i] == rowNums[i - 1] then
			table.remove(rowNums, i)
		end
	end

	for i, num in ipairs(rowNums) do
		local heading = args['heading' .. num] or args['cabeçalho' .. num]
		if heading then
			root
				:tag('tr')
					:tag('th')
						:addClass(args.headingclass or args['classe-cabeçalho'])
						:css('padding', '0.1em')
						:cssText(args.basestyle or args['usil-base'])
						:cssText(args.headingstyle or args['usil-cabeçalho'])
						:cssText(args['heading' .. num .. 'style'] or args['usil-cabeçalho' .. num])
						:newline()
						:wikitext(heading)
		end

		local content = args['content' .. num] or args['conteúdo' .. num]
		if content then
			root
				:tag('tr')
					:tag('td')
						:addClass(args.contentclass or args['classe-conteúdo'])
						:css('padding', hasSubgroup(content) and '0.1em 0 0.2em' or '0 0.1em 0.4em')
						:cssText(args.contentstyle or args['usil-conteúdo'])
						:cssText(args['content' .. num .. 'style'] or args['usil-conteúdo' .. num])
						:newline()
						:wikitext(content)
						:done()
					:newline() -- Without a linebreak after the </td>, a nested list like "* {{hlist| ...}}" doesn't parse correctly.
		end
	end

	if args.below or args.abaixo then
		root
			:tag('tr')
				:tag('td')
					:addClass(args.belowclass or args['classe-abaixo'])
					:css('padding', '0.3em 0.4em 0.3em')
					:css('font-weight', 'bold')
					:cssText(args.belowstyle or args['usil-abaixo'])
					:newline()
					:wikitext(args.below or args.abaixo)
	end

	if not child then
		local nameArg = args.name or args.nome
		local navbarArg = args.navbar or args.tnavbar
		if navbarArg ~= 'none' and navbarArg ~= 'nenhuma' and navbarArg ~= 'nenhum' and navbarArg ~= 'off' and (nameArg or frame:getParent():getTitle():gsub('/Testes$', '') ~= 'Predefinição:Sidebar') then
			root
				:tag('tr')
					:tag('td')
						:css('text-align', 'right')
						:css('font-size', '115%')
						:cssText(args.navbarstyle or args['usil-navbar'] or args.tnavbarstyle or args['usil-tnavbar'])
						:wikitext(navbar{
							nameArg,
							mini = 1,
							fontstyle = args.navbarfontstyle or args['usil-fonte-navbar'] or args.tnavbarfontstyle or args['usil-fonte-tnavbar']
						})
		end
	end

	return tostring(root) .. (child and '[[Categoria:!Páginas que usam sidebar com o parâmetro filha]]' or '')
end

function p.collapsible(frame)
	local args = getArgs(frame)
	local nameArg = args.name or args.nome

	args.abovestyle = 'border-top: 1px solid #aaa; border-bottom: 1px solid #aaa;' .. (args.abovestyle or args['usil-abaixo'] or '')
	args.belowstyle = 'border-top: 1px solid #aaa; border-bottom: 1px solid #aaa;' .. (args.belowstyle or args['usil-abaixo'] or '')
	args.navbarstyle = 'padding-top: 0.6em;' .. (args.navbarstyle or args['usil-navbar'] or args.tnavbarstyle or args['usil-tnavbar'] or '')
	if not nameArg and frame:getParent():getTitle():gsub('/Testes$', '') == 'Predefinição:Menu lateral ocultável' then
		args.navbar = 'none'
	end

	local contentArgs = {}

	for k, v in pairs(args) do
		local num = string.match(k, '^list(%d+)$') or string.match(k, '^lista(%d+)$')
		if num then
			local expand = (args.expanded and args.expanded == 'all'
							or args.expanded and args.expanded == 'tudo'
							or args.expanded and args.expanded == 'todo'
							or args.expanded and args.expanded == 'toda'
							or args.expanded and args.expanded == 'todos'
							or args.expanded and args.expanded == 'todas'
							or args.expanded and args.expanded == args['list' .. num .. 'name']
							or args.expanded and args.expanded == args['lista' .. num .. '-nome']
							or args.expandida and args.expandida == 'all'
							or args.expandida and args.expandida == 'tudo'
							or args.expandida and args.expandida == 'todo'
							or args.expandida and args.expandida == 'toda'
							or args.expandida and args.expandida == 'todos'
							or args.expandida and args.expandida == 'todas'
							or args.expandida and args.expandida == args['list' .. num .. 'name']
							or args.expandida and args.expandida == args['lista' .. num .. '-nome']
						   )

			local row = mw.html.create('div')
			row
				:addClass('NavFrame')
				:addClass((not expand) and 'collapsed' or nil)
				:css('border', 'none')
				:css('padding', 0)
				:cssText(args.listframestyle or args['usil-quadro-lista'])
				:cssText(args['list' .. num .. 'framestyle'] or args['usil-quadro-lista'])
				:tag('div')
					:addClass('NavHead')
					:addClass(args.listtitleclass or args['classe-bet-lista'])
					:css('font-size', '105%')
					:css('background', 'transparent')
					:css('text-align', 'left')
					:cssText(args.basestyle or args['usil-base'])
					:cssText(args.listtitlestyle or args['usil-bet-lista'])
					:cssText(args['list' .. num .. 'titlestyle'] or args['usil-bet-lista' .. num])
					:wikitext(trimAndAddAutomaticNewline(args['list' .. num .. 'title'] or args['bet-lista' .. num] or 'Lista'))
					:done()
				:tag('div')
					:addClass('NavContent')
					:addClass(args.listclass or args['classe-lista'])
					:addClass(args['list' .. num .. 'class'] or args['classe-lista' .. num])
					:css('font-size', '105%')
					:css('padding', '0.2em 0 0.4em')
					:css('text-align', 'center')
					:cssText(args.liststyle or args['usil-lista'])
					:cssText(args['list' .. num .. 'style'] or args['usil-lista' .. num])
					:wikitext(trimAndAddAutomaticNewline(args['list' .. num] or args['lista' .. num]))

			contentArgs['content' .. num] = tostring(row)
			contentArgs['conteúdo' .. num] = tostring(row)
		end
	end

	for k, v in pairs(contentArgs) do
		args[k] = v
	end

	return p.sidebar(frame, args)
end

return p
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy