Module:MBox

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

--- '''Mbox''' is a module for creating message boxes.
--	> Modified by Squatch_
--	
--  @module		mbox
--  @author		[[Technobliterator|Technobliterator]] (Lua conversion)
--  @author		[[Jak Himself|Jak Himself]] (HTML and CSS)
--  @require	[[Module:Arguments]]
--  @release	stable

------------------------------------------
-- This module normally support collaspible image + quote for thinner boxes
-- however in this implementation its broken...
------------------------------------------

local Mbox = {}

local getArgs = require('Module:Arguments').getArgs
-- local i18n = require('Module:I18n').loadMessages('Mbox')
local styles = require('Module:MBox/styles')

function Mbox.__main(frame)
    local args = getArgs(frame)
    
    -- images
    -- local image = i18n:parameter('image', args) or ''
    local image = args.image or ''
    local imageadjust = ''
    if args.imageadjust then
        imageadjust = '|' .. args.imageadjust
    end
    -- local imagewidth = i18n:parameter('imagewidth', args) or '80px'
    local imagewidth = args.imagewidth or '80px'
    local imagelink = '|link='
    -- local imagelinkarg = i18n:parameter('imagelink', args)
    local imagelinkarg = args.imagelink
    if imagelinkarg then
        imagelink = imagelink .. imagelinkarg
    end

    local imagewikitext = '[[File:' .. image .. '|' .. imagewidth  .. imageadjust .. imagelink .. ']]'

    -- id for closure
    -- local id = i18n:parameter('id', args) or 'mbox'
    local id = args.id or 'mbox'
    -- local typeclass = i18n:parameter('type', args)
    local typeclass = args.type
    
	local outer_container = mw.html.create('div')
    local container = outer_container:tag('div')
    	-- :addClass('mbox')
        :attr('id', id)
		:css(styles.mbox)
		if args.border then
			container:css('border-left-color', args.border)
		end
        -- :addClass(typeclass and ('mbox-type-' .. typeclass)) -> replaced by above

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

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

    local contentwrapper = content:tag('div')
        -- :addClass('mbox__content__wrapper')
        :css(styles.content_wrapper)
    -- local header = i18n:parameter('header', args)
    local header = args.header

    if header then
        contentwrapper:tag('div')
            -- :addClass('mbox__content__header')
            :css(styles.content_header)
            -- :addClass('mw-collapsible')
            :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(header)
    end

    -- local textarg = i18n:parameter('text', args)
    local textarg = args.text
    if textarg then
        local text = contentwrapper:tag('div')
            -- :addClass('mbox__content__text')
            :css(styles.content_text)
            :wikitext(textarg)
            -- if collapsed then
            --     text:addClass('mw-collapsed')
            -- end

        -- local comment = i18n:parameter('comment', args)
        local comment = args.comment
        if comment then
            text:tag('div')
                -- :addClass('mbox__content__text__comment')
                :css(styles.content_text_comment)
                -- :addClass('mw-collapsible')
            	:attr('id', 'mw-customcollapsible-' .. id)
                :wikitext(comment)
        end
    end
    
    -- local asidearg = i18n:parameter('aside', args)
    local asidearg = args.aside
    if asidearg then
        local aside = content:tag('div')
            -- :addClass('mbox__content__aside')
            :css(styles.content_aside)
            -- :addClass('mw-collapsible')
            -- :attr('id', 'mw-customcollapsible-' .. id)
            :wikitext(asidearg)
            -- if collapsed then
            --     aside:addClass('mw-collapsed')
            -- end
    end

    contentwrapper:tag('span')
        -- :addClass('mbox__min')
        :css(styles.mbox_min)
        -- :addClass('mw-customtoggle-' .. id)
        :attr('title', 'Minimize')
    
    -- since message boxes are not dismissable on our current theme, left this part out
    -- contentwrapper:tag('span')
    --     :addClass('mbox__close')
    --     :attr('id', id)
    --     :attr('title', i18n:msg('dismiss'))
    local spacer = outer_container:tag('div')
    	:css('height','40px')
    
    return outer_container
end

return Mbox
Cookies help us deliver our services. By using our services, you agree to our use of cookies.