Content deleted Content added
No edit summary Tag: Reverted |
sandbox config |
||
(18 intermediate revisions by 5 users not shown) | |||
Line 4:
local inArray = require("Module:TableTools").inArray
local getArgs -- lazily initialized
-- global passthrough variables
Line 19 ⟶ 20:
[cfg.arg.state]=true,
[cfg.arg.title]=true,[cfg.arg.titleclass]=true,[cfg.arg.titlestyle]=true,
argHash=true
}
-- helper functions
local andnum = function(s, n) return string.format(cfg.arg[s .. '_and_num'], n) end
local isblank = function(v) return (v or '') == '' end
Line 44 ⟶ 46:
local subArgs = {
[cfg.arg.border] = cfg.keyword.border_subgroup,
[cfg.arg.navbar] = cfg.keyword.navbar_plain,
argHash = 0
}
local hasSubArgs = false
Line 55 ⟶ 58:
subArgs[k:sub(#w + 1)] = v
hasSubArgs = true
subArgs.argHash = subArgs.argHash + (v and #v or 0)
end
end
Line 114 ⟶ 118:
-- 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.
return '\n' .. item .. '\n'
end
if nowrapitems == cfg.keyword.nowrapitems_yes then
Line 128 ⟶ 132:
end
if item:match('^[*:;#]') then
return '\n' .. item .. '\n'
end
return item
Line 152 ⟶ 156:
local function renderNavBar(titleCell)
if has_navbar() then
local navbar = require('Module:Navbar
titleCell:wikitext(navbar{
[cfg.navbar.name] = args[cfg.arg.name],
Line 186 ⟶ 190:
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]) .. args.argHash)
:addClass(args[cfg.arg.titleclass])
:css('font-size', '114%')
Line 212 ⟶ 216:
:tag('div')
-- id for aria-labelledby attribute, if no title
:attr('id', (not args[cfg.arg.title]) and
(mw.uri.anchorEncode(args[cfg.arg.above]) or nil)
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
end
Line 239 ⟶ 245:
:addClass(cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '
:css('padding', '0 2px 0 0')
:cssText(args[cfg.arg.imageleftstyle])
Line 255 ⟶ 261:
if listnum == 1 and not (args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group2]) then
groupCell
:attr('id', mw.uri.anchorEncode(args[cfg.arg.group1]) .. args.argHash)
end
Line 325 ⟶ 331:
:addClass(cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '
:css('padding', '0 0 0 2px')
:cssText(args[cfg.arg.imagestyle])
Line 469 ⟶ 475:
tbl
:addClass(cfg.class.navbox_inner)
:css('background', 'transparent')
:css('color', 'inherit')
end
Line 520 ⟶ 527:
-- for each arg: find all the templatestyles strip markers, insert them into a
-- table. then remove all templatestyles markers from the arg
if type(arg) == 'string' then
for marker in string.gfind(arg, strip_marker_pattern) do▼
▲ local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'
▲ for k, arg in pairs(args) do
▲ for marker in gfind(arg, strip_marker_pattern) do
▲ table.insert(templatestyles_markers, marker)
end
argHash = argHash + #arg
args[k] = string.gsub(arg, strip_marker_pattern, '')
end
end
if not args.argHash then args.argHash = argHash end
▲ local hiding_templatestyles = move_hiding_templatestyles(args)
local listnums = {}
Line 540 ⟶ 546:
if type(k) == 'string' then
local listnum = k:match(cfg.pattern.listnum)
if listnum
table.insert(listnums, tonumber(listnum))
end▼
end
end
Line 568 ⟶ 576:
mw.uri.anchorEncode(
args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1]
) .. args.argHash
)
else
Line 587 ⟶ 595:
:attr('role', 'navigation')
:addClass(cfg.class.navbox)
:addClass(args[cfg.arg.navboxclass])
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
:css('padding', '
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
Line 598 ⟶ 605:
nav:attr(
'aria-labelledby',
mw.uri.anchorEncode(
args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1] ) .. args.argHash
)
else
nav:attr('aria-label', cfg.aria_label .. args.argHash)
end
end
Line 609 ⟶ 618:
end
return striped(tostring(res), border)
end --p._navbox
▲end
function p._withCollapsibleGroups(pargs)
Line 683 ⟶ 692:
[cfg.arg.image] = pargs[andnum('image', n)],
[cfg.arg.imageleft] = pargs[andnum('imageleft', n)],
[cfg.arg.listpadding] = pargs[cfg.arg.listpadding],
argHash = pargs.argHash
})
end
Line 697 ⟶ 707:
return p._navbox(targs)
end --p._withCollapsibleGroups
function p._withColumns(pargs)
Line 825 ⟶ 835:
and isblank(pargs[andnum('colfooter', 1)]) then
targs[andnum('list', 1)] = targs[andnum('list', 1)] ..
end
Line 832 ⟶ 842:
targs[cfg.arg.evenodd] = (not isblank(pargs[cfg.arg.evenodd])) and pargs[cfg.arg.evenodd] or nil
targs[cfg.arg.list1padding] = '0px'
targs[andnum('liststyle', 1)] = 'background:transparent;color:inherit;'
targs[cfg.arg.style] = concatstyles({pargs[cfg.arg.style], pargs[cfg.arg.bodystyle]})
targs[cfg.arg.tracking] = 'no'
return p._navbox(targs)
end --p._withColumns
-- Template entry points
Line 844 ⟶ 854:
-- Read the arguments in the order they'll be output in, to make references
-- number in the right order.
local _ = 0
_ = _ + (args[prefix .. cfg.arg.title] and #args[prefix .. cfg.arg.title] or 0)
_ = _ + (args[prefix .. cfg.arg.above] and #args[prefix .. cfg.arg.above] or 0)
-- Limit this to 20 as covering 'most' cases (that's a SWAG) and because
-- iterator approach won't work here
for i = 1, 20 do
_ = _ + (args[prefix .. andnum('group', i)] and #args[prefix .. andnum('group', i)] or 0)
if inArray(cfg.keyword.subgroups, args[prefix .. andnum('list', i)]) then
for _, v in ipairs(cfg.arg.subgroups_and_num) do
Line 858 ⟶ 868:
end
end
_ = _ + (args[prefix .. cfg.arg.below] and #args[prefix .. cfg.arg.below] or 0)
return _
end
Line 865 ⟶ 876:
end
local args = getArgs(frame, {wrappers = {cfg.pattern[boxtype or 'navbox']}})
args.argHash = readArgs(args, "")
args.type = args.type or cfg.keyword[boxtype]
return p['_navbox'](args)
|