Difference between revisions of "Module:Animated"
Jump to navigation
Jump to search
(Created page with "local p = {} local getArgs = require('Module:Arguments').getArgs function p.images(frame) local args = getArgs(frame, {inherited = true}) return p._images(args) end ...") |
m (Replaced newer mw.html with HtmlBuilder) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
+ | local HtmlBuilder = require('Module:HtmlBuilder') | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
Line 61: | Line 62: | ||
if count then | if count then | ||
span:node( | span:node( | ||
− | + | HtmlBuilder.create('span') | |
:css('position', 'relative') | :css('position', 'relative') | ||
:css('top', '-16px') | :css('top', '-16px') | ||
Line 82: | Line 83: | ||
local padding = args.padding | local padding = args.padding | ||
− | local span = | + | local span = HtmlBuilder.create('span'):addClass('animated') |
if size then | if size then | ||
span:css('width', size) | span:css('width', size) | ||
Line 101: | Line 102: | ||
function p.createImageSpan() | function p.createImageSpan() | ||
− | return | + | return HtmlBuilder.create('span'):addClass('image') |
end | end | ||
return p | return p |
Revision as of 05: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 = mw.text.trim(args[1]) for name in mw.text.gsplit(input, '%s*,%s*') do local span = createImageSpan() animatedSpan:node(span)
name = mw.text.trim(name) 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 mw.text.split(mw.text.trim(args[1]), '%s*,%s*') or {} local counts = args[2] and mw.text.split(mw.text.trim(args[2]), '%s*,%s*') or {} for i, name in ipairs(names) do local span = createImageSpan() animatedSpan:node(span)
name = mw.text.trim(name) 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