Jump to content

Module:Mbox: Difference between revisions

From MISERY wiki
imported>FANDOM
No edit summary
 
No edit summary
 
Line 1: Line 1:
-- This Module is used for making templates based in the Lua language.
local p = {}
-- See more details about Lua in [[w:Help:Lua]].
local getArgs = require('Module:Arguments').getArgs
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden.
-- The next line imports the Mbox module from the [[w:c:dev:Global Lua Modules]].
local Mbox = require('Dev:Mbox')
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/Mbox]]


-- The imported Module is overwritten locally to include default styling.
function p.main(frame)
-- For a more flexible Mbox experience, delete the function below and import
-- https://dev.fandom.com/wiki/MediaWiki:Global_Lua_Modules/Mbox.css
-- or paste (and modify as you like) its contents in your wiki's
-- [[MediaWiki:Wikia.css]] (see [[w:Help:Including_additional_CSS_and_JS]])
-- or look at https://dev.fandom.com/wiki/Global_Lua_Modules/Mbox
-- for more customization inspiration
 
--
-- BEGIN DELETION HERE
--
 
local getArgs = require('Dev:Arguments').getArgs
local localCSS = mw.loadData('Module:Mbox/data').localStyle
 
function Mbox.main(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)


    -- styles
     local styles = {}
     local styles = {}
     if args.bordercolor then
     if args.bordercolor then
         styles['border-left-color'] = args.bordercolor
         styles['border-left'] = '4px solid ' .. args.bordercolor
     elseif args.type then
     elseif args.type == 'notice' then
         styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
         styles['border-left'] = '4px solid #3a86c8'
    elseif args.type == 'warning' then
        styles['border-left'] = '4px solid #c8a83a'
    elseif args.type == 'danger' then
        styles['border-left'] = '4px solid #c83a3a'
    else
        styles['border-left'] = '4px solid #5a8a3a'
     end
     end


     if args.bgcolor then
     if args.bgcolor then
         styles['background-color'] = args.bgcolor
         styles['background-color'] = args.bgcolor
    else
        styles['background-color'] = '#1a2a10'
     end
     end
    -- images
    local image = args.image or ''
    local imagewidth = args.imagewidth or '80px'
    local imagelink = ''
    if args.imagelink then
        imagelink = '|link=' .. args.imagelink
    end
    local imagewikitext = ('%sFile:%s|%s%s' .. ']]'):format('[[', image, imagewidth, imagelink)
    -- id for closure
    local id = args.id or 'mbox'


     local container = mw.html.create('div')
     local container = mw.html.create('div')
         :addClass('mbox')
         :addClass('mbox')
         :addClass(args.class)
         :addClass(args.class or '')
         :css(styles)
         :css(styles)
         :css(localCSS['mbox'])
         :css({
         :cssText(args.style)
            ['padding'] = '10px 14px',
            ['margin'] = '8px 0',
            ['display'] = 'flex',
            ['align-items'] = 'flex-start',
            ['gap'] = '12px',
            ['border-radius'] = '2px',
        })
         :cssText(args.style or '')


     local content = container:tag('div')
     local content = container:tag('div')
        :addClass('mbox__content')
         :css({ ['flex'] = '1' })
         :css(localCSS['mbox__content'])


     if args.image then
     if args.image then
         local image = content:tag('div')
         container:tag('div')
             :addClass('mbox__content__image')
             :wikitext('[[File:' .. args.image .. '|' .. (args.imagewidth or '40px') .. ']]')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
        :css(localCSS['mbox__content__image'])
            :wikitext(imagewikitext)
            if args.collapsed then
                image:addClass('mw-collapsed')
            end
     end
     end
    local contentwrapper = content:tag('div')
        :addClass('mbox__content__wrapper')
        :css(localCSS['mbox__content__wrapper'])


     if args.header then
     if args.header then
         contentwrapper:tag('div')
         content:tag('div')
             :addClass('mbox__content__header')
             :css({
            :css(localCSS['mbox__content__header'])
                ['font-weight'] = 'bold',
                ['margin-bottom'] = '4px',
                ['color'] = '#c09040',
                ['text-transform'] = 'uppercase',
                ['letter-spacing'] = '0.05em',
            })
             :wikitext(args.header)
             :wikitext(args.header)
     end
     end


     if args.text then
     if args.text then
         local text = contentwrapper:tag('div')
         content:tag('div')
            :addClass('mbox__content__text')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :css(localCSS['mbox__content__text'])
             :wikitext(args.text)
             :wikitext(args.text)
            if args.collapsed then
                text:addClass('mw-collapsed')
            end


         if args.comment then
         if args.comment then
             text:tag('div')
             content:tag('div')
                 :addClass('mbox__content__text__comment')
                 :css({ ['font-size'] = '0.85em', ['opacity'] = '0.7', ['margin-top'] = '4px' })
                :css(localCSS['mbox__content__text__comment'])
                 :wikitext(args.comment)
                 :wikitext(args.comment)
         end
         end
    end
    contentwrapper:tag('span')
        :addClass('mbox__close')
        :addClass('mw-customtoggle-' .. id)
        :css(localCSS['mbox__close'])
        :attr('title', 'Dismiss')
    if args.aside then
        local aside = content:tag('div')
            :addClass('mbox__content__aside')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :css(localCSS['mbox__content__aside'])
            :wikitext(args.aside)
            if args.collapsed then
                aside:addClass('mw-collapsed')
            end
     end
     end


Line 123: Line 72:
end
end


--
return p
-- END DELETION HERE
--
 
-- The last line produces the output for the template
return Mbox

Latest revision as of 00:28, 29 June 2026

This module is used by most of the basic Notice templates and is invoked by {{MessageBox}}.


local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame)

    local styles = {}
    if args.bordercolor then
        styles['border-left'] = '4px solid ' .. args.bordercolor
    elseif args.type == 'notice' then
        styles['border-left'] = '4px solid #3a86c8'
    elseif args.type == 'warning' then
        styles['border-left'] = '4px solid #c8a83a'
    elseif args.type == 'danger' then
        styles['border-left'] = '4px solid #c83a3a'
    else
        styles['border-left'] = '4px solid #5a8a3a'
    end

    if args.bgcolor then
        styles['background-color'] = args.bgcolor
    else
        styles['background-color'] = '#1a2a10'
    end

    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(args.class or '')
        :css(styles)
        :css({
            ['padding'] = '10px 14px',
            ['margin'] = '8px 0',
            ['display'] = 'flex',
            ['align-items'] = 'flex-start',
            ['gap'] = '12px',
            ['border-radius'] = '2px',
        })
        :cssText(args.style or '')

    local content = container:tag('div')
        :css({ ['flex'] = '1' })

    if args.image then
        container:tag('div')
            :wikitext('[[File:' .. args.image .. '|' .. (args.imagewidth or '40px') .. ']]')
    end

    if args.header then
        content:tag('div')
            :css({
                ['font-weight'] = 'bold',
                ['margin-bottom'] = '4px',
                ['color'] = '#c09040',
                ['text-transform'] = 'uppercase',
                ['letter-spacing'] = '0.05em',
            })
            :wikitext(args.header)
    end

    if args.text then
        content:tag('div')
            :wikitext(args.text)

        if args.comment then
            content:tag('div')
                :css({ ['font-size'] = '0.85em', ['opacity'] = '0.7', ['margin-top'] = '4px' })
                :wikitext(args.comment)
        end
    end

    return container
end

return p