置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Mininav

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
local p = {}
local getArgs = require('module:arguments').getArgs

function p.box(frame)
	local args = getArgs(frame)
	local styles = args[1] == 'child' and '' or frame:extensionTag{name = 'templatestyles', args = {src = 'mininav/style.css'}}
	local div = _box(args, frame):newline()
	local i = 1
	local v = args['list'..i]
	while v do
		div:wikitext(v)
			:newline()
		i = i + 1
		v = args['list'..i]
	end
	return styles..tostring(div)
end

function p.container(frame)
	local args = getArgs(frame)
	local styles = frame:extensionTag{name = 'templatestyles', args = {src = 'mininav/style.css'}}
	local div = _box(args, frame)
	local content = div:tag('div')
		:addClass('mw-collapsible-content')
	local i = 1
	local v = args['list'..i]
	while v do
		content:wikitext(v)
		i = i + 1
		v = args['list'..i]
	end
	return styles..tostring(div)
end

function navbar(frame, name)
	local div = mw.html.create('div')
		:addClass('noprint plainlinks navbar nomobile')
		:wikitext('[[template:'..name..'|<span title="-{zh-hans:查看;zh-hant:檢視}-这个模板">查</span>]] · '..
			'[[template talk:'..name..'|<span title="关于这个模板的讨论页面">论</span>]] · '..
			'['..frame:callParserFunction{name = 'fullurl', args = {'template:'..name, 'action=edit'}}..
			'<span title="您可以编辑这个模板。请在储存变更之前先预览">编</span>]')
	return tostring(div)
end

function _box(args, frame)
	local div = mw.html.create('div')
		:attr{id = args.id, class = args.class}
		:addClass('navbox')
		:tag('div')
			:addClass('navbox-title')
			:wikitext(args[1] == 'child' and '' or navbar(frame, args.name))
			:wikitext(args.title or '')
			:done()
	local state = args.state
	if state ~= 'plain' and state ~= 'off' then
		div:addClass('mw-collapsible')
			:addClass(state)
	end
	return div
end

function p.group(frame)
	local args = getArgs(frame, {removeBlanks = false})
	local text = '<div class="mw-collapsible-content">\n{|class="'
	local state = args.state
	local isTitled = args.title and args.title ~= ''
	if not isTitled then
		state = 'off'
	end
	if state ~= 'plain' and state ~= 'off' then
		text = text..'mw-collapsible '..(state or '')..' '
	end
	text = text..(args.class or '')..'"'
	if args.id and args.id ~= '' then
		text = text..' id="'..args.id..'"'
	end
	text = text..(args.style and ' style="'..args.style..'"' or '')..'\n'
	if isTitled then
		text = text..'|+class="navbox-title"'..
			(args.titlestyle and ' style="'..args.titlestyle..'"' or '')..
			'|'..args.title..'\n'
	end
	return text.._subgroup(args)..'|}</div>'
end

function p.subgroup(frame)
	local args = getArgs(frame, {removeBlanks = false})
	return mw.ustring.sub(_subgroup(args, true), 2)
end

function _subgroup(args, flag)
	local text = ''
	local i = 1
	local v = args['group'..i]
	local attr = 'class="navbox-'..(flag and 'sub' or '')..'group"'
	while v do
		local u = args['list'..i] or ''
		local _, count = mw.ustring.gsub(u, '\n%|%-\n+|%w', '\n%|%-\n+|%w')
		if count > 0 then
			text = text..'|rowspan='..(count + 1)..' '..attr
		else
			text = text..'|'..attr
		end
		local style = args['groupstyle'..i] or args.groupstyle
		if style and style ~= '' then
			text = text..' style="'..style..'"'
		end
		text = text..'|'..v..'\n|'..u..'\n\|-\n'
		i = i + 1
		v = args['group'..i]
	end
	return text
end

return p