📄 editor_plugin.js
字号:
if (attribs['class'] == "mceitemgallery") {
endPos += 2;
var embedHTML = '<!--galleryBegin-->' + attribs["alt"] + '<!--galleryEnd-->';
// Insert embed/object chunk
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + embedHTML + chunkAfter;
}
//File
if (attribs['class'] == "mceitemfile") {
endPos += 2;
var embedHTML = '<!--fileBegin-->' + attribs["alt"] + '<!--fileEnd-->';
// Insert embed/object chunk
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + embedHTML + chunkAfter;
}
//Member File
if (attribs['class'] == "mceitemmfile") {
endPos += 2;
var embedHTML = '<!--mfileBegin-->' + attribs["alt"] + '<!--mfileEnd-->';
// Insert embed/object chunk
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + embedHTML + chunkAfter;
}
if (attribs['class'] == "mce_plugin_f2blog_more" || attribs['name'] == "mce_plugin_f2blog_more") {
endPos += 2;
var embedHTML = '<!--more-->';
// Insert embed/object chunk
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + embedHTML + chunkAfter;
}
if (attribs['class'] == "mce_plugin_f2blog_page" || attribs['name'] == "mce_plugin_f2blog_page") {
endPos += 2;
var embedHTML = '<!--nextpage-->';
// Insert embed/object chunk
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + embedHTML + chunkAfter;
}
}
// Remove normal line breaks
content = content.replace(/\n|\r/g, ' ');
// 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;
}
// Remove anonymous, empty paragraphs.
content = content.replace(new RegExp('<p>(\\s| )*</p>', 'mg'), '');
// 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>');
// Pretty it up for the source editor.
var blocklist = 'blockquote|ul|table|thead|tr|th|td|h\\d|pre|p';
content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>\\s*', 'mg'), '\n<$1>');
content = content.replace(new RegExp('<((/?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*$', ''), '');
break;
}
// 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 + '_f2_more', 'mceButtonNormal');
tinyMCE.switchClass(editor_id + '_f2_page', 'mceButtonNormal');
if (node == null)
return;
do {
if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_f2blog_more') == 0)
tinyMCE.switchClass(editor_id + '_f2_more', 'mceButtonSelected');
if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mce_plugin_f2blog_page') == 0)
tinyMCE.switchClass(editor_id + '_f2_page', 'mceButtonSelected');
} while ((node = node.parentNode));
return true;
},
saveCallback : function(el, content, body) {
// We have a TON of cleanup to do.
// 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>[\\s]*', 'mgi'), '');
content = content.replace(new RegExp('[\\s]*</p>[\\s]*', 'mgi'), '\n\n');
content = content.replace(new RegExp('\\n\\s*\\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>');
// 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 any whitespace
content = content.replace(new RegExp('^\\s*', ''), '');
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_f2blog_more');
var titleTextPage = tinyMCE.getLang('lang_f2blog_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).toLowerCase();
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("f2blog", TinyMCE_f2blogPlugin);
/* 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;
};
/*tinyMCE.orgFixGeckoBaseHREFBug = tinyMCE.fixGeckoBaseHREFBug;
tinyMCE.fixGeckoBaseHREFBug = function(m, e, h) {
if ( tinyMCE.isGecko && m == 1 )
h = h.replace(new RegExp('<((a|img|select|area|iframe|base|input|script|embed|object|link)\\s([^>]*\\s)?)(src)\\s*=', 'gi'), '<$1 x$4=');
else
h = tinyMCE.orgFixGeckoBaseHREFBug(m, e, h);
return h;
};
tinyMCE.orgStoreAwayURLs = tinyMCE.storeAwayURLs;
tinyMCE.storeAwayURLs = function(s) {
// Remove all mce_src, mce_href and replace them with new ones
s = s.replace(new RegExp('mce_(src)\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s = s.replace(new RegExp('<((a|img|select|area|iframe|base|input|script|embed|object|link)\\s([^>]*\\s)?)(src)\\s*=\\s*"([^"]*)"', 'gi'), '<$1 $4="$5" mce_$4="$5"');
return s;
};*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -