Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
le fail
Tag: Reverted
hopefully nothing breaks? full l10n I think
Tag: Reverted
Line 18:
local first, second = 'odd', 'even'
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == 'swap'cfg.keyword.evenodd_swap then
first, second = second, first
else
Line 54:
return '\n' .. item ..'\n'
end
if nowrapitems == 'yes'cfg.keyword.nowrapitems_yes then
local lines = {}
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match('^<span class="cfg.pattern.nowrap">') then
line = format(nowrap_item, prefix .. '<span class="nowrap">' .., content .. '</span>')
end
table.insert(lines, line)
Line 74:
if args[cfg.arg.navbar] ~= cfg.keyword.navbar_off and
args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain and
(args[cfg.arg.name] or not
mw.getCurrentFrame():getParent():getTitle():gsub('/cfg.pattern.sandbox$', '')
== 'Template:Navbox'cfg.pattern.navbox) then
titleCell:wikitext(navbar{
args[cfg.arg.name],
Line 95 ⟶ 97:
:tag('th')
:attr('scope', 'row')
:addClass('navbox-group'cfg.class.navbox_group)
:addClass(args[cfg.arg.titlegroupclass])
:cssText(args[cfg.arg.basestyle])
Line 119 ⟶ 121:
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.titlestyle])
:addClass('navbox-title'cfg.class.navbox_title)
:attr('colspan', titleColspan)
 
Line 146 ⟶ 148:
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow'cfg.class.navbox_abovebelow)
:addClass(args[cfg.arg.aboveclass])
:cssText(args[cfg.arg.basestyle])
Line 153 ⟶ 155:
:tag('div')
-- id for aria-labelledby attribute, if no title
:attr('id',
args[cfg.arg.title] and nil
or mw.uri.anchorEncode(args[cfg.arg.above]))
)
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
end
Line 162 ⟶ 167:
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow'cfg.class.navbox_abovebelow)
:addClass(args[cfg.arg.belowclass])
:cssText(args[cfg.arg.basestyle])
Line 177 ⟶ 182:
row
:tag('td')
:addClass('cfg.class.noviewer')
:addClass('navbox-image'cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
Line 194 ⟶ 199:
 
-- id for aria-labelledby attribute, if lone group with no title or above
if listnum == 1 and not
(args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group2]) then
groupCell
:attr('id', mw.uri.anchorEncode(args[cfg.arg.group1]))
Line 201 ⟶ 207:
groupCell
:attr('scope', 'row')
:addClass('navbox-group'cfg.class.navbox_group)
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
Line 241 ⟶ 247:
local oddEven = cfg.marker.oddeven
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automaticauto striping for this row.
oddEven = listText:find('<th[^>]*"navbox%-title"'cfg.pattern.navbox_title)
and cfg.marker.restart or 'odd'
end
listCell
Line 249 ⟶ 256:
:cssText(rowstyle)
:cssText(args[liststyle_and_num])
:addClass('navbox-list'cfg.class.navbox_list)
:addClass('navbox-' .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args[listclass_and_num])
:tag('div')
:css(
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0 0.25em')
'padding',
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0 0.25em')
or args[cfg.arg.listpadding] or '0 0.25em'
)
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
 
Line 260 ⟶ 271:
row
:tag('td')
:addClass('cfg.class.noviewer')
:addClass('navbox-image'cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
Line 277 ⟶ 288:
return false
end
return not (cfg.list_classes[args[cfg.arg.listclass]]
or cfg.list_classes[args[cfg.arg.bodyclass]])
end
 
local function hasBackgroundColors()
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}basic_style_args) do
if tostring(args[key]):find('background', 1, true) then
return true
Line 289 ⟶ 301:
 
local function hasBorders()
for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}basic_style_args) do
if tostring(args[key]):find('border', 1, true) then
return true
Line 300 ⟶ 312:
 
