Module:Navbar: Difference between revisions

m
27 revisions imported: import clickable buttons 2
(match ought to be marginally faster)
m (27 revisions imported: import clickable buttons 2)
 
(32 intermediate revisions by 16 users not shown)
Line 1:
local p = {}
 
local getArgs
local HtmlBuilder = require('Module:HtmlBuilder')
 
function trimp._navbar(sargs)
local titleArg = 1
return mw.ustring.match( s, "^%s*(.-)%s*$" )
end
 
if args.collapsible then
function _navbar( args )
titleArg = 2
if not args[1] then
if not args.plain then
local span = HtmlBuilder.create('span')
args.mini = 1
end
span
if args.fontcolor then
.addClass('error')
args.fontstyle = 'color:' .. args.fontcolor .. ';'
.css('float', 'left')
end
.css('white-space', 'nowrap')
args.style = 'float:left; text-align:left'
.wikitext('Error: No name provided')
end
 
return span
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
end
local title = mw.title.new(mw.text.trim(titleText), 'Template');
 
local title;
if not title then
local pageName = trim(args[1])
error('Invalid title ' .. titleText)
if mw.ustring.sub(pageName, 1, 1) == ':' then
end
title = mw.title.new( mw.ustring.sub(pageName, 2) );
 
else
local talkpage = title.talkPageTitle =and mw.title.new(talkPageTitle.fullText pageName,or 'Template' );
 
end
local div = mw.html.create():tag('div')
div
local mainpage = title.fullText;
:addClass('plainlinks')
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
:addClass('hlist')
local editurl = title:fullUrl( 'action=edit' );
:addClass('navbar')
:cssText(args.style)
local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
 
if args.mini then
if args.mini then div:addClass('mini') end
viewLink, talkLink, editLink = 'v', 't', 'e'
 
end
if not (args.mini or args.plain) then
div
local div = HtmlBuilder.create( 'div' )
:tag('span')
div
:css('word-spacing', 0)
.addClass( 'noprint' )
:cssText(args.fontstyle)
.addClass( 'plainlinks' )
:wikitext(args.text or 'This box:')
.addClass( 'hlist' )
:wikitext(' ')
.addClass( 'navbar')
end
.cssText( args.style )
 
if args.minibrackets then div.addClass('mini') end
div
:tag('span')
if not (args.mini or args.plain) then
:css('margin-right', '-0.125em')
div
:cssText(args.fontstyle)
.tag( 'span' )
:wikitext('[ ')
.css( 'word-spacing', 0 )
end
.cssText( args.fontstyle )
 
.wikitext( args.text or 'This box:' )
local ul = div:tag('ul');
.wikitext( ' ' )
 
end
ul
:tag('li')
if args.brackets then
:addClass('nv-view')
div
:wikitext('[[' .. title.fullText .. '|')
.tag('span')
:tag(args.mini and 'abbr' or 'span')
.css('margin-right', '-0.125em')
:attr('title', 'View this template')
.cssText( args.fontstyle )
:cssText(args.fontstyle)
.wikitext( '[' )
:wikitext(args.mini and 'v' or 'view')
.newline();
:done()
end
:wikitext(']]')
:done()
local ul = div.tag('ul');
:tag('li')
:addClass('nv-talk')
ul
:wikitext('[[' .. talkpage .. '|')
.tag( 'li' )
:tag(args.mini and 'abbr' or 'span')
.addClass( 'nv-view' )
:attr('title', 'Discuss this template')
.wikitext( '[[' .. mainpage .. '|' )
:cssText(args.fontstyle)
.tag( 'span ' )
:wikitext(args.mini and 't' or 'talk')
.attr( 'title', 'View this template' )
:done()
.cssText( args.fontstyle or '' )
. :wikitext( viewLink ']]');
 
.done()
if not args.noedit then
.wikitext( ']]' )
ul
.done()
. :tag( 'li' )
. :addClass( 'nv-talkedit' )
. :wikitext( '[[' .. talkpagetitle:fullUrl('action=edit') .. '|' ')
:tag(args.mini and 'abbr' .tag(or 'span ' )
. :attr( 'title', 'DiscussEdit this template' )
. :cssText( args.fontstyle or '' )
:wikitext(args.mini and 'e' or 'edit')
.wikitext( talkLink )
. :done()
. :wikitext( ']]' );
end
 
if not args.noedit then
if args.brackets then
ul
div
.tag( 'li' )
:tag('span')
.addClass( 'nv-edit' )
:css('margin-left', '-0.125em')
.wikitext( '[' .. editurl .. ' ' )
:cssText(args.fontstyle)
.tag( 'span ' )
:wikitext(' ]')
.attr( 'title', 'Edit this template' )
end
.cssText( args.fontstyle or '' )
 
.wikitext( editLink )
if args.collapsible then
.done()
div
.wikitext( ']' );
:done()
end
:tag('div')
:css('font-size', '114%')
if args.brackets then
:css('margin', args.mini and '0 4em' or '0 7em')
div
:cssText(args.fontstyle)
.tag('span')
:wikitext(args[1])
.css('margin-left', '-0.125em')
end
.cssText( args.fontstyle or '' )
 
.wikitext( ']' )
return tostring(div:done())
.newline();
end
return tostring(div)
end
 
function p.navbar(frame)
if not getArgs then
local origArgs
getArgs = require('Module:Arguments').getArgs
-- If called via #invoke, use the args passed into the invoking template.
end
-- Otherwise, for testing purposes, assume args are being passed directly in.
return p._navbar(getArgs(frame))
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- behavior of {{navbar}}, change any empty arguments to nil, so Lua will consider
-- them false too.
args = {}
for k, v in pairs(origArgs) do
if v ~= '' then
args[k] = v
end
end
return _navbar(args)
end
 
return p