Module:Navbox: Difference between revisions

From Test Wiki
Content deleted Content added
missed an option
edit for succinctness
Line 82: Line 82:




function formNavBar( div, args )
function formNavBar( args )
if not args[1] then
local class = 'noprint plainlinks hlist navbar';
local title;
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
title = mw.title.new( '' );
local pageName = trim( args[1] )
elseif args[1]:sub(1,1) == ':' then
if pageName:sub(1,1) == ':' then
title = mw.title.new( args[1]:sub(2) );
title = mw.title.new( pageName:sub(2) );
else
else
title = mw.title.new( args[1] );
title = mw.title.new( pageName );
if title.namespace == 0 then
if title.namespace == 0 then
title = mw.title.new( 'Template:' .. args[1] );
title = mw.title.makeTitle( 'Template', pageName );
end
end
end
end
local mainpage, talkpage, editurl;
local mainpage = title.fullText;
mainpage = title.fullText;
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
talkpage = title.talkPageTitle;
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( class )
.addClass( 'noprint' )
.cssText( args.style or '' )
.addClass( 'plainlinks' )
.addClass( 'hlist' )
.addClass( 'navbar')
.cssText( args.style )
if args.mini == nil and args.plain == nil then
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 '' )
.wikitext( args.text or 'This box:' );
.tag( 'span' )
.css( 'word-spacing', 0 )
.cssText( args.fontstyle )
.wikitext( args.text or 'This box:' )
.wikitext( ' ' )
end
end
if args.brackets ~= nil then
if args.brackets then
div.wikitext(' ');
div
div.tag('span')
.tag('span')
.css('margin-right', '-0.125em')
.css('margin-right', '-0.125em')
.cssText( args.fontstyle or '' )
.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.tag( 'li' )
ul
.addClass( 'nv-view' )
.tag( 'li' )
.wikitext( '[[' .. mainpage .. '|' )
.addClass( 'nv-view' )
.tag( 'span ' )
.wikitext( '[[' .. mainpage .. '|' )
.attr( 'title', 'View this template' )
.tag( 'span ' )
.cssText( args.fontstyle or '' )
.attr( 'title', 'View this template' )
.wikitext( inner )
.cssText( args.fontstyle or '' )
.wikitext( viewLink )
.done()
.wikitext( ']]' )
.done()
.done()
.wikitext( ']]' );
.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', 'Edit this template' )
.attr( 'title', 'Discuss this template' )
.cssText( args.fontstyle or '' )
.cssText( args.fontstyle or '' )
.wikitext( inner )
.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 ~= nil then
if args.brackets then
div.tag('span')
div
.css('margin-left', '-0.125em')
.tag('span')
.cssText( args.fontstyle or '' )
.css('margin-left', '-0.125em')
.wikitext( ']' )
.cssText( args.fontstyle or '' )
.newline();
.wikitext( ']' )
.newline();
end
end


Line 208: Line 208:
if args.state == 'plain' then spacerSide = 'right' end
if args.state == 'plain' then spacerSide = 'right' end


if args.name then
titleCell.node(formNavBar({
local div = HtmlBuilder.create('div');
args.name,
local args = {
mini = 1,
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;'
args.name,
mini = 1,
}))
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