Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

attachment_reminder.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. function rcmail_get_compose_message()
  18. {
  19. var msg;
  20. if (window.tinyMCE && (ed = tinyMCE.get(rcmail.env.composebody))) {
  21. msg = ed.getContent();
  22. msg = msg.replace(/<blockquote[^>]*>(.|[\r\n])*<\/blockquote>/gmi, '');
  23. }
  24. else {
  25. msg = $('#' + rcmail.env.composebody).val();
  26. msg = msg.replace(/^>.*$/gmi, '');
  27. }
  28. return msg;
  29. };
  30. function rcmail_check_message(msg)
  31. {
  32. var i, rx, keywords = rcmail.get_label('keywords', 'attachment_reminder').split(",").concat([".doc", ".pdf"]);
  33. keywords = $.map(keywords, function(n) { return RegExp.escape(n); });
  34. rx = new RegExp('(' + keywords.join('|') + ')', 'i');
  35. return msg.search(rx) != -1;
  36. };
  37. function rcmail_have_attachments()
  38. {
  39. return rcmail.env.attachments && $('li', rcmail.gui_objects.attachmentlist).length;
  40. };
  41. function rcmail_attachment_reminder_dialog()
  42. {
  43. var buttons = {};
  44. buttons[rcmail.get_label('addattachment')] = function() {
  45. $(this).remove();
  46. if (window.UI && UI.show_uploadform) // Larry skin
  47. UI.show_uploadform();
  48. else if (window.rcmail_ui && rcmail_ui.show_popup) // classic skin
  49. rcmail_ui.show_popup('uploadmenu', true);
  50. };
  51. buttons[rcmail.get_label('send')] = function(e) {
  52. $(this).remove();
  53. rcmail.env.attachment_reminder = true;
  54. rcmail.command('send', '', e);
  55. };
  56. rcmail.env.attachment_reminder = false;
  57. rcmail.show_popup_dialog(rcmail.get_label('attachment_reminder.forgotattachment'), '', buttons);
  58. };
  59. if (window.rcmail) {
  60. rcmail.addEventListener('beforesend', function(evt) {
  61. var msg = rcmail_get_compose_message(),
  62. subject = $('#compose-subject').val();
  63. if (!rcmail.env.attachment_reminder && !rcmail_have_attachments()
  64. && (rcmail_check_message(msg) || rcmail_check_message(subject))
  65. ) {
  66. rcmail_attachment_reminder_dialog();
  67. return false;
  68. }
  69. });
  70. }