FANDOM


m
(add imageadjust= for center|left|right|thumb, etc)
 
Line 1: Line 1:
 
-- This Module is used for making templates based in the Lua language.
 
-- This Module is used for making templates based in the Lua language.
 
-- See more details about Lua in [[Help:Lua]].
 
-- See more details about Lua in [[Help:Lua]].
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden.
+
-- Based on:
-- The next line imports the Mbox module from the [[w:c:dev:Global Lua Modules]].
+
-- https://dev.fandom.com/wiki/Module:Mbox
local Mbox = require('Dev:Mbox')
+
-- Changes:
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/Mbox]]
+
-- + Support imageadjust param for center|left|right|thumb, etc
  +
-- <nowiki>
  +
local Mbox = {}
  +
local getArgs = require('Dev:Arguments').getArgs
 
 
-- The imported Module is overwritten locally to include default styling.
+
function Mbox.main(frame)
-- For a more flexible Mbox experience, delete the function below and import
+
local args = getArgs(frame)
-- https://dev.fandom.com/wiki/MediaWiki:Global_Lua_Modules/Mbox.css
+
-- or paste (and modify as you like) its contents in your wiki's
+
-- styles
-- [[MediaWiki:Wikia.css]] (see [[Help:Including_additional_CSS_and_JS]])
+
local styles = {}
-- or look at https://dev.fandom.com/wiki/Global_Lua_Modules/Mbox
+
styles['border-left-color'] = args['bordercolor']
-- for more customization inspiration
+
styles['background-color'] = args['bgcolor']
+
  +
-- images
  +
local image = args.image or ''
  +
local imageadjust = ''
  +
if args.imagelink then
  +
imageadjust = '|' .. args.imageadjust
  +
end
  +
local imagewidth = args.imagewidth or '80px'
  +
local imagelink = ''
  +
if args.imagelink then
  +
imagelink = '|link=' .. args.imagelink
  +
end
  +
  +
local imagewikitext = '[[File:' .. image .. '|' .. imagewidth .. imageadjust .. imagelink .. ']]'
  +
  +
-- id for closure
  +
local id = args.id or 'mbox'
  +
  +
local container = mw.html.create('div')
  +
:addClass('mbox')
  +
:addClass(args['type'] and ('mbox-type-' .. args['type']))
  +
:addClass(args.class)
  +
:css(styles)
  +
:cssText(args.style)
  +
  +
local content = container:tag('div')
  +
:addClass('mbox__content')
  +
  +
if args.image then
  +
local image = content:tag('div')
  +
:addClass('mbox__content__image')
  +
:addClass('mw-collapsible')
  +
:attr('id', 'mw-customcollapsible-' .. id)
  +
:wikitext(imagewikitext)
  +
if args.collapsed then
  +
image: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
 
 
-- The last line produces the output for the template
 
 
return Mbox
 
return Mbox

Latest revision as of 05:38, December 7, 2019

-- This Module is used for making templates based in the Lua language.
-- See more details about Lua in [[Help:Lua]].
-- Based on:
-- https://dev.fandom.com/wiki/Module:Mbox
-- Changes:
--   + Support imageadjust param for center|left|right|thumb, etc
-- <nowiki>
local Mbox = {}
local getArgs = require('Dev:Arguments').getArgs
 
function Mbox.main(frame)
    local args = getArgs(frame)
 
    -- styles
    local styles = {}
    styles['border-left-color'] = args['bordercolor']
    styles['background-color'] = args['bgcolor']
 
    -- images
    local image = args.image or ''
    local imageadjust = ''
    if args.imagelink then
        imageadjust = '|' .. args.imageadjust
    end
    local imagewidth = args.imagewidth or '80px'
    local imagelink = ''
    if args.imagelink then
        imagelink = '|link=' .. args.imagelink
    end
 
    local imagewikitext = '[[File:' .. image .. '|' .. imagewidth .. imageadjust .. imagelink .. ']]'
 
    -- id for closure
    local id = args.id or 'mbox'
 
    local container = mw.html.create('div')
        :addClass('mbox')
        :addClass(args['type'] and ('mbox-type-' .. args['type']))
        :addClass(args.class)
        :css(styles)
        :cssText(args.style)
 
    local content = container:tag('div')
        :addClass('mbox__content')
 
    if args.image then
        local image = content:tag('div')
            :addClass('mbox__content__image')
            :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(imagewikitext)
            if args.collapsed then
                image: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
Community content is available under CC-BY-SA unless otherwise noted.