Module:Tabs: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Manual revert
 
(46 intermediate revisions by the same user not shown)
Line 2: Line 2:


local p = {}
local p = {}
function trim(s) -- Allows removing of whitespace and line breaks from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html)
local l = 1
while string.sub(s,l,l) == ' ' do
l = l+1
end
while string.sub(s,l,l+1) == '\n' do
l = l+2
end
local r = string.len(s)
while string.sub(s,r,r) == ' ' do
r = r-1
end
while string.sub(s,r,r-1) == '\n' do
r = r-2
end
return string.sub(s,l,r)
end


function p.Main(frame)
function p.Main(frame)
local args = frame.args
local oArgs = frame:getParent().args
local args = {}
for k, v in pairs(oArgs) do
v = v:match('^%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
local i = 0
local i = 0
local gamesOrder = {
if args['active'] ~= nil then
    ['mt1'] = 2,
active = tonumber(trim(args['active']))
    ['mt2'] = 3,
else
    ['kmt'] = 4,
active = 1
    ['smt1'] = 5,
end
    ['smt2'] = 6,
    ['smtif'] = 7,
    ['smtn'] = 8,
    ['smt3'] = 9,
    ['smt3nm'] = 10,
    ['smtsj'] = 11,
    ['smtsjr'] = 12,
    ['smt4'] = 13,
    ['smt4a'] = 14,
    ['smt5'] = 15,
    ['smt5v'] = 16,
    ['gmt'] = 17,
    ['smti'] = 18,
    ['smtsp'] = 19,
    ['dsp'] = 20,
    ['kad'] = 21,
    ['smtj'] = 22,
    ['20xx'] = 23,
    ['dc20xx'] = 24,
    ['smtifh'] = 25,
    ['smttr'] = 26,
    ['smt2g'] = 27,
    ['dhz'] = 28,
    ['smtdc'] = 29,
    ['dx2'] = 30,
    ['lb1'] = 31,
    ['rds'] = 32,
    ['lb2'] = 33,
    ['lb3'] = 34,
    ['ab'] = 35,
    ['lbs'] = 36,
    ['slb1'] = 37,
    ['slb2'] = 38,
    ['slb3'] = 39,
    ['mjt1'] = 40,
    ['mjt2'] = 41,
    ['r'] = 42,
    ['mjtbt1'] = 43,
    ['mjtbt2'] = 44,
    ['desum'] = 45,
    ['sh1'] = 46,
    ['sh2'] = 47,
    ['sh1'] = 48,
    ['shed'] = 49,
    ['sh2'] = 50,
    ['dsrk1'] = 51,
    ['dsrk2'] = 52,
    ['smtpj'] = 53,
    ['shi'] = 54,
    ['shng'] = 55,
    ['mip'] = 56,
    ['rp'] = 57,
    ['p1'] = 58,
    ['p2is'] = 59,
    ['p2ep'] = 60,
    ['p3'] = 61,
    ['p3f'] = 62,
    ['p3p'] = 63,
    ['p3r'] = 64,
    ['p4'] = 65,
    ['p4g'] = 66,
    ['p5'] = 67,
    ['p5r'] = 68,
    ['p4a'] = 69,
    ['p4au'] = 70,
    ['pq1'] = 71,
    ['pq2'] = 72,
    ['p4d'] = 73,
    ['p3d'] = 74,
    ['p5d'] = 75,
    ['p5s'] = 76,
    ['p5t'] = 77,
    ['p5x'] = 78,
    ['pith'] = 79,
    ['qp3'] = 80,
    ['csp3'] = 81,
    ['p2tlm'] = 82,
    ['atfm'] = 83,
    ['p3m'] = 84,
    ['ipp3'] = 85,
    ['p3bs'] = 86,
    ['p2bim'] = 87,
    ['pmo'] = 88,
    ['p3s'] = 89,
    ['p3e'] = 90,
    ['p4c'] = 91,
    ['p4cb'] = 92,
    ['poa'] = 93,
    ['dcb'] = 94,
    ['dcr'] = 95,
    ['dcbr'] = 96,
    ['dcw'] = 97,
    ['dcl'] = 98,
    ['dcd'] = 99,
    ['dcld'] = 100,
    ['dcf'] = 101,
    ['dci'] = 102,
    ['dcfi'] = 103,
    ['dcpdc'] = 104,
    ['dcmr'] = 105,
    ['dcadc'] = 106,
    ['dcm'] = 107,
    ['dccg'] = 108,
    ['ddsat1'] = 109,
    ['ddsat2'] = 110,
    ['ats'] = 111,
    ['desu1'] = 112,
    ['desu1oc'] = 113,
    ['desu2'] = 114,
    ['desu2rb'] = 115,
    ['desu2ew'] = 116,
    ['jb'] = 117,
    ['smttc'] = 118,
    ['tms'] = 119,
    ['tmse'] = 120,
    ['jqat'] = 121
}
if args[1] and args[2] then
if args[1] and args[2] then
output = ''
local header = mw.html.create( 'div' ):addClass('g-tab-header')
local contents = mw.html.create( 'div' ):addClass('g-tab-contents')
repeat
repeat
output = output .. args[i+1] .. '&' .. args[i+2]
tab = mw.html.create( 'span' ):addClass('g-tab'):wikitext(trim(args[i+1]))
tabcontent = mw.html.create( 'div' ):addClass('g-tab-content'):wikitext('\n' .. trim(args[i+2]) .. '\n')
if active == (i + 2) * 0.5 then
tab = tab:addClass('g-tab-active')
tabcontent = tabcontent:addClass('g-tab-content-active')
end
header = header:node(tab)
contents = contents:node(tabcontent)
i = i + 2
i = i + 2
until args[i+1] == nil or args[i+2] == nil
until args[i+1] == nil or args[i+2] == nil
local child = mw.html.create( 'div' ):addClass(tab):wikitext('Tab')
local output = mw.html.create( 'div' ):addClass('g-tab-container'):node(header):node(contents)
local header = mw.html.create( 'div' ):addClass(tab-header):wikitext( 'Tab header' ):node(child):node(child)


return header
return output
else
else
return 'Values not filled.'
return 'Values not filled.'

Latest revision as of 22:05, 28 September 2024

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

local getArgument = require('Module:Arguments').getArgument

local p = {}

function trim(s) -- Allows removing of whitespace and line breaks from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html)
	local l = 1
	while string.sub(s,l,l) == ' ' do
	l = l+1
	end
	while string.sub(s,l,l+1) == '\n' do
	l = l+2
	end
	local r = string.len(s)
	while string.sub(s,r,r) == ' ' do
	r = r-1
	end
	while string.sub(s,r,r-1) == '\n' do
	r = r-2
	end
	return string.sub(s,l,r)
end

function p.Main(frame)
	local oArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(oArgs) do
		v = v:match('^%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	local i = 0
	if args['active'] ~= nil then
		active = tonumber(trim(args['active']))
	else
		active = 1
	end
	if args[1] and args[2] then
		local header = mw.html.create( 'div' ):addClass('g-tab-header')
		local contents = mw.html.create( 'div' ):addClass('g-tab-contents')
		repeat
			tab = mw.html.create( 'span' ):addClass('g-tab'):wikitext(trim(args[i+1]))
			tabcontent = mw.html.create( 'div' ):addClass('g-tab-content'):wikitext('\n' .. trim(args[i+2]) .. '\n')
			if active == (i + 2) * 0.5 then
				tab = tab:addClass('g-tab-active')
				tabcontent = tabcontent:addClass('g-tab-content-active')
			end
			header = header:node(tab)
			contents = contents:node(tabcontent)
			i = i + 2
		until args[i+1] == nil or args[i+2] == nil
		local output = mw.html.create( 'div' ):addClass('g-tab-container'):node(header):node(contents)

		return output
	else
		return 'Values not filled.'
	end
end

return p