thelounge/client/js/lounge.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
2016-12-18 16:53:28 +01:00
// vendor libraries
const $ = require("jquery");
2016-12-18 16:53:28 +01:00
// our libraries
2017-04-18 09:31:46 +02:00
const socket = require("./socket");
2018-07-08 16:57:02 +02:00
window.vueMounted = () => {
require("./socket-events");
2019-10-17 17:32:59 +02:00
require("./contextMenuFactory");
2018-07-08 16:57:02 +02:00
require("./webpush");
require("./keybinds");
window.addEventListener("popstate", (e) => {
const {state} = e;
if (!state) {
return;
}
2017-09-09 22:36:06 +02:00
let {clickTarget} = state;
if (clickTarget) {
2017-09-09 22:36:06 +02:00
// This will be true when click target corresponds to opening a thumbnail,
// browsing to the previous/next thumbnail, or closing the image viewer.
const imageViewerRelated = clickTarget.includes(".toggle-thumbnail");
2017-09-09 22:36:06 +02:00
// If the click target is not related to the image viewer but the viewer
// is currently opened, we need to close it.
if (!imageViewerRelated && $("#image-viewer").hasClass("opened")) {
clickTarget += ", #image-viewer";
}
// Emit the click to the target, while making sure it is not going to be
// added to the state again.
$(clickTarget).trigger("click", {
pushState: false,
});
}
});
// Only start opening socket.io connection after all events have been registered
socket.open();
2018-07-08 16:57:02 +02:00
};