Difference between revisions of "Module:Navbox"

Jump to navigation Jump to search
971 bytes added ,  15:47, 18 June 2018
m
1 revision imported: Imported see also
m (1 revision imported)
 
m (1 revision imported: Imported see also)
 
(3 intermediate revisions by the same user not shown)
Line 9: Line 9:


local args
local args
local tableRowAdded = false
local border
local border
local listnums = {}
local listnums = {}
Line 78: Line 77:
end
end
return item
return item
end
local function addTableRow(tbl)
-- If any other rows have already been added, then we add a 2px gutter row.
if tableRowAdded then
tbl
:tag('tr')
:css('height', '2px')
:tag('td')
:attr('colspan',2)
end
tableRowAdded = true
return tbl:tag('tr')
end
end


Line 101: Line 85:
args.name,
args.name,
mini = 1,
mini = 1,
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;'
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;'
})
})
end
end
Line 113: Line 97:
if not args.title then return end
if not args.title then return end


local titleRow = addTableRow(tbl)
local titleRow = tbl:tag('tr')


if args.titlegroup then
if args.titlegroup then
Line 150: Line 134:
titleCell
titleCell
:tag('div')
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args.title))
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:addClass(args.titleclass)
Line 171: Line 156:
if not args.above then return end
if not args.above then return end


addTableRow(tbl)
tbl:tag('tr')
:tag('td')
:tag('td')
:addClass('navbox-abovebelow')
:addClass('navbox-abovebelow')
Line 179: Line 164:
:attr('colspan', getAboveBelowColspan())
:attr('colspan', getAboveBelowColspan())
:tag('div')
:tag('div')
-- id for aria-labelledby attribute, if no title
:attr('id', args.title and nil or mw.uri.anchorEncode(args.above))
:wikitext(processItem(args.above, args.nowrapitems))
:wikitext(processItem(args.above, args.nowrapitems))
end
end
Line 185: Line 172:
if not args.below then return end
if not args.below then return end


addTableRow(tbl)
tbl:tag('tr')
:tag('td')
:tag('td')
:addClass('navbox-abovebelow')
:addClass('navbox-abovebelow')
Line 200: Line 187:
--
--
local function renderListRow(tbl, index, listnum)
local function renderListRow(tbl, index, listnum)
local row = addTableRow(tbl)
local row = tbl:tag('tr')


if index == 1 and args.imageleft then
if index == 1 and args.imageleft then
Line 207: Line 194:
:addClass('navbox-image')
:addClass('navbox-image')
:addClass(args.imageclass)
:addClass(args.imageclass)
:css('width', '0%')
:css('width', '1px')               -- Minimize width
:css('padding', '0px 2px 0px 0px')
:css('padding', '0px 2px 0px 0px')
:cssText(args.imageleftstyle)
:cssText(args.imageleftstyle)
:attr('rowspan', 2 * #listnums - 1)
:attr('rowspan', #listnums)
:tag('div')
:tag('div')
:wikitext(processItem(args.imageleft))
:wikitext(processItem(args.imageleft))
Line 217: Line 204:
if args['group' .. listnum] then
if args['group' .. listnum] then
local groupCell = row:tag('th')
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
:attr('id', mw.uri.anchorEncode(args.group1))
end


groupCell
groupCell
Line 223: Line 216:
:addClass(args.groupclass)
:addClass(args.groupclass)
:cssText(args.basestyle)
:cssText(args.basestyle)
 
            :css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width
if args.groupwidth then
groupCell:css('width', args.groupwidth)
end


groupCell
groupCell
Line 279: Line 269:
:addClass('navbox-image')
:addClass('navbox-image')
:addClass(args.imageclass)
:addClass(args.imageclass)
:css('width', '0%')
:css('width', '1px')               -- Minimize width
:css('padding', '0px 0px 0px 2px')
:css('padding', '0px 0px 0px 2px')
:cssText(args.imagestyle)
:cssText(args.imagestyle)
:attr('rowspan', 2 * #listnums - 1)
:attr('rowspan', #listnums)
:tag('div')
:tag('div')
:wikitext(processItem(args.image))
:wikitext(processItem(args.image))
Line 306: Line 296:


local function hasBackgroundColors()
local function hasBackgroundColors()
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle'}) do
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
if tostring(args[key]):find('background', 1, true) then
if tostring(args[key]):find('background', 1, true) then
return true
end
end
end
local function hasBorders()
for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
if tostring(args[key]):find('border', 1, true) then
return true
return true
end
end
Line 331: Line 329:
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
if isIllegible() then table.insert(cats, 'Potentially illegible navboxes') end
if isIllegible() then table.insert(cats, 'Potentially illegible navboxes') end
if hasBorders() then table.insert(cats, 'Navboxes using borders') end
return cats
return cats
end
end
Line 408: Line 407:
:attr('role', 'navigation')
:attr('role', 'navigation')
:node(tbl)
:node(tbl)
if args.title then
-- aria-labelledby title, otherwise above, otherwise lone group
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
if args.title or args.above or (args.group1 and not args.group2) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
else
nav:attr('aria-label', 'Navbox')
nav:attr('aria-label', 'Navbox')
Line 429: Line 429:
:css('padding', '3px')
:css('padding', '3px')
:node(tbl)
:node(tbl)
if args.title then
-- aria-labelledby title, otherwise above, otherwise lone group
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
if args.title or args.above or (args.group1 and not args.group2) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
else
nav:attr('aria-label', 'Navbox')
nav:attr('aria-label', 'Navbox')
Line 445: Line 446:
getArgs = require('Module:Arguments').getArgs
getArgs = require('Module:Arguments').getArgs
end
end
args = getArgs(frame, {wrappers = 'Template:Navbox'})
args = getArgs(frame, {wrappers = {'Template:Navbox', 'Template:Navbox subgroup'}})
if frame.args.border then
-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}.
args.border = frame.args.border
end


-- Read the arguments in the order they'll be output in, to make references number in the right order.
-- Read the arguments in the order they'll be output in, to make references number in the right order.

Navigation menu