Module:Mark
La documentation pour ce module peut être créée à Module:Mark/Documentation
--
-- This module allows the positionning of a mark at and arbitrary position on a div.
-- Depending on the type of the mark (↑ or ↓), it may have a different center .
-- The module will compute the correct coordinates so the mark appears where
-- the user wants it to be.
--
local p = {} -- p stands for package
local function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function p.display( frame )
-- If frame was not provided, this code is being debugged.
args = frame and frame.args or {size = 40, mark = '→', x = '230', y = '170', content = 'foo', color = 'red'}
size = tonumber(args.size)
mark = args.mark
local offsetX = 0
local offsetY = 0
--Convert character patterns to marks
if(mark == '->')then mark = '→'
elseif(mark == '<-')then mark = '←' end
-- Adjust the offset according to the mark.
if(mark == '↑') then
offsetX = size / 2
elseif(mark == '↓') then
offsetX = size / 2
offsetY = size
elseif(mark == '←') then
offsetY = size / 2
elseif(mark == '→') then
offsetX = size
offsetY = size / 2
else -- For all other symbols (O, X, etc.) use coordinates relative to their center.
offsetX = size / 2
offsetY = size / 2
end
x = round(tonumber(args.x) - (offsetX * 25 / 40), 0) -- Adjust according to the ratio of the monospace font.
y = round(tonumber(args.y) - (offsetY), 0)
return -- Use a monospace font so all characters are the same width.
'<div style="position: relative">'..
'<span style="font-family: monospace; float: right; color: '..args.color..'; font-size: '..size..'px; position: absolute; line-height: 1em; left: '..x..'px; top: '..y..'px; z-index: 100">'..mark..'</span>'..
args.content..
'<!--OffsetX:'..offsetX..' / OffsetY:'..offsetY..'-->'..
'</div>'
end
return p