mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-06-23 11:39:33 +02:00
Merge pull request #107 from FluffyJenkins/feature/communityModules
Fixed url parsing breaking with text formatting! <3
This commit is contained in:
commit
31ea9e33c7
2 changed files with 55 additions and 12 deletions
|
@ -52,6 +52,21 @@
|
||||||
var $ChatLog; // The scrolling chat log.
|
var $ChatLog; // The scrolling chat log.
|
||||||
var $ChatInputText; // The text field for entering text.
|
var $ChatInputText; // The text field for entering text.
|
||||||
var userName;
|
var userName;
|
||||||
|
var urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;,:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+,~%\/\.\w\-]*)?\??(?:[\-\+=&;,:%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
|
||||||
|
|
||||||
|
function reverseMatches(msg) {
|
||||||
|
var result = [];
|
||||||
|
var matches = msg.match(urlRegEx);
|
||||||
|
if (matches === null) {
|
||||||
|
matches = [];
|
||||||
|
}
|
||||||
|
for (var i = 0; i <= matches.length; i++) {
|
||||||
|
var split = msg.split(matches[i], 2);
|
||||||
|
result.push(split[0]);
|
||||||
|
msg = split[1];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//Start George Function
|
//Start George Function
|
||||||
//Function provided by George Deac
|
//Function provided by George Deac
|
||||||
|
@ -62,11 +77,30 @@
|
||||||
|
|
||||||
$.fn.linky = function (options) {
|
$.fn.linky = function (options) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
var $el = $(this),
|
var $el = $(this);
|
||||||
linkifiedContent = _linkify($el, options);
|
var content = $el.html();
|
||||||
var formattedContent = replaceFormatting(linkifiedContent);
|
|
||||||
|
|
||||||
$el.html(formattedContent);
|
var match = content.match(urlRegEx);
|
||||||
|
var matchLength = match === null ? 0 : match.length;
|
||||||
|
var messageParts = reverseMatches(content);
|
||||||
|
|
||||||
|
var messageFormatted = [];
|
||||||
|
var urlLinkified = [];
|
||||||
|
var completeMessage = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < matchLength; i++) {
|
||||||
|
urlLinkified.push(_linkify(match[i], options));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < messageParts.length; i++) {
|
||||||
|
messageFormatted.push(replaceFormatting(messageParts[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < messageFormatted.length; i++) {
|
||||||
|
completeMessage.push(messageFormatted[i], urlLinkified[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$el.html(completeMessage.join(""));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,9 +126,8 @@
|
||||||
linkTo: "twitter" // Let's default to Twitter
|
linkTo: "twitter" // Let's default to Twitter
|
||||||
},
|
},
|
||||||
extendedOptions = $.extend(defaultOptions, options),
|
extendedOptions = $.extend(defaultOptions, options),
|
||||||
elContent = $el.html(),
|
elContent = $el,
|
||||||
// Regular expression courtesy of Matthew O'Riordan, see: http://goo.gl/3syEKK
|
// Regular expression courtesy of Matthew O'Riordan, see: http://goo.gl/3syEKK
|
||||||
urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;,:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+,~%\/\.\w\-]*)?\??(?:[\-\+=&;,:%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g,
|
|
||||||
matches;
|
matches;
|
||||||
|
|
||||||
// Linkifying URLs
|
// Linkifying URLs
|
||||||
|
@ -121,7 +154,7 @@
|
||||||
// For any URLs present, unless they are already identified within
|
// For any URLs present, unless they are already identified within
|
||||||
// an `a` element, linkify them.
|
// an `a` element, linkify them.
|
||||||
function _linkifyUrls(matches, $el) {
|
function _linkifyUrls(matches, $el) {
|
||||||
var elContent = $el.html();
|
var elContent = $el;
|
||||||
|
|
||||||
$.each(matches, function () {
|
$.each(matches, function () {
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,15 @@ function connectWebSocket(timeout) {
|
||||||
console.log('disconnected');
|
console.log('disconnected');
|
||||||
|
|
||||||
timeout = timeout | 0;
|
timeout = timeout | 0;
|
||||||
if (!shutdownBool && timeout < (30 * 1000)) {
|
if (!shutdownBool) {
|
||||||
|
if (timeout > (30 * 1000)) {
|
||||||
|
timeout = 30 * 1000;
|
||||||
|
} else if (timeout < (30 * 1000)) {
|
||||||
|
timeout += 1000;
|
||||||
|
}
|
||||||
Script.setTimeout(function () {
|
Script.setTimeout(function () {
|
||||||
connectWebSocket(timeout);
|
connectWebSocket(timeout);
|
||||||
}, timeout + 1000);
|
}, timeout);
|
||||||
} else {
|
} else {
|
||||||
wsReady = -1;
|
wsReady = -1;
|
||||||
}
|
}
|
||||||
|
@ -128,13 +133,18 @@ function sendWS(msg, timeout) {
|
||||||
ws.send(JSON.stringify(msg));
|
ws.send(JSON.stringify(msg));
|
||||||
} else {
|
} else {
|
||||||
timeout = timeout | 0;
|
timeout = timeout | 0;
|
||||||
if (!shutdownBool && timeout < (30 * 1000)) {
|
if (!shutdownBool) {
|
||||||
|
if (timeout > (30 * 1000)) {
|
||||||
|
timeout = 30 * 1000;
|
||||||
|
} else if (timeout < (30 * 1000)) {
|
||||||
|
timeout += 1000;
|
||||||
|
}
|
||||||
Script.setTimeout(function () {
|
Script.setTimeout(function () {
|
||||||
if (wsReady === -1) {
|
if (wsReady === -1) {
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
}
|
}
|
||||||
sendWS(msg, timeout);
|
sendWS(msg, timeout);
|
||||||
}, timeout + 1000);
|
}, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +191,7 @@ function go2(msg) {
|
||||||
var dest = false;
|
var dest = false;
|
||||||
var domainsList = [];
|
var domainsList = [];
|
||||||
try {
|
try {
|
||||||
domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json");
|
domainsList = Script.require(gotoJSONUrl + "?" + Date.now());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue