mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
URLs can be parsed
This commit is contained in:
parent
7a3387b550
commit
1a922704ed
@ -20,6 +20,9 @@ ComunicWeb.components.textParser = {
|
||||
//Prepare users tag parsing
|
||||
this._prepare_user_tag_parsing(info.element);
|
||||
|
||||
//Prepare URL parsing
|
||||
this._prepare_url_tag_parsing(info.element);
|
||||
|
||||
//Parse emojies
|
||||
ComunicWeb.components.emoji.parser.parse({
|
||||
element: info.element
|
||||
@ -27,6 +30,9 @@ ComunicWeb.components.textParser = {
|
||||
|
||||
//Parse users tags
|
||||
this._parse_users_tag(info.element);
|
||||
|
||||
//Parse URLs
|
||||
this._parse_urls(info.element);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -49,6 +55,25 @@ ComunicWeb.components.textParser = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare URL parsing
|
||||
*
|
||||
* @param {HTMLElement} target The target element to prepare
|
||||
*/
|
||||
_prepare_url_tag_parsing: function(target){
|
||||
|
||||
//Find all occurences of users tag
|
||||
while(target.innerHTML.match(/ [a-zA-Z]{2,5}:\/\/[a-zA-Z0-9.=@\?\&:\/]+/i)){
|
||||
|
||||
//Get URL and save it
|
||||
var URL = target.innerHTML.match(/ [a-zA-Z]{2,5}:\/\/[a-zA-Z0-9.=@\?\&:\/]+/i)[0];
|
||||
tempURL = URL.replace("://", ":/");
|
||||
target.innerHTML = target.innerHTML.replace(URL, "<innerURL>"+tempURL+"</innerURL>");
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse users tag
|
||||
*
|
||||
@ -87,5 +112,35 @@ ComunicWeb.components.textParser = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse URLs
|
||||
*
|
||||
* @param {HTMLElement} target The target element where URLs
|
||||
* to be parsed
|
||||
*/
|
||||
_parse_urls: function(target){
|
||||
|
||||
//Get the list of user tags of the target
|
||||
var nodes = target.getElementsByTagName("innerURL");
|
||||
|
||||
for (var num in nodes) {
|
||||
if (nodes.hasOwnProperty(num)) {
|
||||
const node = nodes[num];
|
||||
|
||||
//Small fix for iOS 9
|
||||
if(!node.addEventListener)
|
||||
continue;
|
||||
|
||||
//Get target URL
|
||||
var url = node.innerHTML;
|
||||
url = url.replace(":/", "://");
|
||||
|
||||
//Adapt node
|
||||
node.innerHTML = "<a href='" + url + "' target='_blank'>" + url + "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user