Module:Message box: Difference between revisions

From Chalo Chatu, Zambia online encyclopedia
No edit summary
No edit summary
Line 1: Line 1:
-- Simple Message box module for Chalo Chatu
local p = {}
local p = {}


-- Disable TemplateStyles temporarily
function p.imbox(frame)
local function loadTemplateStyles()
    local args = frame:getParent().args
-- Normally loads Module:Message box/ombox.css
    local text = args['text'] or ''
-- But disabled because TemplateStyles is not installed
    local type = args['type'] or 'notice'
return '' -- Return nothing to avoid raw tags
end


-- This function is called directly by some modules
    local colors = {
function p.ombox(frame)
        notice = '#f9f9f9',
local args = frame:getParent().args
        warning = '#fff2cc',
local boxType = args.type or 'notice'
        error = '#fdd',
local boxClass = 'mbox mbox-' .. boxType
        info = '#eaf3ff'
local boxStyle = args.style or ''
    }
local text = args.text or ''
local box = mw.html.create('table')
box:addClass(boxClass)
box:cssText(boxStyle)
local tr = box:tag('tr')
tr:tag('td'):addClass('mbox-text'):wikitext(text)
return loadTemplateStyles() .. tostring(box)
end


-- This is the "main" function that Module:High-use expects
    local border = {
function p.main(_type, data)
        notice = '#aaa',
local boxType = data.type or 'notice'
        warning = '#fc3',
local boxClass = 'mbox mbox-' .. boxType
        error = '#d33',
local boxStyle = data.style or ''
        info = '#36c'
local text = data.text or ''
    }
 
local box = mw.html.create('table')
    local style = string.format(
box:addClass(boxClass)
        "border:1px solid %s; background:%s; padding:0.5em; margin:0.5em 0;",
box:cssText(boxStyle)
        border[type] or '#aaa',
        colors[type] or '#f9f9f9'
local tr = box:tag('tr')
    )
tr:tag('td'):addClass('mbox-text'):wikitext(text)
 
    return string.format('<div style="%s">%s</div>', style, text)
return loadTemplateStyles() .. tostring(box)
end
end


return p
return p