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 ( tinymce.util.Cookie.get('kitchenSink') == '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, cook = tinymce.util.Cookie, date;
50 date.setTime(date.getTime()+(10*365*24*60*60*1000));
52 if (DOM.isHidden(id)) {
53 cm.setActive('wp_adv', 1);
55 t._resizeIframe(ed, tbId, -28);
56 ed.settings.wordpress_adv_hidden = 0;
57 cook.set('kitchenSink', '1', date);
59 cm.setActive('wp_adv', 0);
61 t._resizeIframe(ed, tbId, 28);
62 ed.settings.wordpress_adv_hidden = 1;
63 cook.set('kitchenSink', '0', date);
68 ed.addButton('wp_more', {
69 title : 'wordpress.wp_more_desc',
70 image : url + '/img/more.gif',
74 ed.addButton('wp_page', {
75 title : 'wordpress.wp_page_desc',
76 image : url + '/img/page.gif',
80 ed.addButton('wp_help', {
81 title : 'wordpress.wp_help_desc',
82 image : url + '/img/help.gif',
86 ed.addButton('wp_adv', {
87 title : 'wordpress.wp_adv_desc',
88 image : url + '/img/toolbars.gif',
93 ed.addButton('add_media', {
94 title : 'wordpress.add_media',
95 image : url + '/img/media.gif',
96 onclick : function() {
97 tb_show('', tinymce.DOM.get('add_media').href);
98 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
102 ed.addButton('add_image', {
103 title : 'wordpress.add_image',
104 image : url + '/img/image.gif',
105 onclick : function() {
106 tb_show('', tinymce.DOM.get('add_image').href);
107 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
111 ed.addButton('add_video', {
112 title : 'wordpress.add_video',
113 image : url + '/img/video.gif',
114 onclick : function() {
115 tb_show('', tinymce.DOM.get('add_video').href);
116 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
120 ed.addButton('add_audio', {
121 title : 'wordpress.add_audio',
122 image : url + '/img/audio.gif',
123 onclick : function() {
124 tb_show('', tinymce.DOM.get('add_audio').href);
125 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
129 // Add Media buttons to fullscreen
130 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
131 if ( 'mceFullScreen' != cmd ) return;
132 if ( 'mce_fullscreen' != ed.id )
133 ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
136 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
137 ed.addCommand('JustifyLeft', function() {
138 var n = ed.selection.getNode();
140 if ( n.nodeName != 'IMG' )
141 ed.editorCommands.mceJustify('JustifyLeft', 'left');
142 else ed.plugins.wordpress.do_align(n, 'alignleft');
145 ed.addCommand('JustifyRight', function() {
146 var n = ed.selection.getNode();
148 if ( n.nodeName != 'IMG' )
149 ed.editorCommands.mceJustify('JustifyRight', 'right');
150 else ed.plugins.wordpress.do_align(n, 'alignright');
153 ed.addCommand('JustifyCenter', function() {
154 var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
156 if ( n.nodeName == 'IMG' && ( P || DL ) )
157 ed.plugins.wordpress.do_align(n, 'aligncenter');
158 else ed.editorCommands.mceJustify('JustifyCenter', 'center');
161 // Word count if script is loaded
162 if ( 'undefined' != typeof wpWordCount ) {
164 ed.onKeyUp.add(function(ed, e) {
165 if ( e.keyCode == last ) return;
166 if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) );
171 // Add listeners to handle more break
172 t._handleMoreBreak(ed, url);
174 // Add custom shortcuts
175 ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
176 ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
177 ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
178 ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
179 ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
180 ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
181 ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
182 ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
183 ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
184 ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
185 ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
186 ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
187 ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
188 ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
189 ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
190 ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
191 ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
193 if ( tinymce.isWebKit ) {
194 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
195 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
199 getInfo : function() {
201 longname : 'WordPress Plugin',
202 author : 'WordPress', // add Moxiecode?
203 authorurl : 'http://wordpress.org',
204 infourl : 'http://wordpress.org',
209 // Internal functions
210 do_align : function(n, a) {
211 var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
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);