Module:DevMbox: Difference between revisions

From CG Studios Wiki
Created page with "-- <nowiki> -- By fandom, see https://dev.fandom.com/wiki/Module:Mbox local Mbox = {} local getArgs = require('Dev:Arguments').getArgs local i18n = require('Dev:I18n').loadMessages('Mbox') function Mbox.main(frame) local args = getArgs(frame) -- styles local styles = {} styles['border-left-color'] = i18n:parameter('bordercolor', args) styles['background-color'] = i18n:parameter('bgcolor', args) -- images local image = i18n:parameter('image'..."
 
No edit summary
 
Line 1: Line 1:
-- <nowiki>
-- <nowiki>
-- By fandom, see https://dev.fandom.com/wiki/Module:Mbox
-- Standalone Mbox module for normal Scribunto (non-Fandom)
 
local Mbox = {}
local Mbox = {}
local getArgs = require('Dev:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local i18n = require('Dev:I18n').loadMessages('Mbox')
 
-- Helper: args key lookup with optional default value
local function param(args, key, default)
    if args[key] and args[key] ~= '' then
        return args[key]
    end
    return default
end


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


    ----------------------------------------
     -- styles
     -- styles
    ----------------------------------------
     local styles = {}
     local styles = {}
     styles['border-left-color'] = i18n:parameter('bordercolor', args)
     styles['border-left-color'] = param(args, 'bordercolor')
     styles['background-color'] = i18n:parameter('bgcolor', args)
     styles['background-color']   = param(args, 'bgcolor')


    ----------------------------------------
     -- images
     -- images
     local image = i18n:parameter('image', args) or ''
    ----------------------------------------
     local imageadjust = ''
     local image       = param(args, 'image', '')
     if args.imageadjust then
     local imagewidth  = param(args, 'imagewidth', '80px')
        imageadjust = '|' .. args.imageadjust
 
    end
     local imageadjust = args.imageadjust and ('|' .. args.imageadjust) or ''
    local imagewidth = i18n:parameter('imagewidth', args) or '80px'
     local imagelink   = '|link=' .. (args.imagelink or '')
     local imagelink = '|link='
 
     local imagelinkarg = i18n:parameter('imagelink', args)
     local imagewikitext = ''
     if imagelinkarg then
     if image ~= '' then
         imagelink = imagelink .. imagelinkarg
         imagewikitext = string.format('[[File:%s|%s%s%s]]',
            image, imagewidth, imageadjust, imagelink
        )
     end
     end


     local imagewikitext = '[[File:' .. image .. '|' .. imagewidth  .. imageadjust .. imagelink .. ']]'
     ----------------------------------------
 
    -- container setup
     -- id for closure
     ----------------------------------------
     local id = i18n:parameter('id', args) or 'mbox'
     local id       = param(args, 'id', 'mbox')
     local typeclass = i18n:parameter('type', args)
     local typeclass = param(args, 'type')
    local collapsed = param(args, 'collapsed')
    local header    = param(args, 'header')
    local asidearg  = param(args, 'aside')
    local textarg  = param(args, 'text')
    local comment  = param(args, 'comment')


     local container = mw.html.create('div')
     local container = mw.html.create('div')
         :addClass('mbox')
         :addClass('mbox')
         :addClass(typeclass and ('mbox-type-' .. typeclass))
         :addClass(typeclass and ('mbox-type-' .. typeclass))
         :addClass(i18n:parameter('class', args))
         :addClass(param(args, 'class'))
         :css(styles)
         :css(styles)
         :cssText(i18n:parameter('style', args))
         :cssText(param(args, 'style'))


     local content = container:tag('div')
     local content = container:tag('div')
         :addClass('mbox__content')
         :addClass('mbox__content')
    local collapsed = i18n:parameter('collapsed', args)


    ----------------------------------------
    -- image block
    ----------------------------------------
     if image ~= '' then
     if image ~= '' then
         local image = content:tag('div')
         local img = content:tag('div')
             :addClass('mbox__content__image')
             :addClass('mbox__content__image')
             :addClass('mw-collapsible')
             :addClass('mw-collapsible')
             :attr('id', 'mw-customcollapsible-' .. id)
             :attr('id', 'mw-customcollapsible-' .. id)
             :wikitext(imagewikitext)
             :wikitext(imagewikitext)
            if collapsed then
 
                image:addClass('mw-collapsed')
        if collapsed then
            end
            img:addClass('mw-collapsed')
        end
     end
     end


    ----------------------------------------
    -- main content wrapper
    ----------------------------------------
     local contentwrapper = content:tag('div')
     local contentwrapper = content:tag('div')
         :addClass('mbox__content__wrapper')
         :addClass('mbox__content__wrapper')
    local header = i18n:parameter('header', args)


     if header then
     if header then
Line 64: Line 87:
     end
     end


     local textarg = i18n:parameter('text', args)
     ----------------------------------------
    -- text area
    ----------------------------------------
     if textarg then
     if textarg then
         local text = contentwrapper:tag('div')
         local text = contentwrapper:tag('div')
Line 71: Line 96:
             :attr('id', 'mw-customcollapsible-' .. id)
             :attr('id', 'mw-customcollapsible-' .. id)
             :wikitext(textarg)
             :wikitext(textarg)
            if collapsed then
                text:addClass('mw-collapsed')
            end


         local comment = i18n:parameter('comment', args)
         if collapsed then
            text:addClass('mw-collapsed')
        end
 
         if comment then
         if comment then
             text:tag('div')
             text:tag('div')
Line 83: Line 108:
     end
     end


    ----------------------------------------
    -- close button (note: message removed)
    ----------------------------------------
     contentwrapper:tag('span')
     contentwrapper:tag('span')
         :addClass('mbox__close')
         :addClass('mbox__close')
         :addClass('mw-customtoggle-' .. id)
         :addClass('mw-customtoggle-' .. id)
         :attr('title', i18n:msg('dismiss'))
         :attr('title', 'Dismiss')


     local asidearg = i18n:parameter('aside', args)
     ----------------------------------------
    -- aside
    ----------------------------------------
     if asidearg then
     if asidearg then
         local aside = content:tag('div')
         local aside = content:tag('div')
Line 95: Line 125:
             :attr('id', 'mw-customcollapsible-' .. id)
             :attr('id', 'mw-customcollapsible-' .. id)
             :wikitext(asidearg)
             :wikitext(asidearg)
            if collapsed then
 
                aside:addClass('mw-collapsed')
        if collapsed then
            end
            aside:addClass('mw-collapsed')
        end
     end
     end



Latest revision as of 21:44, 23 November 2025

Documentation for this module may be created at Module:DevMbox/doc

-- <nowiki>
-- Standalone Mbox module for normal Scribunto (non-Fandom)

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

-- Helper: args key lookup with optional default value
local function param(args, key, default)
    if args[key] and args[key] ~= '' then
        return args[key]
    end
    return default
end

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

    ----------------------------------------
    -- styles
    ----------------------------------------
    local styles = {}
    styles['border-left-color'] = param(args, 'bordercolor')
    styles['background-color']   = param(args, 'bgcolor')

    ----------------------------------------
    -- images
    ----------------------------------------
    local image       = param(args, 'image', '')
    local imagewidth  = param(args, 'imagewidth', '80px')

    local imageadjust = args.imageadjust and ('|' .. args.imageadjust) or ''
    local imagelink   = '|link=' .. (args.imagelink or '')

    local imagewikitext = ''
    if image ~= '' then
        imagewikitext = string.format('[[File:%s|%s%s%s]]',
            image, imagewidth, imageadjust, imagelink
        )
    end

    ----------------------------------------
    -- container setup
    ----------------------------------------
    local id        = param(args, 'id', 'mbox')
    local typeclass = param(args, 'type')
    local collapsed = param(args, 'collapsed')
    local header    = param(args, 'header')
    local asidearg  = param(args, 'aside')
    local textarg   = param(args, 'text')
    local comment   = param(args, 'comment')

    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(typeclass and ('mbox-type-' .. typeclass))
        :addClass(param(args, 'class'))
        :css(styles)
        :cssText(param(args, 'style'))

    local content = container:tag('div')
        :addClass('mbox__content')

    ----------------------------------------
    -- image block
    ----------------------------------------
    if image ~= '' then
        local img = content:tag('div')
            :addClass('mbox__content__image')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(imagewikitext)

        if collapsed then
            img:addClass('mw-collapsed')
        end
    end

    ----------------------------------------
    -- main content wrapper
    ----------------------------------------
    local contentwrapper = content:tag('div')
        :addClass('mbox__content__wrapper')

    if header then
        contentwrapper:tag('div')
            :addClass('mbox__content__header')
            :wikitext(header)
    end

    ----------------------------------------
    -- text area
    ----------------------------------------
    if textarg then
        local text = contentwrapper:tag('div')
            :addClass('mbox__content__text')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(textarg)

        if collapsed then
            text:addClass('mw-collapsed')
        end

        if comment then
            text:tag('div')
                :addClass('mbox__content__text__comment')
                :wikitext(comment)
        end
    end

    ----------------------------------------
    -- close button (note: message removed)
    ----------------------------------------
    contentwrapper:tag('span')
        :addClass('mbox__close')
        :addClass('mw-customtoggle-' .. id)
        :attr('title', 'Dismiss')

    ----------------------------------------
    -- aside
    ----------------------------------------
    if asidearg then
        local aside = content:tag('div')
            :addClass('mbox__content__aside')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(asidearg)

        if collapsed then
            aside:addClass('mw-collapsed')
        end
    end

    return container
end

return Mbox