1 | (function() { |
---|
2 | tinymce.create('tinymce.plugins.dcwiki',{ |
---|
3 | // Init. |
---|
4 | init: function(ed, url) { |
---|
5 | var t = this; |
---|
6 | |
---|
7 | t.editor = ed; |
---|
8 | |
---|
9 | ed.onBeforeSetContent.add(function(ed,o) { |
---|
10 | o.content = t._wiki2html(o.content); |
---|
11 | }); |
---|
12 | ed.onPostProcess.add(function(ed, o) { |
---|
13 | if (o.set) |
---|
14 | o.content = t._wiki2html(o.content); |
---|
15 | if (o.get) |
---|
16 | o.content = t._html2wiki(o.content); |
---|
17 | }); |
---|
18 | |
---|
19 | // Register commands |
---|
20 | ed.addCommand('Bold', function() { |
---|
21 | var s = ed.selection.getContent(); |
---|
22 | var res = '__' + s + '__'; |
---|
23 | |
---|
24 | ed.execCommand('mceInsertContent',false,res); |
---|
25 | }); |
---|
26 | ed.addCommand('Italic', function() { |
---|
27 | var s = ed.selection.getContent(); |
---|
28 | var res = "''" + s + "''"; |
---|
29 | |
---|
30 | ed.execCommand('mceInsertContent',false,res); |
---|
31 | }); |
---|
32 | ed.addCommand('Underline', function() { |
---|
33 | var s = ed.selection.getContent(); |
---|
34 | var res = '++' + s + '++'; |
---|
35 | |
---|
36 | ed.execCommand('mceInsertContent',false,res); |
---|
37 | }); |
---|
38 | ed.addCommand('Strikethrough', function() { |
---|
39 | var s = ed.selection.getContent(); |
---|
40 | var res = '--' + s + '--'; |
---|
41 | |
---|
42 | ed.execCommand('mceInsertContent',false,res); |
---|
43 | }); |
---|
44 | ed.addCommand('mceBlockQuote', function() { |
---|
45 | var s = ed.selection.getContent(); |
---|
46 | var res = '<br />> ' + s; |
---|
47 | |
---|
48 | ed.execCommand('mceInsertContent',false,res); |
---|
49 | }); |
---|
50 | ed.addCommand('InsertUnorderedList', function() { |
---|
51 | var s = ed.selection.getContent(); |
---|
52 | var res = '*' + s; |
---|
53 | |
---|
54 | ed.execCommand('mceInsertContent',false,res); |
---|
55 | }); |
---|
56 | ed.addCommand('InsertOrderedList', function() { |
---|
57 | var s = ed.selection.getContent(); |
---|
58 | var res = '#' + s; |
---|
59 | |
---|
60 | ed.execCommand('mceInsertContent',false,res); |
---|
61 | }); |
---|
62 | |
---|
63 | ed.addCommand('dcCode', function() { |
---|
64 | var s = ed.selection.getContent(); |
---|
65 | var res = '@@' + s + '@@'; |
---|
66 | |
---|
67 | ed.execCommand('mceInsertContent',false,res); |
---|
68 | }); |
---|
69 | ed.addCommand('dcQuote', function() { |
---|
70 | var s = ed.selection.getContent(); |
---|
71 | var res = '{{' + s + '}}'; |
---|
72 | |
---|
73 | ed.execCommand('mceInsertContent',false,res); |
---|
74 | }); |
---|
75 | }, |
---|
76 | |
---|
77 | getInfo: function() { |
---|
78 | return { |
---|
79 | longname: 'Dotclear wiki controls', |
---|
80 | author: 'Tomtom for dotclear', |
---|
81 | authorurl: 'http://dotclear.org', |
---|
82 | infourl: '', |
---|
83 | version: tinymce.majorVersion + "." + tinymce.minorVersion |
---|
84 | }; |
---|
85 | }, |
---|
86 | |
---|
87 | // HTML -> Dotclear wiki |
---|
88 | _html2wiki : function(s) { |
---|
89 | s = tinymce.trim(s); |
---|
90 | |
---|
91 | function rep(re, str) { |
---|
92 | s = s.replace(re, str); |
---|
93 | }; |
---|
94 | |
---|
95 | rep(/<br(\s*\/)?>/gi,"\n"); |
---|
96 | rep(/</gi,'<'); |
---|
97 | rep(/>/gi,'>'); |
---|
98 | |
---|
99 | return s; |
---|
100 | }, |
---|
101 | |
---|
102 | // Dotclear wiki -> HTML |
---|
103 | _wiki2html : function(s) { |
---|
104 | s = tinymce.trim(s); |
---|
105 | |
---|
106 | function rep(re, str) { |
---|
107 | s = s.replace(re, str); |
---|
108 | }; |
---|
109 | |
---|
110 | rep(/</gi,'<'); |
---|
111 | rep(/>/gi,'>'); |
---|
112 | rep(/\n/g,'<br />'); |
---|
113 | |
---|
114 | return s; |
---|
115 | } |
---|
116 | }); |
---|
117 | |
---|
118 | // Register plugin |
---|
119 | tinymce.PluginManager.add('dcwiki',tinymce.plugins.dcwiki); |
---|
120 | })(); |
---|