Open main menu

Changes

Module:Navbox

3,136 bytes added, 00:04, 16 March 2013
pull navbar completely inside Lua
.newline()
.wikitext(args.title)
end
 
 
function formNavBar( div, args )
local class = 'noprint plainlinks hlist navbar';
local title;
if args[1] == '' then
title = mw.title.new( '' );
elseif args[1]:sub(1,1) == ':' then
title = mw.title.new( args[1] );
else
title = mw.title.new( 'Template:' .. args[1] );
end
local mainpage, talkpage, editurl;
mainpage = title.fullText;
talkpage = title.talkPageTitle;
talkpage = talkpage.fullText or '';
editurl = title:fullUrl( 'action=edit' );
if args.mini ~= nil then
class = class .. ' mini';
end
 
div
.addClass( class )
.cssText( args.style or '' )
if args.mini == nil and args.plain == nil then
div.tag( 'span' )
.css( 'word-spacing', 0 )
.cssText( args.fontstyle or '' )
.wikitext( args.text or 'This box:' );
end
if args.brackets ~= nil then
div.wikitext(' ');
div.tag('span')
.css('margin-right', '-0.125em')
.cssText( args.fontstyle or '' )
.wikitext( '[' )
.newline();
end
local ul = div.tag('ul');
local inner
if args.mini ~= nil then
inner = 'v';
else
inner = 'view';
end
ul.tag( 'li' )
.addClass( 'nv-view' )
.wikitext( '[[' .. mainpage .. '|' )
.tag( 'span ' )
.attr( 'title', 'View this template' )
.cssText( args.fontstyle or '' )
.wikitext( inner )
.done()
.wikitext( ']]' );
 
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.mini ~= nil then
inner = 'e';
else
inner = 'edit';
end
ul.tag( 'li' )
.addClass( 'nv-edit' )
.wikitext( '[' .. editurl .. ' ' )
.tag( 'span ' )
.attr( 'title', 'Edit this template' )
.cssText( args.fontstyle or '' )
.wikitext( inner )
.done()
.wikitext( ']' );
 
if args.brackets ~= nil then
div.tag('span')
.css('margin-left', '-0.125em')
.cssText( args.fontstyle or '' )
.wikitext( ']' )
.newline();
end
 
return div;
end
if args.name then
titleCell.wikitext(mwlocal div = HtmlBuilder.getCurrentFramecreate():expandTemplate{ title = 'navbardiv', ); local args = {
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
end
return p._navbox(args)
end
function p.navbar(frame)
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- behavior of {{navbox}}, change any empty arguments to nil, so Lua will consider
-- them false too.
local args = {}
for k, v in pairs(frame:getParent().args) do
if v ~= '' then
args[k] = v
end
end
local div = HtmlBuilder.create('div')
return tostring( formNavBar( div, args ) )
end
return p
Anonymous user