Module:Navbox: Difference between revisions
From Test Wiki
Content deleted Content added
add support for list1padding param |
pull navbar completely inside Lua |
||
| Line 79: | Line 79: | ||
.newline() |
.newline() |
||
.wikitext(args.title) |
.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 |
end |
||
| Line 99: | Line 202: | ||
if args.name then |
if args.name then |
||
local div = HtmlBuilder.create('div'); |
|||
titleCell.wikitext(mw.getCurrentFrame():expandTemplate{ title = 'navbar', args = { |
|||
local args = { |
|||
args.name, |
args.name, |
||
mini = 1, |
mini = 1, |
||
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;' |
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;' |
||
} |
}; |
||
div = formNavBar( div, args ); |
|||
titleCell.node( div ) |
|||
else |
else |
||
titleCell |
titleCell |
||
| Line 406: | Line 513: | ||
end |
end |
||
return p._navbox(args) |
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 |
end |
||