From ad675cbe9738577b236c5a682e4629c562ee4a76 Mon Sep 17 00:00:00 2001 From: rstular Date: Sat, 16 May 2020 23:20:42 +0200 Subject: Linting --- js/chats.js | 657 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 362 insertions(+), 295 deletions(-) (limited to 'js/chats.js') diff --git a/js/chats.js b/js/chats.js index 673099b..5b4bbfd 100644 --- a/js/chats.js +++ b/js/chats.js @@ -2,15 +2,18 @@ const DIRECTORY_URL = "/directory.json"; const CHATS_BEGIN_TAG = ""; const CHATS_END_TAG = ""; -const CHAT_REGEX = /([\S\s]+?)/g; +const CHAT_REGEX = /([\S\s]+)/g; const CHATS_SUBJECT_PREFIX = "ba-ctlmsg-chat-"; // "Global" object for name directory -var directory = null; -var currentlyChattingWith = null; // msgid -var sogovornik = null; // name -var firstPageOfMessages = null; // so we can test if new messages ever arrive - +let directory = null; +let currentlyChattingWith = null; // msgid +let sogovornik = null; // name +let firstPageOfMessages = null; // so we can test if new messages ever arrive + +/** + * Redirects user to login page if it's not logged int + */ async function checkLogin() { localforage.getItem("logged_in").then(function (value) { // This code runs once the value has been loaded @@ -24,23 +27,46 @@ async function checkLogin() { }); } +/** + * Find the matching key for a provided value in an object + * @param {object} object Object to search + * @param {object} value Value to find the matching key for + * @returns {object} Key + */ function getKeyByValue(object, value) { - return Object.keys(object).find(key => object[key] === value); + return Object.keys(object).find(key => object[key] === value); } // -----------HTML HELPERS----------- +/** + * Encode HTML entities + * @param {string} value Value to encode + * @returns {string} Encoded value + */ function htmlEncode(value) { - // Create a in-memory element, set its inner text (which is automatically encoded) - // Then grab the encoded contents back out. The element never exists on the DOM. + /** + Create a in-memory element, set its inner text + (which is automatically encoded) + Then grab the encoded contents back out. + The element never exists on the DOM. + **/ return $("