for key, style in pairs(args) do
if tostring(key):match("cfg.pattern.style$") then
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
return true
Line 311 ⟶ 323:
local function getTrackingCategories(border)
local cats = {}
if needsHorizontalLists(border) then table.insert(cats, 'Navigational boxes without horizontal lists') end
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours'cfg.category.horizontal_lists) end
end
if isIllegible() then table.insert(cats, 'Potentially illegible navboxes') end
if hasBackgroundColors() then
if hasBorders() then table.insert(cats, 'Navboxes using borders') end
table.insert(cats, cfg.category.background_colors)
end
if isIllegible() then table.insert(cats, 'Potentially cfg.category.illegible navboxes') end
if hasBorders() then table.insert(cats, 'Navboxes using cfg.category.borders') end
return cats
end
Line 322 ⟶ 338:
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == cfg.keyword.subpage_doc
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
or subpage == cfg.keyword.subpage_sandbox
or subpage == cfg.keyword.subpage_testcases then
return
end
 
for _, cat in ipairs(getTrackingCategories(border)) do
Line 331 ⟶ 351:
local function renderMainTable(border, listnums)
local tbl = mw.html.create('table')
:addClass('cfg.class.nowraplinks')
:addClass(args[cfg.arg.bodyclass])
 
if args[cfg.arg.title]
and (args[cfg.arg.state] ~= 'plain' cfg.keyword.state_plain
and args[cfg.arg.state] ~= 'off')cfg.keyword.state_off then
if args[cfg.arg.state] == 'cfg.keyword.collapsed' then
args[cfg.arg.state] = 'mw-cfg.class.collapsed'
end
tbl
:addClass('mw-cfg.class.collapsible')
:addClass(args[cfg.arg.state] or 'cfg.class.autocollapse')
end
 
tbl:css('border-spacing', 0)
if border == 'subgroup' or border == 'none' thencfg.keyword.border_subgroup
or border == cfg.keyword.border_none then
tbl
:addClass('navbox-subgroup'cfg.class.navbox_subgroup)
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will be appliedapply to the wrapper table
tbl
:addClass('navbox-inner'cfg.class.navbox_inner)
:css('background', 'transparent')
:css('color', 'inherit')
Line 372 ⟶ 397:
for k, _ in pairs(args) do
if type(k) == 'string' then
local listnum = k:match('^cfg.pattern.list(%d+)$')
if listnum then table.insert(listnums, tonumber(listnum)) end
end
Line 379 ⟶ 404:
 
local border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == 'child'cfg.keyword.border_child then
border = 'subgroup'cfg.keyword.border_subgroup
end
 
Line 386 ⟶ 411:
local tbl = renderMainTable(border, listnums)
 
-- render the appropriate wrapper around the navbox, depending on the border param
local res = mw.html.create()
if border == 'none'cfg.keyword.border_none then
local nav = res:tag('div')
:attr('role', 'navigation')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above]
or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr(
'aria-labelledby',
mw.uri.anchorEncode(args[cfg.arg.title]
or args[cfg.arg.above]
or args[cfg.arg.group1]))
)
)
else
nav:attr('aria-label', 'Navbox'cfg.aria_label)
end
elseif border == 'subgroup'cfg.keyword.border_subgroup then
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
-- parent navbox, and is therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
-- We start with a </div> to avoid the padding being applied, and at the
-- end add a <div> to balance out the parent's </div>
res
:wikitext('</div>')
Line 409 ⟶ 442:
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass('cfg.keyword.navbox')
:addClass(args[cfg.arg.navboxclass])
:cssText(args[cfg.arg.bodystyle])
Line 416 ⟶ 449:
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above]
or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr(
'aria-labelledby',
mw.uri.anchorEncode(args[cfg.arg.title]
or args[cfg.arg.above]
or args[cfg.arg.group1]))
)
)
else
nav:attr('aria-label', 'Navbox'cfg.aria_label)
end
end
 
if (args[cfg.arg.nocat] or 'false'cfg.keyword.nocat_false):lower() == 'false' then
== cfg.keyword.nocat_false then
renderTrackingCategories(res, border)
end
Line 433 ⟶ 474:
getArgs = require('Module:Arguments').getArgs
end
args = getArgs(frame, {wrappers = {'Template:Navbox'cfg.pattern.navbox}})
 
-- Read the arguments in the order they'll be output in, to make references