Module:Navbox: Difference between revisions

Jump to navigation Jump to search
205 bytes removed ,  16 March 2013
edit for succinctness
(missed an option)
(edit for succinctness)
Line 82: Line 82:




function formNavBar( div, args )
function formNavBar( args )
     local class = 'noprint plainlinks hlist navbar';
     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 title;
     args[1] = trim( args[1] or '' );
     local pageName = trim( args[1] )
   
     if pageName:sub(1,1) == ':' then
     if args[1] == '' then
         title = mw.title.new( pageName:sub(2) );
        title = mw.title.new( '' );
    elseif args[1]:sub(1,1) == ':' then
         title = mw.title.new( args[1]:sub(2) );
     else
     else
         title = mw.title.new( args[1] );
         title = mw.title.new( pageName );
         if title.namespace == 0 then
         if title.namespace == 0 then
             title = mw.title.new( 'Template:' .. args[1] );
             title = mw.title.makeTitle( 'Template', pageName );
         end      
         end  
     end       
     end       
      
      
     local mainpage, talkpage, editurl;
     local mainpage = title.fullText;
    mainpage = title.fullText;
     local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
     talkpage = title.talkPageTitle;
     local editurl = title:fullUrl( 'action=edit' );  
    talkpage = talkpage.fullText or '';
     editurl = title:fullUrl( 'action=edit' );  
      
      
     if args.mini ~= nil then
    local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
         class = class .. ' mini';
     if args.mini then
         viewLink, talkLink, editLink = 'v', 't', 'e'
     end
     end
 
   
    local div = HtmlBuilder.create( 'div' )
     div
     div
         .addClass( class )
         .addClass( 'noprint' )
         .cssText( args.style or '' )
        .addClass( 'plainlinks' )
        .addClass( 'hlist' )
        .addClass( 'navbar')
         .cssText( args.style )
   
    if args.mini then div.addClass('mini') end
      
      
     if args.mini == nil and args.plain == nil then
     if not (args.mini or args.plain) then
         div.tag( 'span' )
         div
            .css( 'word-spacing', 0 )
            .tag( 'span' )
            .cssText( args.fontstyle or '' )
                .css( 'word-spacing', 0 )
            .wikitext( args.text or 'This box:' );
                .cssText( args.fontstyle )
                .wikitext( args.text or 'This box:' )
                .wikitext( ' ' )
     end
     end
      
      
     if args.brackets ~= nil then
     if args.brackets then
         div.wikitext(' ');
         div
        div.tag('span')
            .tag('span')
            .css('margin-right', '-0.125em')
                .css('margin-right', '-0.125em')
            .cssText( args.fontstyle or '' )
                .cssText( args.fontstyle )
            .wikitext( '[' )
                .wikitext( '[' )
            .newline();
                .newline();
     end
     end
      
      
     local ul = div.tag('ul');
     local ul = div.tag('ul');
    local inner
    if args.mini ~= nil then
        inner = 'v';
    else
        inner = 'view';
    end
      
      
     ul.tag( 'li' )
     ul
        .addClass( 'nv-view' )
        .tag( 'li' )
        .wikitext( '[[' .. mainpage .. '|' )
            .addClass( 'nv-view' )
        .tag( 'span ' )
            .wikitext( '[[' .. mainpage .. '|' )
            .attr( 'title', 'View this template' )
            .tag( 'span ' )
            .cssText( args.fontstyle or '' )
                .attr( 'title', 'View this template' )
             .wikitext( inner )
                .cssText( args.fontstyle or '' )
                .wikitext( viewLink )
                .done()
             .wikitext( ']]' )
             .done()
             .done()
         .wikitext( ']]' );
         .tag( 'li' )
 
            .addClass( 'nv-talk' )
    if args.mini ~= nil then
            .wikitext( '[[' .. talkpage .. '|' )
        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.noedit == nil then
        if args.mini ~= nil then
            inner = 'e';
        else
            inner = 'edit';
        end
       
        ul.tag( 'li' )
            .addClass( 'nv-edit' )
            .wikitext( '[' .. editurl .. ' ' )
             .tag( 'span ' )
             .tag( 'span ' )
                 .attr( 'title', 'Edit this template' )
                 .attr( 'title', 'Discuss this template' )
                 .cssText( args.fontstyle or '' )
                 .cssText( args.fontstyle or '' )
                 .wikitext( inner )
                 .wikitext( talkLink )
                 .done()
                 .done()
             .wikitext( ']' );
             .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
     end
      
      
     if args.brackets ~= nil then
     if args.brackets then
         div.tag('span')
         div
            .css('margin-left', '-0.125em')
            .tag('span')
            .cssText( args.fontstyle or '' )
                .css('margin-left', '-0.125em')
            .wikitext( ']' )
                .cssText( args.fontstyle or '' )
            .newline();
                .wikitext( ']' )
                .newline();
     end
     end


Line 208: Line 208:
         if args.state == 'plain' then spacerSide = 'right' end
         if args.state == 'plain' then spacerSide = 'right' end


         if args.name then
         titleCell.node(formNavBar({
            local div = HtmlBuilder.create('div');
             args.name,  
             local args = {
            mini = 1,  
                args.name,  
            fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
                mini = 1,  
        }))
                fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
            };
       
            div = formNavBar( div, args );
            titleCell.node( div )
        else
            titleCell
                .tag('span')
                    .addClass('error')
                    .css('float', 'left')
                    .css('white-space', 'nowrap')
                    .wikitext('Error: No name provided')
        end
     end
     end
      
      
Line 532: Line 519:
         end
         end
     end
     end
    local div = HtmlBuilder.create('div')
     return tostring( formNavBar( args ) )
     return tostring( formNavBar( div, 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