8 // Load plugin specific language pack
9 tinymce.PluginManager.requireLangPack('wordpress');
11 tinymce.create('tinymce.plugins.WordPress', {
12 init : function(ed, url) {
13 var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2');
14 var moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
15 var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
17 if ( getUserSetting('hidetb', '0') == '1' )
18 ed.settings.wordpress_adv_hidden = 0;
20 // Hides the specified toolbar and resizes the iframe
21 ed.onPostRender.add(function() {
22 if ( ed.getParam('wordpress_adv_hidden', 1) ) {
23 DOM.hide(ed.controlManager.get(tbId).id);
24 t._resizeIframe(ed, tbId, 28);
29 ed.addCommand('WP_More', function() {
30 ed.execCommand('mceInsertContent', 0, moreHTML);
33 ed.addCommand('WP_Page', function() {
34 ed.execCommand('mceInsertContent', 0, nextpageHTML);
37 ed.addCommand('WP_Help', function() {
38 ed.windowManager.open({
39 url : tinymce.baseURL + '/wp-mce-help.php',
46 ed.addCommand('WP_Adv', function() {
47 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
49 if (DOM.isHidden(id)) {
50 cm.setActive('wp_adv', 1);
52 t._resizeIframe(ed, tbId, -28);
53 ed.settings.wordpress_adv_hidden = 0;
54 setUserSetting('hidetb', '1');
56 cm.setActive('wp_adv', 0);
58 t._resizeIframe(ed, tbId, 28);
59 ed.settings.wordpress_adv_hidden = 1;
60 setUserSetting('hidetb', '0');
65 ed.addButton('wp_more', {
66 title : 'wordpress.wp_more_desc',
67 image : url + '/img/more.gif',
71 ed.addButton('wp_page', {
72 title : 'wordpress.wp_page_desc',
73 image : url + '/img/page.gif',
77 ed.addButton('wp_help', {
78 title : 'wordpress.wp_help_desc',
79 image : url + '/img/help.gif',
83 ed.addButton('wp_adv', {
84 title : 'wordpress.wp_adv_desc',
85 image : url + '/img/toolbars.gif',
90 ed.addButton('add_media', {
91 title : 'wordpress.add_media',
92 image : url + '/img/media.gif',
93 onclick : function() {
94 tb_show('', tinymce.DOM.get('add_media').href);
95 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
99 ed.addButton('add_image', {
100 title : 'wordpress.add_image',
101 image : url + '/img/image.gif',
102 onclick : function() {
103 tb_show('', tinymce.DOM.get('add_image').href);
104 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
108 ed.addButton('add_video', {
109 title : 'wordpress.add_video',
110 image : url + '/img/video.gif',
111 onclick : function() {
112 tb_show('', tinymce.DOM.get('add_video').href);
113 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
117 ed.addButton('add_audio', {
118 title : 'wordpress.add_audio',
119 image : url + '/img/audio.gif',
120 onclick : function() {
121 tb_show('', tinymce.DOM.get('add_audio').href);
122 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
126 // Add Media buttons to fullscreen
127 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
128 if ( 'mceFullScreen' != cmd ) return;
129 if ( 'mce_fullscreen' != ed.id )
130 ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
133 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
134 ed.addCommand('JustifyLeft', function() {
135 var n = ed.selection.getNode();
137 if ( n.nodeName != 'IMG' )
138 ed.editorCommands.mceJustify('JustifyLeft', 'left');
139 else ed.plugins.wordpress.do_align(n, 'alignleft');
142 ed.addCommand('JustifyRight', function() {
143 var n = ed.selection.getNode();
145 if ( n.nodeName != 'IMG' )
146 ed.editorCommands.mceJustify('JustifyRight', 'right');
147 else ed.plugins.wordpress.do_align(n, 'alignright');
150 ed.addCommand('JustifyCenter', function() {
151 var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
153 if ( n.nodeName == 'IMG' && ( P || DL ) )
154 ed.plugins.wordpress.do_align(n, 'aligncenter');
155 else ed.editorCommands.mceJustify('JustifyCenter', 'center');
158 // Word count if script is loaded
159 if ( 'undefined' != typeof wpWordCount ) {
161 ed.onKeyUp.add(function(ed, e) {
162 if ( e.keyCode == last ) return;
163 if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) );
168 // Add listeners to handle more break
169 t._handleMoreBreak(ed, url);
171 // Add custom shortcuts
172 ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
173 ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
174 ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
175 ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
176 ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
177 ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
178 ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
179 ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
180 ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
181 ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
182 ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
183 ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
184 ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
185 ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
186 ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
187 ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
188 ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
190 if ( tinymce.isWebKit ) {
191 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
192 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
196 getInfo : function() {
198 longname : 'WordPress Plugin',
199 author : 'WordPress', // add Moxiecode?
200 authorurl : 'http://wordpress.org',
201 infourl : 'http://wordpress.org',
206 // Internal functions
207 do_align : function(n, a) {
208 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
210 if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) )
213 P = ed.dom.getParent(n, 'p');
214 DL = ed.dom.getParent(n, 'dl');
215 DIV = ed.dom.getParent(n, 'div');
218 cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a;
219 DL.className = DL.className.replace(/align[^ '"]+\s?/g, '');
220 ed.dom.addClass(DL, cls);
221 c = (cls == 'aligncenter') ? ed.dom.addClass(DIV, 'mceIEcenter') : ed.dom.removeClass(DIV, 'mceIEcenter');
223 cls = ed.dom.hasClass(n, a) ? 'alignnone' : a;
224 n.className = n.className.replace(/align[^ '"]+\s?/g, '');
225 ed.dom.addClass(n, cls);
226 if ( cls == 'aligncenter' )
227 ed.dom.setStyle(P, 'textAlign', 'center');
228 else if (P.style && P.style.textAlign == 'center')
229 ed.dom.setStyle(P, 'textAlign', '');
232 ed.execCommand('mceRepaint');
235 // Resizes the iframe by a relative height value
236 _resizeIframe : function(ed, tb_id, dy) {
237 var ifr = ed.getContentAreaContainer().firstChild;
239 DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
240 ed.theme.deltaHeight += dy; // For resize cookie
243 _handleMoreBreak : function(ed, url) {
244 var moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
245 var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
247 // Load plugin specific CSS into editor
248 ed.onInit.add(function() {
249 ed.dom.loadCSS(url + '/css/content.css');
252 // Display morebreak instead if img in element path
253 ed.onPostRender.add(function() {
254 if (ed.theme.onResolveName) {
255 ed.theme.onResolveName.add(function(th, o) {
256 if (o.node.nodeName == 'IMG') {
257 if ( ed.dom.hasClass(o.node, 'mceWPmore') )
259 if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
267 // Replace morebreak with images
268 ed.onBeforeSetContent.add(function(ed, o) {
269 o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
270 o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
273 // Replace images with morebreak
274 ed.onPostProcess.add(function(ed, o) {
276 o.content = o.content.replace(/<img[^>]+>/g, function(im) {
277 if (im.indexOf('class="mceWPmore') !== -1) {
278 var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
279 im = '<!--more'+moretext+'-->';
281 if (im.indexOf('class="mceWPnextpage') !== -1)
282 im = '<!--nextpage-->';
288 // Set active buttons if user selected pagebreak or more break
289 ed.onNodeChange.add(function(ed, cm, n) {
290 cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
291 cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
297 tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);