Editing Module:Navbar

From MINR.ORG WIKI

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
local getArgs
+
local HtmlBuilder = require('Module:HtmlBuilder')
  
function p._navbar(args)
+
function trim(s)
local titleArg = 1
+
    return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
 
+
end
if args.collapsible then
 
titleArg = 2
 
if not args.plain then
 
args.mini = 1
 
end
 
if args.fontcolor then
 
args.fontstyle = 'color:' .. args.fontcolor .. ';'
 
end
 
args.style = 'float:left; text-align:left'
 
end
 
 
 
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
 
local title = mw.title.new(mw.text.trim(titleText), 'Template');
 
 
 
if not title then
 
error('Invalid title ' .. titleText)
 
end
 
 
 
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
 
 
 
local div = mw.html.create():tag('div')
 
div
 
:addClass('plainlinks')
 
:addClass('hlist')
 
:addClass('navbar')
 
:cssText(args.style)
 
 
 
if args.mini then div:addClass('mini') end
 
  
if not (args.mini or args.plain) then
+
function _navbar( args )
div
+
    if not args[1] then
:tag('span')
+
        local span = HtmlBuilder.create('span')
:css('word-spacing', 0)
+
:cssText(args.fontstyle)
+
        span
:wikitext(args.text or 'This box:')
+
            .addClass('error')
:wikitext(' ')
+
            .css('float', 'left')
end
+
            .css('white-space', 'nowrap')
 
+
            .wikitext('Error: No name provided')
if args.brackets then
+
div
+
        return span
:tag('span')
+
    end
:css('margin-right', '-0.125em')
+
:cssText(args.fontstyle)
+
    local title;
:wikitext('[ ')
+
    local pageName = trim(args[1])
end
+
    if mw.ustring.sub(pageName, 1, 1) == ':' then
 
+
        title = mw.title.new( mw.ustring.sub(pageName, 2) );
local ul = div:tag('ul');
+
    else
 
+
        title = mw.title.new( pageName );
ul
+
        if title.namespace == 0 then
:tag('li')
+
            title = mw.title.makeTitle( 'Template', pageName );
:addClass('nv-view')
+
        end   
:wikitext('[[' .. title.fullText .. '|')
+
    end     
:tag(args.mini and 'abbr' or 'span')
+
:attr('title', 'View this template')
+
    local mainpage = title.fullText;
:cssText(args.fontstyle)
+
    local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
:wikitext(args.mini and 'v' or 'view')
+
    local editurl = title:fullUrl( 'action=edit' );
:done()
+
:wikitext(']]')
+
    local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
:done()
+
    if args.mini then
:tag('li')
+
        viewLink, talkLink, editLink = 'v', 't', 'e'
:addClass('nv-talk')
+
    end
:wikitext('[[' .. talkpage .. '|')
+
:tag(args.mini and 'abbr' or 'span')
+
    local div = HtmlBuilder.create( 'div' )
:attr('title', 'Discuss this template')
+
    div
:cssText(args.fontstyle)
+
        .addClass( 'noprint' )
:wikitext(args.mini and 't' or 'talk')
+
        .addClass( 'plainlinks' )
:done()
+
        .addClass( 'hlist' )
:wikitext(']]');
+
        .addClass( 'navbar')
 
+
        .cssText( args.style )
if not args.noedit then
+
ul
+
    if args.mini then div.addClass('mini') end
:tag('li')
+
:addClass('nv-edit')
+
    if not (args.mini or args.plain) then
:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
+
        div
:tag(args.mini and 'abbr' or 'span')
+
            .tag( 'span' )
:attr('title', 'Edit this template')
+
                .css( 'word-spacing', 0 )
:cssText(args.fontstyle)
+
                .cssText( args.fontstyle )
:wikitext(args.mini and 'e' or 'edit')
+
                .wikitext( args.text or 'This box:' )
:done()
+
                .wikitext( ' ' )
:wikitext(']');
+
    end
end
+
 
+
    if args.brackets then
if args.brackets then
+
        div
div
+
            .tag('span')
:tag('span')
+
                .css('margin-right', '-0.125em')
:css('margin-left', '-0.125em')
+
                .cssText( args.fontstyle )
:cssText(args.fontstyle)
+
                .wikitext( '[' )
:wikitext(' ]')
+
                .newline();
end
+
    end
 
+
if args.collapsible then
+
    local ul = div.tag('ul');
div
+
:done()
+
    ul
:tag('div')
+
        .tag( 'li' )
:css('font-size', '114%')
+
            .addClass( 'nv-view' )
:css('margin', args.mini and '0 4em' or '0 7em')
+
            .wikitext( '[[' .. mainpage .. '|' )
:cssText(args.fontstyle)
+
            .tag( 'span ' )
:wikitext(args[1])
+
                .attr( 'title', 'View this template' )
end
+
                .cssText( args.fontstyle or '' )
 
+
                .wikitext( viewLink )
return tostring(div:done())
+
                .done()
 +
            .wikitext( ']]' )
 +
            .done()
 +
        .tag( 'li' )
 +
            .addClass( 'nv-talk' )
 +
            .wikitext( '[[' .. talkpage .. '|' )
 +
            .tag( 'span ' )
 +
                .attr( 'title', 'Discuss this template' )
 +
                .cssText( args.fontstyle or '' )
 +
                .wikitext( talkLink )
 +
                .done()
 +
            .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
 +
 +
    if args.brackets then
 +
        div
 +
            .tag('span')
 +
                .css('margin-left', '-0.125em')
 +
                .cssText( args.fontstyle or '' )
 +
                .wikitext( ']' )
 +
                .newline();
 +
    end
 +
 +
    return div
 
end
 
end
  
 
function p.navbar(frame)
 
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
 
end
 
+
 
return p
 
return p

Please note that all contributions to MINR.ORG WIKI may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see MINR.ORG WIKI:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)