Module: Tabs

No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
Line 1: Line 1:
local p = {}
local p = {}
local colours = {
'2a4b8d',
'b32424',
'14866d',
'ac6600',
'72777d'
}


-- =p.main({args={link1='foo', link2='bar'}})
-- =p.main({args={link1='foo', link2='bar'}})
Line 28: Line 20:
label = args[ 'label' .. tabNum ]
label = args[ 'label' .. tabNum ]
end
end
local colour = colours[ tabNum % #colours ]
out = out .. ' <span class="mdl-tabs-tab">[[' .. link .. '|' .. label .. ']]</span>'
out = out .. ' <span class="mdl-tabs-tab" style="border-color:#' .. colour ..'">[[' .. link .. '|' .. label .. ']]</span>'
tabNum = tabNum + 1
tabNum = tabNum + 1
else
else

Latest revision as of 05:24, 13 November 2023

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

local p = {}

-- =p.main({args={link1='foo', link2='bar'}})
p.main = function ( frame )
	-- Either use the args given (for testing), or those of the parent.
	local args = frame.args
	if #args == 0 and mw.getCurrentFrame():getParent() then
		args = mw.getCurrentFrame():getParent().args
	end
	-- Loop through all numbered links given.
	local tabNum = 1
	local finished = false
	local out = ''
	while not finished do
		-- See if the next numbered link is there.
		if args[ 'link' .. tabNum ] ~= nil and args[ 'link' .. tabNum ] ~= '' then
			local link = args[ 'link' .. tabNum ]
			local label = link
			if args[ 'label' .. tabNum ] ~= nil and args[ 'label' .. tabNum ] ~= '' then
				label = args[ 'label' .. tabNum ]
			end
			out = out .. ' <span class="mdl-tabs-tab">[[' .. link .. '|' .. label .. ']]</span>'
			tabNum = tabNum + 1
		else
			finished = true
		end
	end
	local styles = mw.getCurrentFrame():extensionTag( 'templatestyles', nil, { src = 'Module:Tabs/styles.css' } )
	return styles .. '<span class="mdl-tabs">' .. out .. '</span>'
end

return p
Discuss this page