Module:Sidebar:修订间差异

删除的内容 添加的内容
enwiki>Ahecht
Re-add optimizations for child=yes (avoid duplicated templatestyles and categories). Implement :attr('role', 'navigation') per edit request on talk page.
 
IdleTap-bot​(留言 | 贡献)
导入自求闻百科
 
第45行:
Finds whether a sidebar has a subgroup sidebar.
]]
local function detectChildhasSubgroup(s)
if mw.ustring.find(s, cfg.i18n.pattern.subgroup) then
return true
第81行:
end
return false
end
 
-- there are a lot of list classes in the wild, so we add their TemplateStyles
local function add_list_styles(args)
local frame = mw.getCurrentFrame()
local function add_list_templatestyles(htmlclass, templatestyles)
if has_list_class(args, htmlclass) then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }▼
}
else
return ''
end
end
local plainlist_styles = add_list_templatestyles('plainlist', cfg.i18n.templatestyles.plainlist)
local hlist_styles = add_list_templatestyles('hlist', cfg.i18n.templatestyles.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(args.navbar, args.name) and hlist_styles == '' then
hlist_styles = frame:extensionTag{
name = 'templatestyles', args = { src = cfg.i18n.templatestyles.hlist}
}
end
 
-- hlist -> plainlist is best-effort to preserve old Common.css ordering. [hlist_note]
return hlist_styles .. plainlist_styles
end
 
第116行 ⟶ 第87行:
-- table. then remove all templatestyles markers from the arg
local function move_hiding_templatestyles(args)
local gmatchgfind = string.gmatchgfind
local gsub = string.gsub
local templatestyles_markers = {}
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'
for k, arg in pairs(args) do
for marker in gmatchgfind(arg, strip_marker_pattern) do
table.insert(templatestyles_markers, marker)
end
第144行 ⟶ 第115行:
root = root:tag('table')
if not child then
root
:addClass(cfg.i18n.class.sidebar)
-- force collapsibleClasscollapsibleclass to be sidebar-collapse otherwise output nothing
:addClass(collapsibleClass == cfg.i18n.class.collapse and cfg.i18n.class.collapse or nil)
:addClass('nomobile')
:addClass(args.float == cfg.i18n.float_none and cfg.i18n.class.float_none or nil)
:addClass(args.float == cfg.i18n.float_left and cfg.i18n.class.float_left or nil)
:addClass(args.wraplinks ~= cfg.i18n.wrap_true and cfg.i18n.class.wraplinks or nil)
:addClass(args.bodyclass or args.class)
:attr('role', 'navigation')
:css('width', args.width or nil)
:cssText(args.bodystyle or args.style)
第263行 ⟶ 第232行:
end
 
local hasChild = false
for i, num in ipairs(rowNums) do
local heading = args['heading' .. num]
第282行 ⟶ 第250行:
local content = args['content' .. num]
if content then
local baseContentClass = cfg.i18n.class.content▼
if detectChild(content) then
baseContentClass = cfg.i18n.class.content_with_subgroup
hasChild = true
end
root
:tag('tr')
:tag('td')
:addClass(baseContentClasshasSubgroup(content) and cfg.i18n.class.content_with_subgroup
▲ local baseContentClass = or cfg.i18n.class.content)
:addClass(args.contentclass)
:addClass(args['content' .. num .. 'class'])
第320行 ⟶ 第284行:
:tag('td')
:addClass(cfg.i18n.class.navbar)
:css('line-height', '1.6')
:cssText(args.navbarstyle)
:wikitext(require('Module:Navbar')._navbar{
第328行 ⟶ 第293行:
end
local base_templatestyles = ''frame:extensionTag{
▲ name = 'templatestyles', args = { src = cfg.i18n.templatestyles }
if not child then
▲ }
base_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = cfg.i18n.templatestyles.sidebar }
}
end
local templatestyles = ''
第355行 ⟶ 第317行:
}
end
local differential_names = args.name ~= mw.title.getCurrentTitle().text and mw.title.getCurrentTitle():inNamespace('Template')
 
return table.concat({
add_list_styles(args), -- see [hlist_note] above about ordering
base_templatestyles,
templatestyles,
第364行 ⟶ 第327行:
hiding_templatestyles,
tostring(root),
(hasChild(child and args.tracking ~= 'no') and cfg.i18n.category.child or ''),
((differential_names and args.tracking ~= 'no') and '[[Category:Name參數和實際不同的導航框]]' or ''),
categorizeTemplatesWithInlineStyles(args)
})
第392行 ⟶ 第356行:
:cssText(args.basestyle)
:cssText(args.listtitlestyle)
:cssText('color: var(--color-base)')
:cssText(args['list' .. num .. 'titlestyle'])
:node(title)
第411行 ⟶ 第374行:
cfg.i18n.collapse_title_not_to_add_navbar then
args.navbar = cfg.i18n.navbar_none
args.tracking = 'no'
end