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 'File:Blanksvg.svg'
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

local imgTbl = mainCell.tag('table')
if img ~= '' then
local imgTbl = mainCell.tag('table')
imgTbl
.css('width', (cellWidth + 20) .. 'px')
imgTbl
.css('float', 'left')
.css('width', (cellWidth + 20) .. 'px')
.css('border-collapse', 'collapse')
.css('float', 'left')
.css('margin', '3px')
.css('border-collapse', 'collapse')
.tag('tr')
.css('margin', '3px')
.tag('td')
.tag('tr')
.css('height', (imgHeight + 20) .. 'px')
.tag('td')
.css('border', '1px solid #CCCCCC')
.css('height', (imgHeight + 20) .. 'px')
.css('background-color', '#F8F8F8')
.css('border', '1px solid #CCCCCC')
.css('padding', '0px')
.css('background-color', '#F8F8F8')
.css('text-align', 'center')
.css('padding', '0px')
.wikitext(mw.ustring.format('[[%s|center|border|%dx%dpx|alt=%s|%s]]', img, imgWidth, imgHeight, alt, caption))
.css('text-align', 'center')
.wikitext(mw.ustring.format('[[%s|center|border|%dx%dpx|alt=%s|%s]]', img, imgWidth, imgHeight, alt, caption))
.done()
.done()
.done()
.done()
.tag('tr')
.tag('tr')
.css('vertical-align', 'top')
.css('vertical-align', 'top')
.tag('td')
.tag('td')
.css('display', 'block')
.css('display', 'block')
.css('font-size', '1em')
.css('font-size', '1em')
.css('height', (0.2 + 1.5*lines) .. 'em')
.css('height', (0.2 + 1.5*lines) .. 'em')
.css('padding', '0px')
.css('padding', '0px')
.tag('div')
.tag('div')
.addClass('gallerytext')
.addClass('gallerytext')
.css('height', (0.1 + 1.5*lines) .. 'em')
.css('height', (0.1 + 1.5*lines) .. 'em')
.css('width', textWidth .. 'px')
.css('width', textWidth .. 'px')
.css('line-height', '1.3em')
.css('line-height', '1.3em')
.css('padding', '2px 6px 1px 6px')
.css('padding', '2px 6px 1px 6px')
.css('overflow-y', 'auto')
.css('overflow-y', 'auto')
.css('margin', '0px')
.css('margin', '0px')
.css('border', 'none')
.css('border', 'none')
.css('border-width', '0px')
.css('border-width', '0px')
.wikitext(caption .. ' ')
end
.wikitext(caption .. ' ')
end
end