You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

10 years ago
10 years ago
10 years ago
8 years ago
  1. (function(){
  2. "use strict";
  3. var _t = openerp._t;
  4. var _lt = openerp._lt;
  5. var QWeb = openerp.qweb;
  6. openerp.im_chat.Conversation.include({
  7. escape_keep_url: function(str){
  8. //var url_regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi;
  9. var url_regex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?|(<a)[^>]*href="([^"]*)"[^>]*>([^<]*)<\/a>)/gi;
  10. var last = 0;
  11. var txt = "";
  12. while (true) {
  13. var result = url_regex.exec(str);
  14. if (! result)
  15. break;
  16. txt += _.escape(str.slice(last, result.index));
  17. last = url_regex.lastIndex;
  18. var href = '';
  19. var content = '';
  20. var is_odoo_ref = false;
  21. if (result[8]=='<a'){
  22. href = result[9];
  23. if (href[0]=='#'){
  24. href += '&rnd='+parseInt(Math.random()*1000);
  25. content = result[10];
  26. is_odoo_ref = true;
  27. } else {
  28. //only internal urls are allowed
  29. href = '';
  30. }
  31. }else{
  32. href = _.escape(result[0]);
  33. content = href;
  34. }
  35. txt += '<a href="' + href + '"' + (is_odoo_ref?'':' target="_blank"')+'>' + content + '</a>';
  36. }
  37. txt += _.escape(str.slice(last, str.length));
  38. return txt;
  39. },
  40. });
  41. })();