Module:Notice: Difference between revisions
m added class "nopageimage" to picture |
No edit summary |
||
Line 1: | Line 1: | ||
local | -- Define constants -- | ||
local TEMPLATE_STYLES = 'Module:Notice/styles.css' | |||
-- Define tables of valid values -- | |||
local borderColors ={ | |||
["blue"] = true, | |||
["gray"] = true, | |||
["green"] = true, | |||
["maroon"] = true, | |||
["orange"] = true, | |||
["pink"] = true, | |||
["purple"] = true, | |||
["red"] = true, | |||
["teal"] = true, | |||
["yellow"] = true | |||
} | |||
local backgroundColors ={ | |||
["blue"] = true, | |||
["gray"] = true, | |||
["green"] = true, | |||
["maroon"] = true, | |||
["orange"] = true, | |||
["pink"] = true, | |||
["purple"] = true, | |||
["red"] = true, | |||
["teal"] = true, | |||
["yellow"] = true | |||
} | |||
local alignValues = { | |||
["center"] = true, | |||
["left"] = true, | |||
["right"] = true | |||
} | |||
local textAlignValues = { | |||
["center"] = true, | |||
["left"] = true, | |||
["right"] = true | |||
} | |||
local p = {} | |||
-- Entry point for the module | -- Entry point for the module -- | ||
function p.main(frame) | function p.main(frame) | ||
if | local args = require('Module:ProcessArgs').merge(true) | ||
local alignBox = args.align or 'left' | |||
local alignContent = args.alignContent or '' | |||
local alignHeader = args.alignHeader or '' | |||
local alignText = args.alignText or 'left' | |||
local class = args.class or '' | |||
local color = args.color or 'green' | |||
local colorBack = args.colorBack or '' | |||
local content = args.content or '' | |||
local file = args.file or '' | |||
local fileRight = args.fileRight or '' | |||
local fileSize = args.filesize or '48px' | |||
local header = args.header or '' | |||
local small = args.small or '' | |||
local width = args.width or '' | |||
if alignText ~= '' then | |||
if alignHeader == '' then alignHeader = alignText end | |||
if alignContent == '' then alignContent = alignText end | |||
end | |||
-- use template styles -- | |||
local root = mw.html.create() | |||
root:wikitext(frame:extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = TEMPLATE_STYLES}, | |||
}) | |||
-- base div-section of the notice box -- | |||
local box = root:tag('div') | |||
if small == 'yes' then | |||
box:addClass('notice-small') | |||
else | |||
box:addClass('notice') | |||
if alignValues[alignBox] then | |||
box:addClass(string.format('notice-%s', alignBox)) | |||
else | |||
box:addClass('notice-left') | |||
end | |||
end | |||
if borderColors[color] then | |||
box:addClass(string.format('notice-border-%s', color)) | |||
else | |||
box:css('border-color', color) | |||
end | |||
if colorBack ~= '' then | |||
if backgroundColors[colorBack] then | |||
box:addClass(string.format('notice-background-%s', colorBack)) | |||
else | |||
box:css('background-color', colorBack) | |||
end | |||
end | |||
if width ~= '' then | |||
box:css('width', width) | |||
end | |||
-- add additional classes to the box (optional) -- | |||
if class ~= '' then box:addClass(class) end | |||
-- adding elements to the box -- | |||
-- place file left -- | |||
if file ~= '' then | if file ~= '' then | ||
if fileRight == '' then | |||
box:tag('div') | |||
:addClass('notice-image') | |||
:wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize)) | |||
end | |||
end | |||
-- place text content -- | |||
local contentDiv = '' | |||
if header ~= '' then | |||
contentDiv = box:tag('div') | |||
:addClass('notice-content') | |||
local headerDiv = contentDiv:tag('div') | |||
:addClass('notice-header') | |||
:addClass(string.format('notice-text-%s', alignHeader)) | |||
:wikitext(header) | |||
end | end | ||
if content ~= '' then | |||
if contentDiv == '' then | |||
contentDiv = box:tag('div') | |||
:addClass('notice-content') | |||
end | |||
return tostring(root) | local descriptionDiv = contentDiv:tag('div') | ||
:addClass('notice-description') | |||
:addClass(string.format('notice-text-%s', alignContent)) | |||
:wikitext(content) | |||
end | |||
-- place file right -- | |||
if fileRight ~= '' then | |||
if file ~= '' then | |||
box:tag('div') | |||
:addClass('notice-image') | |||
:wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize)) | |||
end | |||
end | |||
return tostring(root) | |||
end | end | ||
return p | return p |