Module:Sound: Difference between revisions
test |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local fileName = args[1] | local fileName = mw.text.trim(args[1] or "") | ||
local size = args[2] or ' | local size = args[2] or '20px' | ||
if | if fileName == '' then | ||
return '<span style="color:red; font-weight:bold;"> | return '<span style="color:red; font-weight:bold;">Error: No file specified</span>' | ||
end | end | ||
local fileUrl = frame:callParserFunction('filepath', fileName) | local fileUrl = mw.text.trim(frame:callParserFunction('filepath', fileName)) | ||
if fileUrl:sub(1,2) == "//" then fileUrl = "https:" .. fileUrl end | |||
local container = mw.html.create('span') | local container = mw.html.create('span') | ||
:addClass('sound-button') | :addClass('sound-button') | ||
:attr('data-sound-file', fileUrl) | :attr('data-sound-file', fileUrl) | ||
container:wikitext(string.format('[[File:Icon-Volume.png|%s|link=]]', size)) | container:wikitext(string.format('[[File:Icon-Volume.png|%s|middle|link=]]', size)) | ||
return tostring(container) | return (tostring(container):gsub('[\n\r]', '')) | ||
end | end | ||
return p | return p | ||
Latest revision as of 14:42, 1 January 2026
Documentation for this module may be created at Module:Sound/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local fileName = mw.text.trim(args[1] or "")
local size = args[2] or '20px'
if fileName == '' then
return '<span style="color:red; font-weight:bold;">Error: No file specified</span>'
end
local fileUrl = mw.text.trim(frame:callParserFunction('filepath', fileName))
if fileUrl:sub(1,2) == "//" then fileUrl = "https:" .. fileUrl end
local container = mw.html.create('span')
:addClass('sound-button')
:attr('data-sound-file', fileUrl)
container:wikitext(string.format('[[File:Icon-Volume.png|%s|middle|link=]]', size))
return (tostring(container):gsub('[\n\r]', ''))
end
return p