mNo edit summary
No edit summary
 
(3 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 '20px'
     local size = args[2] or '20px'
      
      
     if not fileName or fileName == '' then
     if fileName == '' then
         return '<span style="color:red; font-weight:bold;">Error: No file specified</span>'
         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
     if fileUrl:sub(1,2) == "//" then fileUrl = "https:" .. fileUrl end
      
      
Line 17: Line 17:
         :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