test
 
m test
Line 7: Line 7:
      
      
     if not fileName or fileName == '' then
     if not fileName or fileName == '' then
         return '<span style="color:red; font-weight:bold;">[[Category:Pages with missing sound files]]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 = 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)
         :attr('title', 'Click to play sound: ' .. fileName)
         :attr('title', 'Click to play sound')


     container:wikitext(string.format('[[File:Icon-Volume.png|%s|link=]]', size))
     container:tag('span')
        :addClass('sound-icon-static')
        :wikitext(string.format('[[File:Icon-Volume.png|%s|link=]]', size))
 
    container:tag('span')
        :addClass('sound-icon-playing')
        :wikitext(string.format('[[File:Icon-Volume.gif|%s|link=]]', size))


     return tostring(container)
     return tostring(container)

Revision as of 12:10, 31 December 2025

Documentation for this module may be created at Module:Sound/doc

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local fileName = args[1]
    local size = args[2] or '16px'
    
    if not fileName or fileName == '' then
        return '<span style="color:red; font-weight:bold;">Error: No file specified</span>'
    end

    local fileUrl = 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)
        :attr('title', 'Click to play sound')

    container:tag('span')
        :addClass('sound-icon-static')
        :wikitext(string.format('[[File:Icon-Volume.png|%s|link=]]', size))

    container:tag('span')
        :addClass('sound-icon-playing')
        :wikitext(string.format('[[File:Icon-Volume.gif|%s|link=]]', size))

    return tostring(container)
end

return p