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',
92 // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
93 ed.onExecCommand.add(function( editor, cmd ) {
94 var node, bl, dom = editor.dom;
96 if ( 'JustifyCenter' == cmd ) {
97 if ( ( node = editor.selection.getNode() ) && node.nodeName == 'IMG' ) {
98 if ( ! dom.hasClass( node, "aligncenter" ) && ( bl = editor.forceBlocks.getParentBlock(node) ) && bl.childNodes.length == 1 )
99 dom.setStyle(bl, 'text-align', '');
101 editor.execCommand('mceRepaint');
105 ed.onBeforeExecCommand.add(function( editor, cmd ) {
106 var node, dir, xdir, bl, dom = editor.dom;
108 if ( ( cmd.indexOf('Justify') != -1 ) && ( node = editor.selection.getNode() ) ) {
109 if ( 'JustifyFull' == cmd || node.nodeName !== 'IMG' ) return;
110 dir = cmd.substring(7).toLowerCase();
112 if ( editor.queryCommandState( cmd ) ) {
113 dom.removeClass( node, "alignleft" );
114 dom.removeClass( node, "alignright" );
115 dom.removeClass( node, "aligncenter" );
116 } else if ( 'JustifyCenter' == cmd ) {
117 dom.removeClass( node, "alignleft" );
118 dom.removeClass( node, "alignright" );
120 if ( dom.hasClass( node, "aligncenter" ) ) {
121 dom.removeClass( node, "aligncenter" );
122 if ( ( bl = editor.forceBlocks.getParentBlock(node) ) && bl.childNodes.length == 1 && tinymce.isGecko )
123 editor.selection.select(bl.firstChild);
124 } else dom.addClass( node, "aligncenter" );
127 xdir = ( dir == 'left' ) ? 'right' : 'left';
128 dom.removeClass( node, "aligncenter" );
129 dom.removeClass( node, "align"+xdir );
130 dom.addClass( node, "align"+dir );
135 // Add listeners to handle more break
136 t._handleMoreBreak(ed, url);
138 // Add custom shortcuts
139 ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
140 ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
141 ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
142 ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
143 ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
144 ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
145 ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
146 ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
147 ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
148 ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
149 ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
150 ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
151 ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
152 ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
153 ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
154 ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
155 ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
157 if ( tinymce.isWebKit ) {
158 ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
159 ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
163 getInfo : function() {
165 longname : 'WordPress Plugin',
166 author : 'WordPress', // add Moxiecode?
167 authorurl : 'http://wordpress.org',
168 infourl : 'http://wordpress.org',
173 // Internal functions
175 // Resizes the iframe by a relative height value
176 _resizeIframe : function(ed, tb_id, dy) {
177 var ifr = ed.getContentAreaContainer().firstChild;
179 DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
180 ed.theme.deltaHeight += dy; // For resize cookie
183 _handleMoreBreak : function(ed, url) {
184 var moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
185 var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
187 // Load plugin specific CSS into editor
188 ed.onInit.add(function() {
189 ed.dom.loadCSS(url + '/css/content.css');
192 // Display morebreak instead if img in element path
193 ed.onPostRender.add(function() {
194 if (ed.theme.onResolveName) {
195 ed.theme.onResolveName.add(function(th, o) {
196 if (o.node.nodeName == 'IMG') {
197 if ( ed.dom.hasClass(o.node, 'mceWPmore') )
199 if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
207 // Replace morebreak with images
208 ed.onBeforeSetContent.add(function(ed, o) {
209 o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
210 o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
213 // Replace images with morebreak
214 ed.onPostProcess.add(function(ed, o) {
216 o.content = o.content.replace(/<img[^>]+>/g, function(im) {
217 if (im.indexOf('class="mceWPmore') !== -1) {
218 var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
219 im = '<!--more'+moretext+'-->';
221 if (im.indexOf('class="mceWPnextpage') !== -1)
222 im = '<!--nextpage-->';
228 // Set active buttons if user selected pagebreak or more break
229 ed.onNodeChange.add(function(ed, cm, n) {
230 cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
231 cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
237 tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);