• Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:无畏契约导航条

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(frame, args)
end

function p._main(frame, args)
	-- 可选参数
	local center = args.center or ""     -- 容器居中
	local title = args.title or ""       -- 主标题
	local titleBg = args.titlebg         -- 主标题背景
	local titleColor = args.titlecolor   -- 主标题文本颜色
	local titleCss = args.titlecss or "" -- 主标题额外样式
	local bg = args.bg                   -- 全部元素背景
	local color = args.color             -- 全部元素文本颜色
	local css = args.css or ""           -- 全部元素样式
	local tBg = args.tbg                 -- 全部元素小标题背景
	local tColor = args.tcolor           -- 全部元素小标题文本颜色
	local tCss = args.tcss or ""         -- 全部元素小标题样式

	-- 构建容器
	local mainDiv = mw.html.create("div"):addClass("prog"):css("width", "max-content")
	local partsDiv = mw.html.create("div"):addClass("prog-main")

	-- 构建容器居中
	if center == "1" then
		mainDiv:css("margin", "0 auto")
	end

	-- 构建主标题
	if title ~= "" then
		local titleDiv = mw.html.create("div")
			:addClass("prog-title")
			:attr("style",
				(titleBg and "background:" .. titleBg .. ";" or "")
			 .. (titleColor and "color:" .. titleColor .. ";" or "")
			 .. titleCss
			)
			:wikitext(title)
		mainDiv:node(titleDiv)
	end

	-- 构建各元素
	local parts = {}

	for key, val in pairs(args) do
		if key:match("^part") then
			local partIndex = tonumber(key:match("%d+"))
			parts[partIndex] = {
				val = val,
				ty = args["type" .. partIndex] or "",           -- 元素类型
				bg = args["bg" .. partIndex] or bg,             -- 元素背景
				color = args["color" .. partIndex] or color,    -- 元素文本颜色
				css = args["css" .. partIndex] or css,          -- 元素样式
				detail = args["detail" .. partIndex] or "",     -- 元素内容
				tbg = args["tbg" .. partIndex] or tBg,          -- 元素小标题背景
				tcolor = args["tcolor" .. partIndex] or tColor, -- 元素小标题文本颜色
				tcss = args["tcss" .. partIndex] or tCss        -- 元素小标题样式
			}
		end
	end

	-- 按照索引顺序追加各元素
	for i = 1, #parts do
		if parts[i] then
			local part = parts[i]

			-- 构建元素容器
			local partDiv = mw.html.create("div")
				:addClass("prog-main-part")
				:attr("style",
					"clip-path: poly" .. "gon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%" .. (i == 1 and '' or ', 11px 50%') .. ");"
				 .. (part.bg and "background:" .. part.bg .. ";" or "")
				 .. (part.color and "color:" .. part.color .. ";" or "")
				 .. part.css
				)

			-- 构建含小标题的元素
			if part.ty == "d" then
				local titleDiv = mw.html.create("div")
					:addClass("prog-main-part-title")
					:attr("style",
						(part.tbg and "background:" .. part.tbg .. ";" or "")
					 .. (part.tcolor and "color:" .. part.tcolor .. ";" or "")
					 .. part.tcss
					)
					:wikitext(part.val)
				partDiv:node(titleDiv)

				local detailDiv = mw.html.create("div")
					:addClass("prog-main-part-detail")
					:wikitext(part.detail)
				partDiv:node(detailDiv)

			-- 构建一般元素
			else
				partDiv:node(mw.html.create("div")
					:addClass("prog-main-part-content")
					:wikitext(part.val))
			end

			partsDiv:node(partDiv)
		end
	end

	return mainDiv:node(partsDiv)
end

return p