TinyMCE 3.0 Final from azaozz. see #5674
git-svn-id: https://develop.svn.wordpress.org/trunk@6694 602fd350-edb4-49c9-b593-d223f7449a82
@@ -0,0 +1,15 @@
|
||||
|
||||
.mceWPnextpage, .mceWPmore {
|
||||
border: 0px;
|
||||
border-top: 1px dotted #cccccc;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 12px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.mceWPmore {
|
||||
background: #ffffff url(../img/more_bug.gif) no-repeat right top;
|
||||
}
|
||||
.mceWPnextpage {
|
||||
background: #ffffff url(../img/page_bug.gif) no-repeat right top;
|
||||
}
|
||||
@@ -1,616 +1,153 @@
|
||||
/* Import plugin specific language pack */
|
||||
//tinyMCE.importPluginLanguagePack('wordpress', 'en');
|
||||
/**
|
||||
* Wordpress plugin.
|
||||
*/
|
||||
|
||||
var TinyMCE_wordpressPlugin = {
|
||||
getInfo : function() {
|
||||
return {
|
||||
longname : 'WordPress Plugin',
|
||||
author : 'WordPress',
|
||||
authorurl : 'http://wordpress.org',
|
||||
infourl : 'http://wordpress.org',
|
||||
version : '1'
|
||||
};
|
||||
},
|
||||
(function() {
|
||||
var DOM = tinymce.DOM;
|
||||
|
||||
getControlHTML : function(control_name) {
|
||||
switch (control_name) {
|
||||
case "wp_more":
|
||||
return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_more_button', '{$pluginurl}/images/more.gif', 'wpMore');
|
||||
case "wp_page":
|
||||
return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_page_button', '{$pluginurl}/images/page.gif', 'wpPage');
|
||||
case "wp_help":
|
||||
var buttons = tinyMCE.getButtonHTML(control_name, 'lang_help_button_title', '{$pluginurl}/images/help.gif', 'wpHelp');
|
||||
var hiddenControls = '<div class="zerosize">'
|
||||
+ '<input type="button" accesskey="n" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSpellCheck\',false);" />'
|
||||
+ '<input type="button" accesskey="k" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Strikethrough\',false);" />'
|
||||
+ '<input type="button" accesskey="l" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'InsertUnorderedList\',false);" />'
|
||||
+ '<input type="button" accesskey="o" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'InsertOrderedList\',false);" />'
|
||||
+ '<input type="button" accesskey="w" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Outdent\',false);" />'
|
||||
+ '<input type="button" accesskey="q" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Indent\',false);" />'
|
||||
+ '<input type="button" accesskey="f" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'JustifyLeft\',false);" />'
|
||||
+ '<input type="button" accesskey="c" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'JustifyCenter\',false);" />'
|
||||
+ '<input type="button" accesskey="r" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'JustifyRight\',false);" />'
|
||||
+ '<input type="button" accesskey="j" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'JustifyFull\',false);" />'
|
||||
+ '<input type="button" accesskey="a" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceLink\',true);" />'
|
||||
+ '<input type="button" accesskey="s" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'unlink\',false);" />'
|
||||
+ '<input type="button" accesskey="m" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceImage\',true);" />'
|
||||
+ '<input type="button" accesskey="t" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'wpMore\');" />'
|
||||
+ '<input type="button" accesskey="g" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'wpPage\');" />'
|
||||
+ '<input type="button" accesskey="u" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Undo\',false);" />'
|
||||
+ '<input type="button" accesskey="y" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Redo\',false);" />'
|
||||
+ '<input type="button" accesskey="h" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'wpHelp\',false);" />'
|
||||
+ '<input type="button" accesskey="b" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'Bold\',false);" />'
|
||||
+ '<input type="button" accesskey="v" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'wpAdv\',false);" />'
|
||||
+ '</div>';
|
||||
return buttons+hiddenControls;
|
||||
case "wp_adv":
|
||||
return tinyMCE.getButtonHTML(control_name, 'lang_wordpress_adv_button', '{$pluginurl}/images/toolbars.gif', 'wpAdv');
|
||||
case "wp_adv_start":
|
||||
return '<div id="wpadvbar" style="display:none;"><br />';
|
||||
case "wp_adv_end":
|
||||
return '</div>';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
// Load plugin specific language pack
|
||||
tinymce.PluginManager.requireLangPack('wordpress');
|
||||
|
||||
execCommand : function(editor_id, element, command, user_interface, value) {
|
||||
var inst = tinyMCE.getInstanceById(editor_id);
|
||||
var focusElm = inst.getFocusElement();
|
||||
var doc = inst.getDoc();
|
||||
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')+'" />';
|
||||
|
||||
function getAttrib(elm, name) {
|
||||
return elm.getAttribute(name) ? elm.getAttribute(name) : "";
|
||||
}
|
||||
// Hides the specified toolbar and resizes the iframe
|
||||
ed.onPostRender.add(function() {
|
||||
DOM.hide(ed.controlManager.get(tbId).id);
|
||||
t._resizeIframe(ed, tbId, 28);
|
||||
});
|
||||
|
||||
// Handle commands
|
||||
switch (command) {
|
||||
case "wpMore":
|
||||
var flag = "";
|
||||
var template = new Array();
|
||||
var altMore = tinyMCE.getLang('lang_wordpress_more_alt');
|
||||
|
||||
// Is selection a image
|
||||
if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
|
||||
flag = getAttrib(focusElm, 'class');
|
||||
|
||||
if (flag != 'mce_plugin_wordpress_more') // Not a wordpress
|
||||
return true;
|
||||
|
||||
action = "update";
|
||||
// Register buttons
|
||||
ed.addButton('wp_more', {
|
||||
title : 'wordpress.wp_more_desc',
|
||||
image : url + '/img/more.gif',
|
||||
onclick : function() {
|
||||
ed.execCommand('mceInsertContent', 0, moreHTML);
|
||||
}
|
||||
});
|
||||
|
||||
html = ''
|
||||
+ '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
|
||||
+ ' width="100%" height="10px" '
|
||||
+ 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_wordpress_more" name="mce_plugin_wordpress_more" />';
|
||||
tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
|
||||
tinyMCE.selectedInstance.repaint();
|
||||
return true;
|
||||
|
||||
case "wpPage":
|
||||
var flag = "";
|
||||
var template = new Array();
|
||||
var altPage = tinyMCE.getLang('lang_wordpress_more_alt');
|
||||
|
||||
// Is selection a image
|
||||
if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
|
||||
flag = getAttrib(focusElm, 'name');
|
||||
|
||||
if (flag != 'mce_plugin_wordpress_page') // Not a wordpress
|
||||
return true;
|
||||
|
||||
action = "update";
|
||||
ed.addButton('wp_page', {
|
||||
title : 'wordpress.wp_page_desc',
|
||||
image : url + '/img/page.gif',
|
||||
onclick : function() {
|
||||
// ed.execCommand('mcePageBreak');
|
||||
ed.execCommand('mceInsertContent', 0, nextpageHTML);
|
||||
}
|
||||
});
|
||||
|
||||
html = ''
|
||||
+ '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
|
||||
+ ' width="100%" height="10px" '
|
||||
+ 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_wordpress_page" name="mce_plugin_wordpress_page" />';
|
||||
tinyMCE.execCommand("mceInsertContent",true,html);
|
||||
tinyMCE.selectedInstance.repaint();
|
||||
return true;
|
||||
|
||||
case "wpHelp":
|
||||
var template = new Array();
|
||||
|
||||
template['file'] = tinyMCE.baseURL + '/wp-mce-help.php';
|
||||
template['width'] = 480;
|
||||
template['height'] = 380;
|
||||
|
||||
args = {
|
||||
resizable : 'yes',
|
||||
scrollbars : 'yes'
|
||||
};
|
||||
|
||||
tinyMCE.openWindow(template, args);
|
||||
return true;
|
||||
case "wpAdv":
|
||||
var adv = document.getElementById('wpadvbar');
|
||||
if ( adv.style.display == 'none' ) {
|
||||
adv.style.display = 'block';
|
||||
tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonSelected');
|
||||
} else {
|
||||
adv.style.display = 'none';
|
||||
tinyMCE.switchClass(editor_id + '_wp_adv', 'mceButtonNormal');
|
||||
ed.addButton('wp_help', {
|
||||
title : 'wordpress.wp_help_desc',
|
||||
image : url + '/img/help.gif',
|
||||
onclick : function() {
|
||||
ed.windowManager.open({
|
||||
url : tinymce.baseURL + '/wp-mce-help.php',
|
||||
width : 450,
|
||||
height : 420,
|
||||
inline : 1
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Pass to next handler in chain
|
||||
return false;
|
||||
},
|
||||
ed.addButton('wp_adv', {
|
||||
title : 'wordpress.wp_adv_desc',
|
||||
image : url + '/img/toolbars.gif',
|
||||
onclick : function() {
|
||||
var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
|
||||
|
||||
cleanup : function(type, content) {
|
||||
switch (type) {
|
||||
|
||||
case "insert_to_editor":
|
||||
var startPos = 0;
|
||||
var altMore = tinyMCE.getLang('lang_wordpress_more_alt');
|
||||
var altPage = tinyMCE.getLang('lang_wordpress_page_alt');
|
||||
|
||||
// Parse all <!--more--> tags and replace them with images
|
||||
while ((startPos = content.indexOf('<!--more', startPos)) != -1) {
|
||||
var endPos = content.indexOf('-->', startPos) + 3;
|
||||
// Insert image
|
||||
var moreText = content.substring(startPos + 8, endPos - 3);
|
||||
var contentAfter = content.substring(endPos);
|
||||
content = content.substring(0, startPos);
|
||||
content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
|
||||
content += ' width="100%" height="10px" moretext="'+moreText+'" ';
|
||||
content += 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_wordpress_more" name="mce_plugin_wordpress_more" />';
|
||||
content += contentAfter;
|
||||
|
||||
startPos++;
|
||||
}
|
||||
var startPos = 0;
|
||||
|
||||
// Parse all <!--page--> tags and replace them with images
|
||||
while ((startPos = content.indexOf('<!--nextpage-->', startPos)) != -1) {
|
||||
// Insert image
|
||||
var contentAfter = content.substring(startPos + 15);
|
||||
content = content.substring(0, startPos);
|
||||
content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
|
||||
content += ' width="100%" height="10px" ';
|
||||
content += 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_wordpress_page" name="mce_plugin_wordpress_page" />';
|
||||
content += contentAfter;
|
||||
|
||||
startPos++;
|
||||
}
|
||||
|
||||
// Look for \n in <pre>, replace with <br>
|
||||
var startPos = -1;
|
||||
while ((startPos = content.indexOf('<pre', startPos+1)) != -1) {
|
||||
var endPos = content.indexOf('</pre>', startPos+1);
|
||||
var innerPos = content.indexOf('>', startPos+1);
|
||||
var chunkBefore = content.substring(0, innerPos);
|
||||
var chunkAfter = content.substring(endPos);
|
||||
|
||||
var innards = content.substring(innerPos, endPos);
|
||||
innards = innards.replace(/\n/g, '<br />');
|
||||
content = chunkBefore + innards + chunkAfter;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "get_from_editor":
|
||||
// Parse all img tags and replace them with <!--more-->
|
||||
var startPos = -1;
|
||||
while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
|
||||
var endPos = content.indexOf('/>', startPos);
|
||||
var attribs = this._parseAttributes(content.substring(startPos + 4, endPos));
|
||||
|
||||
if (attribs['class'] == "mce_plugin_wordpress_more" || attribs['name'] == "mce_plugin_wordpress_more") {
|
||||
endPos += 2;
|
||||
|
||||
var moreText = attribs['moretext'] ? attribs['moretext'] : '';
|
||||
var embedHTML = '<!--more'+moreText+'-->';
|
||||
|
||||
// Insert embed/object chunk
|
||||
chunkBefore = content.substring(0, startPos);
|
||||
chunkAfter = content.substring(endPos);
|
||||
content = chunkBefore + embedHTML + chunkAfter;
|
||||
}
|
||||
if (attribs['class'] == "mce_plugin_wordpress_page" || attribs['name'] == "mce_plugin_wordpress_page") {
|
||||
endPos += 2;
|
||||
|
||||
var embedHTML = '<!--nextpage-->';
|
||||
|
||||
// Insert embed/object chunk
|
||||
chunkBefore = content.substring(0, startPos);
|
||||
chunkAfter = content.substring(endPos);
|
||||
content = chunkBefore + embedHTML + chunkAfter;
|
||||
if (DOM.isHidden(id)) {
|
||||
cm.setActive('wp_adv', 1);
|
||||
DOM.show(id);
|
||||
t._resizeIframe(ed, tbId, -28);
|
||||
} else {
|
||||
cm.setActive('wp_adv', 0);
|
||||
DOM.hide(id);
|
||||
t._resizeIframe(ed, tbId, 28);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Remove normal line breaks
|
||||
content = content.replace(/\n|\r/g, ' ');
|
||||
// Add listeners to handle more break
|
||||
t._handleMoreBreak(ed, url);
|
||||
},
|
||||
|
||||
// Look for <br> in <pre>, replace with \n
|
||||
var startPos = -1;
|
||||
while ((startPos = content.indexOf('<pre', startPos+1)) != -1) {
|
||||
var endPos = content.indexOf('</pre>', startPos+1);
|
||||
var innerPos = content.indexOf('>', startPos+1);
|
||||
var chunkBefore = content.substring(0, innerPos);
|
||||
var chunkAfter = content.substring(endPos);
|
||||
|
||||
var innards = content.substring(innerPos, endPos);
|
||||
innards = innards.replace(new RegExp('<br\\s?/?>', 'g'), '\n');
|
||||
innards = innards.replace(new RegExp('\\s$', ''), '');
|
||||
content = chunkBefore + innards + chunkAfter;
|
||||
getInfo : function() {
|
||||
return {
|
||||
longname : 'WordPress Plugin',
|
||||
author : 'WordPress', // add Moxiecode?
|
||||
authorurl : 'http://wordpress.org',
|
||||
infourl : 'http://wordpress.org',
|
||||
version : '1.0a1'
|
||||
};
|
||||
},
|
||||
|
||||
// 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';
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Remove anonymous, empty paragraphs.
|
||||
content = content.replace(new RegExp('<p>(\\s| )*</p>', 'mg'), '');
|
||||
// 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);
|
||||
});
|
||||
|
||||
// Handle table badness.
|
||||
content = content.replace(new RegExp('<(table( [^>]*)?)>.*?<((tr|thead)( [^>]*)?)>', 'mg'), '<$1><$3>');
|
||||
content = content.replace(new RegExp('<((?:tr|thead|tfoot)(?: [^>]*)?)>.*?<((td|th)( [^>]*)?)>', 'mg'), '<$1><$2>');
|
||||
content = content.replace(new RegExp('</(td|th)>.*?<(td( [^>]*)?|th( [^>]*)?|/tr|/thead|/tfoot)>', 'mg'), '</$1><$2>');
|
||||
content = content.replace(new RegExp('</tr>.*?<(tr( [^>]*)?|/table)>', 'mg'), '</tr><$1>');
|
||||
content = content.replace(new RegExp('<(/?(table|tbody|tr|th|td)[^>]*)>(\\s*|(<br ?/?>)*)*', 'g'), '<$1>');
|
||||
// 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] : '';
|
||||
|
||||
// Pretty it up for the source editor.
|
||||
var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p';
|
||||
content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
|
||||
content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>', 'mg'), '\n<$1>');
|
||||
content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>');
|
||||
content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>');
|
||||
content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'mg'), '<br />\n');
|
||||
content = content.replace(new RegExp('^\\s*', ''), '');
|
||||
content = content.replace(new RegExp('\\s*$', ''), '');
|
||||
im = '<!--more'+moretext+'-->';
|
||||
}
|
||||
if (im.indexOf('class="mceWPnextpage') !== -1)
|
||||
im = '<!--nextpage-->';
|
||||
|
||||
return im;
|
||||
});
|
||||
});
|
||||
|
||||
break;
|
||||
// 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'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Pass through to next handler in chain
|
||||
return content;
|
||||
},
|
||||
|
||||
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
|
||||
|
||||
tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonNormal');
|
||||
tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonNormal');
|
||||
|
||||
if (node == null)
|
||||
return;
|
||||
|
||||
do {
|
||||
if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_more') == 0)
|
||||
tinyMCE.switchClass(editor_id + '_wp_more', 'mceButtonSelected');
|
||||
if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_wordpress_page') == 0)
|
||||
tinyMCE.switchClass(editor_id + '_wp_page', 'mceButtonSelected');
|
||||
} while ((node = node.parentNode));
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
saveCallback : function(el, content, body) {
|
||||
// We have a TON of cleanup to do.
|
||||
|
||||
if ( tinyMCE.activeEditor.isHidden() ) {
|
||||
// return content;
|
||||
}
|
||||
|
||||
// Mark </p> if it has any attributes.
|
||||
content = content.replace(new RegExp('(<p[^>]+>.*?)</p>', 'mg'), '$1</p#>');
|
||||
|
||||
// Decode the ampersands of time.
|
||||
// content = content.replace(new RegExp('&', 'g'), '&');
|
||||
|
||||
// Get it ready for wpautop.
|
||||
content = content.replace(new RegExp('\\s*<p>', 'mgi'), '');
|
||||
content = content.replace(new RegExp('\\s*</p>\\s*', 'mgi'), '\n\n');
|
||||
content = content.replace(new RegExp('\\n\\s*\\n', 'mgi'), '\n\n');
|
||||
content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'gi'), '\n');
|
||||
|
||||
// Fix some block element newline issues
|
||||
var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre';
|
||||
content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
|
||||
content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
|
||||
content = content.replace(new RegExp('<li>', 'g'), '\t<li>');
|
||||
|
||||
if ( content.indexOf('<object') != -1 ) {
|
||||
content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'g'), "<param$1>"); // no pee inside object/embed
|
||||
content = content.replace(new RegExp('\\s*</embed>\\s*', 'g'), '</embed>');
|
||||
}
|
||||
|
||||
// Unmark special paragraph closing tags
|
||||
content = content.replace(new RegExp('</p#>', 'g'), '</p>\n');
|
||||
content = content.replace(new RegExp('\\s*(<p[^>]+>.*</p>)', 'mg'), '\n$1');
|
||||
|
||||
// Trim trailing whitespace
|
||||
content = content.replace(new RegExp('\\s*$', ''), '');
|
||||
|
||||
// Hope.
|
||||
return content;
|
||||
|
||||
},
|
||||
|
||||
_parseAttributes : function(attribute_string) {
|
||||
var attributeName = "";
|
||||
var attributeValue = "";
|
||||
var withInName;
|
||||
var withInValue;
|
||||
var attributes = new Array();
|
||||
var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
|
||||
var titleText = tinyMCE.getLang('lang_wordpress_more');
|
||||
var titleTextPage = tinyMCE.getLang('lang_wordpress_page');
|
||||
|
||||
if (attribute_string == null || attribute_string.length < 2)
|
||||
return null;
|
||||
|
||||
withInName = withInValue = false;
|
||||
|
||||
for (var i=0; i<attribute_string.length; i++) {
|
||||
var chr = attribute_string.charAt(i);
|
||||
|
||||
if ((chr == '"' || chr == "'") && !withInValue)
|
||||
withInValue = true;
|
||||
else if ((chr == '"' || chr == "'") && withInValue) {
|
||||
withInValue = false;
|
||||
|
||||
var pos = attributeName.lastIndexOf(' ');
|
||||
if (pos != -1)
|
||||
attributeName = attributeName.substring(pos+1);
|
||||
|
||||
attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
|
||||
|
||||
attributeName = "";
|
||||
attributeValue = "";
|
||||
} else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
|
||||
withInName = true;
|
||||
|
||||
if (chr == '=' && withInName)
|
||||
withInName = false;
|
||||
|
||||
if (withInName)
|
||||
attributeName += chr;
|
||||
|
||||
if (withInValue)
|
||||
attributeValue += chr;
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
};
|
||||
|
||||
//tinyMCE.addPlugin("wordpress", TinyMCE_wordpressPlugin);
|
||||
|
||||
/* This little hack protects our More and Page placeholders from the removeformat command */
|
||||
tinyMCE.orgExecCommand = tinyMCE.execCommand;
|
||||
tinyMCE.execCommand = function (command, user_interface, value) {
|
||||
re = this.orgExecCommand(command, user_interface, value);
|
||||
|
||||
if ( command == 'removeformat' ) {
|
||||
var inst = tinyMCE.getInstanceById('mce_editor_0');
|
||||
doc = inst.getDoc();
|
||||
var imgs = doc.getElementsByTagName('img');
|
||||
for (i=0;img=imgs[i];i++)
|
||||
img.className = img.name;
|
||||
}
|
||||
return re;
|
||||
};
|
||||
wpInstTriggerSave = function (skip_cleanup, skip_callback) {
|
||||
var e, nl = new Array(), i, s;
|
||||
|
||||
this.switchSettings();
|
||||
s = tinyMCE.settings;
|
||||
|
||||
// Force hidden tabs visible while serializing
|
||||
if (tinyMCE.isMSIE && !tinyMCE.isOpera) {
|
||||
e = this.iframeElement;
|
||||
|
||||
do {
|
||||
if (e.style && e.style.display == 'none') {
|
||||
e.style.display = 'block';
|
||||
nl[nl.length] = {elm : e, type : 'style'};
|
||||
}
|
||||
|
||||
if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) {
|
||||
e.className = s.display_tab_class;
|
||||
nl[nl.length] = {elm : e, type : 'class'};
|
||||
}
|
||||
} while ((e = e.parentNode) != null)
|
||||
}
|
||||
|
||||
tinyMCE.settings['preformatted'] = false;
|
||||
|
||||
// Default to false
|
||||
if (typeof(skip_cleanup) == "undefined")
|
||||
skip_cleanup = false;
|
||||
|
||||
// Default to false
|
||||
if (typeof(skip_callback) == "undefined")
|
||||
skip_callback = false;
|
||||
|
||||
// tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML);
|
||||
|
||||
// Remove visual aids when cleanup is disabled
|
||||
if (this.settings['cleanup'] == false) {
|
||||
tinyMCE.handleVisualAid(this.getBody(), true, false, this);
|
||||
tinyMCE._setEventsEnabled(this.getBody(), true);
|
||||
}
|
||||
|
||||
tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body);
|
||||
tinyMCE.selectedInstance.getWin().oldfocus=tinyMCE.selectedInstance.getWin().focus;
|
||||
tinyMCE.selectedInstance.getWin().focus=function() {};
|
||||
var htm = tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true);
|
||||
tinyMCE.selectedInstance.getWin().focus=tinyMCE.selectedInstance.getWin().oldfocus;
|
||||
htm = tinyMCE._customCleanup(this, "submit_content", htm);
|
||||
|
||||
if (!skip_callback && tinyMCE.settings['save_callback'] != "")
|
||||
var content = eval(tinyMCE.settings['save_callback'] + "(this.formTargetElementId,htm,this.getBody());");
|
||||
|
||||
// Use callback content if available
|
||||
if ((typeof(content) != "undefined") && content != null)
|
||||
htm = content;
|
||||
|
||||
// Replace some weird entities (Bug: #1056343)
|
||||
htm = tinyMCE.regexpReplace(htm, "(", "(", "gi");
|
||||
htm = tinyMCE.regexpReplace(htm, ")", ")", "gi");
|
||||
htm = tinyMCE.regexpReplace(htm, ";", ";", "gi");
|
||||
htm = tinyMCE.regexpReplace(htm, """, """, "gi");
|
||||
htm = tinyMCE.regexpReplace(htm, "^", "^", "gi");
|
||||
|
||||
if (this.formElement)
|
||||
this.formElement.value = htm;
|
||||
|
||||
if (tinyMCE.isSafari && this.formElement)
|
||||
this.formElement.innerText = htm;
|
||||
|
||||
// Hide them again (tabs in MSIE)
|
||||
for (i=0; i<nl.length; i++) {
|
||||
if (nl[i].type == 'style')
|
||||
nl[i].elm.style.display = 'none';
|
||||
else
|
||||
nl[i].elm.className = s.hidden_tab_class;
|
||||
}
|
||||
}
|
||||
tinyMCE.wpTriggerSave = function () {
|
||||
var inst, n;
|
||||
for (n in tinyMCE.instances) {
|
||||
inst = tinyMCE.instances[n];
|
||||
if (!tinyMCE.isInstance(inst))
|
||||
continue;
|
||||
inst.wpTriggerSave = wpInstTriggerSave;
|
||||
inst.wpTriggerSave(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
function switchEditors(id) {
|
||||
var inst = tinyMCE.getInstanceById(id);
|
||||
var qt = document.getElementById('quicktags');
|
||||
var H = document.getElementById('edButtonHTML');
|
||||
var P = document.getElementById('edButtonPreview');
|
||||
var ta = document.getElementById(id);
|
||||
var pdr = ta.parentNode;
|
||||
|
||||
if ( ! inst.isHidden(id) ) {
|
||||
edToggle(H, P);
|
||||
|
||||
if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) {
|
||||
// IE rejects the later overflow assignment so we skip this step.
|
||||
// Alternate code might be nice. Until then, IE reflows.
|
||||
} else {
|
||||
// Lock the fieldset's height to prevent reflow/flicker
|
||||
pdr.style.height = pdr.clientHeight + 'px';
|
||||
pdr.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
// Save the coords of the bottom right corner of the rich editor
|
||||
var table = document.getElementById(inst.editorId + '_parent').getElementsByTagName('table')[0];
|
||||
var y1 = table.offsetTop + table.offsetHeight;
|
||||
|
||||
if ( tinymce.util.Cookie.get("TinyMCE_" + inst.editorId + "_height") == null ) {
|
||||
var expires = new Date();
|
||||
expires.setTime(expires.getTime() + 3600000 * 24 * 30);
|
||||
var offset = tinyMCE.isMSIE ? 1 : 2;
|
||||
tinymce.util.Cookie.set("TinyMCE_" + inst.editorId + "_height", "" + (table.offsetHeight - offset), expires);
|
||||
}
|
||||
|
||||
// Unload the rich editor
|
||||
// inst.triggerSave(false, false);
|
||||
// inst.formElement.value;
|
||||
inst.hide(); // tinyMCE.removeMCEControl(id);
|
||||
// document.getElementById(id).value = htm;
|
||||
// --tinyMCE.idCounter;
|
||||
|
||||
// Reveal Quicktags and textarea
|
||||
qt.style.display = 'block';
|
||||
ta.style.display = 'inline';
|
||||
|
||||
// Set the textarea height to match the rich editor
|
||||
y2 = ta.offsetTop + ta.offsetHeight;
|
||||
ta.style.height = (ta.clientHeight + y1 - y2) + 'px';
|
||||
|
||||
// Tweak the widths
|
||||
ta.parentNode.style.paddingRight = '12px';
|
||||
|
||||
if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) {
|
||||
} else {
|
||||
// Unlock the fieldset's height
|
||||
pdr.style.height = 'auto';
|
||||
pdr.style.overflow = 'display';
|
||||
}
|
||||
wpSetDefaultEditor( 'html' );
|
||||
} else {
|
||||
edToggle(P, H);
|
||||
edCloseAllTags(); // :-(
|
||||
|
||||
if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) {
|
||||
} else {
|
||||
// Lock the fieldset's height
|
||||
pdr.style.height = pdr.clientHeight + 'px';
|
||||
pdr.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
// Hide Quicktags and textarea
|
||||
qt.style.display = 'none';
|
||||
ta.style.display = 'none';
|
||||
|
||||
// Tweak the widths
|
||||
ta.parentNode.style.paddingRight = '0px';
|
||||
|
||||
// Load the rich editor with formatted html
|
||||
//if ( tinyMCE.isMSIE ) {
|
||||
// ta.value = wpautop(ta.value);
|
||||
// tinyMCE.addMCEControl(ta, id);
|
||||
//} else {
|
||||
ta.value = wpautop(ta.value);
|
||||
inst.show() // tinyMCE.addMCEControl(ta, id);
|
||||
//tinyMCE.getInstanceById(id).execCommand('mceSetContent', null, htm);
|
||||
//}
|
||||
|
||||
if ( tinyMCE.isMSIE && !tinyMCE.isOpera ) {
|
||||
} else {
|
||||
// Unlock the fieldset's height
|
||||
pdr.style.height = 'auto';
|
||||
pdr.style.overflow = 'display';
|
||||
}
|
||||
wpSetDefaultEditor( 'tinymce' );
|
||||
}
|
||||
}
|
||||
|
||||
function edToggle(A, B) {
|
||||
A.className = 'active';
|
||||
B.className = '';
|
||||
|
||||
B.onclick = A.onclick;
|
||||
A.onclick = null;
|
||||
}
|
||||
|
||||
function wpSetDefaultEditor( editor ) {
|
||||
try {
|
||||
editor = escape( editor.toString() );
|
||||
} catch(err) {
|
||||
editor = 'tinymce';
|
||||
}
|
||||
|
||||
var userID = document.getElementById('user-id');
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime()+(10*365*24*60*60*1000));
|
||||
document.cookie = "wordpress_editor_" + userID.value + "=" + editor + "; expires=" + date.toGMTString();
|
||||
}
|
||||
|
||||
function wpautop(pee) {
|
||||
pee = pee + "\n\n";
|
||||
pee = pee.replace(new RegExp('<br />\\s*<br />', 'gi'), "\n\n");
|
||||
pee = pee.replace(new RegExp('(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)', 'gi'), "\n$1");
|
||||
pee = pee.replace(new RegExp('(</(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])>)', 'gi'), "$1\n\n");
|
||||
pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n");
|
||||
pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n");
|
||||
pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n");
|
||||
pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), '');
|
||||
pee = pee.replace(new RegExp('<p>\\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\\s*</p>', 'gi'), "$1");
|
||||
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
||||
pee = pee.replace(new RegExp('<p><blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
|
||||
pee = pee.replace(new RegExp('</blockquote></p>', 'gi'), '</p></blockquote>');
|
||||
pee = pee.replace(new RegExp('<p>\\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)', 'gi'), "$1");
|
||||
pee = pee.replace(new RegExp('(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\\s*</p>', 'gi'), "$1");
|
||||
pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n");
|
||||
pee = pee.replace(new RegExp('(</?(?:table|thead|tfoot|caption|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\\s*<br />', 'gi'), "$1");
|
||||
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
|
||||
pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 ');
|
||||
//pee = pee.replace(new RegExp('(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' "); // Hmm...
|
||||
return pee;
|
||||
}
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
|
||||
})();
|
||||
|
After Width: | Height: | Size: 295 B |
|
After Width: | Height: | Size: 108 B |
|
After Width: | Height: | Size: 146 B |
|
After Width: | Height: | Size: 108 B |
|
After Width: | Height: | Size: 180 B |
|
After Width: | Height: | Size: 260 B |
|
After Width: | Height: | Size: 43 B |
@@ -1,37 +1,8 @@
|
||||
// EN lang variables
|
||||
|
||||
if (navigator.userAgent.indexOf('Mac OS') != -1) {
|
||||
// Mac OS browsers use Ctrl to hit accesskeys
|
||||
var metaKey = 'Ctrl';
|
||||
}
|
||||
else if (navigator.userAgent.indexOf('Firefox/2') != -1) {
|
||||
// Firefox 2.x uses Alt+Shift to hit accesskeys
|
||||
var metaKey = 'Alt+Shift';
|
||||
}
|
||||
else {
|
||||
var metaKey = 'Alt';
|
||||
}
|
||||
|
||||
tinyMCE.addI18n('',{
|
||||
wordpress_more_button : 'Split post with More tag (' + metaKey + '+t)',
|
||||
wordpress_page_button : 'Split post with Page tag',
|
||||
wordpress_adv_button : 'Show/Hide Advanced Toolbar (' + metaKey + '+v)',
|
||||
wordpress_more_alt : 'More...',
|
||||
wordpress_page_alt : '...page...',
|
||||
help_button_title : 'Help (' + metaKey + '+h)',
|
||||
bold_desc : 'Bold (Ctrl+B)',
|
||||
italic_desc : 'Italic (Ctrl+I)',
|
||||
underline_desc : 'Underline (Ctrl+U)',
|
||||
link_desc : 'Insert/edit link (' + metaKey + '+a)',
|
||||
unlink_desc : 'Unlink (' + metaKey + '+s)',
|
||||
image_desc : 'Insert/edit image (' + metaKey + '+m)',
|
||||
striketrough_desc : 'Strikethrough (' + metaKey + '+k)',
|
||||
justifyleft_desc : 'Align left (' + metaKey + '+f)',
|
||||
justifycenter_desc : 'Align center (' + metaKey + '+c)',
|
||||
justifyright_desc : 'Align right (' + metaKey + '+r)',
|
||||
justifyfull_desc : 'Align full (' + metaKey + '+j)',
|
||||
bullist_desc : 'Unordered list (' + metaKey + '+l)',
|
||||
numlist_desc : 'Ordered list (' + metaKey + '+o)',
|
||||
outdent_desc : 'Outdent (' + metaKey + '+w)',
|
||||
indent_desc : 'Indent list/blockquote (' + metaKey + '+q)'
|
||||
});
|
||||
tinyMCE.addI18n('en.wordpress',{
|
||||
wp_adv_desc : 'Show/Hide Advanced Toolbar',
|
||||
wp_more_desc : 'Split post with More tag',
|
||||
wp_page_desc : 'Split post with Page tag',
|
||||
wp_help_desc : 'Help',
|
||||
wp_more_alt : 'More...',
|
||||
wp_page_alt : 'Next page...'
|
||||
});
|
||||