Refactoring
This commit is contained in:
7
web/bower_components/tinymce/plugins/visualchars/index.js
vendored
Normal file
7
web/bower_components/tinymce/plugins/visualchars/index.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// Exports the "visualchars" plugin for usage with module loaders
|
||||
// Usage:
|
||||
// CommonJS:
|
||||
// require('tinymce/plugins/visualchars')
|
||||
// ES2015:
|
||||
// import 'tinymce/plugins/visualchars'
|
||||
require('./plugin.js');
|
||||
116
web/bower_components/tinymce/plugins/visualchars/plugin.js
vendored
Normal file
116
web/bower_components/tinymce/plugins/visualchars/plugin.js
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* plugin.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/*global tinymce:true */
|
||||
|
||||
tinymce.PluginManager.add('visualchars', function(editor) {
|
||||
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();
|
||||
}
|
||||
|
||||
if (state) {
|
||||
nodeList = [];
|
||||
tinymce.walk(body, function(n) {
|
||||
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(visualCharsRegExp, wrapCharWithSpan);
|
||||
|
||||
div = editor.dom.create('div', null, nodeValue);
|
||||
while ((node = div.lastChild)) {
|
||||
editor.dom.insertAfter(node, nodeList[i]);
|
||||
}
|
||||
|
||||
editor.dom.remove(nodeList[i]);
|
||||
}
|
||||
} else {
|
||||
nodeList = editor.dom.select(compileCharMapToCssSelector(), body);
|
||||
|
||||
for (i = nodeList.length - 1; i >= 0; i--) {
|
||||
editor.dom.remove(nodeList[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
selection.moveToBookmark(bookmark);
|
||||
}
|
||||
|
||||
function toggleActiveState() {
|
||||
var self = this;
|
||||
|
||||
editor.on('VisualChars', function(e) {
|
||||
self.active(e.state);
|
||||
});
|
||||
}
|
||||
|
||||
editor.addCommand('mceVisualChars', toggleVisualChars);
|
||||
|
||||
editor.addButton('visualchars', {
|
||||
title: 'Show invisible characters',
|
||||
cmd: 'mceVisualChars',
|
||||
onPostRender: toggleActiveState
|
||||
});
|
||||
|
||||
editor.addMenuItem('visualchars', {
|
||||
text: 'Show invisible characters',
|
||||
cmd: 'mceVisualChars',
|
||||
onPostRender: toggleActiveState,
|
||||
selectable: true,
|
||||
context: 'view',
|
||||
prependToContext: true
|
||||
});
|
||||
});
|
||||
1
web/bower_components/tinymce/plugins/visualchars/plugin.min.js
vendored
Normal file
1
web/bower_components/tinymce/plugins/visualchars/plugin.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("visualchars",function(e){function t(t){function n(e){return'<span data-mce-bogus="1" class="mce-'+p[e]+'">'+e+"</span>"}function o(){var e,t="";for(e in p)t+=e;return new RegExp("["+t+"]","g")}function a(){var e,t="";for(e in p)t&&(t+=","),t+="span.mce-"+p[e];return t}var s,l,c,u,d,f,p,m,g=e.getBody(),h=e.selection;if(p={"\xa0":"nbsp","\xad":"shy"},r=!r,i.state=r,e.fire("VisualChars",{state:r}),m=o(),t&&(f=h.getBookmark()),r)for(l=[],tinymce.walk(g,function(e){3==e.nodeType&&e.nodeValue&&m.test(e.nodeValue)&&l.push(e)},"childNodes"),c=0;c<l.length;c++){for(u=l[c].nodeValue,u=u.replace(m,n),d=e.dom.create("div",null,u);s=d.lastChild;)e.dom.insertAfter(s,l[c]);e.dom.remove(l[c])}else for(l=e.dom.select(a(),g),c=l.length-1;c>=0;c--)e.dom.remove(l[c],1);h.moveToBookmark(f)}function n(){var t=this;e.on("VisualChars",function(e){t.active(e.state)})}var r,i=this;e.addCommand("mceVisualChars",t),e.addButton("visualchars",{title:"Show invisible characters",cmd:"mceVisualChars",onPostRender:n}),e.addMenuItem("visualchars",{text:"Show invisible characters",cmd:"mceVisualChars",onPostRender:n,selectable:!0,context:"view",prependToContext:!0})});
|
||||
Reference in New Issue
Block a user