From 5da48a95224e925f4b070f2581a121516df33829 Mon Sep 17 00:00:00 2001 From: thomascube Date: Wed, 19 Oct 2011 15:28:11 +0000 Subject: Copy plugins to release branch --- plugins/newmail_notifier/newmail_notifier.js | 120 +++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 plugins/newmail_notifier/newmail_notifier.js (limited to 'plugins/newmail_notifier/newmail_notifier.js') diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js new file mode 100644 index 000000000..16e3edd42 --- /dev/null +++ b/plugins/newmail_notifier/newmail_notifier.js @@ -0,0 +1,120 @@ +/** + * New Mail Notifier plugin script + * + * @version 0.3 + * @author Aleksander Machniak + */ + +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(); + if (prop.desktop) + newmail_notifier_desktop(rcmail.gettext('body', 'newmail_notifier')); +} + +// Stops notification +function newmail_notifier_stop(prop) +{ + // revert original favicon + if (rcmail.env.favicon_href && (!prop || prop.action != 'check-recent')) { + $('').replaceAll('link[rel="shortcut icon"]'); + rcmail.env.favicon_href = null; + } +} + +// Basic notification: window.focus and favicon change +function newmail_notifier_basic() +{ + var w = rcmail.is_framed() ? window.parent : window; + + w.focus(); + + // we cannot simply change a href attribute, we must to replace the link element (at least in FF) + var link = $(''), + oldlink = $('link[rel="shortcut icon"]', w.document); + + rcmail.env.favicon_href = oldlink.attr('href'); + link.replaceAll(oldlink); +} + +// Sound notification +function newmail_notifier_sound() +{ + var elem, src = 'plugins/newmail_notifier/sound.wav'; + + // HTML5 + try { + elem = $('