Upgrade of TinyMCE is in progress.
[citadel.git] / webcit / tiny_mce / plugins / bbcode / editor_plugin_src.js
1 var TinyMCE_BBCodePlugin = {\r
2         getInfo : function() {\r
3                 return {\r
4                         longname : 'BBCode Plugin',\r
5                         author : 'Moxiecode Systems AB',\r
6                         authorurl : 'http://tinymce.moxiecode.com',\r
7                         infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',\r
8                         version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
9                 };\r
10         },\r
11 \r
12         cleanup : function(type, content) {\r
13                 var dialect = tinyMCE.getParam('bbcode_dialect', 'punbb').toLowerCase();\r
14 \r
15                 switch (type) {\r
16                         case "insert_to_editor":\r
17                                 content = this['_' + dialect + '_bbcode2html'](content);\r
18                                 break;\r
19 \r
20                         case "get_from_editor":\r
21                                 content = this['_' + dialect + '_html2bbcode'](content);\r
22                                 break;\r
23                 }\r
24 \r
25                 return content;\r
26         },\r
27 \r
28         // Private methods\r
29 \r
30         // HTML -> BBCode in PunBB dialect\r
31         _punbb_html2bbcode : function(s) {\r
32                 s = tinyMCE.trim(s);\r
33 \r
34                 function rep(re, str) {\r
35                         s = s.replace(re, str);\r
36                 };\r
37 \r
38                 // example: <strong> to [b]\r
39                 rep(/<a href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url]$1[/url]");\r
40                 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");\r
41                 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");\r
42                 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");\r
43                 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");\r
44                 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");\r
45                 rep(/<font>(.*?)<\/font>/gi,"$1");\r
46                 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
47                 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");\r
48                 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");\r
49                 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");\r
50                 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");\r
51                 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");\r
52                 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");\r
53                 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");\r
54                 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");\r
55                 rep(/<\/(strong|b)>/gi,"[/b]");\r
56                 rep(/<(strong|b)>/gi,"[b]");\r
57                 rep(/<\/(em|i)>/gi,"[/i]");\r
58                 rep(/<(em|i)>/gi,"[i]");\r
59                 rep(/<\/u>/gi,"[/u]");\r
60                 rep(/<u>/gi,"[u]");\r
61                 rep(/<br \/>/gi,"\n");\r
62                 rep(/<br\/>/gi,"\n");\r
63                 rep(/<br>/gi,"\n");\r
64                 rep(/<p>/gi,"");\r
65                 rep(/<\/p>/gi,"\n");\r
66                 rep(/&nbsp;/gi," ");\r
67                 rep(/&quot;/gi,"\"");\r
68                 rep(/&lt;/gi,"<");\r
69                 rep(/&gt;/gi,">");\r
70                 rep(/&amp;/gi,"&");\r
71                 rep(/&undefined;/gi,"'"); // quickfix\r
72 \r
73                 return s; \r
74         },\r
75 \r
76         // BBCode -> HTML from PunBB dialect\r
77         _punbb_bbcode2html : function(s) {\r
78                 s = tinyMCE.trim(s);\r
79 \r
80                 function rep(re, str) {\r
81                         s = s.replace(re, str);\r
82                 };\r
83 \r
84                 // example: [b] to <strong>\r
85                 rep(/\n/gi,"<br />");\r
86                 rep(/\[b\]/gi,"<strong>");\r
87                 rep(/\[\/b\]/gi,"</strong>");\r
88                 rep(/\[i\]/gi,"<em>");\r
89                 rep(/\[\/i\]/gi,"</em>");\r
90                 rep(/\[u\]/gi,"<u>");\r
91                 rep(/\[\/u\]/gi,"</u>");\r
92                 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");\r
93                 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");\r
94                 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");\r
95                 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");\r
96                 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");\r
97 \r
98                 return s; \r
99         }\r
100 };\r
101 \r
102 tinyMCE.addPlugin("bbcode", TinyMCE_BBCodePlugin);\r