Difference between revisions of "Module:Animated"
Jump to navigation
Jump to search
m |
m |
||
Line 16: | Line 16: | ||
function p._images(args) | function p._images(args) | ||
local size = args.size or args[2] | local size = args.size or args[2] | ||
− | local | + | local animatedDiv = createAnimatedDiv({ |
size = size, | size = size, | ||
background = args.background, | background = args.background, | ||
Line 25: | Line 25: | ||
local input = args[1] | local input = args[1] | ||
for name in string.gmatch(input, '([^,]+)') do | for name in string.gmatch(input, '([^,]+)') do | ||
− | local | + | local div = createImageDiv() |
− | + | animatedDiv:node(div) | |
name = string.match(name, '^%s*(.-)%s*$') | name = string.match(name, '^%s*(.-)%s*$') | ||
if name ~= '' then | if name ~= '' then | ||
− | + | div:wikitext('[[File:', name) | |
if size then | if size then | ||
− | + | div:wikitext('|', size) | |
end | end | ||
− | + | div:wikitext('|link=File:', name, ']]') | |
end | end | ||
end | end | ||
− | return tostring( | + | return tostring(animatedDiv) |
end | end | ||
function p._grid(args) | function p._grid(args) | ||
− | local | + | local animatedDiv = createAnimatedDiv({ |
size = '32px', | size = '32px', | ||
background = '#888', | background = '#888', | ||
Line 58: | Line 58: | ||
end | end | ||
for i, name in ipairs(names) do | for i, name in ipairs(names) do | ||
− | local | + | local div = createImageDiv() |
− | + | animatedDiv:node(div) | |
name = string.match(name, '^%s*(.-)%s*$') | name = string.match(name, '^%s*(.-)%s*$') | ||
if name ~= '' then | if name ~= '' then | ||
− | + | div:wikitext('[[File:', name, '.png|32px|link=', name, ']]') | |
local count = counts[i] | local count = counts[i] | ||
if count then | if count then | ||
count = string.match(count, '^%s*(.-)%s*$') | count = string.match(count, '^%s*(.-)%s*$') | ||
− | + | ||
+ | div:node( | ||
HtmlBuilder.create('span') | HtmlBuilder.create('span') | ||
:css('position', 'relative') | :css('position', 'relative') | ||
Line 81: | Line 82: | ||
end | end | ||
− | return tostring( | + | return tostring(animatedDiv) |
end | end | ||
− | function | + | local function createAnimatedDiv(args) |
local size = args.size | local size = args.size | ||
local background = args.background | local background = args.background | ||
Line 90: | Line 91: | ||
local padding = args.padding | local padding = args.padding | ||
− | local | + | local div = HtmlBuilder.create('div'):addClass('animated') |
if size then | if size then | ||
− | + | div:css('width', size) | |
− | + | div:css('height', size) | |
end | end | ||
if background then | if background then | ||
− | + | div:css('background-color', background) | |
end | end | ||
if border then | if border then | ||
− | + | div:css('border', border) | |
end | end | ||
if padding then | if padding then | ||
− | + | div:css('padding', padding) | |
end | end | ||
− | return | + | return div |
end | end | ||
− | function | + | local function createImageDiv() |
− | return HtmlBuilder.create(' | + | return HtmlBuilder.create('div'):addClass('image') |
end | end | ||
return p | return p |
Revision as of 06:33, 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 animatedDiv = createAnimatedDiv({ size = size, background = args.background, border = args.border, padding = args.padding })
local input = args[1] for name in string.gmatch(input, '([^,]+)') do local div = createImageDiv() animatedDiv:node(div)
name = string.match(name, '^%s*(.-)%s*$') if name ~= then div:wikitext('[[File:', name) if size then div:wikitext('|', size) end div:wikitext('|link=File:', name, ']]') end end
return tostring(animatedDiv)
end
function p._grid(args)
local animatedDiv = createAnimatedDiv({ 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 div = createImageDiv() animatedDiv:node(div)
name = string.match(name, '^%s*(.-)%s*$') if name ~= then div:wikitext('32px')
local count = counts[i] if count then count = string.match(count, '^%s*(.-)%s*$')
div: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(animatedDiv)
end
local function createAnimatedDiv(args)
local size = args.size local background = args.background local border = args.border local padding = args.padding
local div = HtmlBuilder.create('div'):addClass('animated') if size then div:css('width', size) div:css('height', size) end if background then div:css('background-color', background) end if border then div:css('border', border) end if padding then div:css('padding', padding) end
return div
end
local function createImageDiv()
return HtmlBuilder.create('div'):addClass('image')
end
return p