Mercurial > hg > rc1
comparison plugins/attachment_reminder/attachment_reminder.js @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 /** | |
2 * Attachment Reminder plugin script | |
3 * | |
4 * @licstart The following is the entire license notice for the | |
5 * JavaScript code in this file. | |
6 * | |
7 * Copyright (c) 2013, The Roundcube Dev Team | |
8 * | |
9 * The JavaScript code in this page is free software: you can redistribute it | |
10 * and/or modify it under the terms of the GNU General Public License | |
11 * as published by the Free Software Foundation, either version 3 of | |
12 * the License, or (at your option) any later version. | |
13 * | |
14 * @licend The above is the entire license notice | |
15 * for the JavaScript code in this file. | |
16 */ | |
17 | |
18 function rcmail_get_compose_message() | |
19 { | |
20 var msg; | |
21 | |
22 if (window.tinyMCE && (ed = tinyMCE.get(rcmail.env.composebody))) { | |
23 msg = ed.getContent(); | |
24 msg = msg.replace(/<blockquote[^>]*>(.|[\r\n])*<\/blockquote>/gmi, ''); | |
25 } | |
26 else { | |
27 msg = $('#' + rcmail.env.composebody).val(); | |
28 msg = msg.replace(/^>.*$/gmi, ''); | |
29 } | |
30 | |
31 return msg; | |
32 }; | |
33 | |
34 function rcmail_check_message(msg) | |
35 { | |
36 var i, rx, keywords = rcmail.get_label('keywords', 'attachment_reminder').split(",").concat([".doc", ".pdf"]); | |
37 | |
38 keywords = $.map(keywords, function(n) { return RegExp.escape(n); }); | |
39 rx = new RegExp('(' + keywords.join('|') + ')', 'i'); | |
40 | |
41 return msg.search(rx) != -1; | |
42 }; | |
43 | |
44 function rcmail_have_attachments() | |
45 { | |
46 return rcmail.env.attachments && $('li', rcmail.gui_objects.attachmentlist).length; | |
47 }; | |
48 | |
49 function rcmail_attachment_reminder_dialog() | |
50 { | |
51 var buttons = {}; | |
52 | |
53 buttons[rcmail.get_label('addattachment')] = function() { | |
54 $(this).remove(); | |
55 if (window.UI && UI.show_uploadform) // Larry skin | |
56 UI.show_uploadform(); | |
57 else if (window.rcmail_ui && rcmail_ui.show_popup) // classic skin | |
58 rcmail_ui.show_popup('uploadmenu', true); | |
59 }; | |
60 buttons[rcmail.get_label('send')] = function(e) { | |
61 $(this).remove(); | |
62 rcmail.env.attachment_reminder = true; | |
63 rcmail.command('send', '', e); | |
64 }; | |
65 | |
66 rcmail.env.attachment_reminder = false; | |
67 rcmail.show_popup_dialog(rcmail.get_label('attachment_reminder.forgotattachment'), '', buttons); | |
68 }; | |
69 | |
70 | |
71 if (window.rcmail) { | |
72 rcmail.addEventListener('beforesend', function(evt) { | |
73 var msg = rcmail_get_compose_message(), | |
74 subject = $('#compose-subject').val(); | |
75 | |
76 if (!rcmail.env.attachment_reminder && !rcmail_have_attachments() | |
77 && (rcmail_check_message(msg) || rcmail_check_message(subject)) | |
78 ) { | |
79 rcmail_attachment_reminder_dialog(); | |
80 return false; | |
81 } | |
82 }); | |
83 } |