Editing Module:Sprite
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local g = require("Module:Common") | |||
local | function p.calcSpriteSheetPos(index, spriteSize, sheetSize) | ||
local iconsOnRow = sheetSize / spriteSize | |||
return { | |||
top = -math.floor(index / iconsOnRow) * spriteSize, | |||
local | left = -math.mod(index, iconsOnRow) * spriteSize | ||
} | |||
end | |||
function p.makeSprite(image, index, spriteSize, sheetSize, link, title, align) | |||
local output = "<span style=\"position: relative; height: " | |||
output = output .. spriteSize .. "px; width: " | |||
local | output = output .. spriteSize .. "px; overflow: hidden; display: inline-block; vertical-align: " | ||
output = output .. (align or "middle") .. ";\"><span style=\"position: absolute; height: " | |||
if | output = output .. sheetSize .. "px; width: " .. sheetSize .. "px;" | ||
local spritePos = p.calcSpriteSheetPos(index, spriteSize, sheetSize) | |||
if spritePos.top ~= 0 then | |||
output = output .. "top: " .. spritePos.top .. "px;" | |||
end | end | ||
output = output .. "left: " .. spritePos.left .. "px;\">[[File:" .. image | |||
if g.isGiven(link) then | |||
output = output .. "|link=" .. link | |||
end | |||
if g.isGiven(title) then | |||
output = output .. "|" .. title | |||
end | |||
output = output .. "]]</span></span>" | |||
return output | |||
end | |||
function p.main(frame) | |||
local frame, args = g.getFrameAndArgs(frame) | |||
if not (g.isGiven(args.pos) and tonumber(args.pos)) then | |||
args.pos = 1 | |||
end | |||
if not (g.isGiven(args.size) and tonumber(args.size)) then | |||
args.size = 16 | |||
end | |||
if not (g.isGiven(args.sheetsize) and tonumber(args.sheetsize)) then | |||
args.sheetsize = 256 | |||
end | |||
return p.makeSprite(args.image, tonumber(args.pos) - 1, args.size, | |||
args.sheetsize, args.link, args.title, args.align) | |||
end | end | ||
return p | return p |