Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
listnums to local
Tag: Reverted
oy oy oy take a minute for things
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 args
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)
Line 18 ⟶ 10:
-- 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
local orphanCat = '[[Category:Navbox orphans]]'
if border == 'subgroup' and args.orphan ~= 'yes'cfg.keyword.orphan_yes then
-- No change; striping occurs in outermost navbox.
return wikitext .. orphanCatcfg.category.orphan
end
local first, second = 'odd', 'even'
Line 50 ⟶ 42:
end
end
local regex = orphanCatcfg.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 78 ⟶ 71:
 
local function renderNavBar(titleCell)
if args.navbar ~= cfg.keyword.navbar_off and
 
if args.navbar ~= 'off' and argscfg.navbar ~= 'plain'keyword.navbar_plain and
not (not args.name andor not mw.getCurrentFrame():getParent():getTitle():gsub('/sandbox$', '') == 'Template:Navbox') then
titleCell:wikitext(navbar{
args.name,
Line 91 ⟶ 84:
end
 
--
-- Title row
--
local function renderTitleRow(tbl)
if not args.title then return end
Line 141 ⟶ 131:
:wikitext(processItem(args.title))
end
 
--
-- Above/Below rows
--
 
local function getAboveBelowColspan()
Line 183 ⟶ 169:
end
 
--
-- List rows
--
local function renderListRow(tbl, index, listnum, listnums)
local row = tbl:tag('tr')
Line 196 ⟶ 179:
:addClass(args.imageclass)
:css('width', '1px') -- Minimize width
:css('padding', '0px0 2px 0px0 0px0')
:cssText(args.imageleftstyle)
:attr('rowspan', #listnums)
Line 217 ⟶ 200:
:addClass(args.groupclass)
:cssText(args.basestyle)
:css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width
:css('width', args.groupwidth or '1%')
 
groupCell
Line 248 ⟶ 232:
 
local listText = args['list' .. listnum]
local oddEven = ODD_EVEN_MARKERcfg.marker.oddeven
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('<th[^>]*"navbox%-title"') and RESTART_MARKERcfg.marker.restart or 'odd'
end
listCell
:css('padding', '0px0')
:cssText(args.liststyle)
:cssText(rowstyle)
Line 263 ⟶ 247:
:addClass(args['list' .. listnum .. 'class'])
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em0 0.25em')
:wikitext(processItem(listText, args.nowrapitems))
 
Line 272 ⟶ 256:
:addClass('navbox-image')
:addClass(args.imageclass)
:css('width', '1px') -- Minimize width
:css('padding', '0px0 0px0 0px0 2px')
:cssText(args.imagestyle)
:attr('rowspan', #listnums)
Line 280 ⟶ 264:
end
end
 
 
--
-- Tracking categories
--
 
local function needsHorizontalLists(border)
if border == 'subgroup'cfg.keyword.border_subgroup or args.tracking == 'no' then
args.tracking == cfg.keyword.tracking_no then
return false
end
return not (listClassescfg.list_classes[args.listclass] or listClassescfg.list_classes[args.bodyclass])
local listClasses = {
['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
['hlist vevent'] = true,
}
return not (listClasses[args.listclass] or listClasses[args.bodyclass])
end
 
Line 347 ⟶ 322:
end
 
--
-- Main navbox tables
--
local function renderMainTable(border, listnums)
local tbl = mw.html.create('table')