Module:Tabs: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 16: Line 16:
repeat
repeat
tab = mw.html.create( 'span' ):addClass('g-tab'):wikitext(args[i+2])
tab = mw.html.create( 'span' ):addClass('g-tab'):wikitext(args[i+2])
tabcontent = mw.html.create( 'div' ):addClass('g-tab-content'):wikitext(args[i+1])
if active == (i + 2) * 0.5 then
if active == (i + 2) * 0.5 then
tab = tab:addClass('g-tab-active')
tab = tab:addClass('g-tab-active')
tabcontent = tabcontent:addClass('g-tab-content-active')
end
end
header = header:node(tab)
header = header:node(tab)
contents = contents:node(mw.html.create( 'div' ):addClass('g-tab-content'):wikitext(args[i+1]))
contents = contents:node(tabcontent)
i = i + 2
i = i + 2
until args[i+1] == nil or args[i+2] == nil
until args[i+1] == nil or args[i+2] == nil

Revision as of 07:48, 14 July 2024

Documentation for this module may be created at Module:Tabs/doc

local getArgument = require('Module:Arguments').getArgument

local p = {}

function p.Main(frame)
	local args = frame.args
	local i = 0
	if args['active'] == nil then
		active = 1
	else
		active = args['active']
	end
	if args[1] and args[2] then
		local header = mw.html.create( 'div' ):addClass('g-tab-header')
		local contents = mw.html.create( 'div' ):addClass('g-tab-contents')
		repeat
			tab = mw.html.create( 'span' ):addClass('g-tab'):wikitext(args[i+2])
			tabcontent = mw.html.create( 'div' ):addClass('g-tab-content'):wikitext(args[i+1])
			if active == (i + 2) * 0.5 then
				tab = tab:addClass('g-tab-active')
				tabcontent = tabcontent:addClass('g-tab-content-active')
			end
			header = header:node(tab)
			contents = contents:node(tabcontent)
			i = i + 2
		until args[i+1] == nil or args[i+2] == nil
		local output = mw.html.create( 'div' ):addClass('g-tab-container'):node(header):node(contents)

		return output
	else
		return 'Values not filled.'
	end
end

return p