2 * New Mail Notifier plugin script
5 * @author Aleksander Machniak <alec@alec.pl>
8 if (window.rcmail && rcmail.env.task == 'mail') {
9 rcmail.addEventListener('plugin.newmail_notifier', newmail_notifier_run);
10 rcmail.addEventListener('actionbefore', newmail_notifier_stop);
11 rcmail.addEventListener('init', function() {
12 // bind to messages list select event, so favicon will be reverted on message preview too
13 if (rcmail.message_list)
14 rcmail.message_list.addEventListener('select', newmail_notifier_stop);
18 // Executes notification methods
19 function newmail_notifier_run(prop)
22 newmail_notifier_basic();
24 newmail_notifier_sound();
28 function newmail_notifier_stop(prop)
30 // revert original favicon
31 if (rcmail.env.favicon_href && (!prop || prop.action != 'check-recent')) {
32 $('<link rel="shortcut icon" href="'+rcmail.env.favicon_href+'"/>').replaceAll('link[rel="shortcut icon"]');
33 rcmail.env.favicon_href = null;
37 // Basic notification: window.focus and favicon change
38 function newmail_notifier_basic()
42 // we cannot simply change a href attribute, we must to replace the link element (at least in FF)
43 var link = $('<link rel="shortcut icon" href="plugins/newmail_notifier/favicon.ico"/>'),
44 oldlink = $('link[rel="shortcut icon"]');
46 rcmail.env.favicon_href = oldlink.attr('href');
47 link.replaceAll(oldlink);
51 function newmail_notifier_sound()
53 var elem, src = 'plugins/newmail_notifier/sound.wav';
57 elem = $('<audio src="' + src + '" />');
62 elem = $('<embed id="sound" src="' + src + '" hidden=true autostart=true loop=false />');
63 elem.appendTo($('body'));
64 window.setTimeout("$('#sound').remove()", 5000);