More actions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
local images = args['images'] or '' | local images = args['images'] or '' | ||
local texts = args['texts'] or '' | local texts = args['texts'] or '' | ||
local links = args['links'] or '' | local links = args['links'] or '' | ||
local subtexts = args['subtexts'] or '' | |||
local imageList = mw.text.split(images, ',') | local imageList = mw.text.split(images, ',') | ||
local textList = mw.text.split(texts, ',') | local textList = mw.text.split(texts, ',') | ||
local linkList = mw.text.split(links, ',') | local linkList = mw.text.split(links, ',') | ||
local subtextList = mw.text.split(subtexts, ',') | |||
local html = mw.html.create('div'):addClass('image-grid-container') | local html = mw.html.create('div'):addClass('image-grid-container') | ||
for i = 1, math.max(#imageList, #textList, #linkList) do | for i = 1, math.max(#imageList, #textList, #linkList, #subtextList) do | ||
local image = mw.text.trim(imageList[i] or 'Noimg.png') | local image = mw.text.trim(imageList[i] or 'Noimg.png') | ||
local text = mw.text.trim(textList[i] or '') | local text = mw.text.trim(textList[i] or '') | ||
local link = mw.text.trim(linkList[i] or '') | local link = mw.text.trim(linkList[i] or '') | ||
local subtext = mw.text.trim(linkList[i] or '') | |||
local imageWrapper = html:tag('div'):addClass('image-wrapper') | local imageWrapper = html:tag('div'):addClass('image-wrapper') | ||
Line 29: | Line 32: | ||
if text ~= '' then | if text ~= '' then | ||
imageWrapper:tag('div'):addClass('image-text'):wikitext(text) | imageWrapper:tag('div'):addClass('image-text'):wikitext(text) | ||
end | |||
-- subtext overlay | |||
if subtext ~= '' then | |||
imageWrapper:tag('div'):addClass('image-text-sub'):wikitext(subtext) | |||
end | end | ||
end | end |
Revision as of 17:40, 17 September 2024
Documentation for this module may be created at Module:ImageGrid/doc
local p = {}
function p.renderImageGrid(frame)
local args = frame:getParent().args
local images = args['images'] or ''
local texts = args['texts'] or ''
local links = args['links'] or ''
local subtexts = args['subtexts'] or ''
local imageList = mw.text.split(images, ',')
local textList = mw.text.split(texts, ',')
local linkList = mw.text.split(links, ',')
local subtextList = mw.text.split(subtexts, ',')
local html = mw.html.create('div'):addClass('image-grid-container')
for i = 1, math.max(#imageList, #textList, #linkList, #subtextList) do
local image = mw.text.trim(imageList[i] or 'Noimg.png')
local text = mw.text.trim(textList[i] or '')
local link = mw.text.trim(linkList[i] or '')
local subtext = mw.text.trim(linkList[i] or '')
local imageWrapper = html:tag('div'):addClass('image-wrapper')
if link ~= '' then
imageWrapper:wikitext(string.format('[[File:%s|link=%s]]', image, link))
else
imageWrapper:wikitext(string.format('[[File:%s]]', image))
end
-- text overlay
if text ~= '' then
imageWrapper:tag('div'):addClass('image-text'):wikitext(text)
end
-- subtext overlay
if subtext ~= '' then
imageWrapper:tag('div'):addClass('image-text-sub'):wikitext(subtext)
end
end
-- return string here
return tostring(html)
end
return p