From 7868e3897b0f282611f1ccb1715a30a93404ddc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Tue, 13 Mar 2012 21:46:57 +0000 Subject: [PATCH] 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. --- .../plugins/bbcode/editor_plugin_src.js | 262 ++++++++++-------- 1 file changed, 140 insertions(+), 122 deletions(-) diff --git a/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js index 44d1473a99..183f2bc68d 100755 --- a/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js +++ b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js @@ -44,61 +44,79 @@ _dfrn_html2bbcode : function(s) { s = tinymce.trim(s); - function rep(re, str) { - - //modify code to keep stuff intact within [code][/code] blocks - //Waitman Gobble NO WARRANTY - - - var o = new Array(); - var x = s.split("[code]"); - var i = 0; - - var si = ""; - si = x.shift(); - si = si.replace(re,str); - o.push(si); - - for (i = 0; i < x.length; i++) { - var no = new Array(); - var j = x.shift(); - var g = j.split("[/code]"); - no.push(g.shift()); - si = g.shift(); - si = si.replace(re,str); - no.push(si); - o.push(no.join("[/code]")); - } - - s = o.join("[code]"); - - }; - - - - - /* oembed */ - function _h2b_cb(match) { - function s_h2b(data) { - match = data; + function rep(re, str) { + + //modify code to keep stuff intact within [code][/code] blocks + //Waitman Gobble NO WARRANTY + + + var o = new Array(); + var x = s.split("[code]"); + var i = 0; + + var si = ""; + si = x.shift(); + si = si.replace(re,str); + o.push(si); + + for (i = 0; i < x.length; i++) { + var no = new Array(); + var j = x.shift(); + var g = j.split("[/code]"); + no.push(g.shift()); + si = g.shift(); + si = si.replace(re,str); + no.push(si); + o.push(no.join("[/code]")); + } + + s = o.join("[code]"); + + }; + + + + + /* oembed */ + function _h2b_cb(match) { + /* + function s_h2b(data) { + match = data; } $.ajax({ - type:"POST", + type:"POST", url: 'oembed/h2b', - data: {text: match}, - async: false, - success: s_h2b, - dataType: 'html' - }); - return match; - } + data: {text: match}, + async: false, + success: s_h2b, + dataType: 'html' + }); + */ + + var f, g, tof = [], tor = []; + var find_spanc = /]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:]*>(.*?)<\/span *>)*.*?)<\/span *>/ig; + while (f = find_spanc.exec(match)) { + var find_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; + } if (s.indexOf('class="oembed')>=0){ //alert("request oembed html2bbcode"); s = _h2b_cb(s); } - - /* /oembed */ - + + /* /oembed */ + // example: to [b] rep(/(.*?)<\/a>/gi,"[bookmark=$1]$2[/bookmark]"); @@ -111,16 +129,16 @@ rep(//gi,"[img=$3x$2]$1[/img]"); rep(//gi,"[img=$2x$3]$1[/img]"); rep(//gi,"[img]$1[/img]"); - - rep(/