---- Реализует {{ҷадвали новбарӣ}}, {{зергурӯҳи ҷадвали новбарӣ}} ва {{ҷадвали новбарӣ бо блокҳо}}.-- Основной объём кода заимствован из английского Module:Navbox.--localp={}localgetArgs-- lazily initializedlocalyesno-- lazily initializedlocalstyleratiolocalODD_EVEN_MARKER='\127_ODDEVEN_\127'localRESTART_MARKER='\127_ODDEVEN0_\127'localREGEX_MARKER='\127_ODDEVEN(%d?)_\127'-- общие параметры для всех шаблоновlocalcommonAliases={name={'name','ном'},navigation={'navigation','новбарӣ'},navbar={'navbar','пайванд_барои_дидан'},state={'state'},orphan={'orphan'},tracking={'tracking'},border={'border',1},title={'title','сарлавҳа'},titlegroup={'titlegroup'},above={'above','болоӣ'},image={'image','тасвир'},imageleft={'imageleft','тасвир2','тасвир_аз_чап'},below={'below','поёнӣ'},bodyclass={'bodyclass','синфи_бадан'},titleclass={'titleclass','синфи_сарлавҳа'},titlegroupclass={'titlegroupclass'},aboveclass={'aboveclass','синфи_болоӣ'},belowclass={'belowclass','синфи_поёнӣ'},groupclass={'groupclass','синфи_гурӯҳ'},listclass={'listclass','синфи_феҳристҳо'},imageclass={'imageclass','синфи_тасвир'},basestyle={'basestyle','сабк','сабки_асосӣ'},bodystyle={'style','bodystyle','сабки_бадан'},titlestyle={'titlestyle','сабки_сарлавҳаи_асосӣ','сабки_сарлавҳа'},titlegroupstyle={'titlegroupstyle'},innerstyle={'innerstyle'},abovestyle={'abovestyle','сабки_болоӣ'},belowstyle={'belowstyle','сабки_поёнӣ'},imagestyle={'imagestyle','сабки_тасвир'},imageleftstyle={'imageleftstyle','imagestyle2','сабки_тасвир_аз_чап'},}-- параметрҳои {{ҷадвали новбарӣ}} ва {{зергурӯҳи ҷадвали новбарӣ}}localstandardAliases={groupstyle={'groupstyle','сабки_сарлавҳаҳо','сабки_гурӯҳ'},liststyle={'liststyle','сабки_феҳристҳо'},evenodd={'evenodd','ҷуфт_тоқ','ҷуфт_тоқ'},groupwidth={'groupwidth','бари_гурӯҳ'},listpadding={'listpadding','фосилаи_феҳристҳо'},}-- параметры {{ҷадвали новбарӣ}} ва {{зергурӯҳи ҷадвали новбарӣ}} с нумерациейlocalstandardElementAliases={group={'group%s','сарлавҳа%s','гурӯҳ%s'},list={'list%s','феҳрист%s'},groupstyle={'group%sstyle','сабки_сарлавҳа%s','сабки_гурӯҳҳо%s'},listclass={'list%sclass','синфи%sфеҳрист','синфи_феҳрист%s'},liststyle={'list%sstyle','сабки_феҳрист%s'},listpadding={'list%spadding'}}-- параметры {{ҷадвали новбарӣ бо блокҳо}}-- с нижнего подчеркивания начинаются параметры, конфликтующие с standardAliaseslocalgroupsParentAliases={selected={'selected','блоки_боз','васеъ кардан'},secttitlestyle={'secttitlestyle','сабки_сарлавҳаҳо'},_groupstyle={'groupstyle','сабки_блоков'},_liststyle={'liststyle','сабки_феҳристҳо','contentstyle'},_listpadding={'listpadding','фосилаи_феҳрист','фосилаи_феҳристҳо'}}-- параметры {{ҷадвали новбарӣ бо блокҳо}} с нумерациейlocalgroupsChildAliases={groupname={'abbr%s','номи_блок%s','аббр%s'},state={'state%s'},title={'group%s','блок%s','сарлавҳа%s','гурӯҳ%s','sect%s','section%s','бахш%s'},list1={'list%s','феҳрист%s','content%s'},image={'image%s','тасвир%s'},imageleft={'imageleft%s','тасвир_аз_чап%s'},secttitlestyle={'sect%stitlestyle','сабки%sсарлавҳа','сабки_секции%s'},groupstyle={'group%sstyle','сабки%sблок','сабки_гурӯҳҳо%s','сабки_блок%s'},listclass={'list%sclass','синфи%sфеҳрист','синфи_феҳрист%s'},liststyle={'list%sstyle','сабки%sфеҳрист','сабки_феҳрист%s','content%sstyle'},color={'цвет%s'}}localfunctioncheckAliases(args,aliases,index)for_,aliasinipairs(aliases)dolocalargifindexthenarg=args[string.format(alias,index)]elsearg=args[alias]endifargthenreturnargendendreturnnilendlocalfunctioncheckElAliases(args,name,index)returncheckAliases(args,standardElementAliases[name],index)endlocalfunctionconcatStyles(t)localresfork,vinpairs(t)doifvthenres=resandres..';'..vorvendendreturnresendlocalfunctionstriped(wikitext,args)-- Return wikitext with markers replaced for odd/even striping.-- Child (subgroup) navboxes are flagged with a category that is removed-- by parent navboxes. The result is that the category shows all pages-- where a child navbox is not contained in a parent navbox.localorphanCat='[[Гурӯҳ:Шаблонҳои новбарии беволидайн]]'ifargs.border=='subgroup'andargs.orphan~='yes'then-- No change; striping occurs in outermost navbox.returnwikitext..orphanCatendlocalfirst,second='odd','even'ifargs.evenoddthenifargs.evenodd=='swap'thenfirst,second=second,firstelsefirst=args.evenoddsecond=firstendendlocalchangeriffirst==secondthenchanger=firstelselocalindex=0changer=function(code)ifcode=='0'then-- Current occurrence is for a group before a nested table.-- Set it to first as a valid although pointless class.-- The next occurrence will be the first row after a title-- in a subgroup and will also be first.index=0returnfirstendindex=index+1returnindex%2==1andfirstorsecondendendlocalregex=orphanCat:gsub('([%[%]])','%%%1')return(wikitext:gsub(regex,''):gsub(REGEX_MARKER,changer))-- () omits gsub countendlocalfunctionaddNewline(s)ifs:match('^[*:;#]')ors:match('^{|')thenreturn'\n'..s..'\n'elsereturnsendendlocalfunctionrenderNavBar(titleCell,args)localcurrentFrame=mw.getCurrentFrame()ifargs.navbar~='off'andargs.navbar~='plain'and(args.nameornotcurrentFrame:getParent():getTitle():gsub('/регдон$','')=='Шаблон:Ҷадвали новбарӣ')then-- Check color contrast of the gear iconifnotstyleratiothenstyleratio=require('Module:Color contrast')._styleratioendlocalcontrastStyle=args.titlestyleorargs.basestylelocalgearStyleBlack=(contrastStyleandmw.text.unstripNoWiki(contrastStyle)..'; color:#666;'or'')localgearStyleWhite=(contrastStyleandmw.text.unstripNoWiki(contrastStyle)..'; color:#fff;'or'')localgear=currentFrame:expandTemplate{title='Tnavbar-view',args={args.name,fontcolor=(styleratio{gearStyleBlack}<styleratio{gearStyleWhite})and'white',}}--- Gear creationtitleCell:tag('span'):addClass('navbox-gear'):css('float','left'):css('text-align','left'):css('width','5em'):css('margin-right','0.5em'):wikitext(gear)endend---- Title row--localfunctionrenderTitleRow(tbl,args)ifnotargs.titlethenreturnendlocaltitleRow=tbl:tag('tr')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','colgroup')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'):attr('colspan',titleColspan)renderNavBar(titleCell,args)titleCell:tag('div'):attr('id',mw.uri.anchorEncode(args.title)):addClass(args.titleclass):css('font-size','114%'):css('margin','0 5em'):wikitext(addNewline(args.title))end---- Above/Below rows--localfunctiongetAboveBelowColspan(args)localret=2ifargs.imageleftthenret=ret+1endifargs.imagethenret=ret+1endreturnretendlocalfunctionrenderAboveRow(tbl,args)ifnotargs.abovethenreturnendtbl:tag('tr'):tag('td'):addClass('navbox-abovebelow'):addClass(args.aboveclass):cssText(args.basestyle):cssText(args.abovestyle):attr('colspan',getAboveBelowColspan(args)):tag('div'):wikitext(addNewline(args.above))endlocalfunctionrenderBelowRow(tbl,args)ifnotargs.belowthenreturnendtbl:tag('tr'):tag('td'):addClass('navbox-abovebelow'):addClass(args.belowclass):cssText(args.basestyle):cssText(args.belowstyle):attr('colspan',getAboveBelowColspan(args)):tag('div'):wikitext(addNewline(args.below))end---- List rows--localfunctionhaveSubgroups(args)fori=1,23doifcheckElAliases(args,'group',i)andcheckElAliases(args,'list',i)thenreturntrueendendreturnfalseendlocalfunctionrenderListRow(tbl,args,index,rowspan,rowArgs)localrow=tbl:tag('tr')ifindex==1andargs.imageleftthenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width','1px'):css('padding','0px 7px 0px 0px'):cssText(args.imageleftstyle):attr('rowspan',rowspan):tag('div'):wikitext(addNewline(args.imageleft))endifrowArgs.groupthenlocalgroupCell=row:tag('th')groupCell:attr('scope','row'):addClass('navbox-group'):addClass(args.groupclass):cssText(args.basestyle):css('width',args.groupwidthor'1px')-- If groupwidth not specified, minimize widthgroupCell:cssText(args.groupstyle):cssText(rowArgs.groupstyle):wikitext(rowArgs.group)endlocallistCell=row:tag('td')ifrowArgs.groupthenlistCell:css('text-align','left'):css('border-left-width','2px'):css('border-left-style','solid')elseifhaveSubgroups(args)thenlistCell:attr('colspan',2)endendifnotargs.groupwidththenlistCell:css('width','100%')endlocallistText=rowArgs.listlocaloddEven=ODD_EVEN_MARKERiflistText:sub(1,12)=='</div><table'then-- Assume list text is for a subgroup navbox so no automatic striping for this row.oddEven=listText:find('<th[^>]*"navbox%-title"')andRESTART_MARKERor'odd'endlistCell:css('padding','0px'):cssText(args.liststyle):cssText(rowArgs.liststyle):addClass('navbox-list'):addClass('navbox-'..oddEven):addClass(args.listclass):addClass(rowArgs.listclass):tag('div'):css('padding',rowArgs.listpaddingorargs.listpaddingor'0em 0.25em'):wikitext(addNewline(listText))ifindex==1andargs.imagethenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width','1px'):css('padding','0px 0px 0px 7px'):cssText(args.imagestyle):attr('rowspan',rowspan):tag('div'):wikitext(addNewline(args.image))endend---- Tracking categories--localfunctionneedsChangetoSubgroups(args)fori=1,23doif(checkElAliases(args,'group',i))andnot(checkElAliases(args,'list',i))thenreturntrueendendreturnfalseendlocalfunctionneedsHorizontalLists(args)ifargs.border=='subgroup'orargs.tracking=='no'thenreturnfalseendlocallistClasses={['plainlist']=true,['hlist']=true,['hlist hnum']=true,['hlist hwrap']=true,['hlist vcard']=true,['vcard hlist']=true,['hlist vevent']=true,['hlist hlist-items-nowrap']=true,['hlist-items-nowrap']=true,}returnnot(listClasses[args.listclass]orlistClasses[args.bodyclass])end-- local function hasBackgroundColors()--return mw.ustring.match(titlestyle or '','background') or mw.ustring.match(groupstyle or '','background') or mw.ustring.match(basestyle or '','background')-- endlocalfunctionisIllegible(args)ifnotstyleratiothenstyleratio=require('Module:Color contrast')._styleratioendforkey,styleinpairs(args)doiftostring(key):match("style$")ortostring(key):match("^сабк")thenifstyleratio{mw.text.unstripNoWiki(style)}<4.5thenreturntrueendendendreturnfalseendlocalfunctiongetTrackingCategories(args)localcats={}ifneedsChangetoSubgroups(args)thentable.insert(cats,'Навигационные шаблоны с ошибочным использованием сарлавҳаҳо')endifneedsHorizontalLists(args)thentable.insert(cats,'Навигационные шаблоны без горизонтальных списков')endifisIllegible(args)thentable.insert(cats,'Потенциально нечитаемые навигационные шаблоны')endreturncatsendlocalfunctionrenderTrackingCategories(builder,args)localtitle=mw.title.getCurrentTitle()iftitle.namespace~=10thenreturnend-- not in template spacelocalsubpage=title.subpageTextifsubpage=='doc'orsubpage=='регдон'orsubpage=='санҷишҳо'thenreturnendfori,catinipairs(getTrackingCategories(args))dobuilder:wikitext('[[Гурӯҳ:'..cat..']]')endend---- Main navbox tables--localfunctionrenderMainTable(args,listnums)localtbl=mw.html.create('table'):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)ifargs.border=='subgroup'orargs.border=='none'thentbl:addClass('navbox-subgroup'):cssText(args.bodystyle)else-- regular navbox - 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,args)renderAboveRow(tbl,args)fori,listnuminipairs(listnums)dolocalrowArgs={group=checkElAliases(args,'group',listnum),list=checkElAliases(args,'list',listnum),groupstyle=checkElAliases(args,'groupstyle',listnum),listclass=checkElAliases(args,'listclass',listnum),liststyle=checkElAliases(args,'liststyle',listnum),listpadding=checkElAliases(args,'listpadding',listnum)}renderListRow(tbl,args,i,#listnums,rowArgs)endrenderBelowRow(tbl,args)returntblend-- Read the arguments in the order they'll be output in, to make references number in the right order.localfunctionreadInTheRightOrder(args,groupAliases,listAliases)local__=checkAliases(args,commonAliases.title)_=checkAliases(args,commonAliases.above)fori=1,23do_=checkAliases(args,groupAliases,i)_=checkAliases(args,listAliases,i)end_=checkAliases(args,commonAliases.below)endfunctionp._navbox(args)ifnotyesnothenyesno=require('Module:Yesno')endlocallistnums={}fork,vinpairs(args)dolocallistnum=(''..k):match('^list(%d+)$')or(''..k):match('^феҳрист(%d+)$')iflistnumthentable.insert(listnums,tonumber(listnum))endendtable.sort(listnums)args.border=mw.text.trim(args.borderorargs[1]or'')ifargs.border=='child'thenargs.border='subgroup'endforargname,aliasesListinpairs(commonAliases)doargs[argname]=checkAliases(args,aliasesList)endforargname,aliasesListinpairs(standardAliases)doargs[argname]=checkAliases(args,aliasesList)endargs.navigation=yesno(args.navigation,'')-- render the main body of the navboxlocaltbl=renderMainTable(args,listnums)-- render the appropriate wrapper around the navbox, depending on the border paramlocalres=mw.html.create()ifargs.border=='none'thenlocalnav=res:tag('div'):attr('role','navigation'):node(tbl)ifargs.titlethennav:attr('aria-labelledby',mw.uri.anchorEncode(args.title))elsenav:attr('aria-label','Навигационный шаблон')endifargs.nameandargs.name~='-'thennav:attr('data-name',args.name)endifargs.navigation==truethennav:attr('data-navboxnavigation','1')elseifargs.navigation==falsethennav:attr('data-navboxnavigation','0')endelseifargs.border=='subgroup'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>')-- XXX: hack due to lack of unclosed support in mw.html.:node(tbl):wikitext('<div>')-- XXX: hack due to lack of unclosed support in mw.html.elselocalnav=res:tag('div'):attr('role','navigation'):addClass('navbox'):cssText(args.bodystyle):node(tbl)ifargs.titlethennav:attr('aria-labelledby',mw.uri.anchorEncode(args.title))elsenav:attr('aria-label','Навигационный шаблон')endifargs.nameandargs.name~='-'thennav:attr('data-name',args.name)endifargs.navigation==truethennav:attr('data-navboxnavigation','1')elseifargs.navigation==falsethennav:attr('data-navboxnavigation','0')endendrenderTrackingCategories(res,args)returnstriped(tostring(res),args)endfunctionp.navbox(frame)ifnotgetArgsthengetArgs=require('Module:Arguments').getArgsendifnotyesnothenyesno=require('Module:Yesno')endargs=getArgs(frame,{wrappers={'Шаблон:Ҷадвали новбарӣ','Шаблон:зергурӯҳи ҷадвали новбарӣ'}})ifframe.args.borderthen-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}.args.border=frame.args.borderendreadInTheRightOrder(args,standardElementAliases.group,standardElementAliases.list)returnp._navbox(args)endfunctionp.navboxWithCollapsibleGroups(frame)ifnotgetArgsthengetArgs=require('Module:Arguments').getArgsendlocalargs=getArgs(frame,{wrappers={'Шаблон:Ҷадвали новбарӣ бо блокҳо'}})readInTheRightOrder(args,groupsChildAliases.title,groupsChildAliases.list1)localparent={}forargname,aliasesListinpairs(commonAliases)doparent[argname]=checkAliases(args,aliasesList)endforargname,aliasesListinpairs(groupsParentAliases)doparent[argname]=checkAliases(args,aliasesList)endfori=1,20dolocalchild={}forargname,aliasesListinpairs(groupsChildAliases)dochild[argname]=checkAliases(args,aliasesList,i)endchild.color=child.colorandstring.format('background:%s;',child.color)or''child.border='child'child.navbar='plain'ifparent.selectedandparent.selected==child.groupnamethenchild.state='uncollapsed'endchild.state=child.stateor'collapsed'child.basestyle=concatStyles{parent.basestyle,parent.secttitlestyle,child.secttitlestyle}child.titlestyle=concatStyles{parent._groupstyle,child.groupstyle,child.color}child.liststyle=concatStyles{parent._liststyle,child.liststyle}child.lispadding=parent._listpaddingifchild.titlethenparent['list'..i]=p._navbox(child)elseparent['list'..i]=child.list1endendreturnp._navbox(parent)endreturnp