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')+'" />';
14 if ( getUserSetting('hidetb', '0') == '1' )
15 ed.settings.wordpress_adv_hidden = 0;
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);
26 ed.addCommand('WP_More', function() {
27 ed.execCommand('mceInsertContent', 0, moreHTML);
30 ed.addCommand('WP_Page', function() {
31 ed.execCommand('mceInsertContent', 0, nextpageHTML);
34 ed.addCommand('WP_Help', function() {
35 ed.windowManager.open({
36 url : tinymce.baseURL + '/wp-mce-help.php',
43 ed.addCommand('WP_Adv', function() {
44 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
46 if (DOM.isHidden(id)) {
47 cm.setActive('wp_adv', 1);
49 t._resizeIframe(ed, tbId, -28);
50 ed.settings.wordpress_adv_hidden = 0;
51 setUserSetting('hidetb', '1');
53 cm.setActive('wp_adv', 0);
55 t._resizeIframe(ed, tbId, 28);
56 ed.settings.wordpress_adv_hidden = 1;
57 setUserSetting('hidetb', '0');
62 ed.addButton('wp_more', {
63 title : 'wordpress.wp_more_desc',
64 image : url + '/img/more.gif',
68 ed.addButton('wp_page', {
69 title : 'wordpress.wp_page_desc',
70 image : url + '/img/page.gif',
74 ed.addButton('wp_help', {
75 title : 'wordpress.wp_help_desc',
76 image : url + '/img/help.gif',
80 ed.addButton('wp_adv', {
81 title : 'wordpress.wp_adv_desc',
82 image : url + '/img/toolbars.gif',
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' );
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' );
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' );
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' );
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';
130 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
131 ed.addCommand('JustifyLeft', function() {
132 var n = ed.selection.getNode();
134 if ( n.nodeName != 'IMG' )
135 ed.editorCommands.mceJustify('JustifyLeft', 'left');
136 else ed.plugins.wordpress.do_align(n, 'alignleft');
139 ed.addCommand('JustifyRight', function() {
140 var n = ed.selection.getNode();
142 if ( n.nodeName != 'IMG' )
143 ed.editorCommands.mceJustify('JustifyRight', 'right');
144 else ed.plugins.wordpress.do_align(n, 'alignright');
147 ed.addCommand('JustifyCenter', function() {
148 var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
150 if ( n.nodeName == 'IMG' && ( P || DL ) )
151 ed.plugins.wordpress.do_align(n, 'aligncenter');
152 else ed.editorCommands.mceJustify('JustifyCenter', 'center');
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'}) );
164 // Add listeners to handle more break
165 t._handleMoreBreak(ed, url);
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();});
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');
193 getInfo : function() {
195 longname : 'WordPress Plugin',
196 author : 'WordPress', // add Moxiecode?
197 authorurl : 'http://wordpress.org',
198 infourl : 'http://wordpress.org',
203 // Internal functions
204 do_align : function(n, a) {
205 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
207 if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) )
210 P = ed.dom.getParent(n, 'p');
211 DL = ed.dom.getParent(n, 'dl');
212 DIV = ed.dom.getParent(n, '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');
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', '');
229 ed.execCommand('mceRepaint');
232 // Resizes the iframe by a relative height value
233 _resizeIframe : function(ed, tb_id, dy) {
234 var ifr = ed.getContentAreaContainer().firstChild;
236 DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
237 ed.theme.deltaHeight += dy; // For resize cookie
240 _handleMoreBreak : function(ed, url) {
241 var moreHTML, nextpageHTML;
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')+'" />';
246 // Load plugin specific CSS into editor
247 ed.onInit.add(function() {
248 ed.dom.loadCSS(url + '/css/content.css');
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') )
258 if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
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);
272 // Replace images with morebreak
273 ed.onPostProcess.add(function(ed, o) {
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+'-->';
280 if (im.indexOf('class="mceWPnextpage') !== -1)
281 im = '<!--nextpage-->';
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'));
296 tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);