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

Module:Mbox: Difference between revisions

From Very Bad Wiki
Created page with "-- This Module is used for making templates based in the Lua language. -- See more details about Lua in w:Help:Lua. -- 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 defa..."
 
No edit summary
 
Line 1: Line 1:
-- This Module is used for making templates based in the Lua language.
local Mbox = {}
-- See more details about Lua in [[w:Help:Lua]].
-- 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.
local function getArgs(frame)
-- For a more flexible Mbox experience, delete the function below and import
    local args = {}
-- https://dev.fandom.com/wiki/MediaWiki:Global_Lua_Modules/Mbox.css
    for k, v in pairs(frame:getParent().args) do
-- or paste (and modify as you like) its contents in your wiki's
        if v ~= "" then args[k] = v end
-- [[MediaWiki:Wikia.css]] (see [[w:Help:Including_additional_CSS_and_JS]])
    end
-- or look at https://dev.fandom.com/wiki/Global_Lua_Modules/Mbox
    for k, v in pairs(frame.args) do
-- for more customization inspiration
        if v ~= "" then args[k] = v end
 
    end
--
    return args
-- BEGIN DELETION HERE
end
--
 
local getArgs = require('Dev:Arguments').getArgs
local localCSS = mw.loadData('Module:Mbox/data').localStyle


function Mbox.main(frame)
function Mbox.main(frame)
      
     local args = getArgs(frame)
local args = getArgs(frame)
 
   
-- styles
   
local styles = {}
   
if args.bordercolor then
       
styles['border-left-color'] = args.bordercolor
   
elseif args.type then
       
styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
   
end
 
   
if args.bgcolor then
       
styles['background-color'] = args.bgcolor
   
end
 
   
-- images
   
local image = args.image or ''
   
local imagewidth = args.imagewidth or '80px'
   
local imagelink = ''
   
if args.imagelink then
       
imagelink = '|link=' .. args.imagelink
   
end


      
     -- styles
local imagewikitext = ('%sFile:%s|%s%s' .. ']]'):format('[[', image, imagewidth, imagelink)
    local styles = {}
    if args.bordercolor then
        styles['border-left-color'] = args.bordercolor
    elseif args.type then
        styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
    end
    if args.bgcolor then
        styles['background-color'] = args.bgcolor
    end


      
     -- images
-- id for closure
     local imagewidth = args.imagewidth or '80px'
      
    local imagelink = args.imagelink and ('|link=' .. args.imagelink) or ''
local id = args.id or 'mbox'
    local imagewikitext = ('[[File:%s|%s%s]]'):format(args.image or '', imagewidth, imagelink)


      
     -- id for collapsible toggle
local container = mw.html.create('div')
    local id = args.id or 'mbox'
       
:addClass('mbox')
       
:addClass(args.class)
       
:css(styles)
       
:css(localCSS['mbox'])
       
:cssText(args.style)


      
     local container = mw.html.create('div')
local content = container:tag('div')
         :addClass('mbox')
          
         :addClass(args.class)
:addClass('mbox__content')
        :css(styles)
          
        :cssText(args.style)
:css(localCSS['mbox__content'])


      
     local content = container:tag('div')
if args.image then
         :addClass('mbox__content')
       
local image = content:tag('div')
           
:addClass('mbox__content__image')
           
: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


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


      
     local contentwrapper = content:tag('div')
if args.header then
        :addClass('mbox__content__wrapper')
       
contentwrapper:tag('div')
           
:addClass('mbox__content__header')
           
:css(localCSS['mbox__content__header'])
           
:wikitext(args.header)
   
end


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


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


      
     contentwrapper:tag('span')
contentwrapper:tag('span')
         :addClass('mbox__close')
          
         :addClass('mw-customtoggle-' .. id)
:addClass('mbox__close')
         :attr('title', 'Dismiss')
          
:addClass('mw-customtoggle-' .. id)
          
:css(localCSS['mbox__close'])
       
:attr('title', 'Dismiss')


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


      
     return container
return container
end
end


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

Latest revision as of 04:18, 21 March 2026

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

local Mbox = {}

local function getArgs(frame)
    local args = {}
    for k, v in pairs(frame:getParent().args) do
        if v ~= "" then args[k] = v end
    end
    for k, v in pairs(frame.args) do
        if v ~= "" then args[k] = v end
    end
    return args
end

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

    -- styles
    local styles = {}
    if args.bordercolor then
        styles['border-left-color'] = args.bordercolor
    elseif args.type then
        styles['border-left-color'] = 'var(--type-' .. args.type .. ')'
    end
    if args.bgcolor then
        styles['background-color'] = args.bgcolor
    end

    -- images
    local imagewidth = args.imagewidth or '80px'
    local imagelink = args.imagelink and ('|link=' .. args.imagelink) or ''
    local imagewikitext = ('[[File:%s|%s%s]]'):format(args.image or '', imagewidth, imagelink)

    -- id for collapsible toggle
    local id = args.id or 'mbox'

    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(args.class)
        :css(styles)
        :cssText(args.style)

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

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

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

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

    if args.text then
        local text = contentwrapper:tag('div')
            :addClass('mbox__content__text')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(args.text)
        if args.collapsed then
            text:addClass('mw-collapsed')
        end
        if args.comment then
            text:tag('div')
                :addClass('mbox__content__text__comment')
                :wikitext(args.comment)
        end
    end

    contentwrapper:tag('span')
        :addClass('mbox__close')
        :addClass('mw-customtoggle-' .. id)
        :attr('title', 'Dismiss')

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

    return container
end

return Mbox