diff --git a/client/js/contextMenuFactory.js b/client/js/contextMenuFactory.js index 7c2dc438..057493f4 100644 --- a/client/js/contextMenuFactory.js +++ b/client/js/contextMenuFactory.js @@ -8,12 +8,8 @@ const contextMenuActions = []; const contextMenuItems = []; const {vueApp, findChannel} = require("./vue"); -module.exports = { - addContextMenuItem, - createContextMenu, -}; - addDefaultItems(); +registerEvents(); /** * Used for adding context menu items. eg: @@ -410,3 +406,30 @@ function addDefaultItems() { addDisconnectItem(); addCloseItem(); } + +function registerEvents() { + const viewport = $("#viewport"); + + viewport.on("contextmenu", ".network .chan", function(e) { + return createContextMenu($(this), e).show(); + }); + + viewport.on("click contextmenu", ".user", function(e) { + // If user is selecting text, do not open context menu + // This primarily only targets mobile devices where selection is performed with touch + if (!window.getSelection().isCollapsed) { + return true; + } + + return createContextMenu($(this), e).show(); + }); + + viewport.on("click", "#chat .menu", function(e) { + e.currentTarget = $( + `#sidebar .chan[data-id="${$(this) + .closest(".chan") + .attr("data-id")}"]` + )[0]; + return createContextMenu($(this), e).show(); + }); +} diff --git a/client/js/lounge.js b/client/js/lounge.js index 396a22a6..ff268709 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -10,40 +10,12 @@ const {vueApp, findChannel} = require("./vue"); window.vueMounted = () => { require("./socket-events"); - const contextMenuFactory = require("./contextMenuFactory"); + require("./contextMenuFactory"); const utils = require("./utils"); require("./webpush"); require("./keybinds"); const sidebar = $("#sidebar, #footer"); - const viewport = $("#viewport"); - - viewport.on("contextmenu", ".network .chan", function(e) { - return contextMenuFactory.createContextMenu($(this), e).show(); - }); - - viewport.on("click contextmenu", ".user", function(e) { - // If user is selecting text, do not open context menu - // This primarily only targets mobile devices where selection is performed with touch - if (!window.getSelection().isCollapsed) { - return true; - } - - return contextMenuFactory.createContextMenu($(this), e).show(); - }); - - viewport.on("click", "#chat .menu", function(e) { - e.currentTarget = $( - `#sidebar .chan[data-id="${$(this) - .closest(".chan") - .attr("data-id")}"]` - )[0]; - return contextMenuFactory.createContextMenu($(this), e).show(); - }); - - if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) { - $(document.body).addClass("is-apple"); - } const openWindow = function openWindow(e, {pushState, replaceHistory} = {}) { const self = $(this); diff --git a/client/js/vue.js b/client/js/vue.js index c439a1a3..55a32872 100644 --- a/client/js/vue.js +++ b/client/js/vue.js @@ -48,6 +48,10 @@ const vueApp = new Vue({ }, mounted() { Vue.nextTick(() => window.vueMounted()); + + if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) { + document.body.classList.add("is-apple"); + } }, methods: { onSocketInit() {