]> code.citadel.org Git - citadel.git/blobdiff - webcit/tiny_mce/plugins/bbcode/editor_plugin_src.js
Upgrade of TinyMCE is in progress.
[citadel.git] / webcit / tiny_mce / plugins / bbcode / editor_plugin_src.js
diff --git a/webcit/tiny_mce/plugins/bbcode/editor_plugin_src.js b/webcit/tiny_mce/plugins/bbcode/editor_plugin_src.js
new file mode 100755 (executable)
index 0000000..1d38317
--- /dev/null
@@ -0,0 +1,102 @@
+var TinyMCE_BBCodePlugin = {\r
+       getInfo : function() {\r
+               return {\r
+                       longname : 'BBCode Plugin',\r
+                       author : 'Moxiecode Systems AB',\r
+                       authorurl : 'http://tinymce.moxiecode.com',\r
+                       infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',\r
+                       version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
+               };\r
+       },\r
+\r
+       cleanup : function(type, content) {\r
+               var dialect = tinyMCE.getParam('bbcode_dialect', 'punbb').toLowerCase();\r
+\r
+               switch (type) {\r
+                       case "insert_to_editor":\r
+                               content = this['_' + dialect + '_bbcode2html'](content);\r
+                               break;\r
+\r
+                       case "get_from_editor":\r
+                               content = this['_' + dialect + '_html2bbcode'](content);\r
+                               break;\r
+               }\r
+\r
+               return content;\r
+       },\r
+\r
+       // Private methods\r
+\r
+       // HTML -> BBCode in PunBB dialect\r
+       _punbb_html2bbcode : function(s) {\r
+               s = tinyMCE.trim(s);\r
+\r
+               function rep(re, str) {\r
+                       s = s.replace(re, str);\r
+               };\r
+\r
+               // example: <strong> to [b]\r
+               rep(/<a href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url]$1[/url]");\r
+               rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");\r
+               rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");\r
+               rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");\r
+               rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");\r
+               rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");\r
+               rep(/<font>(.*?)<\/font>/gi,"$1");\r
+               rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
+               rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");\r
+               rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");\r
+               rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");\r
+               rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");\r
+               rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");\r
+               rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");\r
+               rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");\r
+               rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");\r
+               rep(/<\/(strong|b)>/gi,"[/b]");\r
+               rep(/<(strong|b)>/gi,"[b]");\r
+               rep(/<\/(em|i)>/gi,"[/i]");\r
+               rep(/<(em|i)>/gi,"[i]");\r
+               rep(/<\/u>/gi,"[/u]");\r
+               rep(/<u>/gi,"[u]");\r
+               rep(/<br \/>/gi,"\n");\r
+               rep(/<br\/>/gi,"\n");\r
+               rep(/<br>/gi,"\n");\r
+               rep(/<p>/gi,"");\r
+               rep(/<\/p>/gi,"\n");\r
+               rep(/&nbsp;/gi," ");\r
+               rep(/&quot;/gi,"\"");\r
+               rep(/&lt;/gi,"<");\r
+               rep(/&gt;/gi,">");\r
+               rep(/&amp;/gi,"&");\r
+               rep(/&undefined;/gi,"'"); // quickfix\r
+\r
+               return s; \r
+       },\r
+\r
+       // BBCode -> HTML from PunBB dialect\r
+       _punbb_bbcode2html : function(s) {\r
+               s = tinyMCE.trim(s);\r
+\r
+               function rep(re, str) {\r
+                       s = s.replace(re, str);\r
+               };\r
+\r
+               // example: [b] to <strong>\r
+               rep(/\n/gi,"<br />");\r
+               rep(/\[b\]/gi,"<strong>");\r
+               rep(/\[\/b\]/gi,"</strong>");\r
+               rep(/\[i\]/gi,"<em>");\r
+               rep(/\[\/i\]/gi,"</em>");\r
+               rep(/\[u\]/gi,"<u>");\r
+               rep(/\[\/u\]/gi,"</u>");\r
+               rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");\r
+               rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");\r
+               rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");\r
+               rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");\r
+               rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");\r
+\r
+               return s; \r
+       }\r
+};\r
+\r
+tinyMCE.addPlugin("bbcode", TinyMCE_BBCodePlugin);\r