From 56956ec85a4b8fcd40a7223818532edf3ff243cb Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Mon, 14 Apr 2014 02:39:34 +0200 Subject: [PATCH] Better URL parse with jQuery --- client/css/style.css | 3 +++ client/js/chat.js | 36 +++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/client/css/style.css b/client/css/style.css index 4a3fc87..da240f1 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -92,6 +92,9 @@ h2 { right: 0; top: 0; } +#chat a { + color: inherit; +} #chat form { border-top: 1px solid #ddd; bottom: 1px; diff --git a/client/js/chat.js b/client/js/chat.js index f09542a..7aafe09 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -53,8 +53,10 @@ $(function() { users: render("#user"), messages: render("#message"), }; - json.forEach(function(network) { - html += render("#window", network, partials); + json.forEach(function(n) { + html += render( + "#window", n, partials + ); }); $("#windows")[0].innerHTML = html; @@ -62,13 +64,12 @@ $(function() { render("#network", {networks: json}, {channels: render("#channel")}) ).find(".channel") .first() - .addClass("active"); + .addClass("active") + .end(); chat.find(".messages") .scrollGlue({animate: 400}) .scrollToBottom() - .find(".text") - .uri() .end(); chat.find(".window") .find("input") @@ -129,9 +130,6 @@ $(function() { } var msg = $(render("#message", {messages: message})) - .find(".text") - .uri() - .end(); target = target.find(".messages"); target.append(msg); @@ -245,6 +243,19 @@ $(function() { chat.on("focus", "input[type=text]", function() { $(this).closest(".window").find(".messages").scrollToBottom(); }); + + chat.on("mouseover", ".text", function() { + var self = $(this); + if (!self.hasClass("parsed")) { + self.addClass("parsed").html(uri(self.html())); + } + }); + + function uri(text) { + return URI.withinString(text, function(url) { + return "" + url + ""; + }); + } var highest = 1; $.fn.bringToTop = function() { @@ -257,13 +268,4 @@ $(function() { .removeClass("active") .end(); }; - - $.fn.uri = function() { - return this.each(function() { - var html = $(this).html(); - return $(this).html(URI.withinString(html, function(url) { - return "" + url + ""; - })); - }); - }; });