Module:Navbox: Difference between revisions
edit for succinctness
m>Dragons flight (missed an option) |
m>Toohool (edit for succinctness) |
||
Line 82: | Line 82: | ||
function formNavBar( | function formNavBar( args ) | ||
local | if not args[1] then | ||
local span = HtmlBuilder.create('span') | |||
span | |||
.addClass('error') | |||
.css('float', 'left') | |||
.css('white-space', 'nowrap') | |||
.wikitext('Error: No name provided') | |||
return span | |||
end | |||
local title; | local title; | ||
local pageName = trim( args[1] ) | |||
if pageName:sub(1,1) == ':' then | |||
if | title = mw.title.new( pageName:sub(2) ); | ||
title = mw.title.new( | |||
else | else | ||
title = mw.title.new( | title = mw.title.new( pageName ); | ||
if title.namespace == 0 then | if title.namespace == 0 then | ||
title = mw.title. | title = mw.title.makeTitle( 'Template', pageName ); | ||
end | end | ||
end | end | ||
local | local mainpage = title.fullText; | ||
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '' | |||
talkpage = title.talkPageTitle | local editurl = title:fullUrl( 'action=edit' ); | ||
editurl = title:fullUrl( 'action=edit' ); | |||
if args.mini | local viewLink, talkLink, editLink = 'view', 'talk', 'edit' | ||
if args.mini then | |||
viewLink, talkLink, editLink = 'v', 't', 'e' | |||
end | end | ||
local div = HtmlBuilder.create( 'div' ) | |||
div | div | ||
.addClass( | .addClass( 'noprint' ) | ||
.cssText( args.style | .addClass( 'plainlinks' ) | ||
.addClass( 'hlist' ) | |||
.addClass( 'navbar') | |||
.cssText( args.style ) | |||
if args.mini then div.addClass('mini') end | |||
if args.mini | if not (args.mini or args.plain) then | ||
div.tag( 'span' ) | div | ||
.tag( 'span' ) | |||
.css( 'word-spacing', 0 ) | |||
.cssText( args.fontstyle ) | |||
.wikitext( args.text or 'This box:' ) | |||
.wikitext( ' ' ) | |||
end | end | ||
if args.brackets | if args.brackets then | ||
div | div | ||
.tag('span') | |||
.css('margin-right', '-0.125em') | |||
.cssText( args.fontstyle ) | |||
.wikitext( '[' ) | |||
.newline(); | |||
end | end | ||
local ul = div.tag('ul'); | local ul = div.tag('ul'); | ||
ul.tag( 'li' ) | ul | ||
.tag( 'li' ) | |||
.addClass( 'nv-view' ) | |||
.wikitext( '[[' .. mainpage .. '|' ) | |||
.tag( 'span ' ) | |||
.attr( 'title', 'View this template' ) | |||
.wikitext( | .cssText( args.fontstyle or '' ) | ||
.wikitext( viewLink ) | |||
.done() | |||
.wikitext( ']]' ) | |||
.done() | .done() | ||
.tag( 'li' ) | |||
.addClass( 'nv-talk' ) | |||
.wikitext( '[[' .. talkpage .. '|' ) | |||
.tag( 'span ' ) | .tag( 'span ' ) | ||
.attr( 'title', ' | .attr( 'title', 'Discuss this template' ) | ||
.cssText( args.fontstyle or '' ) | .cssText( args.fontstyle or '' ) | ||
.wikitext( | .wikitext( talkLink ) | ||
.done() | .done() | ||
.wikitext( ']' ); | .wikitext( ']]' ); | ||
if not args.noedit then | |||
ul | |||
.tag( 'li' ) | |||
.addClass( 'nv-edit' ) | |||
.wikitext( '[' .. editurl .. ' ' ) | |||
.tag( 'span ' ) | |||
.attr( 'title', 'Edit this template' ) | |||
.cssText( args.fontstyle or '' ) | |||
.wikitext( editLink ) | |||
.done() | |||
.wikitext( ']' ); | |||
end | end | ||
if args.brackets | if args.brackets then | ||
div.tag('span') | div | ||
.tag('span') | |||
.css('margin-left', '-0.125em') | |||
.cssText( args.fontstyle or '' ) | |||
.wikitext( ']' ) | |||
.newline(); | |||
end | end | ||
Line 208: | Line 208: | ||
if args.state == 'plain' then spacerSide = 'right' end | if args.state == 'plain' then spacerSide = 'right' end | ||
titleCell.node(formNavBar({ | |||
args.name, | |||
mini = 1, | |||
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;' | |||
})) | |||
end | end | ||
Line 532: | Line 519: | ||
end | end | ||
end | end | ||
return tostring( formNavBar( args ) ) | |||
return tostring( formNavBar( | |||
end | end | ||
return p | return p |