Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
add text-decoration:inherit; to navbar
Tag: Reverted
sync
Tag: Reverted
Line 7:
local navbar = require('Module:Navbar')._navbar
local getArgs -- lazily initialized
local cfg = mw.loadData('Module:Navbox/configuration')
 
local args
Line 21 ⟶ 20:
-- by parent navboxes. The result is that the category shows all pages
-- where a child navbox is not contained in a parent navbox.
local orphanCat = '[[Category:Navbox orphans]]'
if border == cfg.keyword.border_subgroup'subgroup' and args[cfg.arg.orphan] ~= cfg.keyword.orphan_yes'yes' then
-- No change; striping occurs in outermost navbox.
return wikitext .. cfg.category.orphanorphanCat
end
local first, second = cfg.class.navbox_odd_part'odd', cfg.class.navbox_even_part'even'
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == cfg.keyword.evenodd_swap'swap' then
first, second = second, first
else
first = args[cfg.arg.evenodd]
second = first
end
Line 39:
else
local index = 0
changer = function (code) -- where is code set???
if code == '0' then
-- Current occurrence is for a group before a nested table.
Line 52:
end
end
local regex = cfg.category.orphanorphanCat:gsub('([%[%]])', '%%%1')
return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer)) -- () omits gsub count
end
Line 62:
return '\n' .. item ..'\n'
end
if nowrapitems == cfg.keyword.nowrapitems_yes'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(cfg.pattern.'^<span class="nowrap">') then
line = mwprefix .ustring.format(cfg.nowrap_item, prefix,'<span class="nowrap">' .. content) .. '</span>'
end
table.insert(lines, line)
Line 81:
local function renderNavBar(titleCell)
 
(if args[cfg.argnavbar ~= 'off' and args.name]navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub(cfg.pattern.'/sandbox$', '') == cfg.pattern.navbox'Template:Navbox') then
if args[cfg.arg.navbar] ~= cfg.keyword.navbar_off and
args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain and
(args[cfg.arg.name] and not mw.getCurrentFrame():getParent():getTitle():gsub(cfg.pattern.sandbox, '') == cfg.pattern.navbox) then
titleCell:wikitext(navbar{
args[cfg.arg.name],
[cfg.navbar.mini] = 1,
[cfg.navbar.fontstyle] = (args[cfg.arg.basestyle] or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;box-shadow:none;padding:0;'
(args[cfg.arg.titlestyle] or '') ..
';background:none transparent;border:none;box-shadow:none;padding:0;text-decoration:inherit;'
})
end
Line 99 ⟶ 95:
--
local function renderTitleRow(tbl)
if not args[cfg.arg.title] then return end
 
local titleRow = tbl:tag('tr')
 
if args[cfg.arg.titlegroup] then
titleRow
:tag('th')
:attr('scope', 'row')
:addClass(cfg.class.navbox_group'navbox-group')
:addClass(args[cfg.arg.titlegroupclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.groupstyle])
:cssText(args[cfg.arg.titlegroupstyle])
:wikitext(args[cfg.arg.titlegroup])
end
 
local titleCell = titleRow:tag('th'):attr('scope', 'col')
 
if args[cfg.arg.titlegroup] then
titleCell
:css('border-left', '2px solid #fdfdfd')
Line 124 ⟶ 120:
 
local titleColspan = 2
if args[cfg.arg.imageleft] then titleColspan = titleColspan + 1 end
if args[cfg.arg.image] then titleColspan = titleColspan + 1 end
if args[cfg.arg.titlegroup] then titleColspan = titleColspan - 1 end
 
titleCell
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.titlestyle])
:addClass(cfg.class.navbox_title'navbox-title')
:attr('colspan', titleColspan)
 
Line 139 ⟶ 135:
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]))
:addClass(args[cfg.arg.titleclass])
:css('font-size', '114%')
:css('margin', '0 4em')
:wikitext(processItem(args[cfg.arg.title]))
end
 
