Module:Gallery: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (fix error) |
(trim positional params, and don't render empty images) |
||
Line 4: | Line 4: | ||
local HtmlBuilder = require('Module:HtmlBuilder') |
local HtmlBuilder = require('Module:HtmlBuilder') |
||
function trim(s) |
|||
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1")) |
|||
end |
|||
local function _gallery(args) |
local function _gallery(args) |
||
Line 39: | Line 43: | ||
for i = 1, imageCount do |
for i = 1, imageCount do |
||
local img = args[i*2 - 1] or ' |
local img = trim(args[i*2 - 1] or '') |
||
local caption = args[i*2] or '' |
local caption = trim(args[i*2] or '') |
||
local imgWidth = tonumber(args['width' .. i]) or tonumber(args.width) or 180 |
local imgWidth = tonumber(args['width' .. i]) or tonumber(args.width) or 180 |
||
local alt = args['alt' .. i] or '' |
local alt = args['alt' .. i] or '' |
||
Line 50: | Line 54: | ||
textWidth = cellWidth + 7 |
textWidth = cellWidth + 7 |
||
end |
end |
||
⚫ | |||
if img ~= '' then |
|||
local imgTbl = mainCell.tag('table') |
|||
imgTbl |
|||
.css(' |
.css('width', (cellWidth + 20) .. 'px') |
||
.css(' |
.css('float', 'left') |
||
.css(' |
.css('border-collapse', 'collapse') |
||
. |
.css('margin', '3px') |
||
.tag(' |
.tag('tr') |
||
. |
.tag('td') |
||
.css(' |
.css('height', (imgHeight + 20) .. 'px') |
||
.css(' |
.css('border', '1px solid #CCCCCC') |
||
.css(' |
.css('background-color', '#F8F8F8') |
||
.css(' |
.css('padding', '0px') |
||
. |
.css('text-align', 'center') |
||
.wikitext(mw.ustring.format('[[%s|center|border|%dx%dpx|alt=%s|%s]]', img, imgWidth, imgHeight, alt, caption)) |
|||
⚫ | |||
.done() |
.done() |
||
. |
.tag('tr') |
||
. |
.css('vertical-align', 'top') |
||
. |
.tag('td') |
||
. |
.css('display', 'block') |
||
.css(' |
.css('font-size', '1em') |
||
.css(' |
.css('height', (0.2 + 1.5*lines) .. 'em') |
||
.css(' |
.css('padding', '0px') |
||
. |
.tag('div') |
||
. |
.addClass('gallerytext') |
||
. |
.css('height', (0.1 + 1.5*lines) .. 'em') |
||
.css(' |
.css('width', textWidth .. 'px') |
||
.css(' |
.css('line-height', '1.3em') |
||
.css(' |
.css('padding', '2px 6px 1px 6px') |
||
.css(' |
.css('overflow-y', 'auto') |
||
.css(' |
.css('margin', '0px') |
||
.css(' |
.css('border', 'none') |
||
.css('border', ' |
.css('border-width', '0px') |
||
. |
.wikitext(caption .. ' ') |
||
⚫ | |||
⚫ | |||
end |
end |
||