Jump to content

Module:Sandbox/SD0001/Tabbed window: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix ordering
use Module:Sandbox/SD0001/Calculator to make code less hacky
Line 1: Line 1:
local Arguments = require('Module:Arguments')
local Arguments = require('Module:Arguments')
local Calculator = require('Module:Sandbox/SD0001/Calculator')


local p = {}
local p = {}
Line 6: Line 7:
local args = Arguments.getArgs(frame)
local args = Arguments.getArgs(frame)
local tabs = getTabs(args)
local tabs = getTabs(args)

local wikitext =
local calc = Calculator:new({ class='tpl-tabbed-window', refreshOnLoad = true })
frame:extensionTag('templatestyles', '', {src = 'Template:Calculator-hideifzero/styles.css'})
calc:hidden({ id = 'header', default = 1})
.. 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
for idx, tab in ipairs(tabs) do
wikitext = wikitext .. '{{calculator|type=hidden|id=h'..idx..'|formula=ifequal(header, '..idx..
calc:hidden({ id = 'h'..idx, formula = 'ifequal(header,'..idx..')', default = (idx == 1 and 1 or 0) })
')|default='..(idx == 1 and 1 or 0)..'}}'
end
end
wikitext = wikitext .. '<div style="background-color: var(--background-color-interactive, #eaecf0)">'
local panels = calc:subContainer({
style = 'background-color: var(--background-color-interactive, #eaecf0)'
})

for idx, tab in ipairs(tabs) do
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..'))}}'
panels: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
end
wikitext = wikitext .. '</div>'
for idx, tab in ipairs(tabs) do
for idx, tab in ipairs(tabs) do
calc:hideIfZero({ class = 'panel', role = 'tabpanel', formula = 'h'..idx, text = tab.content })
wikitext = wikitext .. '<div class="calculator-field calculator-hideifzero panel" data-calculator-type="passthru" data-calculator-formula="h'..idx..'" role="tabpanel">'..(tab.content)..'</div>'
end
end


return frame:extensionTag('templatestyles', '', {src = 'User:SD0001/Tabbed window/styles.css'})
wikitext = wikitext .. '</div>'
.. tostring(calc)
return frame:preprocess(wikitext)
end
end



Revision as of 14:03, 29 January 2025

local Arguments = require('Module:Arguments')
local Calculator = require('Module:Sandbox/SD0001/Calculator')

local p = {}

p.main = function(frame)
	local args = Arguments.getArgs(frame)
	local tabs = getTabs(args)

	local calc = Calculator:new({ class='tpl-tabbed-window', refreshOnLoad = true })
	calc:hidden({ id = 'header', default = 1})

	for idx, tab in ipairs(tabs) do
		calc:hidden({ id = 'h'..idx, formula = 'ifequal(header,'..idx..')', default = (idx == 1 and 1 or 0) })
	end
	
	local panels = calc:subContainer({ 
		style = 'background-color: var(--background-color-interactive, #eaecf0)' 
	})

	for idx, tab in ipairs(tabs) do
		panels: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
	
	for idx, tab in ipairs(tabs) do
		calc:hideIfZero({ class = 'panel', role = 'tabpanel', formula = 'h'..idx, text = tab.content })
	end

	return frame:extensionTag('templatestyles', '', {src = 'User:SD0001/Tabbed window/styles.css'})
		.. tostring(calc)
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
				tabs[num] = {header = value, content = args['content'..num]}
			end
		end
	end
	return tabs
end


return p