auto link + remove vertical scrollbar from input

This commit is contained in:
ian ramzy 2020-03-31 12:21:49 -04:00
parent bba20c9533
commit 5df20e1b4c
4 changed files with 50 additions and 3 deletions

View File

@ -122,6 +122,7 @@
<script src="/socket.io/socket.io.js"></script>
<script src="../js/snackbar.js"></script>
<script src="../js/autolink.js"></script>
<script src="../js/chat.js"></script>
</body>
</html>

View File

@ -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*/

42
public/js/autolink.js Normal file
View File

@ -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<a target='_blank' href='$2'>$2</a>");
}
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) ||
"<a target='_blank' href='" +
url +
"'" +
linkAttributes +
">" +
url +
"</a>";
return "" + space + link;
});
};
String.prototype["autoLink"] = autoLink;
}.call(this));

View File

@ -586,7 +586,7 @@ chatInput.addEventListener("keypress", function (event) {
socket.emit("chat message", chatInput.value, roomHash);
$(".chat-messages").append(
'<div class="message-item customer"><div class="message-bloc"><div class="message">' +
chatInput.value +
chatInput.value.autoLink() +
"</div></div></div>"
);
$("#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(
'<div class="message-item moderator"><div class="message-bloc"><div class="message">' +
msg +
msg.autoLink() +
"</div></div></div>"
);
$("#chat-zone").scrollTop($("#chat-zone")[0].scrollHeight);