Modul:Navbox: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
auto hlist
Farras (bicara | kontrib)
k update
Baris 7:
local HtmlBuilder = require('Module:HtmlBuilder')
local Navbar = require('Module:Navbar')
 
local args
local frame
Baris 17:
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
end
 
function addTableRow(tbl)
-- If any other rows have already been added, then we add a 2px gutter row.
Baris 26:
.tag('td')
end
tableRowAdded = true
return tbl.tag('tr')
end
 
 
--
-- Title row
Baris 40:
local titleRow = addTableRow(tbl)
if args.titlegroup then
titleRow
Baris 52:
.wikitext(args.titlegroup)
end
local titleCell = titleRow.tag('th').attr('scope', 'col')
if args.titlegroup then
titleCell
Baris 60:
.css('width', '100%')
end
local titleColspan = 2
if args.imageleft then titleColspan = titleColspan + 1 end
if args.image then titleColspan = titleColspan + 1 end
if args.titlegroup then titleColspan = titleColspan - 1 end
titleCell
.cssText(args.basestyle)
Baris 81:
.wikitext(args.title)
end
 
function renderNavBar(titleCell)
-- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
-- or right to keep the title centered.
local spacerSide = nil
 
if args.navbar == 'off' then
-- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's
Baris 98:
-- to balance out the width of the navbar.
if args.state == 'plain' then spacerSide = 'right' end
 
titleCell.wikitext(Navbar.navbar({
args.name,
Baris 105:
}))
end
-- Render the spacer div.
if spacerSide then
Baris 115:
end
end
 
 
--
-- Above/Below rows
Baris 134:
.wikitext(args.above)
end
 
function renderBelowRow(tbl)
if not args.below then return end
addTableRow(tbl)
.tag('td')
Baris 149:
.wikitext(args.below)
end
 
function getAboveBelowColspan()
local ret = 2
Baris 163:
function renderListRow(tbl, listnum)
local row = addTableRow(tbl)
if listnum == 1 and args.imageleft then
row
Baris 180:
if args['group' .. listnum] then
local groupCell = row.tag('th')
groupCell
.attr('scope', 'row')
Baris 186:
.addClass(args.groupclass)
.cssText(args.basestyle)
if args.groupwidth then
groupCell.css('width', args.groupwidth)
end
groupCell
.cssText(args.groupstyle)
Baris 196:
.wikitext(args['group' .. listnum])
end
local listCell = row.tag('td')
 
if args['group' .. listnum] then
listCell
Baris 207:
listCell.attr('colspan', 2)
end
if not args.groupwidth then
listCell.css('width', '100%')
end
local isOdd = (listnum % 2) == 1
local rowstyle = args.evenstyle
Baris 222:
if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
end
listCell
.css('padding', '0px')
Baris 235:
.newline()
.wikitext(args['list' .. listnum])
 
if listnum == 1 and args.image then
row
Baris 250:
end
end
 
 
--
-- Tracking categories
Baris 257:
function renderTrackingCategories(builder)
local frame = mw.getCurrentFrame()
if not frame then return end
local s = frame:preprocess('{{#ifeq:{{NAMESPACE}}|{{ns:10}}|1|0}}{{SUBPAGENAME}}')
if mw.ustring.sub(s, 1, 1) == '0' then return end -- not in template space
local subpage = mw.ustring.lower(mw.ustring.sub(s, 2))
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
for i, cat in ipairs(getTrackingCategories()) do
builder.wikitext('[[Kategori:' .. cat .. ']]')
end
end
 
function getTrackingCategories()
local cats = {}
if needsHorizontalLists() then table.insert(cats, 'Kotak navigasi tanpa daftar horizontal') end
if hasCustomListSpacing() then table.insert(cats, 'Kotak navigasi berspasi daftar kustom') end
if hasBackgroundColors() then table.insert(cats, 'Kotak navigasi yang memakai warna latar') end
return cats
end
 
function needsHorizontalLists()
if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end
local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist hwrap', 'hlist vcard', 'vcard hlist', 'hlist vevent'}
for i, cls in ipairs(listClasses) do
if args.listclass == cls or args.bodyclass == cls then
Baris 287 ⟶ 286:
end
end
 
return true
end
 
function hasCustomListSpacing()
return args.liststyle == 'padding: 0.25em 0; line-height: 1.3em;' or
args.liststyle == 'padding:0.25em 0; line-height:1.4em; width:auto;' or
args.liststyle == 'padding:0.4em 0; line-height:1.4em;'
end
 
function hasBackgroundColors()
return args.titlestyle or args.groupstyle
end
 
 
--
-- Main navbox tables
Baris 310 ⟶ 303:
.addClass('nowraplinks hlist')
.addClass(args.bodyclass)
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
tbl
Baris 337 ⟶ 330:
end
renderBelowRow(tbl)
return tbl
end
 
function p._navbox(navboxArgs)
args = navboxArgs
for k, v in pairs(args) do
local listnum = ('' .. k):match('^list(%d+)$')
Baris 351 ⟶ 344:
border = trim(args.border or args[1] or '')
 
-- render the main body of the navbox
local tbl = renderMainTable()
 
-- render the appropriate wrapper around the navbox, depending on the border param
local res = HtmlBuilder.create()
Baris 393 ⟶ 386:
local args = {}
local parent_args = frame:getParent().args;
 
-- Out of order parsing bug.
local temp;
Baris 403 ⟶ 396:
end
temp = parent_args.below;
for k, v in pairs(parent_args) do
if v ~= '' then