只读模式
group, 分享
评论更多问题
博客标签总是存在一个
This commit is contained in:
lealife
2015-06-15 18:01:48 +08:00
parent 7e458bb433
commit 6987a38820
1453 changed files with 114561 additions and 91536 deletions

44
public/tinymce/plugins/visualchars/plugin.js Normal file → Executable file
View File

@ -11,13 +11,49 @@
/*global tinymce:true */
tinymce.PluginManager.add('visualchars', function(editor) {
var state;
var self = this, state;
function toggleVisualChars(addBookmark) {
var node, nodeList, i, body = editor.getBody(), nodeValue, selection = editor.selection, div, bookmark;
var charMap, visualCharsRegExp;
charMap = {
'\u00a0': 'nbsp',
'\u00ad': 'shy'
};
function wrapCharWithSpan(value) {
return '<span data-mce-bogus="1" class="mce-' + charMap[value] + '">' + value + '</span>';
}
function compileCharMapToRegExp() {
var key, regExp = '';
for (key in charMap) {
regExp += key;
}
return new RegExp('[' + regExp + ']', 'g');
}
function compileCharMapToCssSelector() {
var key, selector = '';
for (key in charMap) {
if (selector) {
selector += ',';
}
selector += 'span.mce-' + charMap[key];
}
return selector;
}
state = !state;
self.state = state;
editor.fire('VisualChars', {state: state});
visualCharsRegExp = compileCharMapToRegExp();
if (addBookmark) {
bookmark = selection.getBookmark();
@ -26,14 +62,14 @@ tinymce.PluginManager.add('visualchars', function(editor) {
if (state) {
nodeList = [];
tinymce.walk(body, function(n) {
if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1) {
if (n.nodeType == 3 && n.nodeValue && visualCharsRegExp.test(n.nodeValue)) {
nodeList.push(n);
}
}, 'childNodes');
for (i = 0; i < nodeList.length; i++) {
nodeValue = nodeList[i].nodeValue;
nodeValue = nodeValue.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mce-nbsp">$1</span>');
nodeValue = nodeValue.replace(visualCharsRegExp, wrapCharWithSpan);
div = editor.dom.create('div', null, nodeValue);
while ((node = div.lastChild)) {
@ -43,7 +79,7 @@ tinymce.PluginManager.add('visualchars', function(editor) {
editor.dom.remove(nodeList[i]);
}
} else {
nodeList = editor.dom.select('span.mce-nbsp', body);
nodeList = editor.dom.select(compileCharMapToCssSelector(), body);
for (i = nodeList.length - 1; i >= 0; i--) {
editor.dom.remove(nodeList[i], 1);