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) 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', { style = {				visibility = 'hidden',				position = 'relative',			}}) end end if files:match( ';' ) then images[1] = images[1]:gsub('^ ', ' ') local ret = string.wrapHtml( images, ' ', { class = 'animated', style = {			display = 'block',			position = 'absolute',			top = '0px',		}}) 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 return string.wrapHtml( ret, ' ', { style = {			position = 'relative',		}}) else return table.concat(images) end end

return p