From e6d8f97bf2e0bbb4d95df0c4e030eb7ec6ef75a5 Mon Sep 17 00:00:00 2001 From: thomasb Date: Sat, 31 Mar 2012 12:25:48 +0000 Subject: Move plugins repository into roundcubemail root folder; svn:externals are not defined anymore git-svn-id: https://svn.roundcube.net/trunk@6034 208e9e7b-5314-0410-a742-e7e81cd9613c --- .../plugins/newmail_notifier/newmail_notifier.js | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 roundcubemail/plugins/newmail_notifier/newmail_notifier.js (limited to 'roundcubemail/plugins/newmail_notifier/newmail_notifier.js') diff --git a/roundcubemail/plugins/newmail_notifier/newmail_notifier.js b/roundcubemail/plugins/newmail_notifier/newmail_notifier.js new file mode 100644 index 000000000..7c9b55ded --- /dev/null +++ b/roundcubemail/plugins/newmail_notifier/newmail_notifier.js @@ -0,0 +1,120 @@ +/** + * New Mail Notifier plugin script + * + * @version @package_version@ + * @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 = $('