模块:Infobox/item/image:修订间差异

来自Cookie☆Wiki
无编辑摘要
无编辑摘要
第9行: 第9行:
if gallery_mark_index ~= 1 then --< 单张图片
if gallery_mark_index ~= 1 then --< 单张图片
if string.byte(arg, 1) == 127 then
if string.byte(arg, 1) == 127 then
return '<span style="font-size: 24px; font-weight: bold; color: red">\
return '<span style="font-size: 24px; font-weight: bold; color: red">'
请更新画廊的语法: "<gallery>(换行)文件名|标签页名(换行)…</gallery>" \
.. '请更新画廊的语法: "<gallery>(换行)文件名|标签页名(换行)…</gallery>" '
→ "gallery:(换行)文件名:标签页名(换行)…" </span>\
.. '→ "gallery:(换行)文件名:标签页名(换行)…" </span>'
[[Category: 含有在信息框中使用了旧的画廊语法的页面]]'
.. '[[Category: 含有在信息框中使用了旧的画廊语法的页面]]'
end
end
return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
第37行: 第37行:
local current = ''
local current = ''
if i == 1 then current = 'current' end
if i == 1 then current = 'current' end
tab_lis = tab_lis .. string.format('<li class="pi-tab-link \
tab_lis = tab_lis .. string.format('<li class="pi-tab-link '
pi-item-spacing %s" data-pi-tab="pi-tab-%d">',
.. 'pi-item-spacing %s" data-pi-tab="pi-tab-%d">',
current, (i-1)) .. image['title'] .. '</li>'
current, (i-1)) .. image['title'] .. '</li>'


第45行: 第45行:
} }
} }


image_divs = image_divs .. string.format('\
image_divs = image_divs .. string.format(
<div class="pi-image-collection-tab-content %s" id="pi-tab-%s">',
'<div class="pi-image-collection-tab-content %s" id="pi-tab-%s">',
current, (i-1)) .. image .. '</div>'
current, (i-1)) .. image .. '</div>'
end
end


local tabs_ul = '<ul class="pi-image-collection-tabs">' ..
local tabs_ul = '<ul class="pi-image-collection-tabs">'
tab_lis .. '</ul>'
.. tab_lis .. '</ul>'


return '<div class="pi-image-collection">' ..
return '<div class="pi-image-collection">'
tabs_ul .. image_divs .. '</div>'
.. tabs_ul .. image_divs .. '</div>'
end
end



2019年1月15日 (二) 03:49的版本

可在模块:Infobox/item/image/doc创建此模块的帮助文档

local p = {}

function p.make()
    local frame = mw.getCurrentFrame()
    local parent = frame:getParent()
    local arg = parent.args['image']

    local gallery_mark_index = arg:find('gallery:')
    if gallery_mark_index ~= 1 then --< 单张图片
        if string.byte(arg, 1) == 127 then
            return '<span style="font-size: 24px; font-weight: bold; color: red">'
                .. '请更新画廊的语法: "<gallery>(换行)文件名|标签页名(换行)…</gallery>" '
                .. '→ "gallery:(换行)文件名:标签页名(换行)…" </span>'
                .. '[[Category: 含有在信息框中使用了旧的画廊语法的页面]]'
        end
        return frame:expandTemplate{ title = 'Infobox/item/single image', args = {
            image = arg, caption = parent.args['caption']
        } }
    end

    -- 去掉 'gallery:'
    arg = string.sub(arg, 9, -1)

    images = {}
    for image_line in arg:gmatch('[^\r\n]+') do
        -- table.insert(lines, line)
        local sep = image_line:find(':')
        table.insert(images, {
            file = string.sub(image_line, 1, sep-1),
            title = string.sub(image_line, sep+1, -1)
        })
    end

    local tab_lis = ''
    local image_divs = ''
    for i, image in pairs(images) do
        local current = ''
        if i == 1 then current = 'current' end
        tab_lis = tab_lis .. string.format('<li class="pi-tab-link '
            .. 'pi-item-spacing %s" data-pi-tab="pi-tab-%d">',
            current, (i-1)) .. image['title'] .. '</li>'

        local image = frame:expandTemplate{ title = 'Infobox/item/single image', args = {
            image = image['file']
        } }

        image_divs = image_divs .. string.format(
            '<div class="pi-image-collection-tab-content %s" id="pi-tab-%s">',
            current, (i-1)) .. image .. '</div>'
    end

    local tabs_ul = '<ul class="pi-image-collection-tabs">'
        .. tab_lis .. '</ul>'

    return '<div class="pi-image-collection">'
        .. tabs_ul .. image_divs .. '</div>'
end

return p