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.
-- this module implements [[Template:Overlay]] localp={} localmArguments=require('Modul:Arguments') -- used to cache the calculated font color to avoid repeat calculations localprevious_backgroundcolor='' localfontcolor='' localfunctionbuildicon(n,form,lk,c,t) localres ifform=='text'then returntostring( mw.html.create('span') :css('font-weight','bold') :css('color',c) :wikitext(n) ) elseifform=='color'orform=='colour'then returntostring( mw.html.create('span') :css('background-color',c) :wikitext('  ') ) else -- check if the color is difference from the previous color ifc~=previous_backgroundcolorthen -- color changed, so look up the best font color localgreatercontrast=require('Modul:Color contrast')._greatercontrast fontcolor=greatercontrast{c,'white','black',bias=1.3} -- update the previous value for the next check previous_backgroundcolor=c end -- build the inner span for the icon localspan=mw.html.create('span') :css('color',fontcolor) :css('font-size','88%') :css('font-weight','bold') :attr('title',t) :wikitext(n) -- build the outer div localdiv=mw.html.create('div') :css('display','inline-block') :css('width','auto') :css('height','auto') :css('text-align','center') :css('padding',((tonumber(n)or0)<10)and'0px 4px'or'0px 2px') :css('vertical-align','middle') :css('border-radius','3px') :css('background-color',c) -- link the inner span if requested and insert in the div iflk~=''then div:wikitext('[[:'..lk..'|'..tostring(span)..']]') else div:wikitext(tostring(span)) end -- convert to a string returntostring(div) end end localfunctionbuildlegend(data,cols,border,caption) -- create the outer table to hold the columns localroot=mw.html.create('table') :css('width','100%') :css('border',(border~='no')and'1px #ccc solid'or'') -- create the outer row which will contain the columns localouterrow=root:tag('tr') localpercol=math.ceil((#data)/cols) localk=0 forj=1,colsdo -- create the outer cell to hold this column localcolcell=outerrow:tag('td') :css('width',(math.floor(10/cols)/10)..'%') :css('vertical-align','top') -- create the inner table to hold the entries in the column localcoltable=colcell:tag('table') :css('width','100%') :css('font-size','85%') :css('line-height','95%') -- add the entries to the column forl=1,percoldo k=k+1 ifk<=#datathen localrdata=data[k] localtr=coltable:tag('tr'):css('vertical-align','top') tr:tag('td') :css('width','12px') :css('text-align','right') :css('padding-bottom','2px') :wikitext(rdata[1]or'') tr:tag('td') :css('padding-bottom','2px') :wikitext(rdata[2]or'') end end end returncaption..tostring(root) end localfunctionbuildlegenditem(im,lk,t) localres={im,''} ift~=''then iflk~=''then res[2]='[[:'..lk..'|'..t..']]' else res[2]=t end else res[2]='[[:'..lk..'|'..lk..']]' end returnres end functionp.icon(frame) localargs=mArguments.getArgs(frame) returntostring( mw.html.create('div') :css('display','inline-block') :css('line-height','95%') :wikitext(buildicon(args['1']or'', args['form']or'icon', args['link']or'', args['2']or'red', args['tip']or'')) ) end functionp.main(frame) localargs=mArguments.getArgs(frame) localimage=args['image']or'' localwidth=tonumber(args['width']or'500')or500 localheight=tonumber(args['height']or'500')or500 localcolumns=tonumber(args['columns']or'3')or3 localgrid=((args['grid']or''):lower()=='yes')and'yes'or'no' locallegendbox=((args['legendbox']or''):lower()=='no')and'no'or'yes' localoverlay=(image=='')and'no'or(((args['overlay']or''):lower()=='no')and'no'or'yes') localfloat=args['float']or'center' localborder=((args['border']or''):lower()=='no')and'no'or'yes' localpadding=args['padding']or'' -- create the root table localroot=mw.html.create('table') iffloat=='center'orfloat=='centre'then root:css('margin-left','auto') :css('margin-right','auto') elseiffloat=='right'then root:css('float','right') :css('clear','right') :css('margin-left','1em') elseiffloat=='left'then root:css('float','left') :css('clear','left') :css('margin-right','1em') else root:css('float',float) end ifborder=='yes'then root:css('border','1px #ccc solid') end -- create a list of all the overlay numbers localitemnums={} fork,vinpairs(args)do locali=tonumber(tostring(k):match('^%s*overlay([%d]+)%s*$')or'-1') ifi>-1then table.insert(itemnums,i) else i=tonumber(tostring(k):match('^%s*overlay([%d]+)tip%s*$')or'-1') ifi>-1then table.insert(itemnums,i) end end end -- sort to process in order table.sort(itemnums) -- remove duplicates fork=2,#itemnumsdo ifitemnums[k]==itemnums[k-1]then table.remove(itemnums,k) end end -- build the overlay markers and text itemdata={} localcolori=args['color']orargs['colour']or'red' localformi='' fork=1,#itemnumsdo locali=itemnums[k] formi=args['overlay'..i..'form']orformi colori=args['overlay'..i..'color']orargs['overlay'..i..'colour']orcolori locallinki=args['overlay'..i..'link']or'' localtipi=args['overlay'..i..'tip']orargs['overlay'..i]or'' localoverlayi=args['overlay'..i]orargs['overlay'..i..'tip']or'' if(overlayi~=''ortipi~='')then localimagei=buildicon(i,formi,linki,colori,tipi) itemdata[k]=buildlegenditem(imagei,args['overlay'..i..'link']or'',overlayi) end end -- create the overlay image ifimage~=''then localcell=root:tag('tr'):tag('td') cell:attr('align','center') if(padding~='')then cell:css('padding',padding) end if(columns>1andlegendbox=='yes')then cell:attr('colspan',columns) end localimagediv=cell:tag('div') imagediv:css('position','relative') :css('left','0px') :css('top','0px') :css('width',((grid=='yes')and940orwidth)..'px') :css('height',((grid=='yes')and940orheight)..'px') ifgrid=='yes'then imagediv:tag('span') :css('position','absolute') :css('left','0px') :css('top','0px') :css('z-index','2') :wikitext('[[File:Grid 99, 100 int red 50 int yellow (940).svg|940px]]') end imagediv:tag('span') :css('position','absolute') :css('left','0px') :css('top','0px') :css('z-index','0') :css('width',width..'px') :css('height',height..'px') :wikitext('[[File:'..image..'|'..width..'x'..height..'px]]') ifoverlay=='yes'then fork=1,#itemnumsdo locali=itemnums[k] localimagei=(itemdata[k])[1] forj=0,3do localoverlayileftj=args['overlay'..i..'left'..((j==0)and''orj)]or'' localoverlayitopj=args['overlay'..i..'top'..((j==0)and''orj)]or'' ifoverlayileftj~=''then imagediv:tag('div') :css('position','absolute') :css('left',overlayileftj..'px') :css('top',overlayitopj..'px') :css('line-height','95%') :css('z-index','1') :wikitext(imagei) end end end end end -- Split the legend items into sub-legends legend={{},{},{},{},{}} localjmax=itemnums[#itemnums] fori=1,5do ifargs['legend'..i..'start']then -- default is all items j1=0 j2=jmax -- set start item number to (legendistart) or (legend(i-1)end + 1) ifargs['legend'..i..'start']then j1=tonumber(args['legend'..i..'start'])orj1 elseifargs['legend'..(i-1)..'end']then j1=(tonumber(args['legend'..(i-1)..'end'])orj1)+1 end -- set end item number to (legendiend) or (legend(i+1)start - 1) ifargs['legend'..i..'end']then j2=tonumber(args['legend'..i..'end'])orj2 elseifargs['legend'..(i+1)..'start']then j2=(tonumber(args['legend'..(i+1)..'start'])orj2)-1 end -- get the items within the range, marking them as they are used fork=1,#itemnumsdo j=itemnums[k] if(j>=0andj>=j1andj<=j2)then table.insert(legend[i],itemdata[k]) itemnums[k]=-1 end end end end -- Add any left over items to the first legend fork=1,#itemnumsdo ifitemnums[k]>=0then table.insert(legend[1],itemdata[k]) end end -- Build the legend ifcolumns>0then fori=1,5do locallocallegend=legend[i] if(locallegendand#locallegend>0)then localcell=root:tag('tr'):tag('td') cell:wikitext(buildlegend(locallegend,columns,border,args['legend'..i..'title']or'')) end end end returntostring(root) end returnp