Move context menu events to factory

This commit is contained in:
Pavel Djundik 2019-10-17 18:32:59 +03:00
parent af0d48de72
commit 7355c91839
3 changed files with 33 additions and 34 deletions

View File

@ -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();
});
}

View File

@ -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);

View File

@ -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() {