如果你看到本段文字,说明该页面未正常加载全局JS,部分功能将无法使用,请点击 刷新 重新加载页面。
全站通知:
模块:Gallerygrid
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Gallerygrid/doc创建
local p = {};
local getArgs = require('Module:Arguments').getArgs;
function p.render(frame)
-- 解决参数无法传递到模板的问题
local option = {parent = true}
local args = getArgs(frame, option);
local parsedArgs = {}
local itemArray = {}
-- 处理编号参数--
for i, v in ipairs(args) do itemArray[i] = v end
-- 拼html
local grid = {
["widths"] = args.widths or "240px",
["heights"] = args.heights or "120px",
["thumbsize"] = args.thumbsize or "240px",
["gap"] = args.gap or "16px",
["template"] = args.template or "default",
["fit"] = args.fit or "cover"
}
grid["open"] =
"<div class='gallerygrid' style='display: grid;grid-template-columns: repeat(auto-fill," ..
grid.widths .. ");grid-gap:" .. grid.gap .. ";--gallerygrid-fit:"..grid.fit..";'>";
grid["close"] = "</div>"
-- 准备元素
grid["items"] = "";
for i, v in ipairs(itemArray) do
itemArgs = splitArgs(v);
grid["items"] = grid["items"] .. frame:expandTemplate{
--取template参数选择相应的输出模板。
title = "Gallerygrid/"..grid.template,
args = {
filename = itemArgs[1],
text = itemArgs[2],
width = grid.widths,
height = grid.heights
}
}
end
local outputText = grid["open"] .. grid["items"] .. grid["close"]
-- debug
local output = ""
for i, v in ipairs(itemArray) do
output = output .. i .. "=" .. mw.text.nowiki(v) .. ";<br />"
end
return outputText
end
function splitArgs(str)
local itemArgs = mw.text.split(str, "::", true);
return itemArgs
end
return p