Last 5 Pages Viewed: Special:MobileDiff/3343 » Special:MobileDiff/3305 » Special:MobileDiff/2722 » Special:MobileDiff/2610 » Special:MobileDiff/3309

Module:Navbox: Difference between revisions

Jump to navigation Jump to search
per tper
imported>Izno
(add hlist support, move related strings to cfg, add support for finding classes in any class parameter)
w>Izno
(per tper)
Line 1: Line 1:
require('strict')
local p = {}
local p = {}
local navbar = require('Module:Navbar')._navbar
local cfg = mw.loadData('Module:Navbox/configuration')
local cfg = mw.loadData('Module:Navbox/configuration')
local getArgs -- lazily initialized
local getArgs -- lazily initialized
Line 78: Line 78:
~= cfg.pattern.navbox
~= cfg.pattern.navbox
)
)
end
-- extract text color from css, which is the only permitted inline CSS for the navbar
local function extract_color(css_str)
-- return nil because navbar takes its argument into mw.html which handles
-- nil gracefully, removing the associated style attribute
return mw.ustring.match(';' .. css_str .. ';', '.*;%s*([Cc][Oo][Ll][Oo][Rr]%s*:%s*.-)%s*;') or nil
end
end


local function renderNavBar(titleCell)
local function renderNavBar(titleCell)
if has_navbar() then
if has_navbar() then
local navbar = require('Module:Navbar')._navbar
titleCell:wikitext(navbar{
titleCell:wikitext(navbar{
[cfg.navbar.name] = args[cfg.arg.name],
[cfg.navbar.name] = args[cfg.arg.name],
[cfg.navbar.mini] = 1,
[cfg.navbar.mini] = 1,
[cfg.navbar.fontstyle] = (args[cfg.arg.basestyle] or '') .. ';' ..
[cfg.navbar.fontstyle] = extract_color(
(args[cfg.arg.titlestyle] or '') ..
(args[cfg.arg.basestyle] or '') .. ';' .. (args[cfg.arg.titlestyle] or '')
';background:none transparent;border:none;box-shadow:none;padding:0;'
)
})
})
end
end
Line 141: Line 149:
:tag('div')
:tag('div')
-- id for aria-labelledby attribute, if no title
-- id for aria-labelledby attribute, if no title
:attr('id', args[cfg.arg.title] and nil or mw.uri.anchorEncode(args[cfg.arg.above]))
:attr('id', (not args[cfg.arg.title]) and mw.uri.anchorEncode(args[cfg.arg.above]) or nil)
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
end
end
Anonymous user

Navigation menu