模块:Carousel
此模块的文档可以在模块:Carousel/doc创建
local p = {}
function p.render(frame)
local params = {}
if frame:getParent() ~= nil
then
frame = frame:getParent()
end
local liParams = parseLiParams(frame)
if #liParams == 0 then
return ''
end
params.id = genId()
if frame.args['interval'] then
params.interval = frame.args['interval']
else
params.interval = '5000'
end
if frame.args['width'] then
params.width = frame.args['width']
else
params.width = ''
end
params.li = {}
local index = 1
while index < #liParams do
local liIndex = math.ceil(index/2)
params.li[liIndex] = {}
params.li[liIndex].image=liParams[index]
params.li[liIndex].caption=liParams[index+1]
index = index + 2
end
params.li[1].active = 'active'
return mw.ext.mustache.render('Carousel', params, mw.ext.mustache.PARSE_ARGS)
end
function parseLiParams(frame)
local index = 1
local parsedParams = {}
while frame.args[index] ~= nil do
local continue = false
repeat
if frame.args[index] == '' then
if index % 2 == 0 then
parsedParams[#parsedParams] = nil
else
index = index + 1
end
index = index + 1
continue = true
break;
end
parsedParams[#parsedParams + 1] = frame.args[index]
index = index + 1
continue = true
until true
if not continue then
break
end
end
return parsedParams
end
function genId()
return 'carousel-' .. os.clock() * 1e9
end
return p