annotate media/js/tiny_mce/plugins/bbcode/editor_plugin_src.js @ 260:3a4bbf9c2cce

Fixing #107. Apparently some signal handlers were getting connected twice (double import?) and thus saving a forum post would cause 2 email notifications to go out to the post topic's subscribers. Use the dispatch_uid parameter in the connect call to work around this issue.
author Brian Neal <bgneal@gmail.com>
date Wed, 22 Sep 2010 00:24:59 +0000
parents 149c3567fec1
children
rev   line source
bgneal@45 1 /**
bgneal@183 2 * editor_plugin_src.js
bgneal@45 3 *
bgneal@183 4 * Copyright 2009, Moxiecode Systems AB
bgneal@183 5 * Released under LGPL License.
bgneal@183 6 *
bgneal@183 7 * License: http://tinymce.moxiecode.com/license
bgneal@183 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@45 9 */
bgneal@45 10
bgneal@45 11 (function() {
bgneal@45 12 tinymce.create('tinymce.plugins.BBCodePlugin', {
bgneal@45 13 init : function(ed, url) {
bgneal@45 14 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
bgneal@45 15
bgneal@45 16 ed.onBeforeSetContent.add(function(ed, o) {
bgneal@45 17 o.content = t['_' + dialect + '_bbcode2html'](o.content);
bgneal@45 18 });
bgneal@45 19
bgneal@45 20 ed.onPostProcess.add(function(ed, o) {
bgneal@45 21 if (o.set)
bgneal@45 22 o.content = t['_' + dialect + '_bbcode2html'](o.content);
bgneal@45 23
bgneal@45 24 if (o.get)
bgneal@45 25 o.content = t['_' + dialect + '_html2bbcode'](o.content);
bgneal@45 26 });
bgneal@45 27 },
bgneal@45 28
bgneal@45 29 getInfo : function() {
bgneal@45 30 return {
bgneal@45 31 longname : 'BBCode Plugin',
bgneal@45 32 author : 'Moxiecode Systems AB',
bgneal@45 33 authorurl : 'http://tinymce.moxiecode.com',
bgneal@45 34 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
bgneal@45 35 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@45 36 };
bgneal@45 37 },
bgneal@45 38
bgneal@45 39 // Private methods
bgneal@45 40
bgneal@45 41 // HTML -> BBCode in PunBB dialect
bgneal@45 42 _punbb_html2bbcode : function(s) {
bgneal@45 43 s = tinymce.trim(s);
bgneal@45 44
bgneal@45 45 function rep(re, str) {
bgneal@45 46 s = s.replace(re, str);
bgneal@45 47 };
bgneal@45 48
bgneal@45 49 // example: <strong> to [b]
bgneal@45 50 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
bgneal@45 51 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
bgneal@45 52 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
bgneal@45 53 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
bgneal@45 54 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
bgneal@45 55 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
bgneal@45 56 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
bgneal@45 57 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
bgneal@45 58 rep(/<font>(.*?)<\/font>/gi,"$1");
bgneal@45 59 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
bgneal@45 60 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
bgneal@45 61 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
bgneal@45 62 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
bgneal@45 63 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
bgneal@45 64 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
bgneal@45 65 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
bgneal@45 66 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
bgneal@45 67 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
bgneal@45 68 rep(/<\/(strong|b)>/gi,"[/b]");
bgneal@45 69 rep(/<(strong|b)>/gi,"[b]");
bgneal@45 70 rep(/<\/(em|i)>/gi,"[/i]");
bgneal@45 71 rep(/<(em|i)>/gi,"[i]");
bgneal@45 72 rep(/<\/u>/gi,"[/u]");
bgneal@45 73 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
bgneal@45 74 rep(/<u>/gi,"[u]");
bgneal@45 75 rep(/<blockquote[^>]*>/gi,"[quote]");
bgneal@45 76 rep(/<\/blockquote>/gi,"[/quote]");
bgneal@45 77 rep(/<br \/>/gi,"\n");
bgneal@45 78 rep(/<br\/>/gi,"\n");
bgneal@45 79 rep(/<br>/gi,"\n");
bgneal@45 80 rep(/<p>/gi,"");
bgneal@45 81 rep(/<\/p>/gi,"\n");
bgneal@45 82 rep(/&nbsp;/gi," ");
bgneal@45 83 rep(/&quot;/gi,"\"");
bgneal@45 84 rep(/&lt;/gi,"<");
bgneal@45 85 rep(/&gt;/gi,">");
bgneal@45 86 rep(/&amp;/gi,"&");
bgneal@45 87
bgneal@45 88 return s;
bgneal@45 89 },
bgneal@45 90
bgneal@45 91 // BBCode -> HTML from PunBB dialect
bgneal@45 92 _punbb_bbcode2html : function(s) {
bgneal@45 93 s = tinymce.trim(s);
bgneal@45 94
bgneal@45 95 function rep(re, str) {
bgneal@45 96 s = s.replace(re, str);
bgneal@45 97 };
bgneal@45 98
bgneal@45 99 // example: [b] to <strong>
bgneal@45 100 rep(/\n/gi,"<br />");
bgneal@45 101 rep(/\[b\]/gi,"<strong>");
bgneal@45 102 rep(/\[\/b\]/gi,"</strong>");
bgneal@45 103 rep(/\[i\]/gi,"<em>");
bgneal@45 104 rep(/\[\/i\]/gi,"</em>");
bgneal@45 105 rep(/\[u\]/gi,"<u>");
bgneal@45 106 rep(/\[\/u\]/gi,"</u>");
bgneal@45 107 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
bgneal@45 108 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
bgneal@45 109 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
bgneal@45 110 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
bgneal@45 111 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
bgneal@45 112 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
bgneal@45 113
bgneal@45 114 return s;
bgneal@45 115 }
bgneal@45 116 });
bgneal@45 117
bgneal@45 118 // Register plugin
bgneal@45 119 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
bgneal@45 120 })();