Module:Navbox: Difference between revisions
Jump to navigation
Jump to search
m
1 revision imported
(find vanishing TemplateStyles in args, find plainlist in class args) |
m (1 revision imported) Tags: Mobile edit Mobile web edit |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
require('strict') | |||
local p = {} | local p = {} | ||
local navbar = require('Module:Navbar')._navbar | local navbar = require('Module:Navbar')._navbar | ||
Line 70: | Line 71: | ||
end | end | ||
local function has_navbar() | local function has_navbar() | ||
return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off | return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off | ||
Line 142: | Line 142: | ||
: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 | ||
Line 262: | Line 262: | ||
end | end | ||
local function has_list_class(htmlclass) | local function has_list_class(htmlclass) | ||
local patterns = { | local patterns = { | ||
'^' .. htmlclass .. '$', | '^' .. htmlclass .. '$', | ||
Line 277: | Line 270: | ||
} | } | ||
for _ | for arg, _ in pairs(args) do | ||
for _, pattern in ipairs(patterns) do | if type(arg) == 'string' and mw.ustring.find(arg, cfg.pattern.class) then | ||
for _, pattern in ipairs(patterns) do | |||
if mw.ustring.find(args[arg] or '', pattern) then | |||
return true | |||
end | |||
end | end | ||
end | end | ||
Line 289: | Line 284: | ||
-- there are a lot of list classes in the wild, so we add their TemplateStyles | -- there are a lot of list classes in the wild, so we add their TemplateStyles | ||
local function add_list_styles() | local function add_list_styles() | ||
local frame = mw.getCurrentFrame() | |||
local function add_list_templatestyles(htmlclass, templatestyles) | local function add_list_templatestyles(htmlclass, templatestyles) | ||
if has_list_class(htmlclass) then | if has_list_class(htmlclass) then | ||
return frame:extensionTag{ | return frame:extensionTag{ | ||
Line 300: | Line 295: | ||
end | end | ||
local hlist_styles = add_list_templatestyles('hlist', cfg.hlist_templatestyles) | |||
-- | local plainlist_styles = add_list_templatestyles('plainlist', cfg.plainlist_templatestyles) | ||
-- a second workaround for [[phab:T303378]] | |||
return plainlist_styles | -- when that issue is fixed, we can actually use has_navbar not to emit the | ||
-- tag here if we want | |||
if has_navbar() and hlist_styles == '' then | |||
hlist_styles = frame:extensionTag{ | |||
name = 'templatestyles', args = { src = cfg.hlist_templatestyles } | |||
} | |||
end | |||
-- hlist -> plainlist is best-effort to preserve old Common.css ordering. | |||
-- this ordering is not a guarantee because most navboxes will emit only | |||
-- one of these classes [hlist_note] | |||
return hlist_styles .. plainlist_styles | |||
end | end | ||
Line 431: | Line 437: | ||
:addClass(cfg.class.navbox_styles) | :addClass(cfg.class.navbox_styles) | ||
:wikitext( | :wikitext( | ||
add_list_styles() .. -- see [hlist_note] applied to 'before base_templatestyles' | |||
base_templatestyles .. | base_templatestyles .. | ||
templatestyles .. | templatestyles .. | ||
child_templatestyles .. | child_templatestyles .. | ||
table.concat(hiding_templatestyles) | table.concat(hiding_templatestyles) | ||
) | ) |