2017-03-18 09:21:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-18 15:53:28 +00:00
|
|
|
// vendor libraries
|
2017-03-18 09:21:18 +00:00
|
|
|
require("jquery-ui/ui/widgets/sortable");
|
|
|
|
const $ = require("jquery");
|
2017-04-22 04:06:07 +00:00
|
|
|
const moment = require("moment");
|
2016-12-18 15:53:28 +00:00
|
|
|
|
|
|
|
// our libraries
|
2017-03-18 09:21:18 +00:00
|
|
|
require("./libs/jquery/stickyscroll");
|
2018-03-06 11:29:28 +00:00
|
|
|
const slideoutMenu = require("./slideout");
|
2017-03-18 09:21:18 +00:00
|
|
|
const templates = require("../views");
|
2017-04-18 07:31:46 +00:00
|
|
|
const socket = require("./socket");
|
2017-11-23 14:23:32 +00:00
|
|
|
const render = require("./render");
|
2017-05-18 20:08:54 +00:00
|
|
|
require("./socket-events");
|
2017-04-22 13:03:00 +00:00
|
|
|
const storage = require("./localStorage");
|
2017-05-18 20:08:54 +00:00
|
|
|
const utils = require("./utils");
|
2017-07-10 19:47:03 +00:00
|
|
|
require("./webpush");
|
2017-09-06 06:41:11 +00:00
|
|
|
require("./keybinds");
|
2017-08-26 16:36:18 +00:00
|
|
|
require("./clipboard");
|
2018-03-26 08:08:43 +00:00
|
|
|
const contextMenuFactory = require("./contextMenuFactory");
|
|
|
|
const contextMenuContainer = $("#context-menu-container");
|
2016-10-09 19:14:02 +00:00
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
$(function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const sidebar = $("#sidebar, #footer");
|
|
|
|
const chat = $("#chat");
|
2014-09-10 19:23:56 +00:00
|
|
|
|
2017-06-05 11:40:25 +00:00
|
|
|
$(document.body).data("app-name", document.title);
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const viewport = $("#viewport");
|
2014-08-16 16:15:17 +00:00
|
|
|
|
2018-03-15 13:11:15 +00:00
|
|
|
function storeSidebarVisibility(name, state) {
|
|
|
|
if ($(window).outerWidth() < utils.mobileViewportPixels) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.set(name, state);
|
2018-04-08 21:37:33 +00:00
|
|
|
|
|
|
|
utils.togglePreviewMoreButtonsIfNeeded();
|
2018-03-15 13:11:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 07:44:42 +00:00
|
|
|
// If sidebar overlay is visible and it is clicked, close the sidebar
|
|
|
|
$("#sidebar-overlay").on("click", () => {
|
|
|
|
slideoutMenu.toggle(false);
|
|
|
|
storeSidebarVisibility("thelounge.state.sidebar", false);
|
|
|
|
});
|
2018-03-06 11:29:28 +00:00
|
|
|
|
2018-03-17 07:44:42 +00:00
|
|
|
$("#windows").on("click", "button.lt", () => {
|
|
|
|
const isOpen = !slideoutMenu.isOpen();
|
|
|
|
|
|
|
|
slideoutMenu.toggle(isOpen);
|
|
|
|
storeSidebarVisibility("thelounge.state.sidebar", isOpen);
|
2016-06-12 02:16:17 +00:00
|
|
|
});
|
|
|
|
|
2018-03-04 20:03:11 +00:00
|
|
|
viewport.on("click", ".rt", function() {
|
2018-03-15 13:11:15 +00:00
|
|
|
const isOpen = !viewport.hasClass("rt");
|
|
|
|
|
|
|
|
viewport.toggleClass("rt", isOpen);
|
2018-03-04 20:03:11 +00:00
|
|
|
chat.find(".chan.active .chat").trigger("keepToBottom");
|
2018-03-15 13:11:15 +00:00
|
|
|
storeSidebarVisibility("thelounge.state.userlist", isOpen);
|
2018-03-04 20:03:11 +00:00
|
|
|
|
|
|
|
return false;
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|
|
|
|
|
2017-11-01 09:16:19 +00:00
|
|
|
viewport.on("contextmenu", ".network .chan", function(e) {
|
2018-03-26 08:08:43 +00:00
|
|
|
return contextMenuFactory.createContextMenu($(this), e).show();
|
2017-11-01 09:16:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
viewport.on("click contextmenu", ".user", function(e) {
|
2018-01-09 16:16:20 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2018-03-26 08:08:43 +00:00
|
|
|
return contextMenuFactory.createContextMenu($(this), e).show();
|
2016-03-19 18:20:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
viewport.on("click", "#chat .menu", function(e) {
|
2017-12-26 18:40:02 +00:00
|
|
|
e.currentTarget = $(`#sidebar .chan[data-id="${$(this).closest(".chan").data("id")}"]`)[0];
|
2018-03-26 08:08:43 +00:00
|
|
|
return contextMenuFactory.createContextMenu($(this), e).show();
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
contextMenuContainer.on("click contextmenu", function() {
|
|
|
|
contextMenuContainer.hide();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-08-11 05:13:41 +00:00
|
|
|
function resetInputHeight(input) {
|
|
|
|
input.style.height = input.style.minHeight;
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const input = $("#input")
|
2017-04-03 01:03:01 +00:00
|
|
|
.on("input", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const style = window.getComputedStyle(this);
|
2016-07-15 06:42:47 +00:00
|
|
|
|
|
|
|
// Start by resetting height before computing as scrollHeight does not
|
|
|
|
// decrease when deleting characters
|
2016-08-11 05:13:41 +00:00
|
|
|
resetInputHeight(this);
|
2016-07-15 06:42:47 +00:00
|
|
|
|
2016-06-05 02:48:41 +00:00
|
|
|
this.style.height = Math.min(
|
|
|
|
Math.round(window.innerHeight - 100), // prevent overflow
|
|
|
|
this.scrollHeight
|
|
|
|
+ Math.round(parseFloat(style.borderTopWidth) || 0)
|
|
|
|
+ Math.round(parseFloat(style.borderBottomWidth) || 0)
|
|
|
|
) + "px";
|
|
|
|
|
2018-03-04 20:03:11 +00:00
|
|
|
chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing
|
2016-12-11 00:13:26 +00:00
|
|
|
});
|
2014-09-10 19:23:56 +00:00
|
|
|
|
2017-09-19 09:18:54 +00:00
|
|
|
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
|
|
|
|
$(document.body).addClass("is-apple");
|
|
|
|
}
|
|
|
|
|
2018-03-20 15:24:44 +00:00
|
|
|
$("#form").on("submit", function() {
|
|
|
|
// Triggering click event opens the virtual keyboard on mobile
|
|
|
|
// This can only be called from another interactive event (e.g. button click)
|
|
|
|
input.trigger("click").trigger("focus");
|
|
|
|
|
2018-03-05 00:59:16 +00:00
|
|
|
const target = chat.data("id");
|
2018-01-11 11:33:36 +00:00
|
|
|
const text = input.val();
|
2016-05-25 07:23:03 +00:00
|
|
|
|
|
|
|
if (text.length === 0) {
|
2018-03-20 15:24:44 +00:00
|
|
|
return false;
|
2016-05-25 07:23:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
input.val("");
|
2016-08-11 05:13:41 +00:00
|
|
|
resetInputHeight(input.get(0));
|
2016-05-25 07:23:03 +00:00
|
|
|
|
2017-10-05 17:12:26 +00:00
|
|
|
if (text.charAt(0) === "/") {
|
2017-10-03 20:29:19 +00:00
|
|
|
const args = text.substr(1).split(" ");
|
|
|
|
const cmd = args.shift().toLowerCase();
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-10-04 10:31:02 +00:00
|
|
|
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
|
2018-03-20 15:24:44 +00:00
|
|
|
return false;
|
2017-09-02 16:28:36 +00:00
|
|
|
}
|
2017-07-07 04:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 00:59:16 +00:00
|
|
|
socket.emit("input", {target, text});
|
2018-03-20 15:24:44 +00:00
|
|
|
|
|
|
|
return false;
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|
|
|
|
|
2016-05-30 19:38:53 +00:00
|
|
|
chat.on("click", ".inline-channel", function() {
|
2018-04-28 08:19:49 +00:00
|
|
|
const name = $(this).attr("data-chan");
|
2018-01-11 11:33:36 +00:00
|
|
|
const chan = utils.findCurrentNetworkChan(name);
|
2016-05-30 19:38:53 +00:00
|
|
|
|
|
|
|
if (chan.length) {
|
2018-01-30 09:38:33 +00:00
|
|
|
chan.trigger("click");
|
2016-02-29 16:48:57 +00:00
|
|
|
}
|
2018-05-29 09:56:41 +00:00
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: chat.data("id"),
|
|
|
|
text: "/join " + name,
|
|
|
|
});
|
2016-02-29 16:48:57 +00:00
|
|
|
});
|
|
|
|
|
2017-08-30 12:43:31 +00:00
|
|
|
chat.on("click", ".condensed-summary .content", function() {
|
2017-08-06 16:35:01 +00:00
|
|
|
$(this).closest(".msg.condensed").toggleClass("closed");
|
2017-06-22 20:08:36 +00:00
|
|
|
});
|
|
|
|
|
2018-03-27 23:28:20 +00:00
|
|
|
const openWindow = function openWindow(e, {keepSidebarOpen, pushState, replaceHistory} = {}) {
|
2018-01-11 11:33:36 +00:00
|
|
|
const self = $(this);
|
2018-04-28 08:19:49 +00:00
|
|
|
const target = self.attr("data-target");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
if (!target) {
|
2018-05-02 13:57:19 +00:00
|
|
|
return;
|
2014-08-16 16:15:17 +00:00
|
|
|
}
|
|
|
|
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
// This is a rather gross hack to account for sources that are in the
|
|
|
|
// sidebar specifically. Needs to be done better when window management gets
|
|
|
|
// refactored.
|
2017-12-24 07:51:58 +00:00
|
|
|
const inSidebar = self.parents("#sidebar, #footer").length > 0;
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
|
|
|
|
if (inSidebar) {
|
|
|
|
chat.data(
|
|
|
|
"id",
|
|
|
|
self.data("id")
|
|
|
|
);
|
|
|
|
socket.emit(
|
|
|
|
"open",
|
|
|
|
self.data("id")
|
|
|
|
);
|
|
|
|
|
2017-12-28 12:15:28 +00:00
|
|
|
sidebar.find(".active")
|
|
|
|
.removeClass("active")
|
|
|
|
.attr("aria-selected", false);
|
|
|
|
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
self.addClass("active")
|
2017-12-28 12:15:28 +00:00
|
|
|
.attr("aria-selected", true)
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
.find(".badge")
|
2018-06-11 11:29:57 +00:00
|
|
|
.attr("data-highlight", 0)
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
.removeClass("highlight")
|
|
|
|
.empty();
|
|
|
|
|
|
|
|
if (sidebar.find(".highlight").length === 0) {
|
|
|
|
utils.toggleNotificationMarkers(false);
|
|
|
|
}
|
2014-08-16 16:15:17 +00:00
|
|
|
|
2018-03-26 08:46:01 +00:00
|
|
|
if (!keepSidebarOpen && $(window).outerWidth() < utils.mobileViewportPixels) {
|
2018-03-15 13:11:15 +00:00
|
|
|
slideoutMenu.toggle(false);
|
|
|
|
}
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
}
|
2016-06-12 02:16:17 +00:00
|
|
|
|
2018-02-19 19:05:05 +00:00
|
|
|
const lastActive = $("#windows > .active");
|
|
|
|
|
|
|
|
lastActive
|
2016-04-17 10:50:03 +00:00
|
|
|
.removeClass("active")
|
|
|
|
.find(".chat")
|
|
|
|
.unsticky();
|
2014-09-10 19:24:03 +00:00
|
|
|
|
2017-11-23 14:23:32 +00:00
|
|
|
const lastActiveChan = lastActive.find(".chan.active");
|
2016-07-05 23:23:46 +00:00
|
|
|
|
2017-11-23 14:23:32 +00:00
|
|
|
if (lastActiveChan.length > 0) {
|
|
|
|
lastActiveChan
|
|
|
|
.removeClass("active")
|
|
|
|
.find(".unread-marker")
|
|
|
|
.data("unread-id", 0)
|
|
|
|
.appendTo(lastActiveChan.find(".messages"));
|
|
|
|
|
|
|
|
render.trimMessageInChannel(lastActiveChan, 100);
|
|
|
|
}
|
2016-07-24 05:50:15 +00:00
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const chan = $(target)
|
2014-08-16 16:15:17 +00:00
|
|
|
.addClass("active")
|
2016-07-05 23:23:46 +00:00
|
|
|
.trigger("show");
|
2016-04-17 10:50:03 +00:00
|
|
|
|
2018-04-08 05:04:25 +00:00
|
|
|
utils.togglePreviewMoreButtonsIfNeeded();
|
2018-06-01 17:32:30 +00:00
|
|
|
utils.updateTitle();
|
2014-12-11 22:42:22 +00:00
|
|
|
|
2017-08-15 09:44:29 +00:00
|
|
|
const type = chan.data("type");
|
2018-01-11 11:33:36 +00:00
|
|
|
let placeholder = "";
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-08-15 09:44:29 +00:00
|
|
|
if (type === "channel" || type === "query") {
|
2018-06-01 17:32:30 +00:00
|
|
|
placeholder = `Write to ${chan.attr("aria-label")}`;
|
2016-12-21 01:13:05 +00:00
|
|
|
}
|
2017-12-28 12:15:28 +00:00
|
|
|
|
|
|
|
input
|
|
|
|
.prop("placeholder", placeholder)
|
|
|
|
.attr("aria-label", placeholder);
|
2016-12-21 01:13:05 +00:00
|
|
|
|
2014-09-25 23:51:53 +00:00
|
|
|
if (self.hasClass("chan")) {
|
2016-07-06 07:08:27 +00:00
|
|
|
$("#chat-container").addClass("active");
|
2018-04-28 08:19:49 +00:00
|
|
|
$("#nick").text(self.closest(".network").attr("data-nick"));
|
2014-09-25 23:51:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const chanChat = chan.find(".chat");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-23 03:10:14 +00:00
|
|
|
if (chanChat.length > 0 && type !== "special") {
|
2016-07-10 11:01:31 +00:00
|
|
|
chanChat.sticky();
|
2018-03-20 15:24:44 +00:00
|
|
|
|
|
|
|
// On touch devices unfocus (blur) the input to correctly close the virtual keyboard
|
|
|
|
// An explicit blur is required, as the keyboard may open back up if the focus remains
|
|
|
|
// See https://github.com/thelounge/thelounge/issues/2257
|
|
|
|
input.trigger("ontouchstart" in window ? "blur" : "focus");
|
2016-07-10 11:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 02:29:44 +00:00
|
|
|
if (chan.data("needsNamesRefresh") === true) {
|
|
|
|
chan.data("needsNamesRefresh", false);
|
|
|
|
socket.emit("names", {target: self.data("id")});
|
|
|
|
}
|
|
|
|
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
// Pushes states to history web API when clicking elements with a data-target attribute.
|
|
|
|
// States are very trivial and only contain a single `clickTarget` property which
|
|
|
|
// contains a CSS selector that targets elements which takes the user to a different view
|
|
|
|
// when clicked. The `popstate` event listener will trigger synthetic click events using that
|
|
|
|
// selector and thus take the user to a different view/state.
|
2018-03-26 08:46:01 +00:00
|
|
|
if (pushState === false) {
|
2018-03-20 15:24:44 +00:00
|
|
|
return false;
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
const state = {};
|
|
|
|
|
2018-01-30 09:38:33 +00:00
|
|
|
if (self.prop("id")) {
|
|
|
|
state.clickTarget = `#${self.prop("id")}`;
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
} else if (self.hasClass("chan")) {
|
|
|
|
state.clickTarget = `#sidebar .chan[data-id="${self.data("id")}"]`;
|
|
|
|
} else {
|
|
|
|
state.clickTarget = `#footer button[data-target="${target}"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (history && history.pushState) {
|
2018-03-26 08:46:01 +00:00
|
|
|
if (replaceHistory && history.replaceState) {
|
Improve UI of the About section and changelog viewer
- Keep consistent width between the Help page and Changelog (which is already different from other windows 😠)
- Add icons to the About links
- Make sure `li` elements (i.e. all the lists in changelogs) are consistent in size with rest of the client
- Display version and release notes link on the "About The Lounge" header line, smaller, pushed to the right
- Check new releases when opening the Help window in order to display it without having to open the release notes. Release notes are being fed to the Changelog page at that moment to avoid fetching twice.
- Re-check version/fetch release notes after 24h. Since The Lounge can now run 24/7, reconnect when losing the network, we have to assume an "always-on" usage.
- Change icon, animate background color when getting response from GitHub to avoid flashing.
- Combine click handlers with our wonderful window management. These were the same handler, even with similar checks (`target` exists, etc.), just in 2 different places. This is necessary for the next item.
- Combine "Open release notes" and "Go back to Help" button behaviors with window management handlers. The window management code is gross as ever, and is in desperate need of a refactor, but at least there is no duplicated code for the same behavior + history management. This fixes the "Next" history behavior (however reloading the app while viewing the notes does not load on the notes, but this is a bug for a different PR!).
- Added a rule in the history management thingy: if a link we want to add history handling to has an `id`, store that in the state
- Added a button to go back to the Help window
- Fixed links to releases
- Send user to the GitHub issues *list* instead of *new issue form* because if they do not have a GitHub account, they will be redirected to the login page, which is a rather unpleasant experience when you are already confused...
- Fixed a bug that would return data about a new release in `latest` even though it is already the `current`. It was showing the current version as "The Lounge v... is now available".
- Added https://user-images.githubusercontent.com to the CSP rule when prefetch storage is enabled, because that is where we have stored screenshots in the changelog so far. Meh (we can improve that later if we decide to have a dedicated place for screenshots).
- Fetch changelog info even in public mode because users in public mode can access the release notes. They do not see the result of the version checker however.
2017-12-23 03:40:41 +00:00
|
|
|
history.replaceState(state, null, target);
|
|
|
|
} else {
|
|
|
|
history.pushState(state, null, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
sidebar.on("click", ".chan, button", openWindow);
|
|
|
|
$("#help").on("click", "#view-changelog, #back-to-help", openWindow);
|
|
|
|
$("#changelog").on("click", "#back-to-help", openWindow);
|
2014-08-16 16:15:17 +00:00
|
|
|
|
2017-12-15 03:27:09 +00:00
|
|
|
sidebar.on("click", ".close", function() {
|
2018-04-19 06:31:44 +00:00
|
|
|
utils.closeChan($(this).closest(".chan"));
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
|
|
|
|
2017-06-09 11:10:55 +00:00
|
|
|
$(document).on("visibilitychange focus click", () => {
|
2017-04-15 15:40:19 +00:00
|
|
|
if (sidebar.find(".highlight").length === 0) {
|
2017-05-18 20:08:54 +00:00
|
|
|
utils.toggleNotificationMarkers(false);
|
2014-08-16 16:15:17 +00:00
|
|
|
}
|
2017-04-15 15:40:19 +00:00
|
|
|
});
|
2016-12-10 09:33:36 +00:00
|
|
|
|
2017-04-22 04:06:07 +00:00
|
|
|
// Compute how many milliseconds are remaining until the next day starts
|
|
|
|
function msUntilNextDay() {
|
|
|
|
return moment().add(1, "day").startOf("day") - moment();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go through all Today/Yesterday date markers in the DOM and recompute their
|
|
|
|
// labels. When done, restart the timer for the next day.
|
|
|
|
function updateDateMarkers() {
|
|
|
|
$(".date-marker-text[data-label='Today'], .date-marker-text[data-label='Yesterday']")
|
|
|
|
.closest(".date-marker-container")
|
|
|
|
.each(function() {
|
2017-09-01 11:43:24 +00:00
|
|
|
$(this).replaceWith(templates.date_marker({time: $(this).data("time")}));
|
2017-04-22 04:06:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// This should always be 24h later but re-computing exact value just in case
|
|
|
|
setTimeout(updateDateMarkers, msUntilNextDay());
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-04-22 04:06:07 +00:00
|
|
|
setTimeout(updateDateMarkers, msUntilNextDay());
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
window.addEventListener("popstate", (e) => {
|
|
|
|
const {state} = e;
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
if (!state) {
|
|
|
|
return;
|
2017-01-28 17:48:34 +00:00
|
|
|
}
|
2017-04-08 12:34:31 +00:00
|
|
|
|
2017-09-09 20:36:06 +00:00
|
|
|
let {clickTarget} = state;
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
if (clickTarget) {
|
2017-09-09 20:36:06 +00:00
|
|
|
// This will be true when click target corresponds to opening a thumbnail,
|
|
|
|
// browsing to the previous/next thumbnail, or closing the image viewer.
|
2017-09-10 19:00:27 +00:00
|
|
|
const imageViewerRelated = clickTarget.includes(".toggle-thumbnail");
|
2017-09-09 20:36:06 +00: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.
|
2017-04-08 12:34:31 +00:00
|
|
|
$(clickTarget).trigger("click", {
|
2017-11-15 06:35:15 +00:00
|
|
|
pushState: false,
|
2017-04-08 12:34:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-08-28 09:18:31 +00:00
|
|
|
|
|
|
|
// Only start opening socket.io connection after all events have been registered
|
|
|
|
socket.open();
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|