Module:Gallery: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(merge tracking)
(update to sandbox version for mobile view per discussion on the talk page; please revert if this causes script errors or other complete failure)
Line 6: Line 6:


local function trim(s)
local function trim(s)
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
return mw.ustring.gsub(mw.ustring.gsub(s, '%s', ' '), '^%s*(.-)%s*$', '%1')
end
end


Line 15: Line 15:
if k == 'align' or k == 'state' or k == 'style' or k == 'title' or
if k == 'align' or k == 'state' or k == 'style' or k == 'title' or
k == 'width' or k == 'height' or k == 'lines' or
k == 'width' or k == 'height' or k == 'lines' or
k == 'footer' or k == 'perrow' or
k == 'mode' or k == 'footer' or k == 'perrow' or
k:match('^alt%d+$') or k:match('^%d+$') then
k:match('^alt%d+$') or k:match('^%d+$') then
-- valid
-- valid
Line 85: Line 85:
end
end
local gargs = {}
local mainCell = tbl:tag('div'):css('display', 'table-row'):tag('div'):css('display', 'table-cell')
gargs['class'] = 'nochecker bordered-images'
gargs['widths'] = tonumber(args.width) or 180
gargs['heights'] = tonumber(args.height) or 180
gargs['style'] = 'line-height:130%;' .. (args['captionstyle'] or '')
gargs['perrow'] = args.perrow
gargs['mode'] = args.mode
local gallery = {}
local imageCount = math.ceil(#args / 2)
local imageCount = math.ceil(#args / 2)

local cellWidth = tonumber(args.width) or 180
local imgHeight = tonumber(args.height) or 180
local lines = tonumber(args.lines) or 2
local captionstyle = args.captionstyle
for i = 1, imageCount do
for i = 1, imageCount do
local img = trim(args[i*2 - 1] or '')
local img = trim(args[i*2 - 1] or '')
local caption = trim(args[i*2] or '')
local caption = trim(args[i*2] or '')
local imgWidth = tonumber(args.width) or 180
local alt = trim(args['alt' .. i] or '')
local alt = args['alt' .. i] or ''
local textWidth
if cellWidth < 30 then
textWidth = imgHeight + 27
else
textWidth = cellWidth + 7
end

if img ~= '' then
if img ~= '' then
table.insert(gallery, img .. (alt ~= '' and ('|alt=' .. alt) or '') .. '|' .. caption )
local imgTbl = mainCell:tag('div'):css('display', 'table')
imgTbl
:css('width', (cellWidth + 20) .. 'px')
:css('float', 'left')
:css('border-collapse', 'collapse')
:css('margin', '3px')
:tag('div'):css('display', 'table-row')
:tag('div'):css('display', 'table-cell')
:css('height', (imgHeight + 20) .. 'px')
:css('border', '1px solid #CCCCCC')
:css('background-color', '#F8F8F8')
:css('padding', '0px')
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(string.format('[[%s|center|border|%dx%dpx|alt=%s|%s]]', img, imgWidth, imgHeight, alt, mw.text.unstrip(caption)))
:done()
:done()
:tag('div'):css('display', 'table-row')
:css('vertical-align', 'top')
:tag('div'):css('display', 'table-cell')
:css('display', 'block')
:css('font-size', '94%')
:css('padding', '0px')
:tag('div')
:addClass('gallerytext')
:css('min-height', (0.1 + 1.5*lines) .. 'em')
:css('width', textWidth .. 'px')
:css('line-height', '1.3em')
:css('padding', '2px 6px 1px 6px')
:css('margin', '0px')
:css('border', 'none')
:css('border-width', '0px')
:cssText(captionstyle)
:wikitext(caption .. '&nbsp;')
end
end
end
end
tbl:tag('div')
:css('display', 'table-row')
:tag('div')
:css('display', 'table-cell')
:wikitext(
frame:extensionTag{ name = 'gallery', content = '\n' .. table.concat(gallery,'\n'), args = gargs}
)
if args.footer then
if args.footer then
Line 153: Line 122:
:css('line-height', '1em')
:css('line-height', '1em')
:wikitext(args.footer)
:wikitext(args.footer)
end
if args.perrow then
tbl:css('width', 8 + (cellWidth + 20 + 6)*tonumber(args.perrow) .. 'px')
end
end