Module:Navbox: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (Changed protection level of Module:Navbox: lowering to template protection ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))) |
(don't use globals) |
||
Line 14: | Line 14: | ||
local listnums = {} |
local listnums = {} |
||
function trim(s) |
local function trim(s) |
||
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1")) |
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1")) |
||
end |
end |
||
function addNewline(s) |
local function addNewline(s) |
||
if s:match('^[*:;#]') or s:match('^{|') then |
if s:match('^[*:;#]') or s:match('^{|') then |
||
return '\n' .. s ..'\n' |
return '\n' .. s ..'\n' |
||
Line 26: | Line 26: | ||
end |
end |
||
function addTableRow(tbl) |
local function addTableRow(tbl) |
||
-- If any other rows have already been added, then we add a 2px gutter row. |
-- If any other rows have already been added, then we add a 2px gutter row. |
||
if tableRowAdded then |
if tableRowAdded then |
||
Line 41: | Line 41: | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if args.state == 'plain' then spacerSide = 'right' end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- |
-- |
||
-- Title row |
-- Title row |
||
-- |
-- |
||
function renderTitleRow(tbl) |
local function renderTitleRow(tbl) |
||
if not args.title then return end |
if not args.title then return end |
||
Line 90: | Line 123: | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if args.image then ret = ret + 1 end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if not args.above then return end |
if not args.above then return end |
||
Line 142: | Line 148: | ||
end |
end |
||
function renderBelowRow(tbl) |
local function renderBelowRow(tbl) |
||
if not args.below then return end |
if not args.below then return end |
||
Line 155: | Line 161: | ||
.wikitext(addNewline(args.below)) |
.wikitext(addNewline(args.below)) |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
if args.image then ret = ret + 1 end |
|||
⚫ | |||
⚫ | |||
-- |
-- |
||
-- List rows |
-- List rows |
||
-- |
-- |
||
function renderListRow(tbl, listnum) |
local function renderListRow(tbl, listnum) |
||
local row = addTableRow(tbl) |
local row = addTableRow(tbl) |
||
Line 258: | Line 256: | ||
-- Tracking categories |
-- Tracking categories |
||
-- |
-- |
||
function renderTrackingCategories(builder) |
local function renderTrackingCategories(builder) |
||
local frame = mw.getCurrentFrame() |
local frame = mw.getCurrentFrame() |
||
Line 273: | Line 271: | ||
end |
end |
||
function getTrackingCategories() |
local function getTrackingCategories() |
||
local cats = {} |
local cats = {} |
||
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end |
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end |
||
Line 280: | Line 278: | ||
end |
end |
||
function needsHorizontalLists() |
local function needsHorizontalLists() |
||
if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end |
if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end |
||
Line 293: | Line 291: | ||
end |
end |
||
function hasBackgroundColors() |
local function hasBackgroundColors() |
||
return args.titlestyle or args.groupstyle |
return args.titlestyle or args.groupstyle |
||
end |
end |
||
Line 301: | Line 299: | ||
-- Main navbox tables |
-- Main navbox tables |
||
-- |
-- |
||
function renderMainTable() |
local function renderMainTable() |
||
local tbl = HtmlBuilder.create('table') |
local tbl = HtmlBuilder.create('table') |
||
.attr('cellspacing', 0) |
.attr('cellspacing', 0) |