1 | /**
|
---|
2 | * WordPress plugin.
|
---|
3 | */
|
---|
4 |
|
---|
5 | (function() {
|
---|
6 | var DOM = tinymce.DOM;
|
---|
7 |
|
---|
8 | tinymce.create('tinymce.plugins.WordPress', {
|
---|
9 | init : function(ed, url) {
|
---|
10 | var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2'), last = 0, moreHTML, nextpageHTML;
|
---|
11 | moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
|
---|
12 | nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
|
---|
13 |
|
---|
14 | if ( getUserSetting('hidetb', '0') == '1' )
|
---|
15 | ed.settings.wordpress_adv_hidden = 0;
|
---|
16 |
|
---|
17 | // Hides the specified toolbar and resizes the iframe
|
---|
18 | ed.onPostRender.add(function() {
|
---|
19 | if ( ed.getParam('wordpress_adv_hidden', 1) ) {
|
---|
20 | DOM.hide(ed.controlManager.get(tbId).id);
|
---|
21 | t._resizeIframe(ed, tbId, 28);
|
---|
22 | }
|
---|
23 | });
|
---|
24 |
|
---|
25 | // Register commands
|
---|
26 | ed.addCommand('WP_More', function() {
|
---|
27 | ed.execCommand('mceInsertContent', 0, moreHTML);
|
---|
28 | });
|
---|
29 |
|
---|
30 | ed.addCommand('WP_Page', function() {
|
---|
31 | ed.execCommand('mceInsertContent', 0, nextpageHTML);
|
---|
32 | });
|
---|
33 |
|
---|
34 | ed.addCommand('WP_Help', function() {
|
---|
35 | ed.windowManager.open({
|
---|
36 | url : tinymce.baseURL + '/wp-mce-help.php',
|
---|
37 | width : 450,
|
---|
38 | height : 420,
|
---|
39 | inline : 1
|
---|
40 | });
|
---|
41 | });
|
---|
42 |
|
---|
43 | ed.addCommand('WP_Adv', function() {
|
---|
44 | var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
|
---|
45 |
|
---|
46 | if (DOM.isHidden(id)) {
|
---|
47 | cm.setActive('wp_adv', 1);
|
---|
48 | DOM.show(id);
|
---|
49 | t._resizeIframe(ed, tbId, -28);
|
---|
50 | ed.settings.wordpress_adv_hidden = 0;
|
---|
51 | setUserSetting('hidetb', '1');
|
---|
52 | } else {
|
---|
53 | cm.setActive('wp_adv', 0);
|
---|
54 | DOM.hide(id);
|
---|
55 | t._resizeIframe(ed, tbId, 28);
|
---|
56 | ed.settings.wordpress_adv_hidden = 1;
|
---|
57 | setUserSetting('hidetb', '0');
|
---|
58 | }
|
---|
59 | });
|
---|
60 |
|
---|
61 | // Register buttons
|
---|
62 | ed.addButton('wp_more', {
|
---|
63 | title : 'wordpress.wp_more_desc',
|
---|
64 | image : url + '/img/more.gif',
|
---|
65 | cmd : 'WP_More'
|
---|
66 | });
|
---|
67 |
|
---|
68 | ed.addButton('wp_page', {
|
---|
69 | title : 'wordpress.wp_page_desc',
|
---|
70 | image : url + '/img/page.gif',
|
---|
71 | cmd : 'WP_Page'
|
---|
72 | });
|
---|
73 |
|
---|
74 | ed.addButton('wp_help', {
|
---|
75 | title : 'wordpress.wp_help_desc',
|
---|
76 | image : url + '/img/help.gif',
|
---|
77 | cmd : 'WP_Help'
|
---|
78 | });
|
---|
79 |
|
---|
80 | ed.addButton('wp_adv', {
|
---|
81 | title : 'wordpress.wp_adv_desc',
|
---|
82 | image : url + '/img/toolbars.gif',
|
---|
83 | cmd : 'WP_Adv'
|
---|
84 | });
|
---|
85 |
|
---|
86 | // Add Media buttons
|
---|
87 | ed.addButton('add_media', {
|
---|
88 | title : 'wordpress.add_media',
|
---|
89 | image : url + '/img/media.gif',
|
---|
90 | onclick : function() {
|
---|
91 | tb_show('', tinymce.DOM.get('add_media').href);
|
---|
92 | tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
|
---|
93 | }
|
---|
94 | });
|
---|
95 |
|
---|
96 | ed.addButton('add_image', {
|
---|
97 | title : 'wordpress.add_image',
|
---|
98 | image : url + '/img/image.gif',
|
---|
99 | onclick : function() {
|
---|
100 | tb_show('', tinymce.DOM.get('add_image').href);
|
---|
101 | tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
|
---|
102 | }
|
---|
103 | });
|
---|
104 |
|
---|
105 | ed.addButton('add_video', {
|
---|
106 | title : 'wordpress.add_video',
|
---|
107 | image : url + '/img/video.gif',
|
---|
108 | onclick : function() {
|
---|
109 | tb_show('', tinymce.DOM.get('add_video').href);
|
---|
110 | tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
|
---|
111 | }
|
---|
112 | });
|
---|
113 |
|
---|
114 | ed.addButton('add_audio', {
|
---|
115 | title : 'wordpress.add_audio',
|
---|
116 | image : url + '/img/audio.gif',
|
---|
117 | onclick : function() {
|
---|
118 | tb_show('', tinymce.DOM.get('add_audio').href);
|
---|
119 | tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
|
---|
120 | }
|
---|
121 | });
|
---|
122 |
|
---|
123 | // Add Media buttons to fullscreen
|
---|
124 | ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
|
---|
125 | if ( 'mceFullScreen' != cmd ) return;
|
---|
126 | if ( 'mce_fullscreen' != ed.id )
|
---|
127 | ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
|
---|
128 | });
|
---|
129 |
|
---|
130 | // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
|
---|
131 | ed.addCommand('JustifyLeft', function() {
|
---|
132 | var n = ed.selection.getNode();
|
---|
133 |
|
---|
134 | if ( n.nodeName != 'IMG' )
|
---|
135 | ed.editorCommands.mceJustify('JustifyLeft', 'left');
|
---|
136 | else ed.plugins.wordpress.do_align(n, 'alignleft');
|
---|
137 | });
|
---|
138 |
|
---|
139 | ed.addCommand('JustifyRight', function() {
|
---|
140 | var n = ed.selection.getNode();
|
---|
141 |
|
---|
142 | if ( n.nodeName != 'IMG' )
|
---|
143 | ed.editorCommands.mceJustify('JustifyRight', 'right');
|
---|
144 | else ed.plugins.wordpress.do_align(n, 'alignright');
|
---|
145 | });
|
---|
146 |
|
---|
147 | ed.addCommand('JustifyCenter', function() {
|
---|
148 | var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
|
---|
149 |
|
---|
150 | if ( n.nodeName == 'IMG' && ( P || DL ) )
|
---|
151 | ed.plugins.wordpress.do_align(n, 'aligncenter');
|
---|
152 | else ed.editorCommands.mceJustify('JustifyCenter', 'center');
|
---|
153 | });
|
---|
154 |
|
---|
155 | // Word count if script is loaded
|
---|
156 | if ( 'undefined' != typeof wpWordCount ) {
|
---|
157 | ed.onKeyUp.add(function(ed, e) {
|
---|
158 | if ( e.keyCode == last ) return;
|
---|
159 | if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) );
|
---|
160 | last = e.keyCode;
|
---|
161 | });
|
---|
162 | };
|
---|
163 |
|
---|
164 | // Add listeners to handle more break
|
---|
165 | t._handleMoreBreak(ed, url);
|
---|
166 |
|
---|
167 | // Add custom shortcuts
|
---|
168 | ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
|
---|
169 | ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
|
---|
170 | ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
|
---|
171 | ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
|
---|
172 | ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
|
---|
173 | ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
|
---|
174 | ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
|
---|
175 | ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
|
---|
176 | ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
|
---|
177 | ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
|
---|
178 | ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
|
---|
179 | ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
|
---|
180 | ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
|
---|
181 | ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
|
---|
182 | ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
|
---|
183 | ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
|
---|
184 | ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
|
---|
185 | ed.addShortcut('ctrl+s', ed.getLang('save_desc'), function(){if('function'==typeof autosave)autosave();});
|
---|
186 |
|
---|
187 | if ( tinymce.isWebKit ) {
|
---|
188 | ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
|
---|
189 | ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
|
---|
190 | }
|
---|
191 | },
|
---|
192 |
|
---|
193 | getInfo : function() {
|
---|
194 | return {
|
---|
195 | longname : 'WordPress Plugin',
|
---|
196 | author : 'WordPress', // add Moxiecode?
|
---|
197 | authorurl : 'http://wordpress.org',
|
---|
198 | infourl : 'http://wordpress.org',
|
---|
199 | version : '3.0'
|
---|
200 | };
|
---|
201 | },
|
---|
202 |
|
---|
203 | // Internal functions
|
---|
204 | do_align : function(n, a) {
|
---|
205 | var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
|
---|
206 |
|
---|
207 | if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) )
|
---|
208 | return;
|
---|
209 |
|
---|
210 | P = ed.dom.getParent(n, 'p');
|
---|
211 | DL = ed.dom.getParent(n, 'dl');
|
---|
212 | DIV = ed.dom.getParent(n, 'div');
|
---|
213 |
|
---|
214 | if ( DL && DIV ) {
|
---|
215 | cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a;
|
---|
216 | DL.className = DL.className.replace(/align[^ '"]+\s?/g, '');
|
---|
217 | ed.dom.addClass(DL, cls);
|
---|
218 | c = (cls == 'aligncenter') ? ed.dom.addClass(DIV, 'mceIEcenter') : ed.dom.removeClass(DIV, 'mceIEcenter');
|
---|
219 | } else if ( P ) {
|
---|
220 | cls = ed.dom.hasClass(n, a) ? 'alignnone' : a;
|
---|
221 | n.className = n.className.replace(/align[^ '"]+\s?/g, '');
|
---|
222 | ed.dom.addClass(n, cls);
|
---|
223 | if ( cls == 'aligncenter' )
|
---|
224 | ed.dom.setStyle(P, 'textAlign', 'center');
|
---|
225 | else if (P.style && P.style.textAlign == 'center')
|
---|
226 | ed.dom.setStyle(P, 'textAlign', '');
|
---|
227 | }
|
---|
228 |
|
---|
229 | ed.execCommand('mceRepaint');
|
---|
230 | },
|
---|
231 |
|
---|
232 | // Resizes the iframe by a relative height value
|
---|
233 | _resizeIframe : function(ed, tb_id, dy) {
|
---|
234 | var ifr = ed.getContentAreaContainer().firstChild;
|
---|
235 |
|
---|
236 | DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
|
---|
237 | ed.theme.deltaHeight += dy; // For resize cookie
|
---|
238 | },
|
---|
239 |
|
---|
240 | _handleMoreBreak : function(ed, url) {
|
---|
241 | var moreHTML, nextpageHTML;
|
---|
242 |
|
---|
243 | moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
|
---|
244 | nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
|
---|
245 |
|
---|
246 | // Load plugin specific CSS into editor
|
---|
247 | ed.onInit.add(function() {
|
---|
248 | ed.dom.loadCSS(url + '/css/content.css');
|
---|
249 | });
|
---|
250 |
|
---|
251 | // Display morebreak instead if img in element path
|
---|
252 | ed.onPostRender.add(function() {
|
---|
253 | if (ed.theme.onResolveName) {
|
---|
254 | ed.theme.onResolveName.add(function(th, o) {
|
---|
255 | if (o.node.nodeName == 'IMG') {
|
---|
256 | if ( ed.dom.hasClass(o.node, 'mceWPmore') )
|
---|
257 | o.name = 'wpmore';
|
---|
258 | if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
|
---|
259 | o.name = 'wppage';
|
---|
260 | }
|
---|
261 |
|
---|
262 | });
|
---|
263 | }
|
---|
264 | });
|
---|
265 |
|
---|
266 | // Replace morebreak with images
|
---|
267 | ed.onBeforeSetContent.add(function(ed, o) {
|
---|
268 | o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
|
---|
269 | o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
|
---|
270 | });
|
---|
271 |
|
---|
272 | // Replace images with morebreak
|
---|
273 | ed.onPostProcess.add(function(ed, o) {
|
---|
274 | if (o.get)
|
---|
275 | o.content = o.content.replace(/<img[^>]+>/g, function(im) {
|
---|
276 | if (im.indexOf('class="mceWPmore') !== -1) {
|
---|
277 | var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
|
---|
278 | im = '<!--more'+moretext+'-->';
|
---|
279 | }
|
---|
280 | if (im.indexOf('class="mceWPnextpage') !== -1)
|
---|
281 | im = '<!--nextpage-->';
|
---|
282 |
|
---|
283 | return im;
|
---|
284 | });
|
---|
285 | });
|
---|
286 |
|
---|
287 | // Set active buttons if user selected pagebreak or more break
|
---|
288 | ed.onNodeChange.add(function(ed, cm, n) {
|
---|
289 | cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
|
---|
290 | cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
|
---|
291 | });
|
---|
292 | }
|
---|
293 | });
|
---|
294 |
|
---|
295 | // Register plugin
|
---|
296 | tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
|
---|
297 | })();
|
---|