Module:Navbox: Difference between revisions
From Test Wiki
Content deleted Content added
missed an option |
edit for succinctness |
||
| Line 82: | Line 82: | ||
function formNavBar( |
function formNavBar( args ) |
||
if not args[1] then |
|||
local class = 'noprint plainlinks hlist navbar'; |
|||
local |
local span = HtmlBuilder.create('span') |
||
args[1] = trim( args[1] or '' ); |
|||
span |
|||
.addClass('error') |
|||
.css('float', 'left') |
|||
.css('white-space', 'nowrap') |
|||
.wikitext('Error: No name provided') |
|||
return span |
|||
end |
|||
local title; |
|||
if args[1] == '' then |
|||
local pageName = trim( args[1] ) |
|||
if pageName:sub(1,1) == ':' then |
|||
title = mw.title.new( |
title = mw.title.new( pageName:sub(2) ); |
||
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 mainpage |
local mainpage = title.fullText; |
||
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '' |
|||
local editurl = title:fullUrl( 'action=edit' ); |
|||
talkpage = talkpage.fullText or ''; |
|||
editurl = title:fullUrl( 'action=edit' ); |
|||
local viewLink, talkLink, editLink = 'view', 'talk', 'edit' |
|||
if args.mini ~= nil then |
|||
if args.mini then |
|||
class = class .. ' mini'; |
|||
viewLink, talkLink, editLink = 'v', 't', 'e' |
|||
end |
end |
||
local div = HtmlBuilder.create( 'div' ) |
|||
div |
div |
||
.addClass( |
.addClass( 'noprint' ) |
||
. |
.addClass( 'plainlinks' ) |
||
.addClass( 'hlist' ) |
|||
.addClass( 'navbar') |
|||
.cssText( args.style ) |
|||
if args.mini |
if args.mini then div.addClass('mini') end |
||
div.tag( 'span' ) |
|||
if not (args.mini or args.plain) then |
|||
.css( 'word-spacing', 0 ) |
|||
div |
|||
.cssText( args.fontstyle or '' ) |
|||
. |
.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') |
.css('margin-right', '-0.125em') |
||
.cssText( args.fontstyle |
.cssText( args.fontstyle ) |
||
.wikitext( '[' ) |
.wikitext( '[' ) |
||
.newline(); |
.newline(); |
||
end |
end |
||
local ul = div.tag('ul'); |
local ul = div.tag('ul'); |
||
local inner |
|||
if args.mini ~= nil then |
|||
inner = 'v'; |
|||
else |
|||
inner = 'view'; |
|||
end |
|||
ul |
ul |
||
. |
.tag( 'li' ) |
||
.addClass( 'nv-view' ) |
|||
. |
.wikitext( '[[' .. mainpage .. '|' ) |
||
. |
.tag( 'span ' ) |
||
. |
.attr( 'title', 'View this template' ) |
||
. |
.cssText( args.fontstyle or '' ) |
||
.wikitext( viewLink ) |
|||
.done() |
|||
.wikitext( ']]' ) |
|||
.done() |
.done() |
||
. |
.tag( 'li' ) |
||
.addClass( 'nv-talk' ) |
|||
.wikitext( '[[' .. talkpage .. '|' ) |
|||
if args.mini ~= nil then |
|||
inner = 't'; |
|||
else |
|||
inner = 'talk'; |
|||
end |
|||
ul.tag( 'li' ) |
|||
.addClass( 'nv-talk' ) |
|||
.wikitext( '[[' .. talkpage .. '|' ) |
|||
.tag( 'span ' ) |
|||
.attr( 'title', 'Discuss this template' ) |
|||
.cssText( args.fontstyle or '' ) |
|||
.wikitext( inner ) |
|||
.done() |
|||
.wikitext( ']]' ); |
|||
if args.noedit == nil then |
|||
if args.mini ~= nil then |
|||
inner = 'e'; |
|||
else |
|||
inner = 'edit'; |
|||
end |
|||
ul.tag( 'li' ) |
|||
.addClass( 'nv-edit' ) |
|||
.wikitext( '[' .. editurl .. ' ' ) |
|||
.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 |
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;' |
|||
args.name, |
|||
})) |
|||
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;' |
|||
}; |
|||
div = formNavBar( div, args ); |
|||
titleCell.node( div ) |
|||
else |
|||
titleCell |
|||
.tag('span') |
|||
.addClass('error') |
|||
.css('float', 'left') |
|||
.css('white-space', 'nowrap') |
|||
.wikitext('Error: No name provided') |
|||
end |
|||
end |
end |
||
| Line 532: | Line 519: | ||
end |
end |
||
end |
end |
||
return tostring( formNavBar( args ) ) |
|||
local div = HtmlBuilder.create('div') |
|||
return tostring( formNavBar( div, args ) ) |
|||
end |
end |
||