From: yomguy Date: Mon, 4 Feb 2013 13:48:43 +0000 (+0100) Subject: fix urlize (no jquery stuff inducing bad loops) X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=8d097aa99339ae8a9f43e062cf9d01dc128f47fd;p=django-jqchat.git fix urlize (no jquery stuff inducing bad loops) --- diff --git a/jqchat/static/jqchat/jqchat.js b/jqchat/static/jqchat/jqchat.js index e26291b..5a2b2b1 100644 --- a/jqchat/static/jqchat/jqchat.js +++ b/jqchat/static/jqchat/jqchat.js @@ -40,11 +40,9 @@ $(document).ajaxSend(function(event, xhr, settings) { }); -jQuery.fn.urlize = function( base ) { - var x = this.html(); +var urlize = function(text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var text = x.replace(exp,"$1"); - this.html(text); + return text.replace(exp,"$1"); }; // Chat client code. @@ -81,7 +79,7 @@ function processResponse(payload) { // Get the timestamp, store it in global variable to be passed to the server on next call. timestamp = payload.time; for(message in payload.messages) { - $("#chatwindow").append(payload.messages[message].text).urlize( "/" ); + $("#chatwindow").append(urlize(payload.messages[message].text)); } // Scroll down if messages fill up the div. var objDiv = document.getElementById("chatwindow");