includes/clientside/tinymce/plugins/bbcode/editor_plugin_src.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
--- a/includes/clientside/tinymce/plugins/bbcode/editor_plugin_src.js	Wed Dec 26 00:37:26 2007 -0500
+++ b/includes/clientside/tinymce/plugins/bbcode/editor_plugin_src.js	Thu Dec 27 22:09:33 2007 -0500
@@ -1,102 +1,115 @@
-var TinyMCE_BBCodePlugin = {
-	getInfo : function() {
-		return {
-			longname : 'BBCode Plugin',
-			author : 'Moxiecode Systems AB',
-			authorurl : 'http://tinymce.moxiecode.com',
-			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
-			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
-		};
-	},
+/**
+ * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
+ */
 
-	cleanup : function(type, content) {
-		var dialect = tinyMCE.getParam('bbcode_dialect', 'punbb').toLowerCase();
+(function() {
+	tinymce.create('tinymce.plugins.BBCodePlugin', {
+		init : function(ed, url) {
+			var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
+
+			ed.onBeforeSetContent.add(function(ed, o) {
+				o.content = t['_' + dialect + '_bbcode2html'](o.content);
+			});
+
+			ed.onPostProcess.add(function(ed, o) {
+				if (o.set)
+					o.content = t['_' + dialect + '_bbcode2html'](o.content);
 
-		switch (type) {
-			case "insert_to_editor":
-				content = this['_' + dialect + '_bbcode2html'](content);
-				break;
-
-			case "get_from_editor":
-				content = this['_' + dialect + '_html2bbcode'](content);
-				break;
-		}
+				if (o.get)
+					o.content = t['_' + dialect + '_html2bbcode'](o.content);
+			});
+		},
 
-		return content;
-	},
-
-	// Private methods
+		getInfo : function() {
+			return {
+				longname : 'BBCode Plugin',
+				author : 'Moxiecode Systems AB',
+				authorurl : 'http://tinymce.moxiecode.com',
+				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
+				version : tinymce.majorVersion + "." + tinymce.minorVersion
+			};
+		},
 
-	// HTML -> BBCode in PunBB dialect
-	_punbb_html2bbcode : function(s) {
-		s = tinyMCE.trim(s);
+		// Private methods
 
-		function rep(re, str) {
-			s = s.replace(re, str);
-		};
+		// HTML -> BBCode in PunBB dialect
+		_punbb_html2bbcode : function(s) {
+			s = tinymce.trim(s);
+
+			function rep(re, str) {
+				s = s.replace(re, str);
+			};
 
-		// example: <strong> to [b]
-		rep(/<a href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url]$1[/url]");
-		rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
-		rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
-		rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
-		rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
-		rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
-		rep(/<font>(.*?)<\/font>/gi,"$1");
-		rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
-		rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
-		rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
-		rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
-		rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
-		rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
-		rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
-		rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
-		rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
-		rep(/<\/(strong|b)>/gi,"[/b]");
-		rep(/<(strong|b)>/gi,"[b]");
-		rep(/<\/(em|i)>/gi,"[/i]");
-		rep(/<(em|i)>/gi,"[i]");
-		rep(/<\/u>/gi,"[/u]");
-		rep(/<u>/gi,"[u]");
-		rep(/<br \/>/gi,"\n");
-		rep(/<br\/>/gi,"\n");
-		rep(/<br>/gi,"\n");
-		rep(/<p>/gi,"");
-		rep(/<\/p>/gi,"\n");
-		rep(/&nbsp;/gi," ");
-		rep(/&quot;/gi,"\"");
-		rep(/&lt;/gi,"<");
-		rep(/&gt;/gi,">");
-		rep(/&amp;/gi,"&");
-		rep(/&undefined;/gi,"'"); // quickfix
+			// example: <strong> to [b]
+			rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
+			rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
+			rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
+			rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
+			rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
+			rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
+			rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
+			rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
+			rep(/<font>(.*?)<\/font>/gi,"$1");
+			rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
+			rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
+			rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
+			rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
+			rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
+			rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
+			rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
+			rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
+			rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
+			rep(/<\/(strong|b)>/gi,"[/b]");
+			rep(/<(strong|b)>/gi,"[b]");
+			rep(/<\/(em|i)>/gi,"[/i]");
+			rep(/<(em|i)>/gi,"[i]");
+			rep(/<\/u>/gi,"[/u]");
+			rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
+			rep(/<u>/gi,"[u]");
+			rep(/<br \/>/gi,"\n");
+			rep(/<br\/>/gi,"\n");
+			rep(/<br>/gi,"\n");
+			rep(/<p>/gi,"");
+			rep(/<\/p>/gi,"\n");
+			rep(/&nbsp;/gi," ");
+			rep(/&quot;/gi,"\"");
+			rep(/&lt;/gi,"<");
+			rep(/&gt;/gi,">");
+			rep(/&amp;/gi,"&");
 
-		return s; 
-	},
+			return s; 
+		},
 
-	// BBCode -> HTML from PunBB dialect
-	_punbb_bbcode2html : function(s) {
-		s = tinyMCE.trim(s);
+		// BBCode -> HTML from PunBB dialect
+		_punbb_bbcode2html : function(s) {
+			s = tinymce.trim(s);
 
-		function rep(re, str) {
-			s = s.replace(re, str);
-		};
+			function rep(re, str) {
+				s = s.replace(re, str);
+			};
 
-		// example: [b] to <strong>
-		rep(/\n/gi,"<br />");
-		rep(/\[b\]/gi,"<strong>");
-		rep(/\[\/b\]/gi,"</strong>");
-		rep(/\[i\]/gi,"<em>");
-		rep(/\[\/i\]/gi,"</em>");
-		rep(/\[u\]/gi,"<u>");
-		rep(/\[\/u\]/gi,"</u>");
-		rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
-		rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
-		rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
-		rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
-		rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
+			// example: [b] to <strong>
+			rep(/\n/gi,"<br />");
+			rep(/\[b\]/gi,"<strong>");
+			rep(/\[\/b\]/gi,"</strong>");
+			rep(/\[i\]/gi,"<em>");
+			rep(/\[\/i\]/gi,"</em>");
+			rep(/\[u\]/gi,"<u>");
+			rep(/\[\/u\]/gi,"</u>");
+			rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
+			rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
+			rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
+			rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
+			rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
+			rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
 
-		return s; 
-	}
-};
+			return s; 
+		}
+	});
 
-tinyMCE.addPlugin("bbcode", TinyMCE_BBCodePlugin);
+	// Register plugin
+	tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
+})();
\ No newline at end of file