activitytabviewplugin.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * @author Joas Schilling <coding@schilljs.com>
  3. * Copyright (c) 2016
  4. *
  5. * This file is licensed under the Affero General Public License version 3
  6. * or later.
  7. *
  8. * See the COPYING-README file.
  9. */
  10. (function() {
  11. OCA.Comments.ActivityTabViewPlugin = {
  12. /**
  13. * Prepare activity for display
  14. *
  15. * @param {OCA.Activity.ActivityModel} model for this activity
  16. * @param {jQuery} $el jQuery handle for this activity
  17. * @param {string} view The view that displayes this activity
  18. */
  19. prepareModelForDisplay: function (model, $el, view) {
  20. if (model.get('app') !== 'comments' || model.get('type') !== 'comments') {
  21. return;
  22. }
  23. if (view === 'ActivityTabView') {
  24. $el.addClass('comment');
  25. if (model.get('message') && this._isLong(model.get('message'))) {
  26. $el.addClass('collapsed');
  27. var $overlay = $('<div>').addClass('message-overlay');
  28. $el.find('.activitymessage').after($overlay);
  29. $el.on('click', this._onClickCollapsedComment);
  30. }
  31. }
  32. },
  33. /*
  34. * Copy of CommentsTabView._onClickComment()
  35. */
  36. _onClickCollapsedComment: function(ev) {
  37. var $row = $(ev.target);
  38. if (!$row.is('.comment')) {
  39. $row = $row.closest('.comment');
  40. }
  41. $row.removeClass('collapsed');
  42. },
  43. /*
  44. * Copy of CommentsTabView._isLong()
  45. */
  46. _isLong: function(message) {
  47. return message.length > 250 || (message.match(/\n/g) || []).length > 1;
  48. }
  49. };
  50. })();
  51. OC.Plugins.register('OCA.Activity.RenderingPlugins', OCA.Comments.ActivityTabViewPlugin);