]> git.mxchange.org Git - friendica.git/blob - tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js
Merge branch 'master' of git://github.com/friendika/friendika
[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(/<span style=\"color:(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");\r
55                         rep(/<font>(.*?)<\/font>/gi,"$1");\r
56                         rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
57                         rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");\r
58                         rep(/<\/(strong|b)>/gi,"[/b]");\r
59                         rep(/<(strong|b)>/gi,"[b]");\r
60                         rep(/<\/(em|i)>/gi,"[/i]");\r
61                         rep(/<(em|i)>/gi,"[i]");\r
62                         rep(/<\/u>/gi,"[/u]");\r
63                         rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");\r
64                         rep(/<u>/gi,"[u]");\r
65                         rep(/<blockquote[^>]*>/gi,"[quote]");\r
66                         rep(/<\/blockquote>/gi,"[/quote]");\r
67                         rep(/<br \/>/gi,"\n\n");\r
68                         rep(/<br\/>/gi,"\n\n");\r
69                         rep(/<br>/gi,"\n");\r
70                         rep(/<p>/gi,"");\r
71                         rep(/<\/p>/gi,"\n");\r
72                         rep(/&nbsp;/gi," ");\r
73                         rep(/&quot;/gi,"\"");\r
74                         rep(/&lt;/gi,"<");\r
75                         rep(/&gt;/gi,">");\r
76                         rep(/&amp;/gi,"&");\r
77 \r
78                         return s; \r
79                 },\r
80 \r
81                 // BBCode -> HTML from DFRN dialect\r
82                 _dfrn_bbcode2html : function(s) {\r
83                         s = tinymce.trim(s);\r
84 \r
85                         function rep(re, str) {\r
86                                 s = s.replace(re, str);\r
87                         };\r
88 \r
89                         // example: [b] to <strong>\r
90                         rep(/\n/gi,"<br />");\r
91                         rep(/\[b\]/gi,"<strong>");\r
92                         rep(/\[\/b\]/gi,"</strong>");\r
93                         rep(/\[i\]/gi,"<em>");\r
94                         rep(/\[\/i\]/gi,"</em>");\r
95                         rep(/\[u\]/gi,"<u>");\r
96                         rep(/\[\/u\]/gi,"</u>");\r
97                         rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");\r
98                         rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");\r
99                         rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");\r
100                         rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");\r
101 //                      rep(/\[\/code\]\s*\[code\]/gi,"<br />"); // fold multiline code\r
102                         rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");\r
103                         rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");\r
104 \r
105                         return s; \r
106                 }\r
107         });\r
108 \r
109         // Register plugin\r
110         tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);\r
111 })();