mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 05:50:22 +00:00
Move context menu events to factory
This commit is contained in:
parent
af0d48de72
commit
7355c91839
3 changed files with 33 additions and 34 deletions
|
@ -8,12 +8,8 @@ const contextMenuActions = [];
|
||||||
const contextMenuItems = [];
|
const contextMenuItems = [];
|
||||||
const {vueApp, findChannel} = require("./vue");
|
const {vueApp, findChannel} = require("./vue");
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
addContextMenuItem,
|
|
||||||
createContextMenu,
|
|
||||||
};
|
|
||||||
|
|
||||||
addDefaultItems();
|
addDefaultItems();
|
||||||
|
registerEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for adding context menu items. eg:
|
* Used for adding context menu items. eg:
|
||||||
|
@ -410,3 +406,30 @@ function addDefaultItems() {
|
||||||
addDisconnectItem();
|
addDisconnectItem();
|
||||||
addCloseItem();
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -10,40 +10,12 @@ const {vueApp, findChannel} = require("./vue");
|
||||||
|
|
||||||
window.vueMounted = () => {
|
window.vueMounted = () => {
|
||||||
require("./socket-events");
|
require("./socket-events");
|
||||||
const contextMenuFactory = require("./contextMenuFactory");
|
require("./contextMenuFactory");
|
||||||
const utils = require("./utils");
|
const utils = require("./utils");
|
||||||
require("./webpush");
|
require("./webpush");
|
||||||
require("./keybinds");
|
require("./keybinds");
|
||||||
|
|
||||||
const sidebar = $("#sidebar, #footer");
|
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 openWindow = function openWindow(e, {pushState, replaceHistory} = {}) {
|
||||||
const self = $(this);
|
const self = $(this);
|
||||||
|
|
|
@ -48,6 +48,10 @@ const vueApp = new Vue({
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
Vue.nextTick(() => window.vueMounted());
|
Vue.nextTick(() => window.vueMounted());
|
||||||
|
|
||||||
|
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
|
||||||
|
document.body.classList.add("is-apple");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onSocketInit() {
|
onSocketInit() {
|
||||||
|
|
Loading…
Reference in a new issue