Module:Navbox: Difference between revisions
From Test Wiki
Content deleted Content added
find vanishing TemplateStyles in args, find plainlist in class args |
add hlist support, move related strings to cfg, add support for finding classes in any class parameter |
||
| Line 70: | Line 70: | ||
end |
end |
||
-- we will want this later when we want to add tstyles for hlist/plainlist |
|||
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 262: | Line 261: | ||
end |
end |
||
-- uses this now to make the needHlistCategory correct |
|||
-- to use later for when we add list styles via navbox |
|||
local function has_list_class(htmlclass) |
local function has_list_class(htmlclass) |
||
local class_args = { -- rough order of probability of use |
|||
cfg.arg.bodyclass, cfg.arg.listclass, cfg.arg.aboveclass, |
|||
cfg.arg.belowclass, cfg.arg.titleclass, cfg.arg.navboxclass, |
|||
cfg.arg.groupclass, cfg.arg.imageclass |
|||
| ⚫ | |||
local patterns = { |
local patterns = { |
||
'^' .. htmlclass .. '$', |
'^' .. htmlclass .. '$', |
||
| Line 277: | Line 269: | ||
} |
} |
||
for |
for arg, _ in pairs(args) do |
||
if type(arg) == 'string' and mw.ustring.find(arg, cfg.pattern.class) then |
|||
for _, pattern in ipairs(patterns) do |
|||
for _, pattern in ipairs(patterns) do |
|||
if mw.ustring.find(args[arg] or '', pattern) then |
|||
return true |
return true |
||
end |
|||
end |
end |
||
end |
end |
||
| Line 289: | Line 283: | ||
-- 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 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 294: | ||
end |
end |
||
local hlist_styles = add_list_templatestyles('hlist', cfg.hlist_templatestyles) |
|||
-- TODO: get hlist to the point where we can do this for hlist |
|||
| ⚫ | |||
-- see [[MediaWiki talk:Common.css/to do#Hlist]] |
|||
| ⚫ | |||
| ⚫ | |||
-- a second workaround for [[phab:T303378]] |
|||
-- 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] |
|||
| ⚫ | |||
end |
end |
||
| Line 431: | Line 436: | ||
: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 .. |
||
add_list_styles() .. |
|||
table.concat(hiding_templatestyles) |
table.concat(hiding_templatestyles) |
||
) |
) |
||