2008-01-31 18:10:46 +00:00
|
|
|
/**
|
2008-03-21 16:10:33 +00:00
|
|
|
* WordPress plugin.
|
2008-01-31 18:10:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var DOM = tinymce.DOM;
|
|
|
|
|
|
|
|
// Load plugin specific language pack
|
|
|
|
tinymce.PluginManager.requireLangPack('wordpress');
|
|
|
|
|
|
|
|
tinymce.create('tinymce.plugins.WordPress', {
|
|
|
|
init : function(ed, url) {
|
|
|
|
var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2');
|
|
|
|
var moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
|
|
|
|
var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
|
|
|
|
|
|
|
|
// Hides the specified toolbar and resizes the iframe
|
|
|
|
ed.onPostRender.add(function() {
|
2008-02-10 06:27:03 +00:00
|
|
|
if ( ed.getParam('wordpress_adv_hidden', 1) ) {
|
|
|
|
DOM.hide(ed.controlManager.get(tbId).id);
|
|
|
|
t._resizeIframe(ed, tbId, 28);
|
|
|
|
}
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
2008-02-27 05:36:42 +00:00
|
|
|
|
|
|
|
// Register commands
|
|
|
|
ed.addCommand('WP_More', function() {
|
|
|
|
ed.execCommand('mceInsertContent', 0, moreHTML);
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
2008-02-27 05:36:42 +00:00
|
|
|
|
|
|
|
ed.addCommand('WP_Page', function() {
|
|
|
|
ed.execCommand('mceInsertContent', 0, nextpageHTML);
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
2008-02-27 05:36:42 +00:00
|
|
|
|
|
|
|
ed.addCommand('WP_Help', function() {
|
2008-01-31 18:10:46 +00:00
|
|
|
ed.windowManager.open({
|
|
|
|
url : tinymce.baseURL + '/wp-mce-help.php',
|
|
|
|
width : 450,
|
|
|
|
height : 420,
|
|
|
|
inline : 1
|
|
|
|
});
|
2008-02-27 05:36:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ed.addCommand('WP_Adv', function() {
|
2008-01-31 18:10:46 +00:00
|
|
|
var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
|
|
|
|
|
|
|
|
if (DOM.isHidden(id)) {
|
|
|
|
cm.setActive('wp_adv', 1);
|
|
|
|
DOM.show(id);
|
|
|
|
t._resizeIframe(ed, tbId, -28);
|
2008-02-10 06:27:03 +00:00
|
|
|
ed.settings.wordpress_adv_hidden = 0;
|
2008-01-31 18:10:46 +00:00
|
|
|
} else {
|
|
|
|
cm.setActive('wp_adv', 0);
|
|
|
|
DOM.hide(id);
|
|
|
|
t._resizeIframe(ed, tbId, 28);
|
2008-02-10 06:27:03 +00:00
|
|
|
ed.settings.wordpress_adv_hidden = 1;
|
2006-03-30 07:50:33 +00:00
|
|
|
}
|
2008-02-27 05:36:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Register buttons
|
|
|
|
ed.addButton('wp_more', {
|
|
|
|
title : 'wordpress.wp_more_desc',
|
|
|
|
image : url + '/img/more.gif',
|
|
|
|
cmd : 'WP_More'
|
|
|
|
});
|
|
|
|
|
|
|
|
ed.addButton('wp_page', {
|
|
|
|
title : 'wordpress.wp_page_desc',
|
|
|
|
image : url + '/img/page.gif',
|
|
|
|
cmd : 'WP_Page'
|
|
|
|
});
|
|
|
|
|
|
|
|
ed.addButton('wp_help', {
|
|
|
|
title : 'wordpress.wp_help_desc',
|
|
|
|
image : url + '/img/help.gif',
|
|
|
|
cmd : 'WP_Help'
|
|
|
|
});
|
|
|
|
|
|
|
|
ed.addButton('wp_adv', {
|
|
|
|
title : 'wordpress.wp_adv_desc',
|
|
|
|
image : url + '/img/toolbars.gif',
|
|
|
|
cmd : 'WP_Adv'
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
|
|
|
|
2008-02-14 05:45:40 +00:00
|
|
|
// Add class "alignleft" or "alignright" when selecting align for images.
|
|
|
|
ed.onBeforeExecCommand.add(function( editor, cmd ) {
|
|
|
|
var node, dir, xdir;
|
|
|
|
|
|
|
|
if ( ( cmd.indexOf('Justify') != -1 ) && ( node = editor.selection.getNode() ) ) {
|
|
|
|
if ( node.nodeName !== 'IMG' ) return;
|
|
|
|
dir = cmd.substring(7).toLowerCase();
|
|
|
|
if ( 'JustifyCenter' == cmd || editor.queryCommandState( cmd ) ) {
|
|
|
|
editor.dom.removeClass( node, "alignleft" );
|
|
|
|
editor.dom.removeClass( node, "alignright" );
|
|
|
|
} else {
|
|
|
|
xdir = ( dir == 'left' ) ? 'right' : 'left';
|
|
|
|
editor.dom.removeClass( node, "align"+xdir );
|
|
|
|
editor.dom.addClass( node, "align"+dir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2008-01-31 18:10:46 +00:00
|
|
|
// Add listeners to handle more break
|
|
|
|
t._handleMoreBreak(ed, url);
|
2008-02-27 05:36:42 +00:00
|
|
|
|
2008-03-18 06:59:53 +00:00
|
|
|
ed.onPostProcess.add(function(se, o) {
|
|
|
|
o.content = o.content.replace(/\r?\n/g, ' ');
|
|
|
|
});
|
|
|
|
|
2008-02-27 05:36:42 +00:00
|
|
|
// Add custom shortcuts
|
2008-03-04 00:07:29 +00:00
|
|
|
ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
|
|
|
|
ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
|
|
|
|
ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
|
|
|
|
ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
|
|
|
|
ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
|
|
|
|
ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
|
|
|
|
ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
|
|
|
|
ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
|
|
|
|
ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
|
|
|
|
ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
|
|
|
|
ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
|
|
|
|
ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
|
|
|
|
ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
|
|
|
|
ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
|
|
|
|
ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
|
|
|
|
ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
|
|
|
|
ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
|
|
|
|
|
|
|
|
if ( tinymce.isWebKit ) {
|
|
|
|
ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
|
|
|
|
ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
|
|
|
|
}
|
2008-01-31 18:10:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getInfo : function() {
|
|
|
|
return {
|
|
|
|
longname : 'WordPress Plugin',
|
|
|
|
author : 'WordPress', // add Moxiecode?
|
|
|
|
authorurl : 'http://wordpress.org',
|
|
|
|
infourl : 'http://wordpress.org',
|
2008-03-04 00:07:29 +00:00
|
|
|
version : '3.0'
|
2008-01-31 18:10:46 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
// Internal functions
|
|
|
|
|
|
|
|
// Resizes the iframe by a relative height value
|
|
|
|
_resizeIframe : function(ed, tb_id, dy) {
|
|
|
|
var ifr = ed.getContentAreaContainer().firstChild;
|
|
|
|
|
|
|
|
DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
|
|
|
|
ed.theme.deltaHeight += dy; // For resize cookie
|
|
|
|
},
|
|
|
|
|
|
|
|
_handleMoreBreak : function(ed, url) {
|
|
|
|
var moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
|
|
|
|
var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
|
|
|
|
|
|
|
|
// Load plugin specific CSS into editor
|
|
|
|
ed.onInit.add(function() {
|
|
|
|
ed.dom.loadCSS(url + '/css/content.css');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display morebreak instead if img in element path
|
|
|
|
ed.onPostRender.add(function() {
|
|
|
|
if (ed.theme.onResolveName) {
|
|
|
|
ed.theme.onResolveName.add(function(th, o) {
|
|
|
|
if (o.node.nodeName == 'IMG') {
|
|
|
|
if ( ed.dom.hasClass(o.node, 'mceWPmore') )
|
|
|
|
o.name = 'wpmore';
|
|
|
|
if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
|
|
|
|
o.name = 'wppage';
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2006-03-30 07:50:33 +00:00
|
|
|
}
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Replace morebreak with images
|
|
|
|
ed.onBeforeSetContent.add(function(ed, o) {
|
|
|
|
o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
|
|
|
|
o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Replace images with morebreak
|
|
|
|
ed.onPostProcess.add(function(ed, o) {
|
|
|
|
if (o.get)
|
|
|
|
o.content = o.content.replace(/<img[^>]+>/g, function(im) {
|
|
|
|
if (im.indexOf('class="mceWPmore') !== -1) {
|
|
|
|
var m;
|
|
|
|
var moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
|
|
|
|
|
|
|
|
im = '<!--more'+moretext+'-->';
|
|
|
|
}
|
|
|
|
if (im.indexOf('class="mceWPnextpage') !== -1)
|
|
|
|
im = '<!--nextpage-->';
|
|
|
|
|
|
|
|
return im;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set active buttons if user selected pagebreak or more break
|
|
|
|
ed.onNodeChange.add(function(ed, cm, n) {
|
|
|
|
cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
|
|
|
|
cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
|
|
|
|
});
|
2006-09-22 22:24:50 +00:00
|
|
|
}
|
2008-01-31 18:10:46 +00:00
|
|
|
});
|
2006-09-22 22:24:50 +00:00
|
|
|
|
2008-01-31 18:10:46 +00:00
|
|
|
// Register plugin
|
|
|
|
tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
|
|
|
|
})();
|