1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minchat_ynh.git synced 2024-09-03 19:36:29 +02:00

Urls to links or images

This commit is contained in:
Chtixof 2015-04-11 22:22:02 +02:00
parent 841e2a1f99
commit d616b180ed

View file

@ -86,10 +86,24 @@ if ($name.$room=="") {
</div> </div>
<script type="text/javascript" src="lib/jquery-2.1.3.min.js"></script> <script type="text/javascript" src="lib/jquery-2.1.3.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
// regexp used by fonction lienurl
function replacer(match, p1,p2,p3, offset, string){
if (p1.match(/\.(png|jpg|jpeg|gif)$/)) {
return(' <img src="' + p1 + '" />');
} else {
return ' <a href="' + p1 + '">' + p1 + '</a>';
}
}
// remplace les url précédées d'un espace par un lien
function lienurl(s){
return s.replace(/\s(https?:\/\/([-\w\.]+[-\w]+(:\d+)?(\/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?))/g,replacer);
}
$(document).ready(function() { $(document).ready(function() {
var id = 'undefined'; var id = 'undefined';
var pos = 0; var pos = 0;
var lastdate = 0; var lastdate = 0;
var oldscrollHeight = $("#chatbox")[0].scrollHeight;
$("#submitmsg").click(function() { $("#submitmsg").click(function() {
var clientmsg = $("#usermsg").val(); var clientmsg = $("#usermsg").val();
@ -111,7 +125,6 @@ if ($name.$room=="") {
}); });
function loadLog() { function loadLog() {
var oldscrollHeight = $("#chatbox")[0].scrollHeight;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: 'server.php', url: 'server.php',
@ -130,6 +143,9 @@ if ($name.$room=="") {
+"("+heure+") <b>" +"("+heure+") <b>"
+data.data[k][1]+"</b>: "+data.data[k][2]+"<br>"; +data.data[k][1]+"</b>: "+data.data[k][2]+"<br>";
} }
html=lienurl(html);
if (pos==0 && heure!=''){ if (pos==0 && heure!=''){
html='<b>----- '+date.toLocaleDateString()+' -----</b><br>'+html; html='<b>----- '+date.toLocaleDateString()+' -----</b><br>'+html;
} }