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 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.basestyle] or '') .. ';' .. (args[cfg.arg.titlestyle] or '') | |||
) | |||
}) | }) | ||
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 | :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 |