From 5df20e1b4c000dc13631859ea0e5a16f22e76f8a Mon Sep 17 00:00:00 2001 From: ian ramzy Date: Tue, 31 Mar 2020 12:21:49 -0400 Subject: [PATCH] auto link + remove vertical scrollbar from input --- public/chat.html | 1 + public/css/chat.css | 6 +++++- public/js/autolink.js | 42 ++++++++++++++++++++++++++++++++++++++++++ public/js/chat.js | 4 ++-- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 public/js/autolink.js diff --git a/public/chat.html b/public/chat.html index 61d2b87..0efda99 100644 --- a/public/chat.html +++ b/public/chat.html @@ -122,6 +122,7 @@ + diff --git a/public/css/chat.css b/public/css/chat.css index 406dcdc..b84f449 100644 --- a/public/css/chat.css +++ b/public/css/chat.css @@ -252,7 +252,7 @@ button:hover { font-size: inherit; border: none; width: 100%; - height: calc(100%); + height: calc(100% - 5px); resize: none; outline: none; background-color: inherit; @@ -341,4 +341,8 @@ button:hover { word-break: break-all; } +.message a { + text-decoration: underline; +} + /*simple chat*/ diff --git a/public/js/autolink.js b/public/js/autolink.js new file mode 100644 index 0000000..baab926 --- /dev/null +++ b/public/js/autolink.js @@ -0,0 +1,42 @@ +// Generated by CoffeeScript 1.10.0 +(function () { + var autoLink, + slice = [].slice; + + autoLink = function () { + var callback, k, linkAttributes, option, options, pattern, v; + options = 1 <= arguments.length ? slice.call(arguments, 0) : []; + pattern = /(^|[\s\n]|<[A-Za-z]*\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi; + if (!(options.length > 0)) { + return this.replace(pattern, "$1$2"); + } + option = options[0]; + callback = option["callback"]; + linkAttributes = (function () { + var results; + results = []; + for (k in option) { + v = option[k]; + if (k !== "callback") { + results.push(" " + k + "='" + v + "'"); + } + } + return results; + })().join(""); + return this.replace(pattern, function (match, space, url) { + var link; + link = + (typeof callback === "function" ? callback(url) : void 0) || + "" + + url + + ""; + return "" + space + link; + }); + }; + + String.prototype["autoLink"] = autoLink; +}.call(this)); diff --git a/public/js/chat.js b/public/js/chat.js index 6d71ce5..df67cbb 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -586,7 +586,7 @@ chatInput.addEventListener("keypress", function (event) { socket.emit("chat message", chatInput.value, roomHash); $(".chat-messages").append( '
' + - chatInput.value + + chatInput.value.autoLink() + "
" ); $("#chat-zone").scrollTop($("#chat-zone")[0].scrollHeight); @@ -597,7 +597,7 @@ chatInput.addEventListener("keypress", function (event) { socket.on("chat message", function (msg) { $(".chat-messages").append( '
' + - msg + + msg.autoLink() + "
" ); $("#chat-zone").scrollTop($("#chat-zone")[0].scrollHeight);