Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- implements [[Template:Multiple image]] localp={} localautoscaledimages localnonautoscaledimages localnumberofimages=-1 localfunctionisnotempty(s) returnsands:match('^%s*(.-)%s*$')~='' end localfunctionremovepx(s) returntostring(sor''):match('^(.*)[Pp][Xx]%s*$')ors end localfunctiongetdimensions(s,w,h) iftonumber(w)andtonumber(h)then nonautoscaledimages=true returntonumber(w),tonumber(h) end localfile=sandmw.title.new('File:'..mw.uri.decode(mw.ustring.gsub(s,'%|.*$',''),'WIKI')) file=fileandfile.fileor{width=0,height=0} w=tonumber(file.width)or0 h=tonumber(file.height)or0 autoscaledimages=true returnw,h end localfunctionrenderImageCell(image,width,height,link,alt,thumbtime,caption,class,textalign,istyle,border,tcolor) localroot=mw.html.create('') localaltstr='' localclassstr=classand('|class='..class)or'' locallinkstr=linkand('|link='..link)or'' localwidthstr='|'..tostring(width)..'px' localthumbtimestr='' ifisnotempty(alt)then altstr='|alt='..alt end ifwidthstr=='|-nanpx'then widthstr='' end ifisnotempty(thumbtime)then thumbtimestr='|thumbtime='..thumbtime end localimagediv=root:tag('div') imagediv:addClass((border~='infobox')and'thumbimage'ornil) imagediv:cssText(istyle) ifheightthen imagediv:css('height',tostring(height)..'px') imagediv:css('overflow','hidden') end imagediv:wikitext('[[File:'..image..classstr..widthstr..linkstr..altstr..thumbtimestr..']]') ifisnotempty(caption)then localcaptiondiv=root:tag('div') captiondiv:addClass((border~='infobox')and'thumbcaption'ornil) ifisnotempty(textalign)then captiondiv:addClass('text-align-'..textalign) end iftcolor~=''then captiondiv:css('color',tcolor) end captiondiv:wikitext(caption) end returntostring(root) end localfunctiongetWidth(w1,w2) localw ifisnotempty(w1)then w=tonumber(w1) elseifisnotempty(w2)then w=tonumber(w2) end returnwor200 end localfunctiongetPerRow(pstr,ic) -- split string into array using any non-digit as a dilimiter localpr=mw.text.split(pstror'','[^%d][^%d]*') -- if split failed, assume a single row if(#pr<1)then pr={tostring(ic)} end -- convert the array of strings to an array of numbers, -- adding any implied/missing numbers at the end of the array localr=1 localthisrow=tonumber(pr[1]oric)oric localprownum={} while(ic>0)do prownum[r]=thisrow 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]orthisrow)oric,ic) end returnprownum end localfunctionrenderMultipleImages(frame) localpargs=frame:getParent().args localargs=frame.args localwidth=removepx(pargs['width']or'') localdir=pargs['direction']or'' localborder=pargs['border']orargs['border']or'' localalign=pargs['align']orargs['align']or(border=='infobox'and'center'or'') localcapalign=pargs['caption_align']orargs['caption_align']or'' localtotalwidth=removepx(pargs['total_width']orargs['total_width']or'') localimgstyle=pargs['image_style']orargs['image_style'] localheader=pargs['header']orpargs['title']or'' localfooter=pargs['footer']or'' localimagegap=tonumber(pargs['image_gap']or'1')or1 localthumbclass={ ["left"]='floatleft', ["none"]='tnone', ["center"]='tnone', ["centre"]='tnone', ["right"]='floatright' } -- find all the nonempty images localimagenumbers={} localimagecount=0 fork,vinpairs(pargs)do locali=tonumber(tostring(k):match('^%s*image([%d]+)%s*$')or'0') ifi>0andisnotempty(v)then table.insert(imagenumbers,i) imagecount=imagecount+1 end end -- save number of images for tracking category numberofimages=imagecount -- sort the imagenumbers table.sort(imagenumbers) -- create an array with the number of images per row localperrow=getPerRow(dir=='vertical'and'1'orpargs['perrow'],imagecount) -- compute the number of rows localrowcount=#perrow -- store the image widths and compute row widths and maximum row width localheights={} localwidths={} localwidthmax=0 localwidthsum={} localk=0 forr=1,rowcountdo widthsum[r]=0 forc=1,perrow[r]do k=k+1 ifk<=imagecountthen locali=imagenumbers[k] ifisnotempty(totalwidth)then widths[k],heights[k]=getdimensions(pargs['image'..i],pargs['width'..i],pargs['height'..i]) else widths[k]=getWidth(width,pargs['width'..i]) end widthsum[r]=widthsum[r]+widths[k] end end widthmax=math.max(widthmax,widthsum[r]) end -- make sure the gap is non-negative ifimagegap<0thenimagegap=0end -- if total_width has been specified, rescale the image widths ifisnotempty(totalwidth)then totalwidth=tonumber(totalwidth) widthmax=0 k=0 forr=1,rowcountdo localkoffset=k localtw=totalwidth-(3+imagegap)*(perrow[r]-1)-12 localar={} localarsum=0 forj=1,perrow[r]do k=k+1 ifk<=imagecountthen localh=heights[k]or0 if(h>0)then ar[j]=widths[k]/h heights[k]=h else ar[j]=widths[k]/100 end arsum=arsum+ar[j] end end localht=tw/arsum localws=0 k=koffset forj=1,perrow[r]do k=k+1 ifk<=imagecountthen widths[k]=math.floor(ar[j]*ht+0.5) ws=ws+widths[k] ifheights[k]then heights[k]=math.floor(ht) end end end widthsum[r]=ws widthmax=math.max(widthmax,widthsum[r]) end end -- start building the array of images, if there are images ifimagecount>0then -- compute width of outer div localbodywidth=0 forr=1,rowcountdo ifwidthmax==widthsum[r]then bodywidth=widthmax+(3+imagegap)*(perrow[r]-1)+12 end end -- The body has a min-width of 100, which needs to be taken into account on specific widths bodywidth=math.max(100,bodywidth-8); localtc=pargs['color']orpargs['text_color']or'' localbg=pargs['bg_color']orpargs['background_color']orpargs['background color']or'' -- create the array of images localroot=mw.html.create('div') root:addClass('thumb') root:addClass('tmulti') -- root:addClass('tmulti-sandbox') root:addClass(thumbclass[align]or'floatright') ifalign=='center'oralign=='centre'then root:addClass('center') end iftc~=''then root:css('color',tc) end localdiv=root:tag('div') div:addClass((border~='infobox')and'thumbinner multiimageinner'or'multiimageinner') div:css('width',tostring(bodywidth)..'px') :css('max-width',tostring(bodywidth)..'px') ifbg~=''then div:css('background-color',bg) end iftc~=''then div:css('color',tc) end ifborder=='infobox'orborder=='none'then div:css('border','none') end -- add the header ifisnotempty(header)then div:tag('div') :addClass('trow') :tag('div') :addClass('theader') :css('text-align',pargs['header_align']) :css('background-color', (pargs['header_background']~='')andpargs['header_background']ornil) :wikitext(header) end -- loop through the images k=0 forr=1,rowcountdo localrowdiv=div:tag('div'):addClass('trow'); forj=1,perrow[r]do k=k+1 ifk<=imagecountthen localimagediv=rowdiv:tag('div') imagediv:addClass('tsingle') ifbg~=''then imagediv:css('background-color',bg); end ifimagegap>1andk<imagecountthen ifdir=='vertical'then imagediv:css('margin-bottom',tostring(imagegap)..'px') elseifj<perrow[r]then imagediv:css('margin-right',tostring(imagegap)..'px') end end locali=imagenumbers[k] localimg=pargs['image'..i] localw=widths[k] 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],pargs['class'..i],capalign,imgstyle,border,tc)) end end end -- add the footer ifisnotempty(footer)then localfalign=string.lower(pargs['footer_align']orargs['footer_align']or'') falign=(falign=='centre')and'center'orfalign div:tag('div') :addClass('trow') :css('display',(falign~='')and'flow-root'or'flex') :tag('div') :addClass((border~='infobox')and'thumbcaption'ornil) :css('text-align',(falign~='')andfalignornil) :css('background-color', (pargs['footer_background']~='')andpargs['footer_background']ornil) :css('color',(tc~='')andtcornil) :wikitext(footer) end returntostring(root) end return'' end functionp.render(frame) autoscaledimages=false nonautoscaledimages=false numberofimages=0 localcheck=require('Module:Check for unknown parameters')._check localtracking=check({ ['unknown']=frame:expandTemplate{ title='main other', args={'[[Category:Pages using multiple image with unknown parameters|_VALUE_ ]]'} }, ['preview']='Page using [[Template:Multiple image]] with unknown parameter "_VALUE_"', ['ignoreblank']='y', regexp1='image%d+', regexp2='width%d+', regexp3='height%d+', regexp4='class%d+', regexp5='alt%d+', regexp6='link%d+', regexp7='thumbtime%d+', regexp8='caption%d+', 'align','direction','header_background', 'header_align','header','width','total_width', 'caption_align','footer_background','footer_align','footer', 'perrow','title','image_gap','border','image_style', 'color','text_color', 'bg_color','background_color','background color' },frame:getParent().args) returnframe:extensionTag{name='templatestyles',args={src='Multiple image/styles.css',wrapper=".tmulti"}} ..renderMultipleImages(frame) ..(autoscaledimagesand'[[Category:Pages using multiple image with auto scaled images]]'or'') ..(nonautoscaledimagesand'[[Category:Pages using multiple image with manual scaled images]]'or'') ..((numberofimages==0)and'[[Category:Pages using multiple image with zero images]]'or'') ..((numberofimages==1)and'[[Category:Pages using multiple image with one image]]'or'') ..tracking end p['']=function(frame)returnp.render(frame:newChild{title=frame:getTitle()})end returnp