അജ്ഞാത ഉപയോക്താവ്
"ഘടകം:Side box" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
ഘടകം:Side box (മൂലരൂപം കാണുക)
14:40, 20 ഫെബ്രുവരി 2023-നു നിലവിലുണ്ടായിരുന്ന രൂപം
, 20 ഫെബ്രുവരി 2023en:Module:Side_box എന്നതിൽ നിന്ന് ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു
(ചെ.) (ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു) |
en>Jacob.jose (ചെ.) (en:Module:Side_box എന്നതിൽ നിന്ന് ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു) |
||
വരി 1: | വരി 1: | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local p = {} | local p = {} | ||
local function makeData(args) | |||
function | |||
local data = {} | local data = {} | ||
വരി 31: | വരി 11: | ||
end | end | ||
if args.position and args.position:lower() == 'left' then | if args.position and args.position:lower() == 'left' then | ||
table.insert(data.classes, ' | table.insert(data.classes, 'side-box-left') | ||
else | else | ||
table.insert(data.classes, ' | table.insert(data.classes, 'side-box-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 | end | ||
table.insert(data.classes, args.class) | table.insert(data.classes, args.class) | ||
വരി 40: | വരി 29: | ||
if args.image and args.image ~= 'none' then | if args.image and args.image ~= 'none' then | ||
data.image = args.image | 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 | end | ||
-- Copy over data that | -- Copy over data that does not need adjusting | ||
local argsToCopy = { | local argsToCopy = { | ||
-- aria qualities | |||
'role', | |||
'labelledby', | |||
-- Styles | -- Styles | ||
'style', | 'style', | ||
'textstyle', | 'textstyle', | ||
'templatestyles', | |||
-- Above row | -- Above row | ||
വരി 66: | വരി 69: | ||
end | end | ||
function | local function renderSidebox(data) | ||
-- Renders the sidebox HTML. | -- Renders the sidebox HTML. | ||
-- Table root | -- Table root | ||
local root = mw.html.create(' | local root = mw.html.create('div') | ||
root:attr('role', data.role) | |||
:attr('aria-labelledby', data.labelledby) | |||
:addClass('side-box') | |||
for i, class in ipairs(data.classes or {}) do | for i, class in ipairs(data.classes or {}) do | ||
root:addClass(class) | root:addClass(class) | ||
end | end | ||
if data.style then | if data.style then | ||
root:cssText(data.style) | 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 | end | ||
-- The "above" row | -- The "above" row | ||
if data.above then | if data.above then | ||
local | local above = root:newline():tag('div') | ||
above:addClass('side-box-abovebelow') | |||
: | :newline() | ||
: | :wikitext(data.above) | ||
if data.textstyle then | if data.textstyle then | ||
above:cssText(data.textstyle) | |||
end | end | ||
if data.abovestyle then | if data.abovestyle then | ||
above:cssText(data.abovestyle) | |||
end | end | ||
end | end | ||
-- The body row | -- The body row | ||
local | local body = root:newline():tag('div') | ||
body:addClass('side-box-flex') | |||
:addClass(data.collapsible and 'mw-collapsible-content') | |||
:newline() | |||
if data.image then | if data.image then | ||
body:tag('div') | |||
:addClass(' | :addClass('side-box-image') | ||
:wikitext(data.image) | :wikitext(data.image) | ||
end | end | ||
local | local text = body:newline():tag('div') | ||
text:addClass('side-box-text') | |||
:addClass(data.textclass) | |||
if data.textstyle then | if data.textstyle then | ||
text:cssText(data.textstyle) | |||
end | end | ||
text:wikitext(data.text) | |||
if data.imageright then | if data.imageright then | ||
body:newline():tag('div') | |||
:addClass(' | :addClass('side-box-imageright') | ||
:wikitext(data.imageright) | :wikitext(data.imageright) | ||
end | end | ||
വരി 119: | വരി 130: | ||
-- The below row | -- The below row | ||
if data.below then | if data.below then | ||
local | local below = root:newline():tag('div') | ||
below | |||
: | :addClass('side-box-abovebelow') | ||
: | :wikitext(data.below) | ||
if data.textstyle then | if data.textstyle then | ||
below:cssText(data.textstyle) | |||
end | end | ||
end | end | ||
return tostring(root) | root:newline() | ||
local templatestyles = '' | |||
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' } | |||
} .. templatestyles .. tostring(root) | |||
end | |||
function p._main(args) | |||
local data = makeData(args) | |||
return renderSidebox(data) | |||
end | |||
function p.main(frame) | |||
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 | end | ||
return p | return p |