FANDOM


-- <nowiki>
--
-- Implements {{tnavbar}} and variants
--
-- @todo move the hardcoded css to [[MediaWiki:Common.css]] given how many pages it's found on
--
 
local p = {}
local yesno = require( 'Module:Yesno' )
 
function p.navbar( frame )
    local args = frame:getParent().args
 
    -- prevent errors on template page
    if not args[1] then
        return
    end
 
    return p._navbar( args )
end
 
function p._navbar( args )
 
    local tag
 
    if yesno( args.nodiv ) then
        tag = mw.html.create( 'span' )
    else
        tag = mw.html.create( 'div' )
            :css( {
                ['background-color'] = 'transparent',
                padding = '0'
            } )
    end
 
    local tagStyle = args.style or ''
    local fontstyle = args.fontstyle or ''
 
    if args.fontstyle then
        tagStyle = tagStyle .. ';' .. args.fontstyle
    end
 
    if args.fontcolor then
        tagStyle = tagStyle .. ';color:' .. args.fontcolor
        fontstyle = fontstyle .. ';color:' .. args.fontcolor
    end
 
    tag
        :addClass( 'plainlinks' )
        -- no idea what this class does
        :addClass( 'plainlinksneverexpand' )
        :addClass( 'noprint' )
        :css( {
            ['white-space'] = 'nowrap',
            ['font-weight'] = 'normal',
            ['font-size'] = 'xx-small'
        } )
        :cssText( tagStyle )
 
    local prepText = ''
 
    -- we're checking if any of these have been set to 1
    -- if not we add the prepText
    -- @todo find a better way of doing this
    if not ( yesno( args.mini ) or yesno( args.miniv ) or yesno( args.viewplain ) or yesno( args.plain ) ) then
        prepText = 'This box&nbsp;'
    end
 
    local view, talk, edit = 'v', 'd', 'e'
 
    if yesno( args.viewplain ) or yesno( args.plain ) then
        view = 'view'
        talk = 'talk'
        edit = 'edit'
    end
 
    viewSpan = mw.html.create( 'span' )
        :attr( 'title', 'View this template' )
        :cssText( fontstyle )
        :wikitext( view )
 
    talkSpan = mw.html.create( 'span' )
        :attr( 'title', 'Discussion about this template' )
        :cssText( fontstyle )
        :wikitext( talk )
 
    editSpan = mw.html.create( 'span' )
        :attr( 'title', 'You can edit this template. Please use the preview button before saving.' )
        :cssText( fontstyle )
        :wikitext( edit )
 
 
 
    local title = mw.text.trim( args[1] )
    local ns, titleTbl, page, talk
 
    if mw.ustring.sub( title, 1, 1 ) == ':' then
        -- mainspace
        title = mw.ustring.sub( title, 2 )
        page = title
        talk = 'Talk:' .. title
 
    elseif mw.ustring.match( title, ':' ) then
        -- split title to see if it has a valid namespace
        titleTbl = mw.text.split( title, ':' )
        ns = mw.site.namespaces[titleTbl[1]]
 
        if ns ~= nil then
            page = ns.name .. ':' .. table.concat( titleTbl, '', 2 )
 
            if ns.isTalk then
                talk = page
            else
                talk = ns.talk.name .. ':' .. table.concat( titleTbl, '', 2 )
            end
        end
    end
 
    -- this happens if there's no semi-colons in title
    -- or if there is semi-colons but it didn't have valid ns name
    if not page then
        page = 'Template:' .. title
        talk = 'Template talk:' .. title
    end
 
    tag
        :wikitext( prepText )
        :wikitext( '[[' .. page .. '|' .. tostring( viewSpan ) .. ']]' )
 
    if not( yesno( args.miniv ) or yesno( args.viewplain ) ) then
        local frame = mw.getCurrentFrame()
 
        tag
            :wikitext( '&nbsp;' )
            :tag( 'span' )
                :css( 'font-size', '80%' )
                :wikitext( '&bull;' )
                :done()
            :wikitext( '&nbsp;' )
            :wikitext( '[' .. tostring( mw.uri.fullUrl( talk ) ) .. ' ' .. tostring( talkSpan ) .. ']' )
            :wikitext( '&nbsp;' )
            :tag( 'span' )
                :css( 'font-size', '80%' )
                :wikitext( '&bull;' )
                :done()
            :wikitext( '&nbsp;' )
            :wikitext( '[' .. tostring( mw.uri.fullUrl( page, 'action=edit' ) ) .. ' ' .. tostring( editSpan ) .. ']' )
 
    end
 
    tag = tostring( tag )
 
    if yesno( args.nodiv ) then
        tag = tag .. '&nbsp;'
    end
 
    return tag
 
end
 
function p.collapsible( frame )
    local args = frame:getParent().args
    return p._collapsible( args )
end
 
function p._collapsible( args )
 
    local nav_args = {
        [1] = args[2],
        fontcolor = args.fontcolor
    }
 
    -- prevent errors on template page
    if not args[2] then
        return
    end
 
    if yesno( args.plain ) then
        nav_args.plain = '1'
    else
        nav_args.mini = '1'
    end
 
    navbar = p._navbar( nav_args )
 
    local div = mw.html.create( 'div' )
        :css( {
            float = 'left',
            ['text-align'] = 'left',
            width = '6em'
        } )
        :wikitext( navbar )
 
    local span = mw.html.create( 'span' )
        :wikitext( args[1] )
 
    if args.fontcolor then
        span
            :css( 'color', fontcolor )
    end
 
    return tostring( div ) .. tostring( span )
 
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.