You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hide_blockquote.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Hide Blockquotes plugin script
  3. *
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this file.
  6. *
  7. * Copyright (c) 2012-2014, 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. if (window.rcmail)
  18. rcmail.addEventListener('init', function() { hide_blockquote(); });
  19. function hide_blockquote()
  20. {
  21. var limit = rcmail.env.blockquote_limit;
  22. if (limit <= 0)
  23. return;
  24. $('div.message-part div.pre > blockquote', $('#messagebody')).each(function() {
  25. var div, link, q = $(this),
  26. text = $.trim(q.text()),
  27. res = text.split(/\n/);
  28. if (res.length <= limit) {
  29. // there can be also a block with very long wrapped line
  30. // assume line height = 15px
  31. if (q.height() <= limit * 15)
  32. return;
  33. }
  34. div = $('<blockquote class="blockquote-header">')
  35. .css({'white-space': 'nowrap', overflow: 'hidden', position: 'relative'})
  36. .text(res[0]);
  37. link = $('<span class="blockquote-link"></span>')
  38. .css({position: 'absolute', 'z-Index': 2})
  39. .text(rcmail.get_label('hide_blockquote.show'))
  40. .data('parent', div)
  41. .click(function() {
  42. var t = $(this), parent = t.data('parent'), visible = parent.is(':visible');
  43. t.text(rcmail.get_label(visible ? 'hide' : 'show', 'hide_blockquote'))
  44. .detach().appendTo(visible ? q : parent);
  45. parent[visible ? 'hide' : 'show']();
  46. q[visible ? 'show' : 'hide']();
  47. });
  48. link.appendTo(div);
  49. // Modify blockquote
  50. q.hide().css({position: 'relative'}).before(div);
  51. });
  52. }