Vai al contenuto

Modulo:Side box

À prupositu di Wikipedia

La documentazione per questo modulo può essere creata inModulo:Side box/man

-- This module implements {{side box}}.

localyesno=require('Module:Yesno')

localp={}

functionp.main(frame)
localorigArgs=frame:getParent().args
localargs={}
fork,vinpairs(origArgs)do
v=v:match('%s*(.-)%s*$')
ifv~=''then
args[k]=v
end
end
returnp._main(args)
end

functionp._main(args)
localdata=p.makeData(args)
returnp.renderSidebox(data)
end

functionp.makeData(args)
localdata={}

-- Main table classes
data.classes={}
ifyesno(args.metadata)~=falsethen
table.insert(data.classes,'metadata')
end
ifargs.positionandargs.position:lower()=='left'then
table.insert(data.classes,'mbox-small-left')
else
table.insert(data.classes,'mbox-small')
end
table.insert(data.classes,args.class)

-- Image
ifargs.imageandargs.image~='none'then
data.image=args.image
end

-- Copy over data that doesn't need adjusting
localargsToCopy={
-- Styles
'style',
'textstyle',

-- Above row
'above',
'abovestyle',

-- Body row
'text',
'imageright',

-- Below row
'below',
}
fori,keyinipairs(argsToCopy)do
data[key]=args[key]
end

returndata
end

functionp.renderSidebox(data)
-- Renders the sidebox HTML.

-- Table root
localroot=mw.html.create('table')
root:attr('role','presentation')
fori,classinipairs(data.classesor{})do
root:addClass(class)
end
root:css{border='1px solid #aaa',['background-color']='#f9f9f9',color='#000'}
ifdata.stylethen
root:cssText(data.style)
end

-- The "above" row
ifdata.abovethen
localaboveCell=root:newline():tag('tr'):tag('td')
aboveCell
:attr('colspan',data.imagerightand3or2)
:addClass('mbox-text')
ifdata.textstylethen
aboveCell:cssText(data.textstyle)
end
ifdata.abovestylethen
aboveCell:cssText(data.abovestyle)
end
aboveCell
:newline()
:wikitext(data.above)
end

-- The body row
localbodyRow=root:newline():tag('tr'):newline()
ifdata.imagethen
bodyRow:tag('td')
:addClass('mbox-image')
:wikitext(data.image)
else
bodyRow:tag('td'):css('width','1px')
end
localtextCell=bodyRow:newline():tag('td')
textCell:addClass('mbox-text plainlist')
ifdata.textstylethen
textCell:cssText(data.textstyle)
end
textCell:wikitext(data.text)
ifdata.imagerightthen
bodyRow:newline():tag('td')
:addClass('mbox-imageright')
:wikitext(data.imageright)
end

-- The below row
ifdata.belowthen
localbelowCell=root:newline():tag('tr'):tag('td')
belowCell
:attr('colspan',data.imagerightand3or2)
:addClass('mbox-text')
ifdata.textstylethen
belowCell:cssText(data.textstyle)
end
belowCell:wikitext(data.below)
end

root:newline()
returntostring(root)
end

returnp