From bf09fc9bbe6881a4868e5a4489724fdf50cd60e6 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 10 Feb 2014 14:37:50 -0800 Subject: getting bookmark support in tinymce is left as a FIXME. I've got something that almost works, but not quite in editor_plugin_src.js2 --- .../tiny_mce/plugins/bbcode/editor_plugin.js2 | 1 + .../tiny_mce/plugins/bbcode/editor_plugin_src.js | 7 + .../tiny_mce/plugins/bbcode/editor_plugin_src.js2 | 216 +++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin.js2 create mode 100644 library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js2 diff --git a/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin.js2 b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin.js2 new file mode 100644 index 000000000..290508845 --- /dev/null +++ b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin.js2 @@ -0,0 +1 @@ +(function(){tinymce.create("tinymce.plugins.BBCodePlugin",{init:function(e,t){var n=this,r=e.getParam("bbcode_dialect","dfrn").toLowerCase();e.onBeforeSetContent.add(function(e,t){t.content=n["_"+r+"_bbcode2html"](t.content)});e.onPostProcess.add(function(e,t){if(t.set)t.content=n["_"+r+"_bbcode2html"](t.content);if(t.get)t.content=n["_"+r+"_html2bbcode"](t.content)})},getInfo:function(){return{longname:"BBCode Plugin",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_dfrn_html2bbcode:function(e){function t(t,n){e=e.replace(t,n)}function n(e){var t,n,r=[],i=[];var s=/]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;while(t=s.exec(e)){var o=/]* rel=[\"']oembed[\"'][^>]*)>.*?<\/a *>/ig;if(n=o.exec(t[1])){var u=/href=[\"']([^\"']*)[\"']/ig;var a=u.exec(n[1]);if(a[1]){r.push(t[0]);i.push("[EMBED]"+a[1]+"[/EMBED]")}}}for(var f=0;f=0){e=n(e)}t(/#\^(.*?)<\/a>/gi,"#^[url=$1]$2[/url]");t(/(^|[^#\^])(.*?)<\/a>/gi,"$1#^[url=$2]$3[/url]");t(/(.*?)<\/span>/gi,"[size=$1]$2[/size]");t(/(.*?)<\/span>/gi,"[color=$1]$2[/color]");t(/(.*?)<\/font>/gi,"$1");t(//gi,"[img=$1x$2]$3[/img]");t(//gi,"[img=$2x$1]$3[/img]");t(//gi,"[img=$3x$2]$1[/img]");t(//gi,"[img=$2x$3]$1[/img]");t(//gi,"[img]$1[/img]");t(/
    (.*?)<\/ul>/gi,"[list]$1[/list]");t(/
      (.*?)<\/ul>/gi,"[list=]$1[/list]");t(/
        (.*?)<\/ul>/gi,"[list=1]$1[/list]");t(/
          (.*?)<\/ul>/gi,"[list=i]$1[/list]");t(/
            (.*?)<\/ul>/gi,"[list=I]$1[/list]");t(/
              (.*?)<\/ul>/gi,"[list=a]$1[/list]");t(/
                (.*?)<\/ul>/gi,"[list=A]$1[/list]");t(/
              • (.*?)<\/li>/gi,"[li]$1[/li]");t(/(.*?)<\/code>/gi,"[code]$1[/code]");t(/<\/(strong|b)>/gi,"[/b]");t(/<(strong|b)>/gi,"[b]");t(/<\/(em|i)>/gi,"[/i]");t(/<(em|i)>/gi,"[i]");t(/<\/u>/gi,"[/u]");t(/(.*?)<\/span>/gi,"[u]$1[/u]");t(//gi,"[u]");t(/]*>/gi,"[quote]");t(/<\/blockquote>/gi,"[/quote]");t(/
                /gi,"[hr]");t(/
                /gi,"\n");t(//gi,"\n");t(/
                /gi,"\n");t(/

                /gi,"");t(/<\/p>/gi,"\n");t(/ /gi," ");t(/"/gi,'"');t(/</gi,"<");t(/>/gi,">");t(/&/gi,"&");return e},_dfrn_bbcode2html:function(e){function t(t,n){var r=new Array;var i=e.split("[code]");var o=0;var u="";u=i.shift();u=u.replace(t,n);r.push(u);for(o=0;o");t(/\[b\]/gi,"");t(/\[\/b\]/gi,"");t(/\[i\]/gi,"");t(/\[\/i\]/gi,"");t(/\[u\]/gi,"");t(/\[\/u\]/gi,"");t(/\[hr\]/gi,"


                ");t(/[#\^]\[url=([^\]]+)\](.*?)\[\/url\]/gi,"#^$2");t(/[#\^]\[url\](.*?)\[\/url\]/gi,"#^$1");t(/(^|[^#\^])\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$1#^$3");t(/(^|[^#\^])\[url\](.*?)\[\/url\]/gi,"$1#^$2");t(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,'');t(/\[img\](.*?)\[\/img\]/gi,'');t(/\[list\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=1\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=i\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=I\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=a\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[list=A\](.*?)\[\/list\]/gi,'
                  $1
                ');t(/\[li\](.*?)\[\/li\]/gi,"
              • $1
              • ");t(/\[color=(.*?)\](.*?)\[\/color\]/gi,'$2');t(/\[size=(.*?)\](.*?)\[\/size\]/gi,'$2');t(/\[code\](.*?)\[\/code\]/gi,"$1");t(/\[quote.*?\](.*?)\[\/quote\]/gi,"
                $1
                ");e=e.replace(/\[embed\](.*?)\[\/embed\]/gi,n);return e}});tinymce.PluginManager.add("bbcode",tinymce.plugins.BBCodePlugin)})() 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 387ccdd59..ff0109b23 100644 --- a/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js +++ b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js @@ -10,6 +10,13 @@ /* Macgirvin Aug-2010 changed from punbb to dfrn dialect */ +/** + * If you want to try and get bookmark content (#^{somelink}) working in tinymce, + * I've made some progress, but one or the other of insert-url or insert-link gets it wrong, + * and the error compounds on every edit. + * See editor_plugin_src.js2/editor_plugin.js2 if you're interested in fixing this. + */ + (function() { tinymce.create('tinymce.plugins.BBCodePlugin', { init : function(ed, url) { diff --git a/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js2 b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js2 new file mode 100644 index 000000000..bfb4bd9c7 --- /dev/null +++ b/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js2 @@ -0,0 +1,216 @@ +/** + * editor_plugin_src.js + * + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. + * + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing + */ + +/* Macgirvin Aug-2010 changed from punbb to dfrn dialect */ + +(function() { + tinymce.create('tinymce.plugins.BBCodePlugin', { + init : function(ed, url) { + var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase(); + + ed.onBeforeSetContent.add(function(ed, o) { + o.content = t['_' + dialect + '_bbcode2html'](o.content); + }); + + ed.onPostProcess.add(function(ed, o) { + if (o.set) + o.content = t['_' + dialect + '_bbcode2html'](o.content); + + if (o.get) + o.content = t['_' + dialect + '_html2bbcode'](o.content); + }); + }, + + getInfo : function() { + return { + longname : 'BBCode Plugin', + author : 'Moxiecode Systems AB', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode', + version : tinymce.majorVersion + "." + tinymce.minorVersion + }; + }, + + // Private methods + + // HTML -> BBCode in DFRN dialect + _dfrn_html2bbcode : function(s) { + s = tinymce.trim(s); + + function rep(re, str) { + s = s.replace(re,str); + }; + + + /* oembed */ + function _h2b_cb(match) { + 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); + } + + // example: to [b] + + rep(/#\^(.*?)<\/a>/gi,"#^[url=$1]$2[/url]"); + rep(/(^|[^#\^])(.*?)<\/a>/gi,"$1#^[url=$2]$3[/url]"); + rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); + rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); + rep(/(.*?)<\/font>/gi,"$1"); + rep(//gi,"[img=$1x$2]$3[/img]"); + rep(//gi,"[img=$2x$1]$3[/img]"); + rep(//gi,"[img=$3x$2]$1[/img]"); + rep(//gi,"[img=$2x$3]$1[/img]"); + rep(//gi,"[img]$1[/img]"); + + rep(/
                  (.*?)<\/ul>/gi,"[list]$1[/list]"); + rep(/
                    (.*?)<\/ul>/gi,"[list=]$1[/list]"); + rep(/
                      (.*?)<\/ul>/gi,"[list=1]$1[/list]"); + rep(/
                        (.*?)<\/ul>/gi,"[list=i]$1[/list]"); + rep(/
                          (.*?)<\/ul>/gi,"[list=I]$1[/list]"); + rep(/
                            (.*?)<\/ul>/gi,"[list=a]$1[/list]"); + rep(/
                              (.*?)<\/ul>/gi,"[list=A]$1[/list]"); + rep(/
                            • (.*?)<\/li>/gi,'[li]$1[/li]'); + + rep(/(.*?)<\/code>/gi,"[code]$1[/code]"); + rep(/<\/(strong|b)>/gi,"[/b]"); + rep(/<(strong|b)>/gi,"[b]"); + rep(/<\/(em|i)>/gi,"[/i]"); + rep(/<(em|i)>/gi,"[i]"); + rep(/<\/u>/gi,"[/u]"); + rep(/(.*?)<\/span>/gi,"[u]$1[/u]"); + rep(//gi,"[u]"); + rep(/]*>/gi,"[quote]"); + rep(/<\/blockquote>/gi,"[/quote]"); + rep(/
                              /gi,"[hr]"); + rep(/
                              /gi,"\n"); + rep(//gi,"\n"); + rep(/
                              /gi,"\n"); + rep(/

                              /gi,""); + rep(/<\/p>/gi,"\n"); + rep(/ /gi," "); + rep(/"/gi,"\""); + rep(/</gi,"<"); + rep(/>/gi,">"); + rep(/&/gi,"&"); + + return s; + }, + + // BBCode -> HTML from DFRN dialect + _dfrn_bbcode2html : 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]"); + + }; + + + + + + // example: [b] to + rep(/\n/gi,"
                              "); + rep(/\[b\]/gi,""); + rep(/\[\/b\]/gi,""); + rep(/\[i\]/gi,""); + rep(/\[\/i\]/gi,""); + rep(/\[u\]/gi,""); + rep(/\[\/u\]/gi,""); + rep(/\[hr\]/gi,"


                              "); + rep(/[#\^]\[url=([^\]]+)\](.*?)\[\/url\]/gi,"#^$2"); + rep(/[#\^]\[url\](.*?)\[\/url\]/gi,"#^$1"); + rep(/(^|[^#\^])\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$1#^$3"); + rep(/(^|[^#\^])\[url\](.*?)\[\/url\]/gi,"$1#^$2"); + rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,""); + rep(/\[img\](.*?)\[\/img\]/gi,""); + + rep(/\[list\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[list=\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[list=1\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[list=i\](.*?)\[\/list\]/gi,'
                                $1
                              '); + rep(/\[list=I\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[list=a\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[list=A\](.*?)\[\/list\]/gi, '
                                $1
                              '); + rep(/\[li\](.*?)\[\/li\]/gi, '
                            • $1
                            • '); + rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); + rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2"); + rep(/\[code\](.*?)\[\/code\]/gi,"$1"); + rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
                              $1
                              "); + + /* 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 */ + + return s; + } + }); + + // Register plugin + tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin); +})(); -- cgit v1.2.3