From dcd2233aa6ceabe00b06b4fe342b14bf211e9f4a Mon Sep 17 00:00:00 2001 From: sijanec Date: Sun, 17 May 2020 15:07:56 +0200 Subject: popravljen dist, hvala rstular --- dist/js/chats.js | 504 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 504 insertions(+) create mode 100644 dist/js/chats.js (limited to 'dist/js/chats.js') diff --git a/dist/js/chats.js b/dist/js/chats.js new file mode 100644 index 0000000..daf10ab --- /dev/null +++ b/dist/js/chats.js @@ -0,0 +1,504 @@ +// const API_ENDPOINT = "https://gimb.tk/test.php"; +const DIRECTORY_URL = "/directory.json"; +const CHATS_BEGIN_TAG = ""; +const CHATS_END_TAG = ""; +const CHAT_REGEX = /([\S\s]+)/g; +const CHATS_SUBJECT_PREFIX = "ba-ctlmsg-chat-"; + +// "Global" object for name directory +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 + // from the offline store. + if (value !== true) { + window.location.replace("/index.html"); + } + }).catch(function (err) { + // This code runs if there were any errors + console.log(err); + }); +} + +/** + * 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); +} + +// -----------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. + **/ + return $("