Module:Multiple image: Difference between revisions
imported>Fire ページの作成:「-- implements template:multiple image local p = {} local autoscaledimages local nonautoscaledimages local function isnotempty(s) return s and s:match( '^%s*(.-)%s*…」 |
No edit summary |
||
Line 26: | Line 26: | ||
end | end | ||
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle) | local function renderImageCell(image, width, height, link, alt, thumbtime, caption, class, textalign, istyle, border) | ||
local root = mw.html.create('') | local root = mw.html.create('') | ||
local altstr = '|alt=' .. (alt or '') | local altstr = '|alt=' .. (alt or '') | ||
local classstr = class and ('|class=' .. class) or '' | |||
local linkstr = link and ('|link=' .. link) or '' | local linkstr = link and ('|link=' .. link) or '' | ||
local widthstr = '|' .. tostring(width) .. 'px' | local widthstr = '|' .. tostring(width) .. 'px' | ||
local thumbtimestr = '' | local thumbtimestr = '' | ||
if widthstr == '|-nanpx' then | |||
widthstr = '' | |||
end | |||
if isnotempty( thumbtime ) then | if isnotempty( thumbtime ) then | ||
thumbtimestr = '|thumbtime=' .. thumbtime | thumbtimestr = '|thumbtime=' .. thumbtime | ||
Line 39: | Line 43: | ||
local imagediv = root:tag('div') | local imagediv = root:tag('div') | ||
imagediv:addClass('thumbimage') | imagediv:addClass((border ~= 'infobox') and 'thumbimage' or nil) | ||
imagediv:cssText(istyle) | imagediv:cssText(istyle) | ||
if( height ) then | if( height ) then | ||
Line 45: | Line 49: | ||
imagediv:css('overflow', 'hidden') | imagediv:css('overflow', 'hidden') | ||
end | end | ||
imagediv:wikitext('[[file:' .. image .. widthstr .. linkstr .. altstr .. thumbtimestr .. ']]') | imagediv:wikitext('[[file:' .. image .. classstr .. widthstr .. linkstr .. altstr .. thumbtimestr .. ']]') | ||
if isnotempty(caption) then | if isnotempty(caption) then | ||
local captiondiv = root:tag('div') | local captiondiv = root:tag('div') | ||
captiondiv:addClass('thumbcaption') | captiondiv:addClass((border ~= 'infobox') and 'thumbcaption' or nil) | ||
if isnotempty(textalign) then | if isnotempty(textalign) then | ||
captiondiv:addClass('text-align-' .. textalign) | captiondiv:addClass('text-align-' .. textalign) | ||
Line 229: | Line 233: | ||
local div = root:tag('div') | local div = root:tag('div') | ||
div:addClass('thumbinner') | div:addClass((border ~= 'infobox') and 'thumbinner multiimageinner' or 'multiimageinner') | ||
div:css('width', tostring(bodywidth) .. 'px') | div:css('width', tostring(bodywidth) .. 'px') | ||
:css('max-width', tostring(bodywidth) .. 'px') | :css('max-width', tostring(bodywidth) .. 'px') | ||
Line 245: | Line 249: | ||
:addClass('theader') | :addClass('theader') | ||
:css('text-align', pargs['header_align']) | :css('text-align', pargs['header_align']) | ||
:css('background-color', pargs['header_background']) | :css('background-color', | ||
(pargs['header_background'] ~= '') and pargs['header_background'] or nil) | |||
:wikitext(header) | :wikitext(header) | ||
end | end | ||
Line 260: | Line 265: | ||
imagediv:css('background-color', bg); | imagediv:css('background-color', bg); | ||
end | end | ||
if | if imagegap > 1 and k < imagecount then | ||
if dir == 'vertical' then | |||
imagediv:css('margin-bottom', tostring(imagegap) .. 'px') | |||
elseif j < perrow[r] then | |||
imagediv:css('margin-right', tostring(imagegap) .. 'px') | |||
end | |||
end | end | ||
local i = imagenumbers[k] | local i = imagenumbers[k] | ||
Line 270: | Line 279: | ||
imagediv:wikitext(renderImageCell(img, w, heights[k], | imagediv:wikitext(renderImageCell(img, w, heights[k], | ||
pargs['link' .. i], pargs['alt' .. i], | pargs['link' .. i], pargs['alt' .. i], | ||
pargs['thumbtime' .. i], pargs['caption' .. i], capalign, imgstyle)) | pargs['thumbtime' .. i], pargs['caption' .. i], pargs['class' .. i], capalign, imgstyle, border)) | ||
end | end | ||
end | end | ||
Line 276: | Line 285: | ||
-- add the footer | -- add the footer | ||
if( isnotempty(footer) ) then | if( isnotempty(footer) ) then | ||
local falign = string.lower(pargs['footer_align'] or args['footer_align'] or ' | local falign = string.lower(pargs['footer_align'] or args['footer_align'] or '') | ||
falign = (falign == 'centre') and 'center' or falign | falign = (falign == 'centre') and 'center' or falign | ||
div:tag('div') | div:tag('div') | ||
:addClass('trow') | :addClass('trow') | ||
:css('display', (falign ~= ' | :css('display', (falign ~= '') and 'flow-root' or 'flex') | ||
:tag('div') | :tag('div') | ||
:addClass('thumbcaption') | :addClass((border ~= 'infobox') and 'thumbcaption' or nil) | ||
:css('text-align', (falign ~= ' | :css('text-align', (falign ~= '') and falign or nil) | ||
:css('background-color', pargs['footer_background']) | :css('background-color', | ||
(pargs['footer_background'] ~= '') and pargs['footer_background'] or nil) | |||
:wikitext(footer) | :wikitext(footer) | ||
end | end | ||
Line 301: | Line 311: | ||
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '') | .. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '') | ||
end | end | ||
p[''] = function( frame ) return p.render( frame:newChild{title = frame:getTitle()} ) end | |||
return p | return p |