Module: Tabs
(Created page with "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[ 'lin...") |
No edit summary Tag: Reverted |
||
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 20: | Line 28: | ||
label = args[ 'label' .. tabNum ] | label = args[ 'label' .. tabNum ] | ||
end | end | ||
out = out .. ' <span class="mdl-tabs-tab">[[' .. link .. '|' .. label .. ']]</span>' | local color = colors[ tabNum % #colours ] | ||
out = out .. ' <span class="mdl-tabs-tab" style="border-color:#' .. color ..'">[[' .. link .. '|' .. label .. ']]</span>' | |||
tabNum = tabNum + 1 | tabNum = tabNum + 1 | ||
else | else |
Revision as of 02:50, 13 November 2023
Documentation for this module may be created at Module:Tabs/doc
local p = {}
local colours = {
'2a4b8d',
'b32424',
'14866d',
'ac6600',
'72777d'
}
-- =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
local color = colors[ tabNum % #colours ]
out = out .. ' <span class="mdl-tabs-tab" style="border-color:#' .. color ..'">[[' .. 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