Play a sound for new messages + Add a sound user option
(Versions 1.9+)As of AWC1.9 the sound option has been removed; why? So to condense the code and keep things small. After all, it can be added very easily using the event system.
Thanks to the new settings controller in AWC 1.9+ we can easily add new settings to AWC which will allow us to manipulate the setting like the others and will also be saved and restored automatically. So with this new feature we can now add settings to AWC ourselves... so lets add a sound setting back in.
The option itself is added very simply: [ic]avacweb_chat.settings.add('sound', 0, true).add_ui('sound');[/ic]
This specifies the name of the new option, its default value, whether or not to save it, and the add_ui function adds a checkbox for it in the user options panel.
You can find more details about the settings controller here: http://chat.avacweb.net/settings
Anyway, all that would be left to do is to play the sound... which we can use the 'onnew' event which has existed for a while to do that.
Altogether, here is the plug-in code:
- Code:
[panda=js](function(awc){
awc.add_event('onload', function() {
this.settings.add('sound', 0, true).add_ui('sound');
$('body').append('<span id="achat_sound"></span>');
});
awc.add_event('onnew', function() {
var sound_file = 'http://www.freesfx.co.uk/rx2/mp3s/2/1305_1256857800.mp3'; //change this URL to your own sound file if you want
if( this.settings.on('sound') ) {
document.getElementById('achat_sound').innerHTML = '<embed src="' + sound_file + '" hidden="true" autostart="true" loop="false"/>';
}
});
})(avacweb_chat_config);
Hope you all enjoy the new power of AWC1.9