Иһинээҕитигэр көс

Модуль:Navbar

Бикипиэдьийэ диэн сиртэн ылыллыбыт

Для документации этого модуля может быть создана страницаМодуль:Navbar/doc

localp={}

localgetArgs
localHtmlBuilder=require('Модуль:HtmlBuilder')

localfunctiontrim(s)
returnmw.ustring.match(s,"^%s*(.-)%s*$")
end

localfunctionhtmlError(s)
localspan=HtmlBuilder.create('span')

span
.addClass('error')
.css('float','left')
.css('white-space','nowrap')
.wikitext('Error: '..s)

returntostring(span)
end

localfunctiongetTitle(pageName)
pageName=trim(pageName);
localpage_title,talk_page_title;

ifmw.ustring.sub(pageName,1,1)==':'then
page_title=mw.title.new(mw.ustring.sub(pageName,2));
else
page_title=mw.title.new(pageName,'Халыып');
end

ifpage_titlethen
talk_page_title=page_title.talkPageTitle;
else
talk_page_title=nil;
end

returnpage_title,talk_page_title;
end

functionp._navbar(args)
localgood,title,talk_title;
localtitleArg=1

ifargs.collapsiblethen
titleArg=2
ifnotargs.plainthen
args.mini=1
end
ifargs.fontcolorthen
args.fontstyle='color:'..args.fontcolor..';'
end
args.style='float:left; text-align:left; width:6em;'
end

good,title,talk_title=pcall(getTitle,args[titleArg]or(':'..mw.getCurrentFrame():getParent():getTitle()));
ifnotgoodthen
returnhtmlError(title);
end

ifnottitlethen
returnhtmlError('Page does not exist')
end

localmainpage=title.fullText;
localtalkpage=talk_titleandtalk_title.fullTextor''
localediturl=title:fullUrl('action=edit');

localviewLink,talkLink,editLink='view','talk','edit'
ifargs.minithen
viewLink,talkLink,editLink='v','t','e'
end

localdiv=HtmlBuilder.create().tag('div')
div
.addClass('plainlinks')
.addClass('hlist')
.addClass('navbar')
.cssText(args.style)

ifargs.minithendiv.addClass('mini')end

ifnot(args.miniorargs.plain)then
div
.tag('span')
.css('word-spacing',0)
.cssText(args.fontstyle)
.wikitext(args.textor'This box:')
.wikitext(' ')
end

ifargs.bracketsthen
div
.tag('span')
.css('margin-right','-0.125em')
.cssText(args.fontstyle)
.wikitext('[')
.newline();
end

localul=div.tag('ul');

ul
.tag('li')
.addClass('nv-view')
.wikitext('[['..mainpage..'|')
.tag('span')
.attr('title','View this template')
.cssText(args.fontstyleor'')
.wikitext(viewLink)
.done()
.wikitext(']]')
.done()
.tag('li')
.addClass('nv-talk')
.wikitext('[['..talkpage..'|')
.tag('span')
.attr('title','Discuss this template')
.cssText(args.fontstyleor'')
.wikitext(talkLink)
.done()
.wikitext(']]');

ifnotargs.noeditthen
ul
.tag('li')
.addClass('nv-edit')
.wikitext('['..editurl..' ')
.tag('span')
.attr('title','Edit this template')
.cssText(args.fontstyleor'')
.wikitext(editLink)
.done()
.wikitext(']');
end

ifargs.bracketsthen
div
.tag('span')
.css('margin-left','-0.125em')
.cssText(args.fontstyleor'')
.wikitext(']')
.newline();
end

ifargs.collapsiblethen
div
.done()
.tag('span')
.css('font-size','110%')
.cssText(args.fontstyleor'')
.wikitext(args[1])
end

returntostring(div.allDone())
end

functionp.navbar(frame)
ifnotgetArgsthen
getArgs=require('Модуль:Arguments').getArgs
end
returnp._navbar(getArgs(frame))
end

returnp