Modhul:Multiple image: Béda antara owahan

Konten dihapus Konten ditambahkan
anyar
 
Tanpa ringkesan besutan
Larik 1:
-- implements [[template:multiple image]]
local p = {}
 
local autoscaledimages
local nonautoscaledimages
 
local function isnotempty(s)
Baris 6 ⟶ 9:
end
 
local function removepx(s)
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle)
return tostring(s or ''):match('^(.*)[Pp][Xx]%s*$') or s
end
 
local function getdimensions(s, w, h)
if tonumber(w) and tonumber(h) then
nonautoscaledimages = true
return tonumber(w), tonumber(h)
end
local file = s and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(s,'%|.*$',''), 'WIKI'))
file = file and file.file or {width = 0, height = 0}
w = tonumber(file.width) or 0
h = tonumber(file.height) or 0
autoscaledimages = true
return w, h
end
 
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle)
local root = mw.html.create('')
 
local altstr = '|alt=' .. (alt or '')
local linkstr = link and ('|link=' .. link) or ''
Baris 17 ⟶ 37:
thumbtimestr = '|thumbtime=' .. thumbtime
end
 
local imagediv = root:tag('div')
imagediv:addClass('thumbimage')
Baris 29 ⟶ 49:
local captiondiv = root:tag('div')
captiondiv:addClass('thumbcaption')
captiondiv:css('clear', 'left')
if isnotempty(textalign) then
captiondiv:cssaddClass('text-align-', .. textalign)
end
captiondiv:wikitext(caption)
Baris 64 ⟶ 83:
ic = ic - thisrow
r = r + 1
-- use the previous if the next is missing and
-- make sure we don't overstep the number of images
thisrow = math.min(tonumber(pr[r] or thisrow) or ic, ic)
Baris 74 ⟶ 93:
local pargs = frame:getParent().args
local args = frame.args
local width = removepx(pargs['width'] or '')
local dir = pargs['direction'] or ''
local alignborder = pargs['alignborder'] or args['alignborder'] or ''
local align = pargs['align'] or args['align'] or (border == 'infobox' and 'center' or '')
local capalign = pargs['caption_align'] or args['caption_align'] or ''
local totalwidth = removepx(pargs['total_width'] or args['total_width'] or '')
local imgstyle = pargs['image_style'] or args['image_style']
local header = pargs['header'] or pargs['title'] or ''
local footer = pargs['footer'] or ''
local imagegap = tonumber(pargs['image_gap'] or '1') or 1
local perrow = nil
local thumbclass = {
Baris 104 ⟶ 125:
-- sort the imagenumbers
table.sort(imagenumbers)
 
-- create an array with the number of images per row
perrow = getPerRow(dir == 'vertical' and '1' or pargs['perrow'], imagecount)
 
-- compute the number of rows
local rowcount = #perrow
 
-- store the image widths and compute row widths and maximum row width
local heights = {}
local widths = {}
local widthmax = 0
Baris 122 ⟶ 144:
if( k <= imagecount ) then
local i = imagenumbers[k]
if( isnotempty(totalwidth) ) then
widths[k] = getWidth(width, pargs['width' .. i])
widths[k], heights[k] = getdimensions(pargs['image' .. i], pargs['width' .. i], pargs['height' .. i])
endelse
widths[k] = getWidth(width, pargs['width' .. i])
end
widthsum[r] = widthsum[r] + widths[k]
end
Baris 128 ⟶ 154:
widthmax = math.max(widthmax, widthsum[r])
end
 
-- make sure the gap is non-negative
if imagegap < 0 then imagegap = 0 end
 
-- if total_width has been specified, rescale the image widths
local heights = {}
if( isnotempty(totalwidth) ) then
totalwidth = tonumber(totalwidth)
Baris 137 ⟶ 165:
for r=1,rowcount do
local koffset = k
local tw = totalwidth - 4(3 + imagegap) * (perrow[r] - 1) - 12
local ar = {}
local arsum = 0
Baris 144 ⟶ 172:
if( k<= imagecount ) then
local i = imagenumbers[k]
local h = tonumber( pargsheights['height' .. ik] or '' ) or 0
if (h > 0) then
ar[j] = widths[k]/h
Baris 171 ⟶ 199:
widthmax = math.max(widthmax, widthsum[r])
end
end
 
-- start building the array of images, if there are images
Baris 179 ⟶ 207:
for r=1,rowcount do
if( widthmax == widthsum[r] ) then
bodywidth = widthmax + 4(3 + imagegap) * (perrow[r] - 1) + 12
end
end
Baris 190 ⟶ 218:
root:addClass('thumb')
root:addClass('tmulti')
-- root:addClass('tmulti-sandbox')
root:addClass(thumbclass[align] or 'tright')
 
if( align == 'center' or align == 'centre' ) then
root:addClass('center')
end
if( pargs['margin_top'] or args['margin_top']) then
root:css('margin-top', pargs['margin_top'] or args['margin_top'])
end
if( pargs['margin_bottom'] or args['margin_bottom']) then
root:css('margin-bottom', pargs['margin_bottom'] or args['margin_bottom'])
end
if( bg ~= '' ) then
Baris 211 ⟶ 234:
if( bg ~= '' ) then
div:css('background-color', bg)
end
if( border == 'infobox' or border == 'none') then
captiondiv div:css('clearborder', 'leftnone')
end
-- add the header
if( isnotempty(header) ) then
div:tag('div')
:cssaddClass('clear', 'bothtrow')
:csstag('font-weight', 'bolddiv')
:addClass('theader')
:css('text-align', pargs['header_align'] or 'center')
:css('backgroundtext-coloralign', pargs['header_backgroundheader_align'] or 'transparent')
:css('background-color', pargs['footer_backgroundheader_background'] or 'transparent')
:wikitext(header)
end
-- loop through the images
local k = 0
for r=1,rowcount do
local rowdiv = div:tag('div'):addClass('trow');
for j=1,perrow[r] do
k = k + 1
if( k <= imagecount ) then
local imagediv = divrowdiv:tag('div')
imagediv:addClass('tsingle')
if dir ~= 'vertical' then
imagediv:css('float', 'left')
end
if bg ~= '' then
imagediv:css('background-color', bg);
end
if ((imagegap > 1) and (j < perrow[r])) then
imagediv:css('margin', '1px')
imagediv:css('floatmargin-right', tostring(imagegap) .. 'leftpx')
end
local i = imagenumbers[k]
local img = pargs['image' .. i]
Baris 241 ⟶ 268:
imagediv:css('width', tostring(2 + w) .. 'px')
:css('max-width', tostring(2 + w) .. 'px')
imagediv:wikitext(renderImageCell(img, w, heights[k],
pargs['link' .. i], pargs['alt' .. i],
pargs['thumbtime' .. i], pargs['caption' .. i], capalign, imgstyle))
end
end
-- only float content gives a parent height:0, so add a clearing div
if dir ~= 'vertical' then
div:tag('div')
:css('clear', 'left')
end
end
-- add the footer
if( isnotempty(footer) ) then
:css('text-align',local falign = string.lower(pargs['footer_align'] or args['footer_align'] or 'left')
falign = (falign == 'centre') and 'center' or falign
div:tag('div')
:addClass('thumbcaptiontrow')
:css('cleardisplay', (falign ~= 'left') and 'flow-root' or 'flex')
div:tag('div')
:css('text-align', pargs['footer_align'] or args['footer_align'] or 'left')
:addClass('thumbcaption')
:css('background-color', pargs['footer_background'] or 'transparent')
:css('text-align', pargs[(falign ~= 'header_alignleft']) and falign or 'center'nil)
:wikitext(footer)
:css('background-color', pargs['footer_background'])
:wikitext(footer)
end
return tostring(root)
Baris 267 ⟶ 293:
 
function p.render( frame )
autoscaledimages = false
return renderMultipleImages( frame )
nonautoscaledimages = false
 
return frame:extensionTag {name = 'templatestyles', args = {src = 'Multiple image/styles.css', wrapper = ".tmulti"}}
return .. renderMultipleImages( frame )
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')
end
 
return p