Module:Sandbox/SD0001/Tabbed window
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Experimental port of mw:MediaWiki:Gadget-tabbedwindow.js which uses {{Calculator}}. No-JS behaviour is quite broken.
Demo: User:SD0001/Tabbed window.
Usage
{{#invoke:Sandbox/SD0001/Tabbed window|main|tab1=tab1|content1=content1|tab2=tab2|content2=content2}}
More than 2 tabs are supported as well.
local Arguments = require('Module:Arguments')
local p = {}
p.main = function(frame)
local args = Arguments.getArgs(frame)
local tabs = getTabs(args)
local wikitext =
frame:extensionTag('templatestyles', '', {src = 'Template:Calculator-hideifzero/styles.css'})
.. frame:extensionTag('templatestyles', '', {src = 'User:SD0001/Tabbed window/styles.css'})
.. '<div class="tpl-tabbed-window calculator-container" data-calculator-refresh-on-load="true">'
.. '{{calculator|type=hidden|id=header|default=1}}'
for idx, tab in ipairs(tabs) do
wikitext = wikitext .. '{{calculator|type=hidden|id=h'..idx..'|formula=ifequal(header, '..idx..
')|default='..(idx == 1 and 1 or 0)..'}}'
end
wikitext = wikitext .. '<div style="background-color: var(--background-color-interactive, #eaecf0)">'
for idx, tab in ipairs(tabs) do
wikitext = wikitext .. '{{calculator button|contents='..(tab.header)..'|type=default|weight=quiet|formula='..idx..'|for=header|role=tab|style=background-color:rgba(255,255,255,var(--calculator-h'..idx..'))}}'
end
wikitext = wikitext .. '</div>'
for idx, tab in ipairs(tabs) do
wikitext = wikitext .. '<div class="calculator-field calculator-hideifzero panel" data-calculator-type="passthru" data-calculator-formula="h'..idx..'" role="tabpanel">'..(tab.content)..'</div>'
end
wikitext = wikitext .. '</div>'
return frame:preprocess(wikitext)
end
function getTabs(args)
local tabs = {}
for param, value in pairs(args) do
if string.match(param, "^tab%d+") ~= nil then
local num = tonumber(string.match(param, '%d+'))
if num ~= nil and args['content'..num] ~= nil then
table.insert(tabs, {header = value, content = args['content'..num]})
end
end
end
return tabs
end
return p