diff options
author | thomascube <thomas@roundcube.net> | 2011-08-16 19:44:01 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2011-08-16 19:44:01 +0000 |
commit | 5375e84b75eb23e730f9fd44d042a413970bdc7f (patch) | |
tree | 6cb6d62fdd5aa764a64cb7c522d813e8a408e406 /plugins/newmail_notifier/newmail_notifier.js | |
parent | af80aae480b28a82a1c248bfdd6abf96b02ae6d8 (diff) |
Copying plugins into 0.6 release branch
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); + } +} |