-- <nowiki>
local p = {}
local ne = require('Module:Feature').isNotEmpty
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrappers = {'Template:Preview'}
})
return p._main(args)
end
function p._main(args)
local result = mw.html.create():tag('div'):addClass('preview')
if (args.class) then result:addClass(args.class) end
local gallery = mw.html.create():tag('div'):addClass('preview-gallery caption-center')
if (args.file or args.f or args.file1 or args.f1 or args[1]) then
p.GalleryItem((args.file or args.f or args.file1 or args.f1 or args[1]), (args.caption or args.c or args.caption1 or args.c1 or args[2]), args.size, gallery)
local y = 2
while (args['file' .. tostring(y)] or args['f' .. tostring(y)]) do
p.GalleryItem((args['file' .. tostring(y)] or args['f' .. tostring(y)]), (args['caption' .. tostring(y)] or args['c' .. tostring(y)]), args.size, gallery)
y = y + 1
end
if args.notip then
return result:node(gallery)
else
return result
:tag('div'):addClass('hidden looppreview-hover-label')
:tag('i'):wikitext('Hover over previews to view in higher quality.'):done()
:done()
:tag('div'):addClass('hidden looppreview-hover-preference')
:tag('small'):wikitext('([[Special:Preferences#mw-prefsection-gadgets|Preview Preferences]])'):done()
:done()
:node(gallery)
end
else
return result:tag('i'):wikitext('No preview available')
end
end
function p.GalleryItem(file, caption, size, container)
size = size or '380px'
caption = caption or ''
local attr = { ['data-size'] = size }
local w, h = string.match(size, '^(%d+)x(%d+)px$')
if w and h then
attr = { ['data-width'] = w .. 'px', ['data-height'] = h .. 'px' }
end
container:tag('span'):addClass('preview-gallery-item'):tag('span'):addClass('looppreview')
:tag('div'):addClass('video hidden mobileHide'):attr(attr)
:wikitext('[[Media:',file,'.mp4]]')
:done()
:wikitext('[[File:', file, '.gif|', size, '|center|thumb|', caption, ']]')
-- container reference is updated, no need to return.
end
return p