Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ImageGrid: Difference between revisions

From MassiveCraft Wiki
Created page with "local p = {} function p.renderImageGrid(frame) local args = frame:getParent().args local images = mw.text.split(args['images'], ',') local texts = mw.text.split(args['texts'], ',') local imageCount = #images local html = mw.html.create('div'):addClass('image-grid-container') for i = 1, imageCount do local imageWrapper = html:tag('div'):addClass('image-wrapper') local imageTag = imageWrapper:tag('img') :attr('src', ima..."
 
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 3: Line 3:
function p.renderImageGrid(frame)
function p.renderImageGrid(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local images = mw.text.split(args['images'], ',')
     local images = args['images'] or ''
     local texts = mw.text.split(args['texts'], ',')
    local texts = args['texts'] or ''
     local imageCount = #images
    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')
     local html = mw.html.create('div'):addClass('image-grid-container')


     for i = 1, imageCount do
     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(subtextList[i] or '')
 
         local imageWrapper = html:tag('div'):addClass('image-wrapper')
         local imageWrapper = html:tag('div'):addClass('image-wrapper')
         local imageTag = imageWrapper:tag('img')
 
             :attr('src', images[i])
         if link ~= '' then
            :attr('alt', texts[i] or '')
            imageWrapper:wikitext(string.format('[[File:%s|link=%s]]', image, link))
         local textTag = imageWrapper:tag('div'):addClass('image-text'):wikitext(texts[i] or '')
        else
             imageWrapper:wikitext(string.format('[[File:%s]]', image))
        end
 
        local textContainer = imageWrapper:tag('div'):addClass('image-text-container')
 
         -- text overlay
        if text ~= '' then
            textContainer:tag('div'):addClass('image-text-main'):wikitext(text)
        end
       
        -- subtext overlay
        if subtext ~= '' then
            textContainer:tag('div'):addClass('image-text-sub'):wikitext(subtext)
        end
     end
     end


    -- return string here
     return tostring(html)
     return tostring(html)
end
end


return p
return p

Latest revision as of 18:31, 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(subtextList[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

        local textContainer = imageWrapper:tag('div'):addClass('image-text-container')

        -- text overlay
        if text ~= '' then
            textContainer:tag('div'):addClass('image-text-main'):wikitext(text)
        end
        
        -- subtext overlay
        if subtext ~= '' then
            textContainer:tag('div'):addClass('image-text-sub'):wikitext(subtext)
        end
    end

    -- return string here
    return tostring(html)
end

return p