friendica/library/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin.js

1 line
5.6 KiB
JavaScript

(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(t){return e.match(t)}function r(e){var t,n,r=[],i=[];var s=/<span [^>]*class *= *[\"'](?:[^\"']* )*oembed(?: [^\"']*)*[\"'][^>]*>(.*?(?:<span[^>]*>(.*?)<\/span *>)*.*?)<\/span *>/ig;while(t=s.exec(e)){var o=/<a([^>]* 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<r.length;f++)e=e.replace(r[f],i[f]);return e}e=tinymce.trim(e);if(e.indexOf('class="oembed')>=0){e=r(e)}var i=n(/<code>(.*?)<\/code>/gi);t(/<code>(.*?)<\/code>/gi,"[$!$!CODEBLOCK!$!$]");t(/<a class=\"bookmark\" href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[bookmark=$1]$2[/bookmark]");t(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");t(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");t(/<span style=\"color:(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");t(/<font>(.*?)<\/font>/gi,"$1");t(/<img[^>]*?width=\"([^>]*?)\"[^>]*?height=\"([^>]*?)\"[^>]*?src=\"([^>]*?)\"[^>]*?\/>/gi,"[img=$1x$2]$3[/img]");t(/<img[^>]*?height=\"([^>]*?)\"[^>]*?width=\"([^>]*?)\"[^>]*?src=\"([^>]*?)\"[^>]*?\/>/gi,"[img=$2x$1]$3[/img]");t(/<img[^>]*?src=\"([^>]*?)\"[^>]*?height=\"([^>]*?)\"[^>]*?width=\"([^>]*?)\"[^>]*?\/>/gi,"[img=$3x$2]$1[/img]");t(/<img[^>]*?src=\"([^>]*?)\"[^>]*?width=\"([^>]*?)\"[^>]*?height=\"([^>]*?)\"[^>]*?\/>/gi,"[img=$2x$3]$1[/img]");t(/<img[^>]*?src=\"([^>]*?)\"[^>]*?\/>/gi,"[img]$1[/img]");t(/<ul class=\"listbullet\" style=\"list-style-type\: circle\;\">(.*?)<\/ul>/gi,"[list]$1[/list]");t(/<ul class=\"listnone\" style=\"list-style-type\: none\;\">(.*?)<\/ul>/gi,"[list=]$1[/list]");t(/<ul class=\"listdecimal\" style=\"list-style-type\: decimal\;\">(.*?)<\/ul>/gi,"[list=1]$1[/list]");t(/<ul class=\"listlowerroman\" style=\"list-style-type\: lower-roman\;\">(.*?)<\/ul>/gi,"[list=i]$1[/list]");t(/<ul class=\"listupperroman\" style=\"list-style-type\: upper-roman\;\">(.*?)<\/ul>/gi,"[list=I]$1[/list]");t(/<ul class=\"listloweralpha\" style=\"list-style-type\: lower-alpha\;\">(.*?)<\/ul>/gi,"[list=a]$1[/list]");t(/<ul class=\"listupperalpha\" style=\"list-style-type\: upper-alpha\;\">(.*?)<\/ul>/gi,"[list=A]$1[/list]");t(/<li>(.*?)<\/li>/gi,"[li]$1[/li]");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 style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");t(/<u>/gi,"[u]");t(/<blockquote[^>]*>/gi,"[quote]");t(/<\/blockquote>/gi,"[/quote]");t(/<hr \/>/gi,"[hr]");t(/<br (.*?)\/>/gi,"\n");t(/<br \/>/gi,"\n");t(/<br>/gi,"\n");t(/<p>/gi,"");t(/<\/p>/gi,"\n");t(/&nbsp;|\u00a0/gi," ");t(/&quot;/gi,'"');t(/&lt;/gi,"<");t(/&gt;/gi,">");t(/&/gi,"&");t(/<div>/gi,"");t(/<\/div>/gi,"");if(i!=null){for(var s=0;s<i.length;s++){i[s]=i[s].replace("<code>","");i[s]=i[s].replace("</code>","");t(/\[\$!\$!CODEBLOCK!\$!\$\]/i,"[code]"+i[s]+"[/code]")}}return e},_dfrn_bbcode2html:function(e){function t(t,n){e=e.replace(t,n)}function n(t){return e.match(t)}function i(e,t){function n(t){e=t}t=bin2hex(t);$.ajax({url:"oembed/b2h?url="+t,async:false,success:n,dataType:"html"});return e}e=tinymce.trim(e);var r=n(/\[code\](.*?)\[\/code\]/gi);t(/\[code\](.*?)\[\/code\]/gi,"[$!$!CODEBLOCK!$!$]");t(/\n/gi,"<br />");t(/\[b\]/gi,"<strong>");t(/\[\/b\]/gi,"</strong>");t(/\[i\]/gi,"<em>");t(/\[\/i\]/gi,"</em>");t(/\[u\]/gi,"<u>");t(/\[\/u\]/gi,"</u>");t(/\[hr\]/gi,"<hr />");t(/\[bookmark=([^\]]+)\](.*?)\[\/bookmark\]/gi,'<a class="bookmark" href="$1">$2</a>');t(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,'<a href="$1">$2</a>');t(/\[url\](.*?)\[\/url\]/gi,'<a href="$1">$1</a>');t(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,'<img width="$1" height="$2" src="$3" />');t(/\[img\](.*?)\[\/img\]/gi,'<img src="$1" />');t(/\[list\](.*?)\[\/list\]/gi,'<ul class="listbullet" style="list-style-type: circle;">$1</ul>');t(/\[list=\](.*?)\[\/list\]/gi,'<ul class="listnone" style="list-style-type: none;">$1</ul>');t(/\[list=1\](.*?)\[\/list\]/gi,'<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');t(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');t(/\[list=I\](.*?)\[\/list\]/gi,'<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');t(/\[list=a\](.*?)\[\/list\]/gi,'<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');t(/\[list=A\](.*?)\[\/list\]/gi,'<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');t(/\[li\](.*?)\[\/li\]/gi,"<li>$1</li>");t(/\[color=(.*?)\](.*?)\[\/color\]/gi,'<span style="color: $1;">$2</span>');t(/\[size=(.*?)\](.*?)\[\/size\]/gi,'<span style="font-size: $1;">$2</span>');t(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");e=e.replace(/\[embed\](.*?)\[\/embed\]/gi,i);if(r!=null){for(var s=0;s<r.length;s++){r[s]=r[s].replace("[code]","");r[s]=r[s].replace("[/code]","");t(/\[\$!\$!CODEBLOCK!\$!\$\]/i,"<code>"+r[s]+"</code>")}}return e}});tinymce.PluginManager.add("bbcode",tinymce.plugins.BBCodePlugin)})()