3,060
edits
(update from Module:Navbox/sandbox per talk; this implements automatic striping that applies to a navbox and any subgroup (child) navboxes it contains) |
Metriximor (talk | contribs) m (87 revisions imported from wikipedia:Module:Navbox: this is nice to have) |
||
(22 intermediate revisions by 11 users not shown) | |||
Line 9:
local args
local border
local listnums
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
local RESTART_MARKER = '\127_ODDEVEN0_\127'
Line 57 ⟶ 56:
end
local function
if
-- Applying nowrap to lines in a table does not make sense.
return '\n' .. s ..'\n'▼
-- Add newlines to compensate for trim of x in |parm=x in a template.
return
end
if nowrapitems == 'yes' then
end▼
local lines = {}
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local function addTableRow(tbl)▼
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match('^<span class="nowrap">') then
line = prefix .. '<span class="nowrap">' .. content .. '</span>'
end▼
:tag('td')▼
item = table.concat(lines, '\n')
end
if item:match('^[*:;#]') then
end
return
end
Line 86 ⟶ 85:
args.name,
mini = 1,
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;box-shadow:none;padding:0;'
})
end
Line 98 ⟶ 97:
if not args.title then return end
local titleRow =
if args.titlegroup then
Line 135 ⟶ 134:
titleCell
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:css('font-size', '114%')
:css('margin', '0 4em')
:wikitext(
end
Line 156:
if not args.above then return end
:tag('td')
:addClass('navbox-abovebelow')
Line 164:
:attr('colspan', getAboveBelowColspan())
:tag('div')
-- id for aria-labelledby attribute, if no title
:wikitext(addNewline(args.above))▼
end
Line 170 ⟶ 172:
if not args.below then return end
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow')
Line 178 ⟶ 180:
:attr('colspan', getAboveBelowColspan())
:tag('div')
:wikitext(
end
Line 185 ⟶ 187:
--
local function renderListRow(tbl, index, listnum)
local row =
if index == 1 and args.imageleft then
row
:tag('td')
:addClass('noviewer')
:addClass('navbox-image')
:addClass(args.imageclass)
:css('width', '
:css('padding', '0px 2px 0px 0px')
:cssText(args.imageleftstyle)
:attr('rowspan',
:tag('div')
:wikitext(
end
if args['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.title or args.above or args.group2) then
groupCell
end
groupCell
Line 208 ⟶ 217:
:addClass(args.groupclass)
:cssText(args.basestyle)
:css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width
▲ end
groupCell
Line 255 ⟶ 261:
:addClass('navbox-' .. oddEven)
:addClass(args.listclass)
:addClass(args['list' .. listnum .. 'class'])
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:wikitext(
if index == 1 and args.image then
row
:tag('td')
:addClass('noviewer')
:addClass('navbox-image')
:addClass(args.imageclass)
:css('width', '
:css('padding', '0px 0px 0px 2px')
:cssText(args.imagestyle)
:attr('rowspan',
:tag('div')
:wikitext(
end
end
Line 291 ⟶ 299:
local function hasBackgroundColors()
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
if tostring(args[key]):find('background', 1, true) then
return true
end
end
▲end
for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
if tostring(args[key]):find('border', 1, true) then
return true
end
Line 316 ⟶ 332:
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
if isIllegible() then table.insert(cats, 'Potentially illegible navboxes') end
if hasBorders() then table.insert(cats, 'Navboxes using borders') end
return cats
end
Line 325 ⟶ 342:
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
for
builder:wikitext('[[Category:' .. cat .. ']]')
end
Line 339 ⟶ 356:
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
if args.state == 'collapsed' then args.state = 'mw-collapsed' end
tbl
:addClass('mw-collapsible')
:addClass(args.state or 'autocollapse')
end
Line 370 ⟶ 388:
function p._navbox(navboxArgs)
args = navboxArgs
listnums = {}
for k,
if type(k) == 'string' then
if listnum then table.insert(listnums, tonumber(listnum)) end
end
end
table.sort(listnums)
Line 391 ⟶ 412:
:attr('role', 'navigation')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args.title or args.above or (args.group1 and not args.group2) then
▲ nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
nav:attr('aria-label', 'Navbox')
Line 408 ⟶ 430:
:attr('role', 'navigation')
:addClass('navbox')
:addClass(args.navboxclass)
:cssText(args.bodystyle)
:cssText(args.style)
:css('padding', '3px')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args.title or args.above or (args.group1 and not args.group2) then
▲ nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
nav:attr('aria-label', 'Navbox')
Line 419 ⟶ 443:
end
if (args.nocat or 'false'):lower() == 'false' then
end
return striped(tostring(res))
end
Line 428 ⟶ 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.
|