source: trunk/library/tiny_mce/plugins/bbcode/editor_plugin_src.js @ 4829

Revision 4829, 4.3 KB checked in by airton, 13 years ago (diff)

Ticket #2146 - Implementacao da funcionalidade de multiplas assinaturas - Adicao da biblioteca TinyMCE

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