Movatterモバイル変換


[0]ホーム

URL:


跳至內容
WikipediaChū-iû ê Pek-kho-choân-su
Chhiau-chhoē

模組:Navbox

Wikipedia (chū-iû ê pek-kho-choân-su) beh kā lí kóng...

可在模組:Navbox/doc建立此模組的說明文件

---- This module will implement {{Navbox}}--localp={}localnavbar=require('Module:Navbar')._navbarlocalgetArgs-- lazily initializedlocalargslocaltableRowAdded=falselocalborderlocallistnums={}localfunctiontrim(s)return(mw.ustring.gsub(s,"^%s*(.-)%s*$","%1"))endlocalfunctionaddNewline(s)ifs:match('^[*:;#]')ors:match('^{|')thenreturn'\n'..s..'\n'elsereturnsendendlocalfunctionaddTableRow(tbl)-- If any other rows have already been added, then we add a 2px gutter row.iftableRowAddedthentbl:tag('tr'):css('height','2px'):tag('td'):attr('colspan',3)endtableRowAdded=truereturntbl:tag('tr')endlocalfunctionrenderNavBar(titleCell)-- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left-- or right to keep the title centered.localspacerSide=nilifargs.navbar=='off'then-- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's-- also no show/hide link, then we need a spacer on the right to achieve the left shift.ifargs.state=='plain'thenspacerSide='right'endelseifargs.navbar=='plain'or(notargs.nameandmw.getCurrentFrame():getParent():getTitle()=='Template:Navbox'and(border=='subgroup'orborder=='child'orborder=='none'))then-- No navbar. Need a spacer on the left to balance out the width of the show/hide link.ifargs.state~='plain'thenspacerSide='left'endelse-- Will render navbar (or error message). If there's no show/hide link, need a spacer on the right-- to balance out the width of the navbar.ifargs.state=='plain'thenspacerSide='right'endtitleCell:wikitext(navbar{args.name,mini=1,fontstyle=(args.basestyleor'')..';'..(args.titlestyleor'')..';background:none transparent;border:none;'})end-- Render the spacer div.ifspacerSidethentitleCell:tag('span'):css('float',spacerSide):css('width','8em'):css('font-size','80%'):css('margin-'..(spacerSide=='left'and'right'or'left'),'0.5em'):wikitext('&nbsp;')endend----   Title row--localfunctionrenderTitleRow(tbl)ifnotargs.titlethenreturnendlocaltitleRow=addTableRow(tbl)ifargs.titlegroupthentitleRow:tag('th'):attr('scope','row'):addClass('navbox-group'):addClass(args.titlegroupclass):cssText(args.basestyle):cssText(args.groupstyle):cssText(args.titlegroupstyle):wikitext(args.titlegroup)endlocaltitleCell=titleRow:tag('th'):attr('scope','col')ifargs.titlegroupthentitleCell:css('border-left','2px solid #fdfdfd'):css('width','100%')endlocaltitleColspan=2ifargs.imageleftthentitleColspan=titleColspan+1endifargs.imagethentitleColspan=titleColspan+1endifargs.titlegroupthentitleColspan=titleColspan-1endtitleCell:cssText(args.basestyle):cssText(args.titlestyle):addClass('navbox-title'):addClass(args.titleclass):attr('colspan',titleColspan)renderNavBar(titleCell)titleCell:tag('div'):css('font-size','110%'):wikitext(addNewline(args.title))end----   Above/Below rows--localfunctiongetAboveBelowColspan()localret=2ifargs.imageleftthenret=ret+1endifargs.imagethenret=ret+1endreturnretendlocalfunctionrenderAboveRow(tbl)ifnotargs.abovethenreturnendaddTableRow(tbl):tag('td'):addClass('navbox-abovebelow'):addClass(args.aboveclass):cssText(args.basestyle):cssText(args.abovestyle):attr('colspan',getAboveBelowColspan()):tag('div'):wikitext(addNewline(args.above))endlocalfunctionrenderBelowRow(tbl)ifnotargs.belowthenreturnendaddTableRow(tbl):tag('td'):addClass('navbox-abovebelow'):addClass(args.belowclass):cssText(args.basestyle):cssText(args.belowstyle):attr('colspan',getAboveBelowColspan()):tag('div'):wikitext(addNewline(args.below))end----   List rows--localfunctionrenderListRow(tbl,listnum)localrow=addTableRow(tbl)iflistnum==1andargs.imageleftthenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width','0%'):css('padding','0px 2px 0px 0px'):cssText(args.imageleftstyle):attr('rowspan',2*#listnums-1):tag('div'):wikitext(addNewline(args.imageleft))endifargs['group'..listnum]thenlocalgroupCell=row:tag('th')groupCell:attr('scope','row'):addClass('navbox-group'):addClass(args.groupclass):cssText(args.basestyle)ifargs.groupwidththengroupCell:css('width',args.groupwidth)endgroupCell:cssText(args.groupstyle):cssText(args['group'..listnum..'style']):wikitext(args['group'..listnum])endlocallistCell=row:tag('td')ifargs['group'..listnum]thenlistCell:css('text-align','left'):css('border-left-width','2px'):css('border-left-style','solid')elselistCell:attr('colspan',2)endifnotargs.groupwidththenlistCell:css('width','100%')endlocalisOdd=(listnum%2)==1localrowstyle=args.evenstyleifisOddthenrowstyle=args.oddstyleendlocalevenOddifargs.evenodd=='swap'thenifisOddthenevenOdd='even'elseevenOdd='odd'endelseifisOddthenevenOdd=args.evenoddor'odd'elseevenOdd=args.evenoddor'even'endendlistCell:css('padding','0px'):cssText(args.liststyle):cssText(rowstyle):cssText(args['list'..listnum..'style']):addClass('navbox-list'):addClass('navbox-'..evenOdd):addClass(args.listclass):tag('div'):css('padding',(listnum==1andargs.list1padding)orargs.listpaddingor'0em 0.25em'):wikitext(addNewline(args['list'..listnum]))iflistnum==1andargs.imagethenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width','0%'):css('padding','0px 0px 0px 2px'):cssText(args.imagestyle):attr('rowspan',2*#listnums-1):tag('div'):wikitext(addNewline(args.image))endend----   Tracking categories--localfunctionneedsHorizontalLists()ifborder=='child'orborder=='subgroup'orargs.tracking=='no'thenreturnfalseendlocallistClasses={'plainlist','hlist','hlist hnum','hlist hwrap','hlist vcard','vcard hlist','hlist vevent'}fori,clsinipairs(listClasses)doifargs.listclass==clsorargs.bodyclass==clsthenreturnfalseendendreturntrueendlocalfunctionhasBackgroundColors()returnmw.ustring.match(args.titlestyleor'','background')ormw.ustring.match(args.groupstyleor'','background')ormw.ustring.match(args.basestyleor'','background')endlocalfunctionargNameAndRealTitleAreDifferent()ifborder=='child'orborder=='subgroup'orargs.tracking=='no'thenreturnfalseendifargs.name~=mw.title.getCurrentTitle().textthenreturntrueendreturnfalseend--local function getTrackingCategories()--    local cats = {}--    if needsHorizontalLists() then table.insert(cats, '没有使用水平列表的导航框') end--    if hasBackgroundColors() then table.insert(cats, '使用背景颜色的导航框') end--    if argNameAndRealTitleAreDifferent() then table.insert(cats, 'name參數和實際不同的導航框') end--    return cats--endlocalfunctionrenderTrackingCategories(builder)localtitle=mw.title.getCurrentTitle()iftitle.namespace~=10thenreturnend-- not in template spacelocalsubpage=title.subpageTextifsubpage=='doc'orsubpage=='sandbox'orsubpage=='testcases'thenreturnend--    for i, cat in ipairs(getTrackingCategories()) do--        builder:wikitext('[[Category:' .. cat .. ']]')--    endend----   Main navbox tables--localfunctionrenderMainTable()localtbl=mw.html.create('table'):attr('cellspacing',0):addClass('nowraplinks'):addClass(args.bodyclass)ifargs.titleand(args.state~='plain'andargs.state~='off')thentbl:addClass('collapsible'):addClass(args.stateor'autocollapse')endtbl:css('border-spacing',0)ifborder=='subgroup'orborder=='child'orborder=='none'thentbl:addClass('navbox-subgroup'):cssText(args.bodystyle):cssText(args.style)else-- regular navobx - bodystyle and style will be applied to the wrapper tabletbl:addClass('navbox-inner'):css('background','transparent'):css('color','inherit')endtbl:cssText(args.innerstyle)renderTitleRow(tbl)renderAboveRow(tbl)fori,listnuminipairs(listnums)dorenderListRow(tbl,listnum)endrenderBelowRow(tbl)returntblendfunctionp._navbox(navboxArgs)args=navboxArgsfork,vinpairs(args)dolocallistnum=(''..k):match('^list(%d+)$')iflistnumthentable.insert(listnums,tonumber(listnum))endendtable.sort(listnums)border=trim(args.borderorargs[1]or'')-- render the main body of the navboxlocaltbl=renderMainTable()-- render the appropriate wrapper around the navbox, depending on the border paramlocalres=mw.html.create()ifborder=='none'thenres:node(tbl)elseifborder=='subgroup'orborder=='child'then-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the-- padding being applied, and at the end add a <div> to balance out the parent's </div>res:wikitext('</div>')-- mw.html 未支持 unclosed:node(tbl):wikitext('<div>')-- mw.html 未支持 unclosedelseres:tag('table'):attr('cellspacing',0):addClass('navbox'):css('border-spacing',0):cssText(args.bodystyle):cssText(args.style):tag('tr'):tag('td'):css('padding','2px'):node(tbl)endrenderTrackingCategories(res)returntostring(res)endfunctionp.navbox(frame)ifnotgetArgsthengetArgs=require('Module:Arguments').getArgsendargs=getArgs(frame,{wrappers='Template:Navbox'})-- Read the arguments in the order they'll be output in, to make references number in the right order.local__=args.title_=args.abovefori=1,35do_=args["group"..tostring(i)]_=args["list"..tostring(i)]end_=args.belowreturnp._navbox(args)endreturnp
Lâi-goân: "https://zh-min-nan.wikipedia.org/w/index.php?title=模組:Navbox&oldid=3110176"

[8]ページ先頭

©2009-2026 Movatter.jp