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");
|
2017-03-18 09:21:18 +00:00
|
|
|
const URI = require("urijs");
|
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");
|
Improve the version checking part of the changelog feature
- There is no client caching of the changelog/version anymore. Instead, server returns the expiration date of its cache, and that is used by the client as well.
- There is now a "Check now" button on the client that appears when data is stale. This means that info is fetched only once and never refreshed (it was refreshed every hour before) unless the user explicitly wants to check latest version, which in turn is as stale as server info is, i.e. 15 minutes max.
- Button style is shared with the "Join a channel" feature, `.btn-small` (not `.btn-sm` to be explicit that this is not a Bootstrap thing).
- Version checker content is now centralized in the `version_checker` template, instead of being partially in the checker template, partially in the Help template, and partially in the code.
- A "Try again" button lets user attempt to fetch info instead of forcing them to reload the page.
- Use Flexbox to display a nicer version checker: icon is slightly bigger, and button is always aligned on the right.
- Changelog logic has been removed from `lounge.js` and moved into the component file.
- Changelog template is only passed what it needs instead of everything the server gives us.
- Public version now displays version checker, since server is caching things.
- Cleaner code overall.
2017-12-24 23:18:24 +00:00
|
|
|
const Changelog = require("./socket-events/changelog");
|
2017-12-22 17:18:10 +00:00
|
|
|
const JoinChannel = require("./join-channel");
|
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");
|
|
|
|
const contextMenuContainer = $("#context-menu-container");
|
|
|
|
const contextMenu = $("#context-menu");
|
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-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
|
|
|
});
|
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
function positionContextMenu(that, e) {
|
2018-01-11 11:33:36 +00:00
|
|
|
let offset;
|
|
|
|
const menuWidth = contextMenu.outerWidth();
|
|
|
|
const menuHeight = contextMenu.outerHeight();
|
2016-02-12 11:34:10 +00:00
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
if (that.hasClass("menu")) {
|
|
|
|
offset = that.offset();
|
|
|
|
offset.left -= menuWidth - that.outerWidth();
|
|
|
|
offset.top += that.outerHeight();
|
|
|
|
return offset;
|
2016-02-12 11:34:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
offset = {left: e.pageX, top: e.pageY};
|
|
|
|
|
|
|
|
if ((window.innerWidth - offset.left) < menuWidth) {
|
|
|
|
offset.left = window.innerWidth - menuWidth;
|
2016-02-12 11:34:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
if ((window.innerHeight - offset.top) < menuHeight) {
|
|
|
|
offset.top = window.innerHeight - menuHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
2016-02-12 11:34:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
function showContextMenu(that, e) {
|
2018-01-11 11:33:36 +00:00
|
|
|
const target = $(e.currentTarget);
|
|
|
|
let output = "";
|
2016-02-12 11:34:10 +00:00
|
|
|
|
|
|
|
if (target.hasClass("user")) {
|
2016-12-18 15:53:28 +00:00
|
|
|
output = templates.contextmenu_item({
|
2016-02-12 11:34:10 +00:00
|
|
|
class: "user",
|
2017-11-01 09:16:19 +00:00
|
|
|
action: "whois",
|
2016-02-12 11:34:10 +00:00
|
|
|
text: target.text(),
|
2017-11-15 06:35:15 +00:00
|
|
|
data: target.data("name"),
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
2017-11-01 09:16:19 +00:00
|
|
|
output += templates.contextmenu_divider();
|
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "action-whois",
|
|
|
|
action: "whois",
|
|
|
|
text: "User information",
|
|
|
|
data: target.data("name"),
|
|
|
|
});
|
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "action-query",
|
|
|
|
action: "query",
|
|
|
|
text: "Direct messages",
|
|
|
|
data: target.data("name"),
|
|
|
|
});
|
|
|
|
|
|
|
|
const channel = target.closest(".chan");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-20 09:45:12 +00:00
|
|
|
if (utils.hasRoleInChannel(channel, ["op"]) && channel.data("type") === "channel") {
|
2017-11-01 09:16:19 +00:00
|
|
|
output += templates.contextmenu_divider();
|
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "action-kick",
|
|
|
|
action: "kick",
|
|
|
|
text: "Kick",
|
|
|
|
data: target.data("name"),
|
|
|
|
});
|
|
|
|
}
|
2016-05-01 09:41:17 +00:00
|
|
|
} else if (target.hasClass("chan")) {
|
2017-12-11 06:19:50 +00:00
|
|
|
let itemClass;
|
|
|
|
|
|
|
|
if (target.hasClass("lobby")) {
|
|
|
|
itemClass = "network";
|
|
|
|
} else if (target.hasClass("query")) {
|
2017-12-12 05:52:45 +00:00
|
|
|
itemClass = "query";
|
2017-12-11 06:19:50 +00:00
|
|
|
} else {
|
|
|
|
itemClass = "chan";
|
|
|
|
}
|
|
|
|
|
2016-12-18 15:53:28 +00:00
|
|
|
output = templates.contextmenu_item({
|
2017-12-11 06:19:50 +00:00
|
|
|
class: itemClass,
|
2017-11-01 09:16:19 +00:00
|
|
|
action: "focusChan",
|
2017-12-28 12:15:28 +00:00
|
|
|
text: target.attr("aria-label"),
|
2017-11-15 06:35:15 +00:00
|
|
|
data: target.data("target"),
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
2016-12-18 15:53:28 +00:00
|
|
|
output += templates.contextmenu_divider();
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-06 02:53:13 +00:00
|
|
|
if (target.hasClass("lobby")) {
|
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "list",
|
2017-11-01 09:16:19 +00:00
|
|
|
action: "list",
|
2017-12-06 02:53:13 +00:00
|
|
|
text: "List all channels",
|
2017-11-01 09:16:19 +00:00
|
|
|
data: target.data("id"),
|
2017-12-06 02:53:13 +00:00
|
|
|
});
|
2017-12-13 04:52:26 +00:00
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "join",
|
|
|
|
action: "join",
|
2017-12-21 18:11:49 +00:00
|
|
|
text: "Join a channel…",
|
2017-12-13 04:52:26 +00:00
|
|
|
data: target.data("id"),
|
|
|
|
});
|
2017-12-06 02:53:13 +00:00
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-19 11:39:50 +00:00
|
|
|
if (target.hasClass("channel")) {
|
|
|
|
output += templates.contextmenu_item({
|
|
|
|
class: "list",
|
|
|
|
action: "banlist",
|
|
|
|
text: "List banned users",
|
|
|
|
data: target.data("id"),
|
|
|
|
});
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-12-18 15:53:28 +00:00
|
|
|
output += templates.contextmenu_item({
|
2016-02-12 11:34:10 +00:00
|
|
|
class: "close",
|
2017-11-01 09:16:19 +00:00
|
|
|
action: "close",
|
2016-03-09 20:04:07 +00:00
|
|
|
text: target.hasClass("lobby") ? "Disconnect" : target.hasClass("channel") ? "Leave" : "Close",
|
2017-11-15 06:35:15 +00:00
|
|
|
data: target.data("target"),
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
contextMenuContainer.show();
|
|
|
|
contextMenu
|
|
|
|
.html(output)
|
2016-03-19 18:20:11 +00:00
|
|
|
.css(positionContextMenu($(that), e));
|
2016-02-12 11:34:10 +00:00
|
|
|
|
|
|
|
return false;
|
2016-03-19 18:20:11 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 09:16:19 +00:00
|
|
|
viewport.on("contextmenu", ".network .chan", function(e) {
|
|
|
|
return showContextMenu(this, e);
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-19 18:20:11 +00:00
|
|
|
return showContextMenu(this, e);
|
|
|
|
});
|
|
|
|
|
|
|
|
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];
|
2016-03-19 18:20:11 +00:00
|
|
|
return showContextMenu(this, e);
|
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-07-29 06:10:29 +00:00
|
|
|
$("button#set-nick").on("click", function() {
|
2017-05-18 20:08:54 +00:00
|
|
|
utils.toggleNickEditor(true);
|
2016-07-29 06:10:29 +00:00
|
|
|
|
|
|
|
// Selects existing nick in the editable text field
|
2018-01-11 11:33:36 +00:00
|
|
|
const element = document.querySelector("#nick-value");
|
2016-07-29 06:10:29 +00:00
|
|
|
element.focus();
|
2018-01-11 11:33:36 +00:00
|
|
|
const range = document.createRange();
|
2016-07-29 06:10:29 +00:00
|
|
|
range.selectNodeContents(element);
|
2018-01-11 11:33:36 +00:00
|
|
|
const selection = window.getSelection();
|
2016-07-29 06:10:29 +00:00
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("button#cancel-nick").on("click", cancelNick);
|
|
|
|
$("button#submit-nick").on("click", submitNick);
|
|
|
|
|
|
|
|
function submitNick() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const newNick = $("#nick-value").text().trim();
|
2016-10-01 17:04:03 +00:00
|
|
|
|
|
|
|
if (newNick.length === 0) {
|
|
|
|
cancelNick();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:08:54 +00:00
|
|
|
utils.toggleNickEditor(false);
|
2016-07-29 06:10:29 +00:00
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: chat.data("id"),
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "/nick " + newNick,
|
2016-07-29 06:10:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelNick() {
|
2017-05-18 20:08:54 +00:00
|
|
|
utils.setNick(sidebar.find(".chan.active").closest(".network").data("nick"));
|
2016-07-29 06:10:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 09:38:33 +00:00
|
|
|
$("#nick-value").on("keypress", function(e) {
|
2016-07-29 06:10:29 +00:00
|
|
|
switch (e.keyCode ? e.keyCode : e.which) {
|
|
|
|
case 13: // Enter
|
|
|
|
// Ensures a new line is not added when pressing Enter
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
2018-01-30 09:38:33 +00:00
|
|
|
}).on("keyup", function(e) {
|
2016-07-29 06:10:29 +00:00
|
|
|
switch (e.keyCode ? e.keyCode : e.which) {
|
|
|
|
case 13: // Enter
|
|
|
|
submitNick();
|
|
|
|
break;
|
|
|
|
case 27: // Escape
|
|
|
|
cancelNick();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-30 19:38:53 +00:00
|
|
|
chat.on("click", ".inline-channel", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const name = $(this).data("chan");
|
|
|
|
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
|
|
|
} else {
|
|
|
|
socket.emit("input", {
|
|
|
|
target: chat.data("id"),
|
2017-11-15 06:35:15 +00:00
|
|
|
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-26 08:46:01 +00:00
|
|
|
const openWindow = function openWindow(e, {keepSidebarOpen, pushState, replaceHistory}) {
|
2018-01-11 11:33:36 +00:00
|
|
|
const self = $(this);
|
|
|
|
const target = self.data("target");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
if (!target) {
|
2018-03-20 15:24:44 +00:00
|
|
|
return false;
|
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")
|
|
|
|
.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
|
|
|
|
2017-06-05 11:40:25 +00:00
|
|
|
let title = $(document.body).data("app-name");
|
2017-12-28 12:15:28 +00:00
|
|
|
const chanTitle = chan.attr("aria-label");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-28 12:15:28 +00:00
|
|
|
if (chanTitle.length > 0) {
|
|
|
|
title = `${chanTitle} — ${title}`;
|
2014-11-07 19:52:38 +00:00
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2014-11-07 19:52:38 +00:00
|
|
|
document.title = title;
|
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") {
|
2017-12-28 12:15:28 +00:00
|
|
|
placeholder = `Write to ${chanTitle}`;
|
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");
|
2017-05-18 20:08:54 +00:00
|
|
|
utils.setNick(self.closest(".network").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")});
|
|
|
|
}
|
|
|
|
|
2017-12-23 03:10:14 +00:00
|
|
|
if (target === "#settings") {
|
2017-08-15 09:44:29 +00:00
|
|
|
$("#session-list").html("<p>Loading…</p>");
|
|
|
|
socket.emit("sessions:get");
|
|
|
|
}
|
|
|
|
|
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 (target === "#help" || target === "#changelog") {
|
Improve the version checking part of the changelog feature
- There is no client caching of the changelog/version anymore. Instead, server returns the expiration date of its cache, and that is used by the client as well.
- There is now a "Check now" button on the client that appears when data is stale. This means that info is fetched only once and never refreshed (it was refreshed every hour before) unless the user explicitly wants to check latest version, which in turn is as stale as server info is, i.e. 15 minutes max.
- Button style is shared with the "Join a channel" feature, `.btn-small` (not `.btn-sm` to be explicit that this is not a Bootstrap thing).
- Version checker content is now centralized in the `version_checker` template, instead of being partially in the checker template, partially in the Help template, and partially in the code.
- A "Try again" button lets user attempt to fetch info instead of forcing them to reload the page.
- Use Flexbox to display a nicer version checker: icon is slightly bigger, and button is always aligned on the right.
- Changelog logic has been removed from `lounge.js` and moved into the component file.
- Changelog template is only passed what it needs instead of everything the server gives us.
- Public version now displays version checker, since server is caching things.
- Cleaner code overall.
2017-12-24 23:18:24 +00:00
|
|
|
Changelog.requestIfNeeded();
|
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
|
|
|
function closeChan(chan) {
|
2018-01-11 11:33:36 +00:00
|
|
|
let cmd = "/close";
|
2017-12-15 03:27:09 +00:00
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
if (chan.hasClass("lobby")) {
|
|
|
|
cmd = "/quit";
|
2018-01-11 11:33:36 +00:00
|
|
|
const server = chan.find(".name").html();
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-09-18 01:50:41 +00:00
|
|
|
if (!confirm("Disconnect from " + server + "?")) { // eslint-disable-line no-alert
|
2014-08-16 16:15:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2014-08-16 16:15:17 +00:00
|
|
|
socket.emit("input", {
|
|
|
|
target: chan.data("id"),
|
2017-11-15 06:35:15 +00:00
|
|
|
text: cmd,
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|
|
|
|
chan.css({
|
|
|
|
transition: "none",
|
2017-11-15 06:35:15 +00:00
|
|
|
opacity: 0.4,
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|
|
|
|
return false;
|
2017-12-15 03:27:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sidebar.on("click", ".close", function() {
|
|
|
|
closeChan($(this).closest(".chan"));
|
2014-08-16 16:15:17 +00:00
|
|
|
});
|
|
|
|
|
2017-11-01 09:16:19 +00:00
|
|
|
const contextMenuActions = {
|
2018-03-05 00:59:16 +00:00
|
|
|
join(itemData) {
|
2017-12-22 17:18:10 +00:00
|
|
|
const network = $(`#join-channel-${itemData}`).closest(".network");
|
|
|
|
JoinChannel.openForm(network);
|
2017-12-13 04:52:26 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
close(itemData) {
|
2017-12-15 03:27:09 +00:00
|
|
|
closeChan($(`.networks .chan[data-target="${itemData}"]`));
|
2017-11-01 09:16:19 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
focusChan(itemData) {
|
2018-01-30 09:38:33 +00:00
|
|
|
$(`.networks .chan[data-target="${itemData}"]`).trigger("click");
|
2017-11-01 09:16:19 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
list(itemData) {
|
2017-12-06 02:53:13 +00:00
|
|
|
socket.emit("input", {
|
2017-11-01 09:16:19 +00:00
|
|
|
target: itemData,
|
2017-12-06 02:53:13 +00:00
|
|
|
text: "/list",
|
|
|
|
});
|
2017-11-01 09:16:19 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
banlist(itemData) {
|
2017-12-19 11:39:50 +00:00
|
|
|
socket.emit("input", {
|
|
|
|
target: itemData,
|
|
|
|
text: "/banlist",
|
|
|
|
});
|
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
whois(itemData) {
|
2017-11-01 09:16:19 +00:00
|
|
|
const chan = utils.findCurrentNetworkChan(itemData);
|
|
|
|
|
|
|
|
if (chan.length) {
|
2018-01-30 09:38:33 +00:00
|
|
|
chan.trigger("click");
|
2017-11-01 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: $("#chat").data("id"),
|
|
|
|
text: "/whois " + itemData,
|
|
|
|
});
|
|
|
|
|
2018-03-04 20:03:11 +00:00
|
|
|
$(`.channel.active .userlist .user[data-name="${itemData}"]`).trigger("click");
|
2017-11-01 09:16:19 +00:00
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
query(itemData) {
|
2017-11-01 09:16:19 +00:00
|
|
|
const chan = utils.findCurrentNetworkChan(itemData);
|
|
|
|
|
|
|
|
if (chan.length) {
|
2018-01-30 09:38:33 +00:00
|
|
|
chan.trigger("click");
|
2017-11-01 09:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
socket.emit("input", {
|
|
|
|
target: $("#chat").data("id"),
|
|
|
|
text: "/query " + itemData,
|
|
|
|
});
|
|
|
|
},
|
2018-03-05 00:59:16 +00:00
|
|
|
kick(itemData) {
|
2017-11-01 09:16:19 +00:00
|
|
|
socket.emit("input", {
|
|
|
|
target: $("#chat").data("id"),
|
|
|
|
text: "/kick " + itemData,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
contextMenuActions.execute = (name, ...args) => contextMenuActions[name] && contextMenuActions[name](...args);
|
|
|
|
|
|
|
|
contextMenu.on("click", ".context-menu-item", function() {
|
|
|
|
const $this = $(this);
|
|
|
|
const itemData = $this.data("data");
|
|
|
|
const contextAction = $this.data("action");
|
|
|
|
contextMenuActions.execute(contextAction, itemData);
|
2016-02-12 11:34:10 +00:00
|
|
|
});
|
|
|
|
|
2018-02-23 19:22:05 +00:00
|
|
|
if ($(document.body).hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) {
|
2016-10-05 21:30:17 +00:00
|
|
|
$("#connect").one("show", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const params = URI(document.location.search).search(true);
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-10-05 21:30:17 +00:00
|
|
|
// Possible parameters: name, host, port, password, tls, nick, username, realname, join
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only
|
2018-01-11 11:33:36 +00:00
|
|
|
for (let key in params) {
|
2016-10-05 21:30:17 +00:00
|
|
|
if (params.hasOwnProperty(key)) {
|
2018-01-11 11:33:36 +00:00
|
|
|
const value = params[key];
|
2016-10-05 21:30:17 +00:00
|
|
|
// \W searches for non-word characters
|
|
|
|
key = key.replace(/\W/g, "");
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const element = $("#connect input[name='" + key + "']");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-10-05 21:30:17 +00:00
|
|
|
// if the element exists, it isn't disabled, and it isn't hidden
|
|
|
|
if (element.length > 0 && !element.is(":disabled") && !element.is(":hidden")) {
|
|
|
|
if (element.is(":checkbox")) {
|
|
|
|
element.prop("checked", (value === "1" || value === "true") ? true : false);
|
|
|
|
} else {
|
|
|
|
element.val(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-03-03 16:43:30 +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
|
|
|
});
|