Module:Switcher

MyWikiBiz, Author Your Legacy — Saturday June 01, 2024
Revision as of 07:29, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

local p = {}

function p.main(frame)
	local root = mw.html.create('div'):addClass('switcher-container')
	local default = (tonumber(frame.args.default) or 0) * 2 - 1
	for i,v in ipairs(frame.args) do
		if i % 2 == 1 then
			local span = root
				:tag('div')
					:wikitext(frame.args[i])
					:tag('span')
						:addClass('switcher-label')
						:css('display', 'none')
						:wikitext(mw.text.trim(frame.args[i + 1]))
			if i == default then
				span:attr('data-switcher-default', '')
			end
		end
	end
	return root
end

return p