diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-05-19 09:54:09 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-05-19 09:54:09 +0000 |
| commit | 8f35ee81b6f626be5b16c330fa47a85e4d720209 (patch) | |
| tree | a2f58183c953c301c6f671aed6498eaa12cb1510 /plugins/newmail_notifier/newmail_notifier.js | |
| parent | cb4bc36f0c7a6b7edbf979324692820354e81241 (diff) | |
- Removed focus_on_new_message option, added newmail_notify plugin
git-svn-id: https://svn.roundcube.net/trunk@4788 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins/newmail_notifier/newmail_notifier.js')
| -rw-r--r-- | plugins/newmail_notifier/newmail_notifier.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js new file mode 100644 index 000000000..6e1ae9fbb --- /dev/null +++ b/plugins/newmail_notifier/newmail_notifier.js @@ -0,0 +1,64 @@ +/** + * New Mail Notifier plugin script + * + * @version 0.1 + * @author Aleksander Machniak <alec@alec.pl> + */ + +if (window.rcmail && rcmail.env.task == 'mail') { + rcmail.addEventListener('plugin.newmail_notifier', newmail_notifier_run); + rcmail.addEventListener('actionbefore', newmail_notifier_stop); + rcmail.addEventListener('init', function() { + // bind to messages list select event, so favicon will be reverted on message preview too + if (rcmail.message_list) + rcmail.message_list.addEventListener('select', newmail_notifier_stop); + }); +} + +// Executes notification methods +function newmail_notifier_run(prop) +{ + if (prop.basic) + newmail_notifier_basic(); + if (prop.sound) + newmail_notifier_sound(); +} + +// Stops notification +function newmail_notifier_stop(prop) +{ + // revert original favicon + if (rcmail.env.favicon_href && (!prop || prop.action != 'check-recent')) { + $('<link rel="shortcut icon" href="'+rcmail.env.favicon_href+'"/>').replaceAll('link[rel="shortcut icon"]'); + rcmail.env.favicon_href = null; + } +} + +// Basic notification: window.focus and favicon change +function newmail_notifier_basic() +{ + window.focus(); + + // we cannot simply change a href attribute, we must to replace the link element (at least in FF) + var link = $('<link rel="shortcut icon" href="plugins/newmail_notifier/favicon.ico"/>'), + oldlink = $('link[rel="shortcut icon"]'); + + rcmail.env.favicon_href = oldlink.attr('href'); + link.replaceAll(oldlink); +} + +// Sound notification +function newmail_notifier_sound() +{ + // HTML5 + try { + var elem = $('<audio src="success.wav" />'); + elem.get(0).play(); + } + // old method + catch (e) { + var elem = $('<embed id="sound" src="success.wav" hidden=true autostart=true loop=false />'); + elem.appendTo($('body')); + window.setTimeout("$('#sound').remove()", 5000); + } +} |
