Module:Animate

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno, itemVariants = loader.require('String', 'Table', 'Yesno', 'Item/Variants')

local p = {}

- -- Template: Animate -- -- Creates a cycling animation. - local function appendPNG(image) if not(image:match('%.%a%a%a?%a?')) then image = image..".png" end image = image:gsub('^File:','') return image end

function p.animate(frame) local args = getArgs(frame) local files = args[1] or '' local size = args[2] or '' local link = args.link or args[3] or '' local class = args.class or '' local fixed = yesno(args.fixed, true) local caption = args.caption if files:match("UNIQ%-%-gallery") then return files end if size ~= '' then size = '|' .. size end if link ~= '' then link = '|link=' .. link end if class ~= '' then class = '|class=' .. class end local images = {} local firstimg files = table.concat(table.map(string.split(files, '%s*;%s*'), function(s) local t = itemVariants[s] or {s} return table.concat(t,';') end),';') for image in string.gsplit(files, '%s*;%s*') do		if image == '' then table.insert(images, string.wrapTag(' ', 'span')) else table.insert(images, string.wrapTag(string.makeLink{ "File:", appendPNG(image), size, link, class }, 'span')) end if not firstimg then firstimg = string.wrapHtml(string.makeLink{ "File:", appendPNG(image), size, link, class }, 'span', { class = 'infobox-fakeimage' }) end end local ret if files:match( ';' ) then images[1] = images[1]:gsub('^ ', ' ') ret = string.wrapHtml( images, ' ', { class = 'animated' }) if fixed then ret = firstimg .. ret -- firstimg is a ghost image, it expands the box to a fixed size when there is momentarily no image end ret = string.wrapHtml( ret, 'div', { class = 'infobox-animated-wrapper' }) else ret = table.concat(images) end if caption then ret = ret .. string.wrapHtml(caption, 'div', { class = 'pi-item-spacing pi-caption' }) end return ret end

return p