Difference between revisions of "Module:Animated"
Jump to navigation
Jump to search
m |
m |
||
Line 49: | Line 49: | ||
}) | }) | ||
− | local names = args[1] and string. | + | local names = args[1] and string.match(args[1], '([^,]+)') or {} |
− | local counts = args[2] and string. | + | local counts = args[2] and string.match(args[2], '([^,]+)') or {} |
for i, name in ipairs(names) do | for i, name in ipairs(names) do | ||
local span = p.createImageSpan() | local span = p.createImageSpan() |
Revision as of 06:09, 9 April 2017
local p = {}
local HtmlBuilder = require('Module:HtmlBuilder') local getArgs = require('Module:Arguments').getArgs
function p.images(frame)
local args = getArgs(frame, {inherited = true}) return p._images(args)
end
function p.grid(frame)
local args = getArgs(frame, {inherited = true}) return p._grid(args)
end
function p._images(args)
local size = args.size or args[2] local animatedSpan = p.createAnimatedSpan({ size = size, background = args.background, border = args.border, padding = args.padding })
local input = args[1] for name in string.gmatch(input, '([^,]+)') do local span = p.createImageSpan() animatedSpan:node(span)
name = string.match(name, '^%s*(.-)%s*$') if name ~= then span:wikitext('[[File:', name) if size then span:wikitext('|', size) end span:wikitext('|link=File:', name, ']]') end end
return tostring(animatedSpan)
end
function p._grid(args)
local animatedSpan = p.createAnimatedSpan({ size = '32px', background = '#888', border = '1px solid #333', padding = args.padded and '10px' or nil })
local names = args[1] and string.match(args[1], '([^,]+)') or {} local counts = args[2] and string.match(args[2], '([^,]+)') or {} for i, name in ipairs(names) do local span = p.createImageSpan() animatedSpan:node(span)
name = string.match(name, '^%s*(.-)%s*$') if name ~= then span:wikitext('32px')
local count = counts[i] if count then span:node( HtmlBuilder.create('span') :css('position', 'relative') :css('top', '-16px') :css('left', '25px') :css('font-weight', 'bold') :css('color', 'white') :css('text-shadow', '1px 1px black') :wikitext(count)) end end end
return tostring(animatedSpan)
end
function p.createAnimatedSpan(args)
local size = args.size local background = args.background local border = args.border local padding = args.padding
local span = HtmlBuilder.create('span'):addClass('animated') if size then span:css('width', size) span:css('height', size) end if background then span:css('background-color', background) end if border then span:css('border', border) end if padding then span:css('padding', padding) end
return span
end
function p.createImageSpan()
return HtmlBuilder.create('span'):addClass('image')
end
return p