Module:Side box: Difference between revisions

m
1 revision imported from wikipedia:Module:Side_box
m (1 revision imported)
m (1 revision imported from wikipedia:Module:Side_box)
 
(One intermediate revision by one other user not shown)
Line 1:
-- This module implements {{side box}}.
 
local yesno = require('Module:Yesno')
 
local p = {}
 
local function p.mainmakeData(frameargs)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
 
function p._main(args)
local data = p.makeData(args)
return p.renderSidebox(data)
end
 
function p.makeData(args)
local data = {}
 
Line 31 ⟶ 11:
end
if args.position and args.position:lower() == 'left' then
table.insert(data.classes, 'mboxside-smallbox-left')
else
table.insert(data.classes, 'mboxside-smallbox-right')
end
if args.collapsible then
table.insert(data.classes, 'mw-collapsible')
if args.collapsible == "collapsed" then
table.insert(data.classes, 'mw-collapsed')
end
data.collapsible = true
end
 
table.insert(data.classes, args.class)
Line 40 ⟶ 29:
if args.image and args.image ~= 'none' then
data.image = args.image
end
-- we have to check to see if a downstream use has plainlist like
-- Template:Sister_project. also it's the default. wikitext is :(
if args.textclass == 'plainlist' or not args.textclass then
data.textclass = 'plainlist'
data.plainlist_templatestyles = 'Plainlist/styles.css'
else
data.textclass = args.textclass
end
 
-- Copy over data that doesn'tdoes not need adjusting
local argsToCopy = {
-- aria qualities
'role',
'labelledby',
 
-- Styles
'style',
'textstyle',
'templatestyles',
 
-- Above row
Line 66 ⟶ 69:
end
 
local function p.renderSidebox(data)
-- Renders the sidebox HTML.
 
-- Table root
local root = mw.html.create('tablediv')
root:attr('role', 'presentation'data.role)
:attr('aria-labelledby', data.labelledby)
:addClass('side-box')
for i, class in ipairs(data.classes or {}) do
root:addClass(class)
end
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'}
if data.style then
root:cssText(data.style)
end
local frame = mw.getCurrentFrame()
if data.plainlist_templatestyles then
root:wikitext(frame:extensionTag{
name = 'templatestyles', args = { src = data.plainlist_templatestyles }
})
end
 
-- The "above" row
if data.above then
local aboveCellabove = root:newline():tag('tr'):tag('tddiv')
above:addClass('side-box-abovebelow')
aboveCell
:newline()
:attr('colspan', data.imageright and 3 or 2)
:addClasswikitext('mbox-text'data.above)
if data.textstyle then
aboveCellabove:cssText(data.textstyle)
end
if data.abovestyle then
aboveCellabove:cssText(data.abovestyle)
end
aboveCell
:newline()
:wikitext(data.above)
end
 
-- The body row
local bodyRowbody = root:newline():tag('trdiv'):newline()
body:addClass('side-box-flex')
:addClass(data.collapsible and 'mw-collapsible-content')
:newline()
if data.image then
bodyRowbody:tag('tddiv')
:addClass('mboxside-box-image')
:wikitext(data.image)
else
bodyRow:tag('td'):css('width', '1px')
end
local textCelltext = bodyRowbody:newline():tag('tddiv')
textCelltext:addClass('mboxside-box-text plainlist')
:addClass(data.textclass)
if data.textstyle then
textCelltext:cssText(data.textstyle)
end
textCelltext:wikitext(data.text)
if data.imageright then
bodyRowbody:newline():tag('tddiv')
:addClass('mboxside-box-imageright')
:wikitext(data.imageright)
end
Line 120 ⟶ 130:
-- The below row
if data.below then
local belowCellbelow = root:newline():tag('tr'):tag('tddiv')
below
belowCell
:addClass('side-box-abovebelow')
:attr('colspan', data.imageright and 3 or 2)
:addClasswikitext('mbox-text'data.below)
if data.textstyle then
belowCellbelow:cssText(data.textstyle)
end
belowCell:wikitext(data.below)
end
 
root:newline()
local templatestyles = ''
return tostring(root)
if data.templatestyles then
templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = data.templatestyles }
}
end
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Side box/styles.css' }
return} .. templatestyles .. tostring(root)
end
 
function p._main(args)
local data = p.makeData(args)
return p.renderSidebox(data)
end
 
function p.makeDatamain(argsframe)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
 
rtl-contributors
1,630

edits