]> git.mxchange.org Git - friendica.git/blob - tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js
added code, quote styles to editor
[friendica.git] / tinymce / jscripts / tiny_mce / plugins / bbcode / editor_plugin_src.js
1 /**\r
2  * editor_plugin_src.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  */\r
10 \r
11 /* Macgirvin Aug-2010 changed from punbb to dfrn dialect */\r
12 \r
13 (function() {\r
14         tinymce.create('tinymce.plugins.BBCodePlugin', {\r
15                 init : function(ed, url) {\r
16                         var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase();\r
17 \r
18                         ed.onBeforeSetContent.add(function(ed, o) {\r
19                                 o.content = t['_' + dialect + '_bbcode2html'](o.content);\r
20                         });\r
21 \r
22                         ed.onPostProcess.add(function(ed, o) {\r
23                                 if (o.set)\r
24                                         o.content = t['_' + dialect + '_bbcode2html'](o.content);\r
25 \r
26                                 if (o.get)\r
27                                         o.content = t['_' + dialect + '_html2bbcode'](o.content);\r
28                         });\r
29                 },\r
30 \r
31                 getInfo : function() {\r
32                         return {\r
33                                 longname : 'BBCode Plugin',\r
34                                 author : 'Moxiecode Systems AB',\r
35                                 authorurl : 'http://tinymce.moxiecode.com',\r
36                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',\r
37                                 version : tinymce.majorVersion + "." + tinymce.minorVersion\r
38                         };\r
39                 },\r
40 \r
41                 // Private methods\r
42 \r
43                 // HTML -> BBCode in DFRN dialect\r
44                 _dfrn_html2bbcode : function(s) {\r
45                         s = tinymce.trim(s);\r
46 \r
47                         function rep(re, str) {\r
48                                 s = s.replace(re, str);\r
49                         };\r
50 \r
51                         // example: <strong> to [b]\r
52                         rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");\r
53                         rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");\r
54                         rep(/<font>(.*?)<\/font>/gi,"$1");\r
55                         rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
56                         rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");\r
57                         rep(/<\/(strong|b)>/gi,"[/b]");\r
58                         rep(/<(strong|b)>/gi,"[b]");\r
59                         rep(/<\/(em|i)>/gi,"[/i]");\r
60                         rep(/<(em|i)>/gi,"[i]");\r
61                         rep(/<\/u>/gi,"[/u]");\r
62                         rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");\r
63                         rep(/<u>/gi,"[u]");\r
64                         rep(/<blockquote[^>]*>/gi,"[quote]");\r
65                         rep(/<\/blockquote>/gi,"[/quote]");\r
66                         rep(/<br \/>/gi,"\n");\r
67                         rep(/<br\/>/gi,"\n");\r
68                         rep(/<br>/gi,"\n");\r
69                         rep(/<p>/gi,"");\r
70                         rep(/<\/p>/gi,"\n");\r
71                         rep(/&nbsp;/gi," ");\r
72                         rep(/&quot;/gi,"\"");\r
73                         rep(/&lt;/gi,"<");\r
74                         rep(/&gt;/gi,">");\r
75                         rep(/&amp;/gi,"&");\r
76 \r
77                         return s; \r
78                 },\r
79 \r
80                 // BBCode -> HTML from DFRN dialect\r
81                 _dfrn_bbcode2html : function(s) {\r
82                         s = tinymce.trim(s);\r
83 \r
84                         function rep(re, str) {\r
85                                 s = s.replace(re, str);\r
86                         };\r
87 \r
88                         // example: [b] to <strong>\r
89                         rep(/\n/gi,"<br />");\r
90                         rep(/\[b\]/gi,"<strong>");\r
91                         rep(/\[\/b\]/gi,"</strong>");\r
92                         rep(/\[i\]/gi,"<em>");\r
93                         rep(/\[\/i\]/gi,"</em>");\r
94                         rep(/\[u\]/gi,"<u>");\r
95                         rep(/\[\/u\]/gi,"</u>");\r
96                         rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");\r
97                         rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");\r
98                         rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");\r
99                         rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");\r
100                         rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");\r
101                         rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");\r
102 \r
103                         return s; \r
104                 }\r
105         });\r
106 \r
107         // Register plugin\r
108         tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);\r
109 })();