Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
neither of these fixed it
keep trying i guess with this revert?
Tag: Reverted
Line 1:
--
-- This module implements {{Navbox}}
--
 
local p = {}
 
local navbar = require('Module:Navbar')._navbar
local cfg = mw.loadData('Module:Navbox/configuration')
local getArgs -- lazily initialized
local cfg = mw.loadData('Module:Navbox/configuration')
 
local args
local format = string.formatborder
local listnums
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
local RESTART_MARKER = '\127_ODDEVEN0_\127'
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'
 
local function striped(wikitext, border)
-- Return wikitext with markers replaced for odd/even striping.
-- Child (subgroup) navboxes are flagged with a category that is removed
-- by parent navboxes. The result is that the category shows all pages
-- where a child navbox is not contained in a parent navbox.
if border == cfg.keyword.border_subgroup and args[cfg.arg.orphan] ~= cfg.keyword.orphan_yes then
args[cfg.arg.orphan] ~= cfg.keyword.orphan_yes then
-- No change; striping occurs in outermost navbox.
return wikitext .. cfg.category.orphan
end
local first, second = 'odd'cfg.class.navbox_odd_part, 'even'cfg.class.navbox_even_part
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == cfg.keyword.evenodd_swap then
Line 30 ⟶ 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 44 ⟶ 53:
end
local regex = cfg.category.orphan:gsub('([%[%]])', '%%%1')
return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer)) -- () omits gsub count
return (wikitext:gsub(regex, ''):gsub(cfg.marker.regex, changer))
end
 
Line 59 ⟶ 67:
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match(cfg.pattern.nowrap) then
line = mw.ustring.format(cfg.nowrap_item, prefix, content)
end
table.insert(lines, line)
Line 72 ⟶ 80:
 
local function renderNavBar(titleCell)
 
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
(args[cfg.arg.name] or 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[cfg.arg.titlestyle] or '') ..
';background:none transparent;border:none;box-shadow:none;padding:0;'
})
end
Line 88 ⟶ 95:
end
 
--
-- Title row
--
local function renderTitleRow(tbl)
if not args[cfg.arg.title] then return end
Line 135 ⟶ 145:
:wikitext(processItem(args[cfg.arg.title]))
end
 
--
-- Above/Below rows
--
 
local function getAboveBelowColspan()
Line 155 ⟶ 169:
: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]))
: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 176 ⟶ 187:
end
 
--
local function renderListRow(tbl, index, listnum, listnums_size)
-- List rows
--
local function renderListRow(tbl, index, listnum)
local row = tbl:tag('tr')
 
