Difference between revisions of "Module:Animated"
Jump to navigation
Jump to search
m |
m |
||
Line 49: | Line 49: | ||
}) | }) | ||
− | local names = args[1] | + | local names = {} |
− | + | local counts = {} | |
+ | if args[1] then | ||
+ | string.gsub(args[1], "([^,]+)", function(name) names[#names + 1] = name end) | ||
+ | end | ||
+ | if args[2] then | ||
+ | string.gsub(args[2], "([^,]+)", function(count) counts[#counts + 1] = count end) | ||
+ | end | ||
for i, name in ipairs(names) do | for i, name in ipairs(names) do | ||
local span = p.createImageSpan() | local span = p.createImageSpan() | ||
Line 61: | Line 67: | ||
local count = counts[i] | local count = counts[i] | ||
if count then | if count then | ||
+ | count = string.match(count, '^%s*(.-)%s*$') | ||
span:node( | span:node( | ||
HtmlBuilder.create('span') | HtmlBuilder.create('span') |
Revision as of 06:22, 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 = {} local counts = {} if args[1] then string.gsub(args[1], "([^,]+)", function(name) names[#names + 1] = name end) end if args[2] then string.gsub(args[2], "([^,]+)", function(count) counts[#counts + 1] = count end) end 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 count = string.match(count, '^%s*(.-)%s*$') 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