4 |
4 |
5 (function() { |
5 (function() { |
6 var DOM = tinymce.DOM; |
6 var DOM = tinymce.DOM; |
7 |
7 |
8 tinymce.create('tinymce.plugins.WordPress', { |
8 tinymce.create('tinymce.plugins.WordPress', { |
|
9 mceTout : 0, |
|
10 |
9 init : function(ed, url) { |
11 init : function(ed, url) { |
10 var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2'), last = 0, moreHTML, nextpageHTML; |
12 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')+'" />'; |
13 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')+'" />'; |
14 nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />'; |
13 |
15 |
14 if ( getUserSetting('hidetb', '0') == '1' ) |
16 if ( getUserSetting('hidetb', '0') == '1' ) |
15 ed.settings.wordpress_adv_hidden = 0; |
17 ed.settings.wordpress_adv_hidden = 0; |
16 |
18 |
17 // Hides the specified toolbar and resizes the iframe |
19 // Hides the specified toolbar and resizes the iframe |
18 ed.onPostRender.add(function() { |
20 ed.onPostRender.add(function() { |
19 if ( ed.getParam('wordpress_adv_hidden', 1) ) { |
21 var adv_toolbar = ed.controlManager.get(tbId); |
20 DOM.hide(ed.controlManager.get(tbId).id); |
22 if ( ed.getParam('wordpress_adv_hidden', 1) && adv_toolbar ) { |
|
23 DOM.hide(adv_toolbar.id); |
21 t._resizeIframe(ed, tbId, 28); |
24 t._resizeIframe(ed, tbId, 28); |
22 } |
25 } |
23 }); |
26 }); |
24 |
27 |
25 // Register commands |
28 // Register commands |
39 inline : 1 |
42 inline : 1 |
40 }); |
43 }); |
41 }); |
44 }); |
42 |
45 |
43 ed.addCommand('WP_Adv', function() { |
46 ed.addCommand('WP_Adv', function() { |
44 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager; |
47 var cm = ed.controlManager, id = cm.get(tbId).id; |
45 |
48 |
46 if (DOM.isHidden(id)) { |
49 if ( 'undefined' == id ) |
|
50 return; |
|
51 |
|
52 if ( DOM.isHidden(id) ) { |
47 cm.setActive('wp_adv', 1); |
53 cm.setActive('wp_adv', 1); |
48 DOM.show(id); |
54 DOM.show(id); |
49 t._resizeIframe(ed, tbId, -28); |
55 t._resizeIframe(ed, tbId, -28); |
50 ed.settings.wordpress_adv_hidden = 0; |
56 ed.settings.wordpress_adv_hidden = 0; |
51 setUserSetting('hidetb', '1'); |
57 setUserSetting('hidetb', '1'); |
120 } |
126 } |
121 }); |
127 }); |
122 |
128 |
123 // Add Media buttons to fullscreen |
129 // Add Media buttons to fullscreen |
124 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { |
130 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { |
|
131 var DOM = tinymce.DOM; |
125 if ( 'mceFullScreen' != cmd ) return; |
132 if ( 'mceFullScreen' != cmd ) return; |
126 if ( 'mce_fullscreen' != ed.id ) |
133 if ( 'mce_fullscreen' != ed.id && DOM.get('add_audio') && DOM.get('add_video') && DOM.get('add_image') && DOM.get('add_media') ) |
127 ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media'; |
134 ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media'; |
128 }); |
135 }); |
129 |
136 |
130 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images. |
137 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images. |
131 ed.addCommand('JustifyLeft', function() { |
138 ed.addCommand('JustifyLeft', function() { |
158 if ( e.keyCode == last ) return; |
165 if ( e.keyCode == last ) return; |
159 if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) ); |
166 if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) ); |
160 last = e.keyCode; |
167 last = e.keyCode; |
161 }); |
168 }); |
162 }; |
169 }; |
|
170 |
|
171 ed.onSaveContent.add(function(ed, o) { |
|
172 if ( typeof(switchEditors) == 'object' ) { |
|
173 if ( ed.isHidden() ) |
|
174 o.content = o.element.value; |
|
175 else |
|
176 o.content = switchEditors.pre_wpautop(o.content); |
|
177 } |
|
178 }); |
|
179 |
|
180 /* disable for now |
|
181 ed.onBeforeSetContent.add(function(ed, o) { |
|
182 o.content = t._setEmbed(o.content); |
|
183 }); |
|
184 |
|
185 ed.onPostProcess.add(function(ed, o) { |
|
186 if ( o.get ) |
|
187 o.content = t._getEmbed(o.content); |
|
188 }); |
|
189 */ |
163 |
190 |
164 // Add listeners to handle more break |
191 // Add listeners to handle more break |
165 t._handleMoreBreak(ed, url); |
192 t._handleMoreBreak(ed, url); |
166 |
193 |
167 // Add custom shortcuts |
194 // Add custom shortcuts |
186 |
213 |
187 if ( tinymce.isWebKit ) { |
214 if ( tinymce.isWebKit ) { |
188 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold'); |
215 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold'); |
189 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic'); |
216 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic'); |
190 } |
217 } |
|
218 |
|
219 ed.onInit.add(function(ed) { |
|
220 tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) { |
|
221 ed.plugins.wordpress._hideButtons(); |
|
222 }); |
|
223 tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) { |
|
224 ed.plugins.wordpress._hideButtons(); |
|
225 }); |
|
226 }); |
|
227 |
|
228 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) { |
|
229 ed.plugins.wordpress._hideButtons(); |
|
230 }); |
|
231 |
|
232 ed.onSaveContent.add(function(ed, o) { |
|
233 ed.plugins.wordpress._hideButtons(); |
|
234 }); |
|
235 |
|
236 ed.onMouseDown.add(function(ed, e) { |
|
237 if ( e.target.nodeName != 'IMG' ) |
|
238 ed.plugins.wordpress._hideButtons(); |
|
239 }); |
191 }, |
240 }, |
192 |
241 |
193 getInfo : function() { |
242 getInfo : function() { |
194 return { |
243 return { |
195 longname : 'WordPress Plugin', |
244 longname : 'WordPress Plugin', |
199 version : '3.0' |
248 version : '3.0' |
200 }; |
249 }; |
201 }, |
250 }, |
202 |
251 |
203 // Internal functions |
252 // Internal functions |
|
253 _setEmbed : function(c) { |
|
254 return c.replace(/\[embed\]([\s\S]+?)\[\/embed\][\s\u00a0]*/g, function(a,b){ |
|
255 return '<img width="300" height="200" src="' + tinymce.baseURL + '/plugins/wordpress/img/trans.gif" class="wp-oembed mceItemNoResize" alt="'+b+'" title="'+b+'" />'; |
|
256 }); |
|
257 }, |
|
258 |
|
259 _getEmbed : function(c) { |
|
260 return c.replace(/<img[^>]+>/g, function(a) { |
|
261 if ( a.indexOf('class="wp-oembed') != -1 ) { |
|
262 var u = a.match(/alt="([^\"]+)"/); |
|
263 if ( u[1] ) |
|
264 a = '[embed]' + u[1] + '[/embed]'; |
|
265 } |
|
266 return a; |
|
267 }); |
|
268 }, |
|
269 |
|
270 _showButtons : function(n, id) { |
|
271 var ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y; |
|
272 |
|
273 vp = ed.dom.getViewPort(ed.getWin()); |
|
274 p1 = DOM.getPos(ed.getContentAreaContainer()); |
|
275 p2 = ed.dom.getPos(n); |
|
276 |
|
277 X = Math.max(p2.x - vp.x, 0) + p1.x; |
|
278 Y = Math.max(p2.y - vp.y, 0) + p1.y; |
|
279 |
|
280 DOM.setStyles(id, { |
|
281 'top' : Y+5+'px', |
|
282 'left' : X+5+'px', |
|
283 'display' : 'block' |
|
284 }); |
|
285 |
|
286 if ( this.mceTout ) |
|
287 clearTimeout(this.mceTout); |
|
288 |
|
289 this.mceTout = setTimeout( function(){ed.plugins.wordpress._hideButtons();}, 5000 ); |
|
290 }, |
|
291 |
|
292 _hideButtons : function() { |
|
293 if ( !this.mceTout ) |
|
294 return; |
|
295 |
|
296 if ( document.getElementById('wp_editbtns') ) |
|
297 tinymce.DOM.hide('wp_editbtns'); |
|
298 |
|
299 if ( document.getElementById('wp_gallerybtns') ) |
|
300 tinymce.DOM.hide('wp_gallerybtns'); |
|
301 |
|
302 clearTimeout(this.mceTout); |
|
303 this.mceTout = 0; |
|
304 }, |
|
305 |
204 do_align : function(n, a) { |
306 do_align : function(n, a) { |
205 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor; |
307 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor; |
206 |
308 |
207 if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) ) |
309 if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) ) |
208 return; |
310 return; |
237 ed.theme.deltaHeight += dy; // For resize cookie |
339 ed.theme.deltaHeight += dy; // For resize cookie |
238 }, |
340 }, |
239 |
341 |
240 _handleMoreBreak : function(ed, url) { |
342 _handleMoreBreak : function(ed, url) { |
241 var moreHTML, nextpageHTML; |
343 var moreHTML, nextpageHTML; |
242 |
344 |
243 moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />'; |
345 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')+'" />'; |
346 nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />'; |
245 |
347 |
246 // Load plugin specific CSS into editor |
348 // Load plugin specific CSS into editor |
247 ed.onInit.add(function() { |
349 ed.onInit.add(function() { |