diff --git a/src/public/app/menus/context_menu.js b/src/public/app/menus/context_menu.js deleted file mode 100644 index 2eab81ddc..000000000 --- a/src/public/app/menus/context_menu.js +++ /dev/null @@ -1,178 +0,0 @@ -import keyboardActionService from '../services/keyboard_actions.js'; - -class ContextMenu { - constructor() { - this.$widget = $("#context-menu-container"); - this.$widget.addClass("dropend"); - this.dateContextMenuOpenedMs = 0; - - $(document).on('click', () => this.hide()); - } - - async show(options) { - this.options = options; - - if (this.$widget.hasClass("show")) { - // The menu is already visible. Hide the menu then open it again - // at the new location to re-trigger the opening animation. - await this.hide(); - } - - this.$widget.empty(); - - this.addItems(this.$widget, options.items); - - keyboardActionService.updateDisplayedShortcuts(this.$widget); - - this.positionMenu(); - - this.dateContextMenuOpenedMs = Date.now(); - } - - positionMenu() { - // the code below tries to detect when dropdown would overflow from page - // in such case we'll position it above click coordinates, so it will fit into the client - - const CONTEXT_MENU_PADDING = 5; // How many pixels to pad the context menu from edge of screen - const CONTEXT_MENU_OFFSET = 0; // How many pixels to offset the context menu by relative to cursor, see #3157 - - const clientHeight = document.documentElement.clientHeight; - const clientWidth = document.documentElement.clientWidth; - const contextMenuHeight = this.$widget.outerHeight(); - const contextMenuWidth = this.$widget.outerWidth(); - let top, left; - - if (this.options.y + contextMenuHeight - CONTEXT_MENU_OFFSET > clientHeight - CONTEXT_MENU_PADDING) { - // Overflow: bottom - top = clientHeight - contextMenuHeight - CONTEXT_MENU_PADDING; - } else if (this.options.y - CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { - // Overflow: top - top = CONTEXT_MENU_PADDING; - } else { - top = this.options.y - CONTEXT_MENU_OFFSET; - } - - if (this.options.orientation === 'left') { - if (this.options.x + CONTEXT_MENU_OFFSET > clientWidth - CONTEXT_MENU_PADDING) { - // Overflow: right - left = clientWidth - contextMenuWidth - CONTEXT_MENU_OFFSET; - } else if (this.options.x - contextMenuWidth + CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { - // Overflow: left - left = CONTEXT_MENU_PADDING; - } else { - left = this.options.x - contextMenuWidth + CONTEXT_MENU_OFFSET; - } - } else { - if (this.options.x + contextMenuWidth - CONTEXT_MENU_OFFSET > clientWidth - CONTEXT_MENU_PADDING) { - // Overflow: right - left = clientWidth - contextMenuWidth - CONTEXT_MENU_PADDING; - } else if (this.options.x - CONTEXT_MENU_OFFSET < CONTEXT_MENU_PADDING) { - // Overflow: left - left = CONTEXT_MENU_PADDING; - } else { - left = this.options.x - CONTEXT_MENU_OFFSET; - } - } - - this.$widget.css({ - display: "block", - top: top, - left: left - }).addClass("show"); - } - - addItems($parent, items) { - for (const item of items) { - if (!item) { - continue; - } - - if (item.title === '----') { - $parent.append($("