Jump to content

Module:Switcher

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 06:58, 2 August 2020 (Created page with 'local function index(t, k) return function(frame) local root = mw.html.create('div'):addClass('switcher-container') local default = (tonumber(k) or 0) * 2 -...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local function index(t, k)
	return function(frame)
		local root = mw.html.create('div'):addClass('switcher-container')
		local default = (tonumber(k) or 0) * 2 - 1
		for i=1,#frame.args,2 do
			local span = root
				:tag('div')
					:wikitext(frame.args[i])
					:tag('span')
						:addClass('switcher-label')
						:css('display', 'none')
						:wikitext(frame.args[i + 1])
			if i == default then
				span:attr('data-switcher-default', '')
			end
		end
		return root
	end
end

return setmetatable({}, {__index = index})