Module:Overlay
Appearance
![]() | This module depends on the following other modules: |
Implements {{Overlay}}
local p = {}
local mArguments = require('Module:Arguments')
local function buildimage(n, lk, f, c, t)
local res = ''
if (f == 'color' or f == 'colour') then
res = '<span title="' .. t .. 'style="background-color:' .. c .. '"> </span>'
if( lk ~= '' ) then
res = '[[' .. lk .. '|' .. res .. ']]'
end
elseif (f == 'text') then
res = '<span title="' .. t .. 'style="font-weight:bold; font-size:85%; color:' .. c .. '">' .. n .. '</span>'
if( link ~= '' ) then
res = '[[' .. lk .. '|' .. res .. ']]'
end
else
t = (lk ~= '') and ('link=' .. lk .. '|' .. t) or t
res = '[[File:' .. n .. 'white, ' .. c .. 'rounded rectangle.svg|50x' .. ((n < 10) and 13 or 12) .. 'px|' .. t .. ']]'
end
return res
end
function p.main(frame)
local args = mArguments.getArgs(frame)
local image = args['image'] or ''
local width = tonumber(args['width'] or '500') or 500
local height = tonumber(args['height'] or '500') or 500
local columns = tonumber(args['columns'] or '3') or 3
local grid = (args['grid']:lower() == 'yes') and 'yes' or 'no'
local legendbox = (args['legendbox']:lower() == 'no') and 'no' or 'yes'
local overlay = (image == '') and 'no' or ( (args['overlay']:lower() == 'no') and 'no' or 'yes' )
local float = args['float'] or 'center'
local border = (args['border']:lower() == 'no') and 'no' or 'yes'
-- create the root table
local root = mw.html.create('table')
if float == 'center' or float == 'centre' then
root:css('margin-left', 'auto')
:css('margin-right', 'auto')
else
root:css('float', float)
end
if border == 'yes' then
root:css('border', '1px #ccc solid')
end
if image ~= '' then
local cell = root:tag('tr'):tag('td')
cell:css('text-align', 'center')
if( columns > 1 and legendbox == 'yes' ) then
cell:attr('colspan', columns)
end
if grid == 'yes' then
local div = cell:tag('div')
div:css('position','relative')
:css('left', '0px')
:css('top', '0px')
:css('width', '940px')
:css('height', '940px')
div:tag('span')
:css('position', 'absolute')
:css('left', '0px')
:css('top', '0px')
:css('z-index', '2')
:wikitext('[[File:Grid 99, 100 int red 50 int yellow (940).svg|940px]]')
local imagediv = cell:tag('div')
imagediv:css('position', 'relative')
:css('left', '0px')
:css('top', '0px')
:css('width', width .. 'px')
:css('height', height .. 'px')
imagediv:tag('span')
:css('position', 'absolute')
:css('left', '0px')
:css('top', '0px')
:css('z-index', '0')
:wikitext('[[File:' .. image '|' .. width .. 'x' .. height .. 'px]]')
if overlay == 'yes' then
local colori = args['color'] or args['colour'] or 'red'
for i=1,50 do
colori = args['overlay' .. i .. 'color'] or args['overlay' .. i .. 'colour'] or colori
local linki = args['overlay' .. i .. 'link'] or ''
local formi = args['overlay' .. i ..'form'] or ''
local tipi = args['overlay' .. i .. 'tip'] or ''
local overlayi = args['overlay' .. i] or ''
local imagei = (overlayi ~= '' or tipi ~= '')
and buildimage(i, linki, formi, colori, tipi) or ''
for j=1,3 do
if args['overlay' .. i .. 'left' .. j] then
imagediv:tag('span')
:css('position', 'absolute')
:css('left', (args['overlay' .. i .. 'left' .. j] or '') .. px)
:css('top', (args['overlay' .. i .. 'top' .. j] or '') .. px)
:css('z-index', '1')
:wikitext(imagei)
end
end
end
end -- end if overlay
end
end
return tostring(root)
end
return p