]> git.mxchange.org Git - friendica.git/commitdiff
In HTML2BBCode: fetch the URL of [EMBED] using JavaScript instead of an ajax-call...
authorTobias Hößl <tobias@hoessl.eu>
Tue, 13 Mar 2012 21:46:57 +0000 (21:46 +0000)
committerTobias Hößl <tobias@hoessl.eu>
Tue, 13 Mar 2012 21:46:57 +0000 (21:46 +0000)
library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js

index 44d1473a99fe2bbe5b6c739f2a84d035bd297bb5..183f2bc68d3e155a05b7c2e43ec9246738f05fa7 100755 (executable)
                _dfrn_html2bbcode : function(s) {\r
                        s = tinymce.trim(s);\r
 \r
-                       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) {\r
+\r
+                               //modify code to keep stuff intact within [code][/code] blocks\r
+                               //Waitman Gobble NO WARRANTY\r
+\r
+\r
+                               var o = new Array();\r
+                               var x = s.split("[code]");\r
+                               var i = 0;\r
+\r
+                               var si = "";\r
+                               si = x.shift();\r
+                               si = si.replace(re,str);\r
+                               o.push(si);\r
+\r
+                               for (i = 0; i < x.length; i++) {\r
+                                       var no = new Array();\r
+                                       var j = x.shift();\r
+                                       var g = j.split("[/code]");\r
+                                       no.push(g.shift());\r
+                                       si = g.shift();\r
+                                       si = si.replace(re,str);\r
+                                       no.push(si);\r
+                                       o.push(no.join("[/code]"));\r
+                               }\r
+\r
+                               s = o.join("[code]");\r
+\r
+                       };\r
+\r
+\r
+\r
+\r
+                       /* oembed */\r
+                       function _h2b_cb(match) {\r
+                               /*\r
+                               function s_h2b(data) {\r
+                                               match = data;\r
                                }\r
                                $.ajax({\r
-                                       type:"POST",
+                                       type:"POST",\r
                                        url: 'oembed/h2b',\r
-                                       data: {text: match},
-                                       async: false,
-                                       success: s_h2b,
-                                       dataType: 'html'
-                               });
-                               return match;
-                       }
+                                       data: {text: match},\r
+                                       async: false,\r
+                                       success: s_h2b,\r
+                                       dataType: 'html'\r
+                               });\r
+                               */\r
+                               \r
+                               var f, g, tof = [], tor = [];\r
+                               var find_spanc = /<span [^>]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:<span[^>]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;\r
+                               while (f = find_spanc.exec(match)) {\r
+                                       var find_a = /<a([^>]* rel=[\"']oembed[\"'][^>]*)>.*?<\/a *>/ig;\r
+                                       if (g = find_a.exec(f[1])) {\r
+                                               var find_href = /href=[\"']([^\"']*)[\"']/ig;\r
+                                               var m2 = find_href.exec(g[1]);\r
+                                               if (m2[1]) {\r
+                                                       tof.push(f[0]);\r
+                                                       tor.push("[EMBED]" + m2[1] + "[/EMBED]");\r
+                                               }\r
+                                       }\r
+                               }\r
+                               for (var i = 0; i < tof.length; i++) match = match.replace(tof[i], tor[i]);\r
+                               \r
+                               return match;\r
+                       }\r
                        if (s.indexOf('class="oembed')>=0){\r
                                //alert("request oembed html2bbcode");\r
                                s = _h2b_cb(s);\r
                        }\r
-                       
-                       /* /oembed */
-
+                       \r
+                       /* /oembed */\r
+\r
 \r
                        // example: <strong> to [b]\r
                        rep(/<a class=\"bookmark\" href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[bookmark=$1]$2[/bookmark]");\r
                        rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");\r
                        rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");\r
                        rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
-
-                       rep(/<ul class=\"listbullet\" style=\"list-style-type\: circle\;\">(.*?)<\/ul>/gi,"[list]$1[/list]");
-                       rep(/<ul class=\"listnone\" style=\"list-style-type\: none\;\">(.*?)<\/ul>/gi,"[list=]$1[/list]");
-                       rep(/<ul class=\"listdecimal\" style=\"list-style-type\: decimal\;\">(.*?)<\/ul>/gi,"[list=1]$1[/list]");
-                       rep(/<ul class=\"listlowerroman\" style=\"list-style-type\: lower-roman\;\">(.*?)<\/ul>/gi,"[list=i]$1[/list]");
-                       rep(/<ul class=\"listupperroman\" style=\"list-style-type\: upper-roman\;\">(.*?)<\/ul>/gi,"[list=I]$1[/list]");
-                       rep(/<ul class=\"listloweralpha\" style=\"list-style-type\: lower-alpha\;\">(.*?)<\/ul>/gi,"[list=a]$1[/list]");
-                       rep(/<ul class=\"listupperalpha\" style=\"list-style-type\: upper-alpha\;\">(.*?)<\/ul>/gi,"[list=A]$1[/list]");
-                       rep(/<li>(.*?)<\/li>/gi,'[li]$1[/li]');
-
+\r
+                       rep(/<ul class=\"listbullet\" style=\"list-style-type\: circle\;\">(.*?)<\/ul>/gi,"[list]$1[/list]");\r
+                       rep(/<ul class=\"listnone\" style=\"list-style-type\: none\;\">(.*?)<\/ul>/gi,"[list=]$1[/list]");\r
+                       rep(/<ul class=\"listdecimal\" style=\"list-style-type\: decimal\;\">(.*?)<\/ul>/gi,"[list=1]$1[/list]");\r
+                       rep(/<ul class=\"listlowerroman\" style=\"list-style-type\: lower-roman\;\">(.*?)<\/ul>/gi,"[list=i]$1[/list]");\r
+                       rep(/<ul class=\"listupperroman\" style=\"list-style-type\: upper-roman\;\">(.*?)<\/ul>/gi,"[list=I]$1[/list]");\r
+                       rep(/<ul class=\"listloweralpha\" style=\"list-style-type\: lower-alpha\;\">(.*?)<\/ul>/gi,"[list=a]$1[/list]");\r
+                       rep(/<ul class=\"listupperalpha\" style=\"list-style-type\: upper-alpha\;\">(.*?)<\/ul>/gi,"[list=A]$1[/list]");\r
+                       rep(/<li>(.*?)<\/li>/gi,'[li]$1[/li]');\r
+\r
                        rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");\r
                        rep(/<\/(strong|b)>/gi,"[/b]");\r
                        rep(/<(strong|b)>/gi,"[b]");\r
                // BBCode -> HTML from DFRN dialect\r
                _dfrn_bbcode2html : function(s) {\r
                        s = tinymce.trim(s);\r
-
-
-                        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]");
-
-                        };
-
-
-
-
-
+\r
+\r
+                        function rep(re, str) {\r
+\r
+                                //modify code to keep stuff intact within [code][/code] blocks\r
+                                //Waitman Gobble NO WARRANTY\r
+\r
+\r
+                                var o = new Array();\r
+                                var x = s.split("[code]");\r
+                                var i = 0;\r
+\r
+                                var si = "";\r
+                                si = x.shift();\r
+                                si = si.replace(re,str);\r
+                                o.push(si);\r
+\r
+                                for (i = 0; i < x.length; i++) {\r
+                                        var no = new Array();\r
+                                        var j = x.shift();\r
+                                        var g = j.split("[/code]");\r
+                                        no.push(g.shift());\r
+                                        si = g.shift();\r
+                                        si = si.replace(re,str);\r
+                                        no.push(si);\r
+                                        o.push(no.join("[/code]"));\r
+                                }\r
+\r
+                                s = o.join("[code]");\r
+\r
+                        };\r
+\r
+\r
+\r
+\r
+\r
                        // example: [b] to <strong>\r
                        rep(/\n/gi,"<br />");\r
                        rep(/\[b\]/gi,"<strong>");\r
                        rep(/\[\/i\]/gi,"</em>");\r
                        rep(/\[u\]/gi,"<u>");\r
                        rep(/\[\/u\]/gi,"</u>");\r
-                       rep(/\[hr\]/gi,"<hr />");
+                       rep(/\[hr\]/gi,"<hr />");\r
                        rep(/\[bookmark=([^\]]+)\](.*?)\[\/bookmark\]/gi,"<a class=\"bookmark\" href=\"$1\">$2</a>");\r
                        rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");\r
                        rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");\r
                        rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3\" />");\r
                        rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");\r
-
-                       rep(/\[list\](.*?)\[\/list\]/gi, '<ul class="listbullet" style="list-style-type: circle;">$1</ul>');
-                       rep(/\[list=\](.*?)\[\/list\]/gi, '<ul class="listnone" style="list-style-type: none;">$1</ul>');
-                       rep(/\[list=1\](.*?)\[\/list\]/gi, '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');
-                       rep(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');
-                       rep(/\[list=I\](.*?)\[\/list\]/gi, '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');
-                       rep(/\[list=a\](.*?)\[\/list\]/gi, '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');
-                       rep(/\[list=A\](.*?)\[\/list\]/gi, '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');
-                       rep(/\[li\](.*?)\[\/li\]/gi, '<li>$1</li>');
+\r
+                       rep(/\[list\](.*?)\[\/list\]/gi, '<ul class="listbullet" style="list-style-type: circle;">$1</ul>');\r
+                       rep(/\[list=\](.*?)\[\/list\]/gi, '<ul class="listnone" style="list-style-type: none;">$1</ul>');\r
+                       rep(/\[list=1\](.*?)\[\/list\]/gi, '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');\r
+                       rep(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');\r
+                       rep(/\[list=I\](.*?)\[\/list\]/gi, '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');\r
+                       rep(/\[list=a\](.*?)\[\/list\]/gi, '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');\r
+                       rep(/\[list=A\](.*?)\[\/list\]/gi, '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');\r
+                       rep(/\[li\](.*?)\[\/li\]/gi, '<li>$1</li>');\r
                        rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");\r
                        rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");\r
                        rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");\r
                        rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");\r
-
-                       /* oembed */
-                       function _b2h_cb(match, url) {
-                               url = bin2hex(url);
-                               function s_b2h(data) {
-                                               match = data;
-                               }
-                               $.ajax({
-                                       url: 'oembed/b2h?url=' + url,
-                                       async: false,
-                                       success: s_b2h,
-                                       dataType: 'html'
-                               });
-                               return match;
-                       }
-                       s = s.replace(/\[embed\](.*?)\[\/embed\]/gi, _b2h_cb);
-                       
-                       /* /oembed */
+\r
+                       /* oembed */\r
+                       function _b2h_cb(match, url) {\r
+                               url = bin2hex(url);\r
+                               function s_b2h(data) {\r
+                                               match = data;\r
+                               }\r
+                               $.ajax({\r
+                                       url: 'oembed/b2h?url=' + url,\r
+                                       async: false,\r
+                                       success: s_b2h,\r
+                                       dataType: 'html'\r
+                               });\r
+                               return match;\r
+                       }\r
+                       s = s.replace(/\[embed\](.*?)\[\/embed\]/gi, _b2h_cb);\r
+                       \r
+                       /* /oembed */\r
 \r
                        return s; \r
                }\r