目前各个板块正在施工制作,现无法确定正式上线时间

全站通知:

模块:选项卡面板

来自我的世界潜行者WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:选项卡面板/doc创建

local p = {}

local html = {}
html.begin = [[<div class="panel %s">]]		--panel-primary
html.begin_head = [[<ul class="panel-heading nav nav-tabs" role="tablist" style="margin: -0.5px -1px 0;padding: 0.5px 1px 0;">]]
html.tab_label = [[
<li role="presentation" %s>
<span data-target="#%s" role="tab" data-toggle="tab" class="panel-title" style="font-weight:bold;padding:7px 5px;%s">%s</span></li>
]]
html.end_head = [[</ul>]]
html.begin_body = [[<div class="panel-body tab-content" style="padding:3px;">]]
html.begin_pane = [[<div role="tabpanel" class="tab-pane%s" id="%s">]]
html.end_pane = [[</div>]]
html.end_body = [[</div>]]
html.end_html = [[</div>]]

p.html = html

--------------------------------------------------
-- 主要过程
--------------------------------------------------
--[[
{{#invoke: 选项卡面板| 解析
| 样式=primary
| 标签样式=
| 标签1=商船护送
| 标签2=海域突进
| 选中=2
| ID1=shangchuan
| ID2=haiyu
| 内容1=【商船护送】相关内容
| 内容2=【海域突进】相关内容
}}	]]
--解析参数列表
function ParseArguments(frame)
	local data = {}
	data.theme = frame.args['样式'] or frame.args['主题']
	data.label_style = frame.args['标签样式']
	local selected = tonumber(frame.args['选中'] or 1) or 1
	
	local i = 1
	local labelN = '标签'..i
	while frame.args[labelN] do
		data[i] = {
			title = frame.args[labelN],
			text = frame.args['内容'..i],
			id = frame.args['Id'..i] or frame.args['ID'..i],
			active = i == selected
		}
		i = i + 1
		labelN = '标签'..i
	end
	
	return data
end

--解析一个包含全部信息的表格,并生成整个面板
function GenerateWholePanel(data)
	local result = GeneratePanelBegin(data)
	for i, v in ipairs(data) do
		result = result .. GenerateContentBegin(i,v.id,v.active)
		result = result .. v.text
	end
	result = result.. GenerateEnd()
	return result
end
p.GenerateWholePanel = GenerateWholePanel

--生成面板开头
function GeneratePanelBegin(data)
	local result = html.begin:format(
			'panel-'..(data.theme or 'primary'))
	result = result..html.begin_head
	
	for i, v in ipairs(data) do
		result = result .. html.tab_label:format(
			v.active and 'class="active"' or '', 
			generateId(v.id,i),
			data.label_style or 'font-weight:bolder;',
			v.title or '标签'..i
		)
	end
	result = result..html.end_head
	return result
end

--生成面板内容开始的部分
function GenerateContentBegin(index, id, active)
	local result = index == 1 
				and html.begin_body
				or html.end_pane
	result = result .. html.begin_pane:format(
					active and ' active' or '',
					generateId(id, index) )
	return result
end

--生成面板最终结尾
function GenerateEnd()
	return html.end_pane..html.end_body..html.end_html
end

--------------------------------------------------
-- 函数入口
--------------------------------------------------
p['解析'] = function(frame)
	local data = ParseArguments(frame)
	return GenerateWholePanel(data)
end

--[[
{{#invoke: 选项卡面板| 开始
| 样式=primary
| 标签样式=
| 标签1=商船护送
| 标签2=海域突进
| 选中=2
| ID1=shangchuan
| ID2=haiyu
}}	]]
p['开始'] = function(frame)
	local data = ParseArguments(frame)
	return GeneratePanelBegin(data)
end

--{{#invoke:选项卡面板| 开始内容|1| ID=shangchuan|选中=1}}
p['开始内容'] = function(frame)
	local index = tonumber(frame.args[1] or '')
	if not index then return '' end
	
	local selected = frame.args['选中'] 
	for j = 1, 5 do
		if selected then break end
		selected = frame.args[j] and frame.args[j]:match('选中')
	end
	
	return GenerateContentBegin(
		index,
		frame.args['Id'] or frame.args['ID'] or frame.args[2],
		selected
		)
end

--{{#invoke:选项卡面板|结束}}
p['结束'] = GenerateEnd

--测试函数
p['测试'] = function(frame)
	local foo = p[frame.args[1]]
	mw.log(frame.args[1], foo)
	frame.args[1] = frame.args[2]
	mw.log(frame.args[1], frame.args[2])
	local buff = foo(frame):gsub('<','&lt;'):gsub('>','&gt;')
	return '<nowiki>'..buff..'</nowiki>'
end
--------------------------------------------------
-- 工具函数
--------------------------------------------------
function generateId(text, index)
	text = text and text ~= '' and text:lower() or tostring(index)
	return 'TbPn-'..text;
end


return p