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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. (function() {
  11. /**
  12. * Construct a new CommentsModifyMenuinstance
  13. * @constructs CommentsModifyMenu
  14. * @memberof OC.Comments
  15. * @private
  16. */
  17. var CommentsModifyMenu = OC.Backbone.View.extend({
  18. tagName: 'div',
  19. className: 'commentsModifyMenu popovermenu bubble menu',
  20. _scopes: [
  21. {
  22. name: 'edit',
  23. displayName: t('comments', 'Edit comment'),
  24. iconClass: 'icon-rename'
  25. },
  26. {
  27. name: 'delete',
  28. displayName: t('comments', 'Delete comment'),
  29. iconClass: 'icon-delete'
  30. }
  31. ],
  32. initialize: function() {
  33. },
  34. events: {
  35. 'click a.action': '_onClickAction'
  36. },
  37. /**
  38. * Event handler whenever an action has been clicked within the menu
  39. *
  40. * @param {Object} event event object
  41. */
  42. _onClickAction: function(event) {
  43. var $target = $(event.currentTarget)
  44. if (!$target.hasClass('menuitem')) {
  45. $target = $target.closest('.menuitem')
  46. }
  47. OC.hideMenus()
  48. this.trigger('select:menu-item-clicked', event, $target.data('action'))
  49. },
  50. /**
  51. * Renders the menu with the currently set items
  52. */
  53. render: function() {
  54. this.$el.html(OCA.Comments.Templates['commentsmodifymenu']({
  55. items: this._scopes
  56. }))
  57. },
  58. /**
  59. * Displays the menu
  60. * @param {Event} context the click event
  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)