Module:Image area: Difference between revisions
Jump to navigation
Jump to search
bleh |
No edit summary |
||
| Line 31: | Line 31: | ||
caption = mw.title.getCurrentTitle().subpageText .. ' within ' .. args[1] | caption = mw.title.getCurrentTitle().subpageText .. ' within ' .. args[1] | ||
end | end | ||
local | local margin = args.margin | ||
if not margin or margin == '' then | |||
margin = 'unset' | |||
end | |||
local newWidth = tonumber(args['new width']) | local newWidth = tonumber(args['new width']) | ||
local newHeight = tonumber(args['new height']) | local newHeight = tonumber(args['new height']) | ||
| Line 65: | Line 68: | ||
['overflow'] = 'hidden', | ['overflow'] = 'hidden', | ||
['border'] = '1px solid #EEE', | ['border'] = '1px solid #EEE', | ||
['margin'] = margin, | |||
}) | }) | ||
:done() | :done() | ||
Latest revision as of 23:32, 26 November 2025
Documentation [edit]
This page is a stub - it only covers the very basics of its subject. More information should be added to make the page informative and useful. If no more information is available, the page should be considered for a merge, redirect, or deletion.
Details: documentation to be written
If you can correct the issue, please edit the page to do so, then remove this notice.
Please see Template:Image area for usage information. Use the template rather than invoking the module.Details: documentation to be written
If you can correct the issue, please edit the page to do so, then remove this notice.
The above documentation is transcluded from Module:Image area/doc.
local err = require('Module:Error').call
local p = {}
function p.main(frame)
return p.call(frame:getParent().args)
end
function p.call(args)
local defaultWidth = 250-- default viewport size if not passed in parameter
-- Edit presets here
local presetList = {
enessa = {
class = 'enessa-map',
width = 7000,
height = 3799,
},
}
local preset = mw.ustring.lower(args[1] or '')
if preset and preset ~= '' then
if presetList[preset] then
preset = presetList[preset]
else
return err('first parameter is invalid')
end
else
return err('first parameter is required')
end
local caption = args.caption
if not caption or caption == '' then
caption = mw.title.getCurrentTitle().subpageText .. ' within ' .. args[1]
end
local margin = args.margin
if not margin or margin == '' then
margin = 'unset'
end
local newWidth = tonumber(args['new width'])
local newHeight = tonumber(args['new height'])
if not newWidth then
if not newHeight then
newWidth = defaultWidth
else
newWidth = preset.width * newHeight / preset.height
end
end
if not newHeight then
newHeight = preset.height * newWidth / preset.width
end
local x1, y1, x2, y2 = args.x1 or '', args.y1 or '', args.x2 or '', args.y2 or ''
if x1 == '' or y1 == '' or x2 == '' or y2 == '' then
return err('all four coordinates must be specified')
end
local areaWidth = math.abs(x2 - x1)
local areaHeight = math.abs(y2 - y1)
local resizeRatio = newWidth / areaWidth
return mw.html.create('div')
:addClass('background-' .. preset.class)
:attr('alt', caption)
:attr('title', caption)
:css({
['width'] = newWidth .. 'px',
['height'] = newHeight .. 'px',
['background-size'] = preset.width * resizeRatio .. 'px ' .. preset.height * resizeRatio .. 'px',
['background-position'] = -1 * x1 * resizeRatio .. 'px ' .. -1 * y1 * resizeRatio .. 'px',
['background-repeat'] = 'no-repeat',
['overflow'] = 'hidden',
['border'] = '1px solid #EEE',
['margin'] = margin,
})
:done()
end
return p