Line 183 ⟶ 197:
:tag('td')
:addClass(cfg.class.noviewer)
:addClass(cfg.class.navbox_imageimage)
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0 2px 0 0')
:cssText(args[cfg.arg.imageleftstyle])
:attr('rowspan', listnums_size#listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.imageleft]))
end
 
localif group_and_num = format(args[cfg.arg.group_and_num,group_part .. listnum)] then
local groupstyle_and_num = format(cfg.arg.groupstyle_and_num, listnum)
if args[group_and_num] 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
(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 210 ⟶ 221:
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
:css('width', args[cfg.arg.groupwidth] or '1%') -- If groupwidth not specified, minimize width
:css('width', args[cfg.arg.groupwidth] or '1%')
 
groupCell
:cssText(args[cfg.arg.groupstyle])
:cssText(args[groupstyle_and_numcfg.arg.group_part .. listnum .. cfg.arg.style_part])
:wikitext(args[group_and_numcfg.arg.group_part .. listnum])
end
 
local listCell = row:tag('td')
 
if args[group_and_numcfg.arg.group_part .. listnum] then
listCell
:css('text-align', 'left')
Line 241 ⟶ 251:
end
 
local list_and_numlistText = format(args[cfg.arg.list_and_num,list_part .. listnum)]
local oddEven = ODD_EVEN_MARKER
local liststyle_and_num = format(cfg.arg.liststyle_and_num, listnum)
local listclass_and_num = format(cfg.arg.listclass_and_num, listnum)
local listText = args[list_and_num]
local oddEven = cfg.marker.oddeven
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no autoautomatic striping for this row.
oddEven = listText:find(cfg.pattern.navbox_title) and RESTART_MARKER or cfg.class.navbox_odd_part
and cfg.marker.restart or 'odd'
end
listCell
Line 255 ⟶ 261:
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args[liststyle_and_numcfg.arg.list_part .. listnum .. cfg.arg.style_part])
:addClass(cfg.class.navbox_list)
:addClass('navbox-'cfg.class.navbox_part .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args[listclass_and_numcfg.arg.list_part .. listnum .. cfg.arg.class_part])
:tag('div')
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0 0.25em')
:css(
'padding',
(index == 1 and args[cfg.arg.list1padding])
or args[cfg.arg.listpadding] or '0 0.25em'
)
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
 
Line 274 ⟶ 276:
:addClass(cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0 0 0 2px')
:cssText(args[cfg.arg.imagestyle])
:attr('rowspan', listnums_size#listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
Line 283 ⟶ 285:
end
 
 
local function needsHorizontalLists(border)
--
if border == cfg.keyword.border_subgroup or
-- Tracking categories
args[cfg.arg.tracking] == cfg.keyword.tracking_no then
--
 
local function needsHorizontalLists()
if border == cfg.keyword.border_subgroup or args[cfg.arg.tracking] == cfg.keyword.tracking_no then
return false
end
-- FIXME: These should be finding the classes in list_classes, not looking for equality.
return not (cfg.list_classes[args[cfg.arg.listclass]]
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(basic_style_args){cfg.arg.titlestyle, docfg.arg.groupstyle,
cfg.arg.basestyle, cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('background', 1, true) then
return true
Line 301 ⟶ 308:
 
local function hasBorders()
for _, key in ipairs(basic_style_args){cfg.arg.groupstyle, docfg.arg.basestyle,
cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('border', 1, true) then
return true
Line 321 ⟶ 329:
end
 
local function getTrackingCategories(border)
local cats = {}
if needsHorizontalLists(border) then table.insert(cats, cfg.category.horizontal_lists) end
if hasBackgroundColors() then table.insert(cats, cfg.category.horizontal_listsbackground_colors) end
end
if hasBackgroundColors() then
table.insert(cats, cfg.category.background_colors)
end
if isIllegible() then table.insert(cats, cfg.category.illegible) end
if hasBorders() then table.insert(cats, cfg.category.borders) end
Line 334 ⟶ 338:
end
 
local function renderTrackingCategories(builder, border)
local title = mw.title.getCurrentTitle()
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == cfg.keyword.subpage_doc or subpage == cfg.keyword.subpage_sandbox
or subpage == cfg.keyword.subpage_sandboxsubpage_testcases then return end
or subpage == cfg.keyword.subpage_testcases then
return
end
 
for _, cat in ipairs(getTrackingCategories(border)) do
builder:wikitext('[[Category:' .. cat .. ']]')
end
end
 
--
local function renderMainTable(border, listnums)
-- Main navbox tables
--
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 and
and args[cfg.arg.state] ~= cfg.keyword.state_plainstate_off) then
andif args[cfg.arg.state] ~== cfg.keyword.state_offstate_collapsed then args[cfg.arg.state] = cfg.class.collapsed end
if args[cfg.arg.state] == cfg.keyword.state_collapsed then
args[cfg.arg.state] = cfg.class.collapsed
end
tbl
:addClass(cfg.class.collapsible)
Line 366 ⟶ 367:
 
tbl:css('border-spacing', 0)
if border == cfg.keyword.border_subgroup or border == cfg.keyword.border_none then
or border == cfg.keyword.border_none then
tbl
:addClass(cfg.class.navbox_subgroup)
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will applybe applied to the wrapper table
tbl
:addClass(cfg.class.navbox_inner)
Line 382:
renderTitleRow(tbl)
renderAboveRow(tbl)
local listnums_size = #listnums
for i, listnum in ipairs(listnums) do
renderListRow(tbl, i, listnum, listnums_size)
end
renderBelowRow(tbl)
Line 393 ⟶ 392:
function p._navbox(navboxArgs)
args = navboxArgs
local listnums = {}
 
for k, _ in pairs(args) do
Line 403 ⟶ 402:
table.sort(listnums)
 
local border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == cfg.keyword.border_child then
border = cfg.keyword.border_subgroup
Line 409 ⟶ 408:
 
-- render the main body of the navbox
local tbl = renderMainTable(border, listnums)
 
-- render the appropriate wrapper around the navbox, depending on the border param
local res = mw.html.create()
if border == cfg.keyword.border_none then
Line 418 ⟶ 417:
: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
ornav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.group1title] andor notargs[cfg.arg.above] or args[cfg.arg.group2group1]) 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)
end
elseif border == 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
-- Wepadding being applied, and at the startend withadd a </div> to avoidbalance out the paddingparent's being applied, and at the</div>
-- end add a <div> to balance out the parent's </div>
res
:wikitext('</div>')
Line 449 ⟶ 440:
: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
ornav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.group1title] andor notargs[cfg.arg.above] or args[cfg.arg.group2group1]) 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)
Line 463 ⟶ 447:
end
 
if (args[cfg.arg.nocat] or cfg.keyword.nocat_false):lower() == cfg.keyword.nocat_false then
renderTrackingCategories(res)
== cfg.keyword.nocat_false then
renderTrackingCategories(res, border)
end
return striped(tostring(res, border))
end
 
Line 474 ⟶ 457:
getArgs = require('Module:Arguments').getArgs
end
args = getArgs(frame, {wrappers = {cfg.pattern.navbox}})
 
-- Read the arguments in the order they'll be output in, to make references number in the right order.
-- number in the right order.
local _
_ = args[cfg.arg.title]
_ = args[cfg.arg.above]
for i = 1, 20 do
_ = args[format(cfg.arg.group_and_num,group_part .. tostring(i)]
_ = args[format(cfg.arg.list_and_num,list_part .. tostring(i)]
end
_ = args[cfg.arg.below]