Module:Box: Difference between revisions
Appearance
Content deleted Content added
m Themes |
m Themes |
||
Line 4: | Line 4: | ||
local themes = { |
local themes = { |
||
["0"] = { |
|||
"border: thin solid |
"border: thin solid #00619d;", |
||
"background-color: |
"background-color: #a7d7f9; border-bottom: thin solid gray; color: inherit;", |
||
"background-color: #f6f6f6; color: inherit;"}, |
"background-color: #f6f6f6; color: inherit;"}, |
||
["1"] = { |
|||
"border: thin solid #e39c79;", |
"border: thin solid #e39c79;", |
||
"background-color: #f5deb3; border-bottom: thin solid #e39c79; color: inherit;", |
"background-color: #f5deb3; border-bottom: thin solid #e39c79; color: inherit;", |
||
"background-color: #fffcf1; color: inherit;"}, |
"background-color: #fffcf1; color: inherit;"}, |
||
["2"] = { |
|||
"border: thin solid #228b22;", |
"border: thin solid #228b22;", |
||
"background-color: #90ee90; border-bottom: thin solid #228b22; color: inherit;", |
"background-color: #90ee90; border-bottom: thin solid #228b22; color: inherit;", |
||
"background-color: #f5fffa; color: inherit;"}, |
"background-color: #f5fffa; color: inherit;"}, |
||
["3"] = { |
|||
"border: thin solid #4682b4;", |
"border: thin solid #4682b4;", |
||
"background-color: #b0c4de; border-bottom: thin solid #4682b4; color: inherit;", |
"background-color: #b0c4de; border-bottom: thin solid #4682b4; color: inherit;", |
||
"background-color: #f0f8ff; color: inherit;"}, |
"background-color: #f0f8ff; color: inherit;"}, |
||
["4"] = { |
|||
"border: thin solid #cd5c5c;", |
"border: thin solid #cd5c5c;", |
||
"background-color: #f08080; border-bottom: thin solid #cd5c5c; color: inherit;", |
"background-color: #f08080; border-bottom: thin solid #cd5c5c; color: inherit;", |
||
"background-color: #ffe4e1; color: inherit;"}, |
"background-color: #ffe4e1; color: inherit;"}, |
||
["5"] = { |
|||
"border: thin solid #9370db;", |
"border: thin solid #9370db;", |
||
"background-color: #d8bfd8; border-bottom: thin solid #9370db; color: inherit;", |
"background-color: #d8bfd8; border-bottom: thin solid #9370db; color: inherit;", |
||
"background-color: #fff0f5; color: inherit;"}, |
"background-color: #fff0f5; color: inherit;"}, |
||
["6"] = { |
|||
"border: thin solid #ffd700;", |
"border: thin solid #ffd700;", |
||
"background-color: #ffff99; border-bottom: thin solid #ffd700; color: inherit;", |
"background-color: #ffff99; border-bottom: thin solid #ffd700; color: inherit;", |
||
"background-color: #fffff0; color: inherit;"}, |
"background-color: #fffff0; color: inherit;"}, |
||
["7"] = { |
|||
"border: thin solid #4169e1;", |
"border: thin solid #4169e1;", |
||
"background-color: #87cefa; border-bottom: thin solid #4169e1; color: inherit;", |
"background-color: #87cefa; border-bottom: thin solid #4169e1; color: inherit;", |
||
"background-color: #f0ffff; color: inherit;"}, |
"background-color: #f0ffff; color: inherit;"}, |
||
["8"] = { |
|||
"border: thin solid #e78a69;", |
"border: thin solid #e78a69;", |
||
"background-color: #ffdab9; border-bottom: thin solid #e78a69; color: inherit;", |
"background-color: #ffdab9; border-bottom: thin solid #e78a69; color: inherit;", |
||
"background-color: #fff5ee; color: inherit;"}, |
"background-color: #fff5ee; color: inherit;"}, |
||
["9"] = { |
|||
"border: thin solid #71be3f;", |
"border: thin solid #71be3f;", |
||
"background-color: #c0eaa6; border-bottom: thin solid #71be3f; color: inherit;", |
"background-color: #c0eaa6; border-bottom: thin solid #71be3f; color: inherit;", |
||
"background-color: #f6fff1; color: inherit;"}, |
"background-color: #f6fff1; color: inherit;"}, |
||
["10"] = { |
|||
"border: thin solid #4290bc;", |
"border: thin solid #4290bc;", |
||
"background-color: #9ad4f6; border-bottom: thin solid #4290bc; color: inherit;", |
"background-color: #9ad4f6; border-bottom: thin solid #4290bc; color: inherit;", |
||
"background-color: #f4faff; color: inherit;"}, |
"background-color: #f4faff; color: inherit;"}, |
||
["11"] = { |
|||
"border: thin solid #c289c3;", |
"border: thin solid #c289c3;", |
||
"background-color: #e6c6e6; border-bottom: thin solid #c289c3; color: inherit;", |
"background-color: #e6c6e6; border-bottom: thin solid #c289c3; color: inherit;", |
||
"background-color: #fff8ff; color: inherit;"}, |
"background-color: #fff8ff; color: inherit;"}, |
||
["12"] = { |
|||
"border: thin solid #c56b74;", |
"border: thin solid #c56b74;", |
||
"background-color: #f4b8bf; border-bottom: thin solid #c56b74; color: inherit;", |
"background-color: #f4b8bf; border-bottom: thin solid #c56b74; color: inherit;", |
||
"background-color: #fff6f8; color: inherit;"}, |
"background-color: #fff6f8; color: inherit;"}, |
||
["13"] = { |
|||
"border: thin solid #8488dc;", |
"border: thin solid #8488dc;", |
||
"background-color: #ced1fa; border-bottom: thin solid #8488dc; color: inherit;", |
"background-color: #ced1fa; border-bottom: thin solid #8488dc; color: inherit;", |
||
"background-color: #f5f5ff; color: inherit;"}, |
"background-color: #f5f5ff; color: inherit;"}, |
||
["14"] = { |
|||
"border: thin solid #aaaaaa;", |
"border: thin solid #aaaaaa;", |
||
"background-color: #e4e4e4; border-bottom: thin solid #aaaaaa; color: inherit;", |
"background-color: #e4e4e4; border-bottom: thin solid #aaaaaa; color: inherit;", |
||
Line 77: | Line 77: | ||
p._theme(args) |
p._theme(args) |
||
div:cssText(theme[ |
div:cssText(theme[1]) |
||
if args.title and args.titlebackground then |
if args.title and args.titlebackground then |
||
Line 121: | Line 121: | ||
function p._theme(args) |
function p._theme(args) |
||
if not args.theme then |
|||
theme = themes["0"] |
|||
return |
|||
end |
|||
if not themes[args.theme] then |
|||
theme = themes["0"] |
|||
return |
|||
end |
|||
theme = themes[args.theme] |
|||
end |
end |
||
Line 128: | Line 137: | ||
local node = mw.html.create'div' |
local node = mw.html.create'div' |
||
node:cssText(theme[ |
node:cssText(theme[2]) |
||
if args.titlebackground then |
if args.titlebackground then |
||
Line 166: | Line 175: | ||
local node = mw.html.create'div' |
local node = mw.html.create'div' |
||
node:cssText(theme[ |
node:cssText(theme[3]) |
||
if args.background then |
if args.background then |
Revision as of 13:38, 6 August 2017
Creates boxes using <div>
tags rather than tables.
local getArgs = require('Module:Arguments').getArgs
local p = {}
local themes = {
["0"] = {
"border: thin solid #00619d;",
"background-color: #a7d7f9; border-bottom: thin solid gray; color: inherit;",
"background-color: #f6f6f6; color: inherit;"},
["1"] = {
"border: thin solid #e39c79;",
"background-color: #f5deb3; border-bottom: thin solid #e39c79; color: inherit;",
"background-color: #fffcf1; color: inherit;"},
["2"] = {
"border: thin solid #228b22;",
"background-color: #90ee90; border-bottom: thin solid #228b22; color: inherit;",
"background-color: #f5fffa; color: inherit;"},
["3"] = {
"border: thin solid #4682b4;",
"background-color: #b0c4de; border-bottom: thin solid #4682b4; color: inherit;",
"background-color: #f0f8ff; color: inherit;"},
["4"] = {
"border: thin solid #cd5c5c;",
"background-color: #f08080; border-bottom: thin solid #cd5c5c; color: inherit;",
"background-color: #ffe4e1; color: inherit;"},
["5"] = {
"border: thin solid #9370db;",
"background-color: #d8bfd8; border-bottom: thin solid #9370db; color: inherit;",
"background-color: #fff0f5; color: inherit;"},
["6"] = {
"border: thin solid #ffd700;",
"background-color: #ffff99; border-bottom: thin solid #ffd700; color: inherit;",
"background-color: #fffff0; color: inherit;"},
["7"] = {
"border: thin solid #4169e1;",
"background-color: #87cefa; border-bottom: thin solid #4169e1; color: inherit;",
"background-color: #f0ffff; color: inherit;"},
["8"] = {
"border: thin solid #e78a69;",
"background-color: #ffdab9; border-bottom: thin solid #e78a69; color: inherit;",
"background-color: #fff5ee; color: inherit;"},
["9"] = {
"border: thin solid #71be3f;",
"background-color: #c0eaa6; border-bottom: thin solid #71be3f; color: inherit;",
"background-color: #f6fff1; color: inherit;"},
["10"] = {
"border: thin solid #4290bc;",
"background-color: #9ad4f6; border-bottom: thin solid #4290bc; color: inherit;",
"background-color: #f4faff; color: inherit;"},
["11"] = {
"border: thin solid #c289c3;",
"background-color: #e6c6e6; border-bottom: thin solid #c289c3; color: inherit;",
"background-color: #fff8ff; color: inherit;"},
["12"] = {
"border: thin solid #c56b74;",
"background-color: #f4b8bf; border-bottom: thin solid #c56b74; color: inherit;",
"background-color: #fff6f8; color: inherit;"},
["13"] = {
"border: thin solid #8488dc;",
"background-color: #ced1fa; border-bottom: thin solid #8488dc; color: inherit;",
"background-color: #f5f5ff; color: inherit;"},
["14"] = {
"border: thin solid #aaaaaa;",
"background-color: #e4e4e4; border-bottom: thin solid #aaaaaa; color: inherit;",
"background-color: #ffffff; color: inherit;"}
}
local theme = nil
function p.box(frame)
local args = getArgs(frame)
return p._box(args)
end
function p._box(args)
local div = mw.html.create'div'
p._theme(args)
div:cssText(theme[1])
if args.title and args.titlebackground then
div:css('background-color', args.titlebackground)
elseif args.background then
div:css('background-color', args.background)
end
if args.border then
div:css('border', args.border)
end
if args.color then
div:css('color', args.color)
end
if args.margin then
div:css('margin', args.margin)
else
div:css('margin', 'auto')
end
if args.radius then
div:css('border-radius', args.radius)
end
if args.width then
div:css('width', args.width)
end
if args.style then
div:cssText(args.style)
end
if args.title then
div:node(p._title(args))
end
div:node(p._body(args))
return div:allDone()
end
function p._theme(args)
if not args.theme then
theme = themes["0"]
return
end
if not themes[args.theme] then
theme = themes["0"]
return
end
theme = themes[args.theme]
end
function p._title(args)
local node = mw.html.create'div'
node:cssText(theme[2])
if args.titlebackground then
node:css('background', args.titlebackground)
end
if args.border then
node:css('bottom-border', args.border)
end
if args.titlecolor then
node:css('color', args.titlecolor)
end
if args.titlefont then
node:css('font', args.titlefont)
else
node:css('font-weight', 'bold')
end
if args.titlepadding then
node:css('padding', args.titlepadding)
else
node:css('padding', '0.5em 1em 0.5em 1em')
end
if args.titlestyle then
node:cssText(args.titlestyle)
end
node:wikitext(args.title)
node:done()
return node
end
function p._body(args)
local node = mw.html.create'div'
node:cssText(theme[3])
if args.background then
node:css('background-color', args.background)
end
if args.font then
node:css('font', args.font)
end
if args.padding then
node:css('padding', args.padding)
else
node:css('padding', '0.5em 1em 0.5em 1em')
end
if args.radius then
node:css('border-radius', args.radius)
end
if args.bodystyle then
node:cssText(args.bodystyle)
end
node:wikitext(args['1'])
node:done()
return node
end
return p