Module:Navbox: Difference between revisions
From Podpedia
Content added Content deleted
(Testing different version of module; will immediately revert if this does not produce the intended result) |
Tag: Undo |
||
Line 9: | Line 9: | ||
local args |
local args |
||
local tableRowAdded = false |
|||
local border |
local border |
||
local listnums = {} |
local listnums = {} |
||
Line 57: | Line 56: | ||
end |
end |
||
local function |
local function processItem(item, nowrapitems) |
||
if |
if item:sub(1, 2) == '{|' then |
||
-- Applying nowrap to lines in a table does not make sense. |
|||
⚫ | |||
-- Add newlines to compensate for trim of x in |parm=x in a template. |
|||
else |
|||
return |
return '\n' .. item ..'\n' |
||
end |
end |
||
if nowrapitems == 'yes' then |
|||
⚫ | |||
local lines = {} |
|||
for line in (item .. '\n'):gmatch('([^\n]*)\n') do |
|||
local function addTableRow(tbl) |
|||
local prefix, content = line:match('^([*:;#]+)%s*(.*)') |
|||
-- If any other rows have already been added, then we add a 2px gutter row. |
|||
if prefix and not content:match('^<span class="nowrap">') then |
|||
if tableRowAdded then |
|||
line = prefix .. '<span class="nowrap">' .. content .. '</span>' |
|||
tbl |
|||
end |
|||
table.insert(lines, line) |
|||
⚫ | |||
⚫ | |||
item = table.concat(lines, '\n') |
|||
:attr('colspan',2) |
|||
end |
end |
||
if item:match('^[*:;#]') then |
|||
⚫ | |||
tableRowAdded = true |
|||
⚫ | |||
return |
return item |
||
end |
end |
||
Line 86: | 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 98: | Line 97: | ||
if not args.title then return end |
if not args.title then return end |
||
local titleRow = |
local titleRow = tbl:tag('tr') |
||
if args.titlegroup then |
if args.titlegroup then |
||
Line 139: | Line 138: | ||
:css('font-size', '114%') |
:css('font-size', '114%') |
||
:css('margin', '0 4em') |
:css('margin', '0 4em') |
||
:wikitext( |
:wikitext(processItem(args.title)) |
||
end |
end |
||
Line 156: | Line 155: | ||
if not args.above then return end |
if not args.above then return end |
||
⚫ | |||
addTableRow(tbl) |
|||
:tag('td') |
:tag('td') |
||
:addClass('navbox-abovebelow') |
:addClass('navbox-abovebelow') |
||
Line 164: | Line 163: | ||
:attr('colspan', getAboveBelowColspan()) |
:attr('colspan', getAboveBelowColspan()) |
||
:tag('div') |
:tag('div') |
||
:wikitext( |
:wikitext(processItem(args.above, args.nowrapitems)) |
||
end |
end |
||
Line 170: | Line 169: | ||
if not args.below then return end |
if not args.below then return end |
||
tbl:tag('tr') |
|||
addTableRow(tbl) |
|||
:tag('td') |
:tag('td') |
||
:addClass('navbox-abovebelow') |
:addClass('navbox-abovebelow') |
||
Line 178: | Line 177: | ||
:attr('colspan', getAboveBelowColspan()) |
:attr('colspan', getAboveBelowColspan()) |
||
:tag('div') |
:tag('div') |
||
:wikitext( |
:wikitext(processItem(args.below, args.nowrapitems)) |
||
end |
end |
||
Line 185: | Line 184: | ||
-- |
-- |
||
local function renderListRow(tbl, index, listnum) |
local function renderListRow(tbl, index, listnum) |
||
local row = |
local row = tbl:tag('tr') |
||
if index == 1 and args.imageleft then |
if index == 1 and args.imageleft then |
||
Line 192: | Line 191: | ||
:addClass('navbox-image') |
:addClass('navbox-image') |
||
:addClass(args.imageclass) |
:addClass(args.imageclass) |
||
:css('width', ' |
: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', |
:attr('rowspan', #listnums) |
||
:tag('div') |
:tag('div') |
||
:wikitext( |
:wikitext(processItem(args.imageleft)) |
||
end |
end |
||
Line 208: | Line 207: | ||
: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) |
|||
⚫ | |||
groupCell |
groupCell |
||
Line 257: | Line 253: | ||
:tag('div') |
:tag('div') |
||
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') |
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') |
||
:wikitext( |
:wikitext(processItem(listText, args.nowrapitems)) |
||
if index == 1 and args.image then |
if index == 1 and args.image then |
||
Line 264: | Line 260: | ||
:addClass('navbox-image') |
:addClass('navbox-image') |
||
:addClass(args.imageclass) |
:addClass(args.imageclass) |
||
:css('width', ' |
: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', |
:attr('rowspan', #listnums) |
||
:tag('div') |
:tag('div') |
||
:wikitext( |
:wikitext(processItem(args.image)) |
||
end |
end |
||
end |
end |
||
Line 325: | Line 321: | ||
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end |
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end |
||
for |
for _, cat in ipairs(getTrackingCategories()) do |
||
builder:wikitext('[[Category:' .. cat .. ']]') |
builder:wikitext('[[Category:' .. cat .. ']]') |
||
end |
end |
||
Line 371: | Line 367: | ||
args = navboxArgs |
args = navboxArgs |
||
for k, |
for k, _ in pairs(args) do |
||
if type(k) == 'string' then |
|||
local listnum = ('' .. k):match('^list(%d+)$') |
|||
local listnum = k:match('^list(%d+)$') |
|||
if listnum then table.insert(listnums, tonumber(listnum)) end |
|||
end |
|||
end |
end |
||
table.sort(listnums) |
table.sort(listnums) |