Module:Tabber: Difference between revisions

From Coral Island Wiki
Jump to navigation Jump to search
(Created page with "-- Written by bitomic ---- Inspired by IZ*ONE Wiki w:c:iz-one:Template:Lyrics local p = {} function p.main( frame ) local args = frame:getParent().args return p.buildTabber( args ) end function p.buildTabber( args ) local frame = mw.getCurrentFrame() local infobox = mw.html.create( 'infobox' ):attr( 'theme', 'tabber' ) local panel = mw.html.create( 'panel' ) -- Because, apparently, you can't count args through `#args` local flag = true...")
 
(Copied from Coral Island Wiki)
Line 1: Line 1:
-- Written by [[User:Bitomic|bitomic]]
---- Inspired by IZ*ONE Wiki [[w:c:iz-one:Template:Lyrics]]
local p = {}
local p = {}
local lib = require('Module:Feature')


function p.main( frame )
function p.main(frame)
local args = frame:getParent().args
local args = require('Module:Arguments').getArgs(frame)
 
return p.buildTabber( args )
return p._main(args, frame)
end
end


function p.buildTabber( args )
function p._main(args, frame)
local frame = mw.getCurrentFrame()
if args == nil then return ''
local infobox = mw.html.create( 'infobox' ):attr( 'theme', 'tabber' )
elseif type(args) ~= 'table' then return args
local panel = mw.html.create( 'panel' )
end
frame = frame or mw.getCurrentFrame()
-- Because, apparently, you can't count args through `#args`
local tabber = mw.html.create('div'):addClass('wds-tabber')
local flag = true
local labels = mw.html.create():tag('ul'):addClass('wds-tabs wds-tabs__wrapper' .. (args.no_border == nil and ' with-bottom-border' or ''))
local contents = mw.html.create()
local i = 1
local i = 1
while flag do
local y = '1'
local tab_name = args[ 2 * i - 1 ]
local validTabs = 0
local tab_content = args[ 2 * i ]
local function addContent(container, content)
if tab_name and tab_content then
if type(content) == 'string' then
local section = createSection( tab_name, tab_content )
if args.nowiki then
panel:node( section )
local content =  
frame:preprocess(
i = i + 1
mw.text.decode(
else
mw.text.unstripNoWiki(
flag = false
content
)
)
)
container:wikitext(content) --plain string content encased in nowiki as to avoid bad mediawiki parsing
else
container:wikitext(content) --plain string content
end
elseif type(content) == 'table' and tostring(content) == 'table' then --table content
for _, subContent in ipairs(content) do
addContent(container, subContent)
end
elseif type(content) == 'table' then container:node(content) --html content
end
end
end
end
infobox:node( panel )
while (args[i] and args[i+1]) or (args['label' .. y] and args['content' .. y]) do
local label = args['label' .. y] or args[i]
return frame:preprocess( tostring( infobox ) )
local content = args['content' .. y] or args[i+1]
end
if lib.isNotEmpty(label) and lib.isNotEmpty(content) then
 
validTabs = validTabs + 1
function createSection( title, content )
labels
content = mw.text.trim( content )
:tag('li')
local section = mw.html.create( 'section' )
:addClass('wds-tabs__tab' .. (i==1 and ' wds-is-current' or ''))
local label = mw.html.create( 'label' ):wikitext( title )
:tag('div')
local header = mw.html.create( 'header' ):wikitext( title )
:addClass('wds-tabs__tab-label')
local data = mw.html.create( 'data' )
:wikitext(label)
local default = mw.html.create( 'default' ):wikitext( content )
data:node( default )
local contentContainer =  
section:node( label )
contents
section:node( header )
:tag('div')
section:node( data )
:addClass('wds-tab__content' .. (i==1 and ' wds-is-current' or ''))
addContent(contentContainer, content)
end
i = i + 2 --unnamed go in pairs
y = tostring(tonumber(y)+1)
end
if validTabs <2 then return (args['content1'] or args[2] or '') end
tabber:node(labels)
tabber:node(contents)
return section
return tabber
end
end


return p
return p

Revision as of 15:49, 30 December 2023

This module implements {{Tabber}}.


local p = {}
local lib = require('Module:Feature')

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)

	return p._main(args, frame)
end

function p._main(args, frame)
	if args == nil then return ''
	elseif type(args) ~= 'table' then return args
	end
	frame = frame or mw.getCurrentFrame()
	
	local tabber = mw.html.create('div'):addClass('wds-tabber')
	local labels = mw.html.create():tag('ul'):addClass('wds-tabs wds-tabs__wrapper' .. (args.no_border == nil and ' with-bottom-border' or ''))
	local contents = mw.html.create()
	local i = 1
	local y = '1'
	local validTabs = 0
	
	local function addContent(container, content)
		if type(content) == 'string' then
			if args.nowiki then
				local content = 
				frame:preprocess(
					mw.text.decode(
						mw.text.unstripNoWiki(
							content
						)
					)
				)
				container:wikitext(content) --plain string content encased in nowiki as to avoid bad mediawiki parsing
			else
				container:wikitext(content) --plain string content
			end
		elseif type(content) == 'table' and tostring(content) == 'table' then --table content 
			for _, subContent in ipairs(content) do
				addContent(container, subContent)
			end
		elseif type(content) == 'table' then container:node(content) --html content
		end
	end
	
	while (args[i] and args[i+1]) or (args['label' .. y] and args['content' .. y]) do
		local label = args['label' .. y] or args[i]
		local content = args['content' .. y] or args[i+1]
		if lib.isNotEmpty(label) and lib.isNotEmpty(content) then
			validTabs = validTabs + 1
			labels
				:tag('li')
					:addClass('wds-tabs__tab' .. (i==1 and ' wds-is-current' or ''))
					:tag('div')
						:addClass('wds-tabs__tab-label')
						:wikitext(label)
						
			local contentContainer = 
			contents
				:tag('div')
					:addClass('wds-tab__content' .. (i==1 and ' wds-is-current' or ''))
			addContent(contentContainer, content)
		end
		i = i + 2 --unnamed go in pairs
		y = tostring(tonumber(y)+1)
	end
	if validTabs <2 then return (args['content1'] or args[2] or '') end
	tabber:node(labels)
	tabber:node(contents)
	
	return tabber
end

return p