annotate WebContent/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js @ 5:0be9d53a6967

editor for annotations
author dwinter
date Tue, 13 Dec 2011 17:43:46 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 tinymce.create('tinymce.plugins.BBCodePlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 ed.onBeforeSetContent.add(function(ed, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 o.content = t['_' + dialect + '_bbcode2html'](o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 ed.onPostProcess.add(function(ed, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 if (o.set)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 o.content = t['_' + dialect + '_bbcode2html'](o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 if (o.get)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 o.content = t['_' + dialect + '_html2bbcode'](o.content);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 longname : 'BBCode Plugin',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 // Private methods
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 // HTML -> BBCode in PunBB dialect
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 _punbb_html2bbcode : function(s) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 s = tinymce.trim(s);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 function rep(re, str) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 s = s.replace(re, str);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 // example: <strong> to [b]
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 rep(/<font>(.*?)<\/font>/gi,"$1");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 rep(/<\/(strong|b)>/gi,"[/b]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 rep(/<(strong|b)>/gi,"[b]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 rep(/<\/(em|i)>/gi,"[/i]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 rep(/<(em|i)>/gi,"[i]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 rep(/<\/u>/gi,"[/u]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 rep(/<u>/gi,"[u]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 rep(/<blockquote[^>]*>/gi,"[quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 rep(/<\/blockquote>/gi,"[/quote]");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 rep(/<br \/>/gi,"\n");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 rep(/<br\/>/gi,"\n");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 rep(/<br>/gi,"\n");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 rep(/<p>/gi,"");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 rep(/<\/p>/gi,"\n");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 rep(/&nbsp;|\u00a0/gi," ");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 rep(/&quot;/gi,"\"");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 rep(/&lt;/gi,"<");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 rep(/&gt;/gi,">");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 rep(/&amp;/gi,"&");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 return s;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 // BBCode -> HTML from PunBB dialect
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 _punbb_bbcode2html : function(s) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 s = tinymce.trim(s);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 function rep(re, str) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 s = s.replace(re, str);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 // example: [b] to <strong>
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 rep(/\n/gi,"<br />");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 rep(/\[b\]/gi,"<strong>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 rep(/\[\/b\]/gi,"</strong>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 rep(/\[i\]/gi,"<em>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 rep(/\[\/i\]/gi,"</em>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 rep(/\[u\]/gi,"<u>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106 rep(/\[\/u\]/gi,"</u>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 return s;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 })();