Line 152 ⟶ 148:
local function getAboveBelowColspan()
local ret = 2
if args[cfg.arg.imageleft] then ret = ret + 1 end
if args[cfg.arg.image] then ret = ret + 1 end
return ret
end
 
local function renderAboveRow(tbl)
if not args[cfg.arg.above] then return end
 
tbl:tag('tr')
:tag('td')
:addClass(cfg.class.navbox_abovebelow'navbox-abovebelow')
:addClass(args[cfg.arg.aboveclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.abovestyle])
:attr('colspan', getAboveBelowColspan())
: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
 
local function renderBelowRow(tbl)
if not args[cfg.arg.below] then return end
 
tbl:tag('tr')
:tag('td')
:addClass(cfg.class.navbox_abovebelow'navbox-abovebelow')
:addClass(args[cfg.arg.belowclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.belowstyle])
:attr('colspan', getAboveBelowColspan())
:tag('div')
:wikitext(processItem(args[cfg.arg.below], args[cfg.arg.nowrapitems]))
end
 
Line 193 ⟶ 189:
local row = tbl:tag('tr')
 
if index == 1 and args[cfg.arg.imageleft] then
row
:tag('td')
:addClass(cfg.class.'noviewer')
:addClass(cfg.class.'navbox-image')
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '00px 2px 00px 00px')
:cssText(args[cfg.arg.imageleftstyle])
:attr('rowspan', #listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.imageleft]))
end
 
if args[cfg.arg.group_part'group' .. listnum] then
local groupCell = row:tag('th')
 
-- 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]))
end
 
groupCell
:attr('scope', 'row')
:addClass(cfg.class.navbox_group'navbox-group')
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
:css('width', args[cfg.arg.groupwidth] or '1%') -- If groupwidth not specified, minimize width
 
groupCell
:cssText(args[cfg.arg.groupstyle])
:cssText(args[cfg.arg.group_part'group' .. listnum .. cfg.arg.style_part'style'])
:wikitext(args[cfg.arg.group_part'group' .. listnum])
end
 
local listCell = row:tag('td')
 
if args[cfg.arg.group_part'group' .. listnum] then
listCell
:css('text-align', 'left')
Line 240 ⟶ 236:
end
 
if not args[cfg.arg.groupwidth] then
listCell:css('width', '100%')
end
Line 246 ⟶ 242:
local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
if index % 2 == 1 then
rowstyle = args[cfg.arg.oddstyle]
else
rowstyle = args[cfg.arg.evenstyle]
end
 
local listText = args[cfg.arg.list_part'list' .. listnum]
local oddEven = ODD_EVEN_MARKER
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find(cfg.pattern.navbox_title'<th[^>]*"navbox%-title"') and RESTART_MARKER or cfg.class.navbox_odd_part'odd'
end
listCell
:css('padding', '00px')
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args[cfg.arg.list_part'list' .. listnum .. cfg.arg.style_part'style'])
:addClass(cfg.class.navbox_list'navbox-list')
:addClass(cfg.class.navbox_part'navbox-' .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args[cfg.arg.list_part'list' .. listnum .. cfg.arg.class_part'class'])
:tag('div')
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '00em 0.25em')
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
 
