Module:Overfloat image
Appearance
This module depends on the following other modules: |
This module uses TemplateStyles: |
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local group_indexed_args = require('Module:Indexed arguments').group_indexed_args
local table_style = require('Module:Table style')._main
local function _overfloat_image(args)
-- container div
local container_styles = {}
if args.width then
container_styles['width'] = args.width .. 'px'
end
local container_div = mw.html.create('div')
:addClass('wst-overfloat-image')
:css(container_styles)
:wikitext(args.image)
local cats = {}
-- items
local indexed_args = group_indexed_args(args, {first_index_aliases = {'item', 'hpos', 'x', 'vpos', 'y'}})
for i, item_args in ipairs(indexed_args) do
local item_styles = {}
local hpos = 'left'
if item_args.hpos == 'r' or item_args.hpos == 'right' then
hpos = 'right'
end
local vpos = 'top'
if item_args.vpos == 'b' or item_args.vpos == 'bottom' then
vpos = 'bottom'
end
local x = tonumber(item_args.x)
local y = tonumber(item_args.y)
local width = tonumber(item_args.width)
local height = tonumber(item_args.height)
local border = tonumber(item_args.border)
if x then
item_styles[hpos] = x .. 'px'
end
if y then
item_styles[vpos] = y .. 'px'
end
if width then
item_styles['width'] = width .. 'px'
end
if height then
item_styles['height'] = height .. 'px'
end
if border then
item_styles['border'] = border .. 'px'
end
local item_el = container_div:tag('div')
:addClass('wst-overfloat-image-' .. hpos .. ' wst-overfloat-image-' .. vpos)
:css(item_styles)
if item_args.ts then
item_el = item_el:tag('table'):tag('tr'):tag('td')
:cssText(table_style({item_args.ts, nowrapper = true}))
if height then
item_el:css({['height'] = (height - 8) .. 'px'})
end
table.insert(cats, '[[Category:' .. 'Overfloat image with table style' .. ']]')
end
item_el:wikitext(item_args.item)
end
container_div:wikitext(table.concat(cats))
return container_div
end
function p.overfloat_image(frame)
return _overfloat_image(getArgs(frame))
end
return p