Module:Tnavbar: Difference between revisions

From PSP2i Wiki
(Created page with "-- <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...")
 
No edit summary
 
Line 1: Line 1:
-- <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 p = {}
local yesno = require( 'Module:Yesno' )
local yesno = require( 'Module:Yesno' )

Latest revision as of 22:46, 7 November 2021

Documentation for this module may be created at Module:Tnavbar/doc

local p = {}
local yesno = require( 'Module:Yesno' )

function p._navbar( args )

    local tag


    tag = mw.html.create( 'div' )
        :css( {
            ['background-color'] = 'transparent',
            padding = '0'
        } )

    tag
        :addClass( 'plainlinks' )
        :addClass( 'noprint' )
        :css( {
            ['white-space'] = 'nowrap',
            ['font-weight'] = 'normal',
            ['font-size'] = 'xx-small'
        } )

    viewSpan = mw.html.create( 'span' )
        :attr( 'title', 'View this template' )
        :cssText( fontstyle )
        :wikitext( 'v' )

    talkSpan = mw.html.create( 'span' )
        :attr( 'title', 'Discussion about this template' )
        :cssText( fontstyle )
        :wikitext( 'd' )

    editSpan = mw.html.create( 'span' )
        :attr( 'title', 'You can edit this template. Please use the preview button before saving.' )
        :cssText( fontstyle )
        :wikitext( 'e' )

    

    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( '[[' .. page .. '|' .. tostring( viewSpan ) .. ']]' )
        :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 ) .. ']' )

    return tostring( tag )
end


function p._collapsible( args )
    local nav_args = {
        [1] = args[2]
    }

    local div = mw.html.create( 'div' )
        :css( {
            float = 'left',
            ['text-align'] = 'left',
            width = '6em'
        } )
        :addClass( 'navbar' )
        :wikitext(p._navbar(nav_args))

    local span = mw.html.create('span'):wikitext(args[1])

    return tostring( div ) .. tostring( span )

end

return p