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.

commentsmodifymenu.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2018
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. /* global Handlebars */
  11. (function() {
  12. /**
  13. * Construct a new CommentsModifyMenuinstance
  14. * @constructs CommentsModifyMenu
  15. * @memberof OC.Comments
  16. * @private
  17. */
  18. var CommentsModifyMenu = OC.Backbone.View.extend({
  19. tagName: 'div',
  20. className: 'commentsModifyMenu popovermenu bubble menu',
  21. _scopes: [
  22. {
  23. name: 'edit',
  24. displayName: t('comments', 'Edit comment'),
  25. iconClass: 'icon-rename'
  26. },
  27. {
  28. name: 'delete',
  29. displayName: t('comments', 'Delete comment'),
  30. iconClass: 'icon-delete'
  31. }
  32. ],
  33. initialize: function() {
  34. },
  35. events: {
  36. 'click a.action': '_onClickAction'
  37. },
  38. /**
  39. * Event handler whenever an action has been clicked within the menu
  40. *
  41. * @param {Object} event event object
  42. */
  43. _onClickAction: function(event) {
  44. var $target = $(event.currentTarget);
  45. if (!$target.hasClass('menuitem')) {
  46. $target = $target.closest('.menuitem');
  47. }
  48. OC.hideMenus();
  49. this.trigger('select:menu-item-clicked', event, $target.data('action'));
  50. },
  51. /**
  52. * Renders the menu with the currently set items
  53. */
  54. render: function() {
  55. this.$el.html(OCA.Comments.Templates['commentsmodifymenu']({
  56. items: this._scopes
  57. }));
  58. },
  59. /**
  60. * Displays the menu
  61. */
  62. show: function(context) {
  63. this._context = context;
  64. for(var i in this._scopes) {
  65. this._scopes[i].active = false;
  66. }
  67. var $el = $(context.target);
  68. var offsetIcon = $el.offset();
  69. var offsetContainer = $el.closest('.authorRow').offset();
  70. // adding some extra top offset to push the menu below the button.
  71. var position = {
  72. top: offsetIcon.top - offsetContainer.top + 48,
  73. left: '',
  74. right: ''
  75. };
  76. position.left = offsetIcon.left - offsetContainer.left;
  77. if (position.left > 200) {
  78. // we need to position the menu to the right.
  79. position.left = '';
  80. position.right = this.$el.closest('.comment').find('.date').width();
  81. this.$el.removeClass('menu-left').addClass('menu-right');
  82. } else {
  83. this.$el.removeClass('menu-right').addClass('menu-left');
  84. }
  85. this.$el.css(position);
  86. this.render();
  87. this.$el.removeClass('hidden');
  88. OC.showMenu(null, this.$el);
  89. }
  90. });
  91. OCA.Comments = OCA.Comments || {};
  92. OCA.Comments.CommentsModifyMenu = CommentsModifyMenu;
  93. })(OC, OCA);