In HTML2BBCode: fetch the URL of [EMBED] using JavaScript instead of an ajax-call to a php-script. Once there actually is embedded Code in the HTML, this function is called after every single keypress. Not only is making an ajax-call every keypress bandith intensive - it also made typing hard / slow. Making a lot of JavaScript-RegExp-Computation every keypress isn't exactly great either, but still performs better.

This commit is contained in:
Tobias Hößl 2012-03-13 21:46:57 +00:00
parent 43430ef561
commit 7868e3897b

View file

@ -79,6 +79,7 @@
/* oembed */ /* oembed */
function _h2b_cb(match) { function _h2b_cb(match) {
/*
function s_h2b(data) { function s_h2b(data) {
match = data; match = data;
} }
@ -90,6 +91,23 @@
success: s_h2b, success: s_h2b,
dataType: 'html' dataType: 'html'
}); });
*/
var f, g, tof = [], tor = [];
var find_spanc = /<span [^>]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:<span[^>]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;
while (f = find_spanc.exec(match)) {
var find_a = /<a([^>]* rel=[\"']oembed[\"'][^>]*)>.*?<\/a *>/ig;
if (g = find_a.exec(f[1])) {
var find_href = /href=[\"']([^\"']*)[\"']/ig;
var m2 = find_href.exec(g[1]);
if (m2[1]) {
tof.push(f[0]);
tor.push("[EMBED]" + m2[1] + "[/EMBED]");
}
}
}
for (var i = 0; i < tof.length; i++) match = match.replace(tof[i], tor[i]);
return match; return match;
} }
if (s.indexOf('class="oembed')>=0){ if (s.indexOf('class="oembed')>=0){