跳转到内容

模块:背景图片

来自SS唯基

这个模块是干什么用的?

该模块用于模版:背景图片,请直接看相关模版


local p = {}

function p.main(frame)
    local args = frame:getParent() and frame:getParent().args or {}
    for k, v in pairs(frame.args) do
        if args[k] == nil then args[k] = v end
    end

    local imgFile    = args.url or args[1] or 'Test-background.jpg'
    local position   = args.position  and mw.text.trim(args.position)  or 'center center'
    local opacity    = args.opacity   and mw.text.trim(args.opacity)   or '1'
    local shade      = tonumber(args.shade) or 0
    local shadeColor = args.shadeColor and mw.text.trim(args.shadeColor) or 'white'
    local color      = args.color     and mw.text.trim(args.color)     or 'transparent'
    local animate    = args.animate   and mw.text.trim(args.animate)   or 'show'
    local action     = args.action    and mw.text.trim(args.action)

    local defaults = {
        show='2s', shrink='4s ease-out', clear='2s', appear='5s ease', look='5s ease',
    }
    local animTiming = action or defaults[animate] or '2s'

    local html = mw.html.create()
    local outer = html:tag('div')
        :attr('class', 'wiki-bg-outer wiki-bg-anim-' .. animate)
        :cssText(
            'position:fixed;top:0;left:0;width:100%;height:100%;' ..
            'z-index:-1;pointer-events:none;' ..
            'opacity:' .. opacity
        )

    outer:tag('div'):attr('class', 'wiki-bg-color')
        :cssText('position:fixed;top:0;left:0;width:100%;height:100%;background:' .. color)

    outer:wikitext('[[File:' .. imgFile .. '|link=|frameless]]')

    -- Always-on auto overlay: white in light mode, dark in dark mode (via CSS @media)
    outer:tag('div'):attr('class', 'wiki-bg-shade-auto')

    if shade > 0 then
        outer:tag('div'):attr('class', 'wiki-bg-shade')
            :cssText(
                'position:fixed;top:0;left:0;width:100%;height:100%;' ..
                'background:' .. shadeColor .. ';opacity:' .. tostring(shade)
            )
    end

    return tostring(html)
end

return p