Module:Navigation: Difference between revisions
From PC Gaming Shelter
No edit summary |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function renderRow(label, image, target, model) | local function renderRow(label, image, target, model, badge) | ||
local defaultTarget = label | local defaultTarget = label | ||
if not target then | if not target then | ||
| Line 15: | Line 15: | ||
if image ~= '' and model == '0' then | if image ~= '' and model == '0' then | ||
labelClass = 'navthumb-label h-100 with-icon' | labelClass = 'navthumb-label h-100 with-icon' | ||
end | |||
local badgeClass = 'navthumb-badge' | |||
if model == '0' then | |||
badgeClass = 'navthumb-badge ml-auto' | |||
end | end | ||
local html = mw.html.create() | local html = mw.html.create() | ||
local card = html:tag('div'):addClass(cardClass) | local card = html:tag('div'):addClass(cardClass) | ||
if image ~= '' and model == '1' then | if image ~= '' and model == '1' then | ||
card:tag('div'):addClass('navthumb-image'):attr({ | card:tag('div'):addClass('navthumb-image'):attr({ | ||
| Line 24: | Line 30: | ||
}):done() | }):done() | ||
end | end | ||
if image ~= '' and model == '0' then | if image ~= '' and model == '0' then | ||
card:tag('div'):addClass(labelClass):attr({ | card:tag('div'):addClass(labelClass):attr({ | ||
| Line 34: | Line 41: | ||
card:tag('div'):addClass(labelClass):wikitext(string.format('[[%s|%s]]', target, label)):done() | card:tag('div'):addClass(labelClass):wikitext(string.format('[[%s|%s]]', target, label)):done() | ||
end | end | ||
if badge ~= '' then | |||
card:tag('div'):addClass(badgeClass):wikitext(badge) | |||
end | |||
return html | return html | ||
end | end | ||
| Line 51: | Line 62: | ||
while args['label' .. i] do | while args['label' .. i] do | ||
local label = args['label' .. i] | local label = args['label' .. i] | ||
local badge = args['badge' .. i] | |||
local imageUrl = '' | local imageUrl = '' | ||
| Line 61: | Line 73: | ||
local target = args['target' .. i] or label | local target = args['target' .. i] or label | ||
body:node(renderRow(label, imageUrl, target, showThumbs)) | body:node(renderRow(label, imageUrl, target, showThumbs, badge)) | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
Revision as of 13:17, 18 June 2026
Documentation for this module may be created at Module:Navigation/doc
local p = {}
local function renderRow(label, image, target, model, badge)
local defaultTarget = label
if not target then
target = defaultTarget
end
local cardClass = 'navthumb'
if image ~= '' and model == '1' then
cardClass = 'navthumb p-3'
end
local labelClass = 'navthumb-label'
if image ~= '' and model == '0' then
labelClass = 'navthumb-label h-100 with-icon'
end
local badgeClass = 'navthumb-badge'
if model == '0' then
badgeClass = 'navthumb-badge ml-auto'
end
local html = mw.html.create()
local card = html:tag('div'):addClass(cardClass)
if image ~= '' and model == '1' then
card:tag('div'):addClass('navthumb-image'):attr({
['data-bg'] = image,
}):done()
end
if image ~= '' and model == '0' then
card:tag('div'):addClass(labelClass):attr({
['data-bg'] = image,
}):css({
['background-size'] = 'contain',
['background-repeat'] = 'no-repeat',
}):wikitext(string.format('[[%s|%s]]', target, label)):done()
else
card:tag('div'):addClass(labelClass):wikitext(string.format('[[%s|%s]]', target, label)):done()
end
if badge ~= '' then
card:tag('div'):addClass(badgeClass):wikitext(badge)
end
return html
end
function p.data(frame)
local args = frame:getParent().args or {}
local title = args[1] or args['title'] or 'Navigate'
local showThumbs = args['show thumbs'] or '1'
local html = mw.html.create()
local card = html:tag('div'):addClass('card bg-dark thumbwall mb-3')
local header = card:tag('div'):addClass('card-header'):wikitext(title):done()
local body = card:tag('div'):addClass('card-body')
local i = 1
while args['label' .. i] do
local label = args['label' .. i]
local badge = args['badge' .. i]
local imageUrl = ''
local image = args['image' .. i] or ''
if image and image ~= '' then
imageUrl = frame:preprocess(
string.format('{{filepath:{{PAGENAME:%s}}}}', image)
)
end
local target = args['target' .. i] or label
body:node(renderRow(label, imageUrl, target, showThumbs, badge))
i = i + 1
end
return html
end
return p
