Module:Navbox: Difference between revisions

Jump to navigation Jump to search
3,492 bytes removed ,  16 March 2013
navbar code moved to Module:Navbar
(edit for succinctness)
(navbar code moved to Module:Navbar)
Line 6: Line 6:
   
   
local HtmlBuilder = require('Module:HtmlBuilder')
local HtmlBuilder = require('Module:HtmlBuilder')
local Navbar = require('Module:Navbar')


local args
local args
Line 81: Line 82:
end
end


function formNavBar( args )
    if not args[1] then
        local span = HtmlBuilder.create('span')
        span
            .addClass('error')
            .css('float', 'left')
            .css('white-space', 'nowrap')
            .wikitext('Error: No name provided')
       
        return span
    end
   
    local title;
    local pageName = trim( args[1] )
    if pageName:sub(1,1) == ':' then
        title = mw.title.new( pageName:sub(2) );
    else
        title = mw.title.new( pageName );
        if title.namespace == 0 then
            title = mw.title.makeTitle( 'Template', pageName );
        end   
    end     
   
    local mainpage = title.fullText;
    local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
    local editurl = title:fullUrl( 'action=edit' );
   
    local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
    if args.mini then
        viewLink, talkLink, editLink = 'v', 't', 'e'
    end
   
    local div = HtmlBuilder.create( 'div' )
    div
        .addClass( 'noprint' )
        .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
        div
            .tag( 'span' )
                .css( 'word-spacing', 0 )
                .cssText( args.fontstyle )
                .wikitext( args.text or 'This box:' )
                .wikitext( ' ' )
    end
   
    if args.brackets then
        div
            .tag('span')
                .css('margin-right', '-0.125em')
                .cssText( args.fontstyle )
                .wikitext( '[' )
                .newline();
    end
   
    local ul = div.tag('ul');
   
    ul
        .tag( 'li' )
            .addClass( 'nv-view' )
            .wikitext( '[[' .. mainpage .. '|' )
            .tag( 'span ' )
                .attr( 'title', 'View this template' )
                .cssText( args.fontstyle or '' )
                .wikitext( viewLink )
                .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
function renderNavBar(titleCell)
function renderNavBar(titleCell)
     -- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
     -- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
Line 208: Line 99:
         if args.state == 'plain' then spacerSide = 'right' end
         if args.state == 'plain' then spacerSide = 'right' end


         titleCell.node(formNavBar({  
         titleCell.wikitext(Navbar.navbar({  
             args.name,  
             args.name,  
             mini = 1,  
             mini = 1,  
Line 507: Line 398:
     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
    return tostring( formNavBar( args ) )
end
end
   
   
return p
return p
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu