Module:Message box: Difference between revisions
Content added Content deleted
(initial code for ambox) |
(more ambox stuff - still a little broken) |
||
Line 18: | Line 18: | ||
end |
end |
||
return page or mw.title.getCurrentTitle() |
return page or mw.title.getCurrentTitle() |
||
⚫ | |||
local function generateBoxStructure() |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return root, substCheck, box, row, imageLeftCell |
|||
end |
end |
||
Line 49: | Line 40: | ||
]] |
]] |
||
-- Process config data |
------------------------ Process config data ---------------------------- |
||
-- Type data. |
|||
local typeData = data.types[args.type] |
local typeData = data.types[args.type] |
||
local invalidType = args.type and not typeData and true or false |
local invalidType = args.type and not typeData and true or false |
||
typeData = typeData or data.types[data.default] |
typeData = typeData or data.types[data.default] |
||
-- Process data for collapsible text fields |
|||
local text, talk, fix, date, info |
|||
if data.useCollapsibleTextFields then |
|||
⚫ | |||
talk = args.talk |
|||
fix = args.fix |
|||
date = args.date |
|||
info = args.info |
|||
else |
|||
text = args.text |
|||
⚫ | |||
-- Find whether we are using a small message box and process our data accordingly. |
|||
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false |
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false |
||
local smallClass, image, imageRight |
local smallClass, image, imageRight, imageSize |
||
if isSmall then |
if isSmall then |
||
smallClass = data.smallClass or 'mbox-small' |
smallClass = data.smallClass or 'mbox-small' |
||
image = args.smallimage or args.image |
image = args.smallimage or args.image |
||
imageRight = args.smallimageright or args.imageright |
imageRight = args.smallimageright or args.imageright |
||
text = args.smalltext or |
text = args.smalltext or text |
||
imageSize = data.imageSmallSize or '30x30px' |
imageSize = data.imageSmallSize or '30x30px' |
||
else |
else |
||
image = args.image |
image = args.image |
||
imageRight = args.imageright |
imageRight = args.imageright |
||
⚫ | |||
imageSize = '40x40px' |
imageSize = '40x40px' |
||
end |
end |
||
-- Get the box structure |
------------------------ Get the box structure ---------------------------- |
||
local root, substCheck, box, row, imageLeftCell = generateBoxStructure() |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
------------------------ Build the box ---------------------------- |
|||
-- Do the subst check. |
-- Do the subst check. |
||
Line 104: | Line 118: | ||
local imageCheckBlank = data.imageCheckBlank |
local imageCheckBlank = data.imageCheckBlank |
||
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then |
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then |
||
imageLeftCell |
|||
⚫ | |||
if not isSmall and data.imageCellDiv then |
if not isSmall and data.imageCellDiv then |
||
imageLeftCell = imageLeftCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageLeftCell so that the image is inside it. |
imageLeftCell = imageLeftCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageLeftCell so that the image is inside it. |
||
Line 118: | Line 130: | ||
-- Add the text. |
-- Add the text. |
||
if data.useCollapsibleTextFields then |
|||
⚫ | |||
textCell |
|||
.cssText(args.textstyle) |
.cssText(args.textstyle) |
||
. |
local textCellSpan = textCell.tag('span') |
||
textCellSpan |
|||
.addClass('mbox-text-span') |
|||
⚫ | |||
if not isSmall then |
|||
textCellSpan |
|||
⚫ | |||
.addClass('hide-when-compact') |
|||
.wikitext(talk) |
|||
.wikitext(fix) |
|||
.done() |
|||
end |
|||
textCellSpan |
|||
.wikitext(date and mw.ustring.format(" <small>''(%s)''</small>", date)) |
|||
if not isSmall then |
|||
textCellSpan |
|||
.tag('span') |
|||
.addClass('hide-when-compact') |
|||
.wikitext(info and ' ' .. info) |
|||
end |
|||
else |
|||
textCell |
|||
.cssText(args.textstyle) |
|||
.wikitext(text) |
|||
end |
|||
-- Add the right-hand image. |
-- Add the right-hand image. |
||
if imageRight and not (data.imageRightNone and imageRight == 'none') then |
if imageRight and not (data.imageRightNone and imageRight == 'none') then |
||
if not isSmall and data.imageCellDiv then |
|||
⚫ | |||
imageRightCell = imageRightCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it. |
|||
⚫ | |||
end |
|||
imageRightCell |
|||
.wikitext(imageRight) |
.wikitext(imageRight) |
||
end |
end |
||
Line 140: | Line 178: | ||
end |
end |
||
-- Add error messages and |
------------------------ Add error messages and categories ---------------------------- |
||
-- Add error message and tracking category for invalid type parameters. |
|||
if invalidType then |
if invalidType then |
||
local catsort = (nsid == 0 and 'Main:' or '') .. title.prefixedText |
local catsort = (nsid == 0 and 'Main:' or '') .. title.prefixedText |
||
Line 199: | Line 239: | ||
data.imageSmallSize = '20x20px' |
data.imageSmallSize = '20x20px' |
||
data.imageCellDiv = true |
data.imageCellDiv = true |
||
data. |
data.useCollapsibleTextFields = true |
||
data.imageRightNone = true |
|||
return p.build(data, args) |
return p.build(data, args) |
||
end |
end |
||
Line 414: | Line 455: | ||
v = mw.text.trim(v) |
v = mw.text.trim(v) |
||
end |
end |
||
if v ~= '' then |
if v ~= '' or k == 'talk' or k == 'sect' or k == 'date' then |
||
args[k] = v |
args[k] = v |
||
end |
end |