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