if index == 1 and args[cfg.arg.image] then
row
:tag('td')
:addClass(cfg.class.'noviewer')
:addClass(cfg.class.navbox_image'navbox-image')
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '00px 00px 00px 2px')
:cssText(args[cfg.arg.imagestyle])
:attr('rowspan', #listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
end
end
Line 291 ⟶ 287:
 
local function needsHorizontalLists()
if border == cfg.keyword.border_subgroup'subgroup' or args[cfg.arg.tracking] == cfg.keyword.tracking_no'no' then
return false
end
local listClasses = {
-- FIXME: These should be finding the classes in list_classes, not looking for equality.
['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
return not (cfg.list_classes[args[cfg.arg.listclass]] or cfg.list_classes[args[cfg.arg.bodyclass]])
['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
['hlist vevent'] = true,
}
return not (cfg.list_classeslistClasses[args[cfg.arg.listclass]] or cfg.list_classeslistClasses[args[cfg.arg.bodyclass]])
end
 
local function hasBackgroundColors()
for _, key in ipairs({cfg.arg.'titlestyle', cfg.arg.'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
cfg.arg.basestyle, cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('background', 1, true) then
return true
Line 308 ⟶ 307:
 
local function hasBorders()
for _, key in ipairs({cfg.arg.'groupstyle', cfg.arg.'basestyle', 'abovestyle', 'belowstyle'}) do
cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('border', 1, true) then
return true
Line 320 ⟶ 318:
 
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 331 ⟶ 329:
local function getTrackingCategories()
local cats = {}
if needsHorizontalLists() then table.insert(cats, cfg.category.horizontal_lists'Navigational boxes without horizontal lists') end
if hasBackgroundColors() then table.insert(cats, cfg.category.background_colors'Navboxes using background colours') end
if isIllegible() then table.insert(cats, cfg.category.'Potentially illegible navboxes') end
if hasBorders() then table.insert(cats, cfg.category.'Navboxes using borders') end
return cats
end
Line 342 ⟶ 340:
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == cfg.keyword.subpage_doc'doc' or subpage == cfg.keyword.subpage_sandbox'sandbox' or subpage == 'testcases' then return end
or subpage == cfg.keyword.subpage_testcases then return end
 
for _, cat in ipairs(getTrackingCategories()) do
Line 355 ⟶ 352:
local function renderMainTable()
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] ~= cfg.keyword.state_plain'plain' and args.state ~= 'off') then
if args[cfg.arg.state] ~== cfg.keyword.state_off)'collapsed' then args.state = 'mw-collapsed' end
if args[cfg.arg.state] == cfg.keyword.state_collapsed then args[cfg.arg.state] = cfg.class.collapsed end
tbl
:addClass(cfg.class.'mw-collapsible')
:addClass(args[cfg.arg.state] or cfg.class.'autocollapse')
end
 
tbl:css('border-spacing', 0)
if border == cfg.keyword.border_subgroup'subgroup' or border == cfg.keyword.border_none'none' then
tbl
:addClass(cfg.class.navbox_subgroup'navbox-subgroup')
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will be applied to the wrapper table
tbl
:addClass(cfg.class.navbox_inner'navbox-inner')
:css('background', 'transparent')
:css('color', 'inherit')
end
tbl:cssText(args[cfg.arg.innerstyle])
 
renderTitleRow(tbl)
Line 396 ⟶ 392:
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 402 ⟶ 398:
table.sort(listnums)
 
border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == cfg.keyword.border_child'child' then
border = cfg.keyword.border_subgroup'subgroup'
end
 
Line 412 ⟶ 408:
-- render the appropriate wrapper around the navbox, depending on the border param
local res = mw.html.create()
if border == cfg.keyword.border_none'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', cfg.aria_label'Navbox')
end
elseif border == cfg.keyword.border_subgroup'subgroup' then
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
Line 433 ⟶ 429:
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass(cfg.class.'navbox')
:addClass(args[cfg.arg.navboxclass])
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
:css('padding', '3px')
: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', cfg.aria_label'Navbox')
end
end
 
if (args[cfg.arg.nocat] or cfg.keyword.nocat_false'false'):lower() == cfg.keyword.nocat_false'false' then
renderTrackingCategories(res)
end
Line 457 ⟶ 453:
getArgs = require('Module:Arguments').getArgs
end
args = getArgs(frame, {wrappers = {'Template:Navbox'}})
 
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = args[cfg.arg.title]
_ = args[cfg.arg.above]
for i = 1, 20 do
_ = args[cfg.arg.group_part"group" .. tostring(i)]
_ = args[cfg.arg.list_part"list" .. tostring(i)]
end
_ = args[cfg.arg.below]
 
return p._navbox(args)