Module:Portal bar/sandbox: Difference between revisions

Content deleted Content added
use the main version of Module:Portal
better implementation of nbsp
 
(27 intermediate revisions by 4 users not shown)
Line 1:
-- This module implements {{portal bar}}.
 
require('Module:No globalsstrict')
 
-- determine whether we're being called from a sandbox
local portalModule = require('Module:Portal')
local isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true)
local getImageName = portalModule.image
local sandbox = isSandbox and '/sandbox' or ''
 
local portalModule = require('Module:Portal'..sandbox)
local getImageName = portalModule.image_image
local checkPortals = portalModule._checkPortals
local processPortalArgs = portalModule._processPortalArgs
Line 11 ⟶ 15:
local p = {}
 
local function sandboxsandboxVersion(args, s)
return args.sandboxisSandbox and s.."-sand" or s
end
 
Line 22 ⟶ 26:
-- Normalize arguments
for key, default in pairs({border=true,redlinks=false,sandbox=false,tracking=true}) do
if args[key] == nil then args[key] = default end
args[key] = yesno(args[key], default)
Line 28 ⟶ 32:
 
local nav = mw.html.create( 'div' )
:addClass(sandboxsandboxVersion(args,'portal-bar'))
:addClass( 'noprint metadata noviewer' )
:attr( 'role', 'navigation' )
:attr( 'aria-label' , 'Portals' )
:addClass(sandboxsandboxVersion(args,args.border and 'portal-bar-bordered' or 'portal-bar-unbordered'))
local trackingCat = ''
Line 45 ⟶ 49:
end
 
local headerrelated = nav:tagyesno('span'args.related)
if #portals > 1related then
header:addClass(sandbox(args,'portal-bar-header'))
nav:addClass(sandboxsandboxVersion(args,'portal-bar-linkrelated'))
header:wikitext('[[Wikipedia:Contents/Portals|Portal]]')
else
if #portals > 1 then
local header = nav:wikitexttag('sspan')
header:addClass(sandboxsandboxVersion(args,'portal-bar-header'))
header:wikitext('[[Wikipedia:Contents/Portals|Portal]]')
if #portals > 1 then
header:wikitext(':s')
end
header:wikitext(':')
end
local container = nav:tag('divul')
container:addClass(sandboxsandboxVersion(args,'portal-bar-content'))
if related then
container:addClass(sandboxVersion('portal-bar-content-related'))
end
local size = related and '27x25px' or '21x19px'
header:wikitext(':')
local container = nav:tag('div')
container:addClass(sandbox(args,'portal-bar-content'))
for _, portal in ipairs( portals ) do
container
:tag( 'divli' )
:addClass(sandboxsandboxVersion(args,'portal-bar-item'))
:wikitext( string.format('<span class="nowrap">[[File:%s|%s]] </span>[[Portal:%s|%s]]', portal, portal))
:tag( 'span' )
:addClassgetImageName(sandbox(argsportal,true), size, portal,' portal-bar-logo'))
:wikitext( string.format(
'[[File:%s|21x19px|alt=]]', getImageName{ portal }
) )
:done()
:tag('span')
:addClass(sandbox(args,'portal-bar-link'))
:wikitext( string.format('[[Portal:%s|%s]]', portal, portal))
end
local styleFile = 'Module:Portal bar'..sandbox..'/styles.css'
styleFile = styleFile..(args.sandbox and 'sandbox/' or '')
styleFile = styleFile..'styles.css'
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = styleFile }