initial
This commit is contained in:
commit
9883323161
17470 files changed
+4470592
No files matched your search
@@ -0,0 +1,601 @@
|
||||
(function () {
|
||||
var searchreplace = (function () {
|
||||
'use strict';
|
||||
|
||||
var Cell = function (initial) {
|
||||
var value = initial;
|
||||
var get = function () {
|
||||
return value;
|
||||
};
|
||||
var set = function (v) {
|
||||
value = v;
|
||||
};
|
||||
var clone = function () {
|
||||
return Cell(get());
|
||||
};
|
||||
return {
|
||||
get: get,
|
||||
set: set,
|
||||
clone: clone
|
||||
};
|
||||
};
|
||||
|
||||
var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
||||
|
||||
var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
||||
|
||||
function isContentEditableFalse(node) {
|
||||
return node && node.nodeType === 1 && node.contentEditable === 'false';
|
||||
}
|
||||
function findAndReplaceDOMText(regex, node, replacementNode, captureGroup, schema) {
|
||||
var m;
|
||||
var matches = [];
|
||||
var text, count = 0, doc;
|
||||
var blockElementsMap, hiddenTextElementsMap, shortEndedElementsMap;
|
||||
doc = node.ownerDocument;
|
||||
blockElementsMap = schema.getBlockElements();
|
||||
hiddenTextElementsMap = schema.getWhiteSpaceElements();
|
||||
shortEndedElementsMap = schema.getShortEndedElements();
|
||||
function getMatchIndexes(m, captureGroup) {
|
||||
captureGroup = captureGroup || 0;
|
||||
if (!m[0]) {
|
||||
throw new Error('findAndReplaceDOMText cannot handle zero-length matches');
|
||||
}
|
||||
var index = m.index;
|
||||
if (captureGroup > 0) {
|
||||
var cg = m[captureGroup];
|
||||
if (!cg) {
|
||||
throw new Error('Invalid capture group');
|
||||
}
|
||||
index += m[0].indexOf(cg);
|
||||
m[0] = cg;
|
||||
}
|
||||
return [
|
||||
index,
|
||||
index + m[0].length,
|
||||
[m[0]]
|
||||
];
|
||||
}
|
||||
function getText(node) {
|
||||
var txt;
|
||||
if (node.nodeType === 3) {
|
||||
return node.data;
|
||||
}
|
||||
if (hiddenTextElementsMap[node.nodeName] && !blockElementsMap[node.nodeName]) {
|
||||
return '';
|
||||
}
|
||||
txt = '';
|
||||
if (isContentEditableFalse(node)) {
|
||||
return '\n';
|
||||
}
|
||||
if (blockElementsMap[node.nodeName] || shortEndedElementsMap[node.nodeName]) {
|
||||
txt += '\n';
|
||||
}
|
||||
if (node = node.firstChild) {
|
||||
do {
|
||||
txt += getText(node);
|
||||
} while (node = node.nextSibling);
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
function stepThroughMatches(node, matches, replaceFn) {
|
||||
var startNode, endNode, startNodeIndex, endNodeIndex, innerNodes = [], atIndex = 0, curNode = node, matchLocation = matches.shift(), matchIndex = 0;
|
||||
out:
|
||||
while (true) {
|
||||
if (blockElementsMap[curNode.nodeName] || shortEndedElementsMap[curNode.nodeName] || isContentEditableFalse(curNode)) {
|
||||
atIndex++;
|
||||
}
|
||||
if (curNode.nodeType === 3) {
|
||||
if (!endNode && curNode.length + atIndex >= matchLocation[1]) {
|
||||
endNode = curNode;
|
||||
endNodeIndex = matchLocation[1] - atIndex;
|
||||
} else if (startNode) {
|
||||
innerNodes.push(curNode);
|
||||
}
|
||||
if (!startNode && curNode.length + atIndex > matchLocation[0]) {
|
||||
startNode = curNode;
|
||||
startNodeIndex = matchLocation[0] - atIndex;
|
||||
}
|
||||
atIndex += curNode.length;
|
||||
}
|
||||
if (startNode && endNode) {
|
||||
curNode = replaceFn({
|
||||
startNode: startNode,
|
||||
startNodeIndex: startNodeIndex,
|
||||
endNode: endNode,
|
||||
endNodeIndex: endNodeIndex,
|
||||
innerNodes: innerNodes,
|
||||
match: matchLocation[2],
|
||||
matchIndex: matchIndex
|
||||
});
|
||||
atIndex -= endNode.length - endNodeIndex;
|
||||
startNode = null;
|
||||
endNode = null;
|
||||
innerNodes = [];
|
||||
matchLocation = matches.shift();
|
||||
matchIndex++;
|
||||
if (!matchLocation) {
|
||||
break;
|
||||
}
|
||||
} else if ((!hiddenTextElementsMap[curNode.nodeName] || blockElementsMap[curNode.nodeName]) && curNode.firstChild) {
|
||||
if (!isContentEditableFalse(curNode)) {
|
||||
curNode = curNode.firstChild;
|
||||
continue;
|
||||
}
|
||||
} else if (curNode.nextSibling) {
|
||||
curNode = curNode.nextSibling;
|
||||
continue;
|
||||
}
|
||||
while (true) {
|
||||
if (curNode.nextSibling) {
|
||||
curNode = curNode.nextSibling;
|
||||
break;
|
||||
} else if (curNode.parentNode !== node) {
|
||||
curNode = curNode.parentNode;
|
||||
} else {
|
||||
break out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function genReplacer(nodeName) {
|
||||
var makeReplacementNode;
|
||||
if (typeof nodeName !== 'function') {
|
||||
var stencilNode_1 = nodeName.nodeType ? nodeName : doc.createElement(nodeName);
|
||||
makeReplacementNode = function (fill, matchIndex) {
|
||||
var clone = stencilNode_1.cloneNode(false);
|
||||
clone.setAttribute('data-mce-index', matchIndex);
|
||||
if (fill) {
|
||||
clone.appendChild(doc.createTextNode(fill));
|
||||
}
|
||||
return clone;
|
||||
};
|
||||
} else {
|
||||
makeReplacementNode = nodeName;
|
||||
}
|
||||
return function (range) {
|
||||
var before;
|
||||
var after;
|
||||
var parentNode;
|
||||
var startNode = range.startNode;
|
||||
var endNode = range.endNode;
|
||||
var matchIndex = range.matchIndex;
|
||||
if (startNode === endNode) {
|
||||
var node_1 = startNode;
|
||||
parentNode = node_1.parentNode;
|
||||
if (range.startNodeIndex > 0) {
|
||||
before = doc.createTextNode(node_1.data.substring(0, range.startNodeIndex));
|
||||
parentNode.insertBefore(before, node_1);
|
||||
}
|
||||
var el = makeReplacementNode(range.match[0], matchIndex);
|
||||
parentNode.insertBefore(el, node_1);
|
||||
if (range.endNodeIndex < node_1.length) {
|
||||
after = doc.createTextNode(node_1.data.substring(range.endNodeIndex));
|
||||
parentNode.insertBefore(after, node_1);
|
||||
}
|
||||
node_1.parentNode.removeChild(node_1);
|
||||
return el;
|
||||
}
|
||||
before = doc.createTextNode(startNode.data.substring(0, range.startNodeIndex));
|
||||
after = doc.createTextNode(endNode.data.substring(range.endNodeIndex));
|
||||
var elA = makeReplacementNode(startNode.data.substring(range.startNodeIndex), matchIndex);
|
||||
for (var i = 0, l = range.innerNodes.length; i < l; ++i) {
|
||||
var innerNode = range.innerNodes[i];
|
||||
var innerEl = makeReplacementNode(innerNode.data, matchIndex);
|
||||
innerNode.parentNode.replaceChild(innerEl, innerNode);
|
||||
}
|
||||
var elB = makeReplacementNode(endNode.data.substring(0, range.endNodeIndex), matchIndex);
|
||||
parentNode = startNode.parentNode;
|
||||
parentNode.insertBefore(before, startNode);
|
||||
parentNode.insertBefore(elA, startNode);
|
||||
parentNode.removeChild(startNode);
|
||||
parentNode = endNode.parentNode;
|
||||
parentNode.insertBefore(elB, endNode);
|
||||
parentNode.insertBefore(after, endNode);
|
||||
parentNode.removeChild(endNode);
|
||||
return elB;
|
||||
};
|
||||
}
|
||||
text = getText(node);
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
if (regex.global) {
|
||||
while (m = regex.exec(text)) {
|
||||
matches.push(getMatchIndexes(m, captureGroup));
|
||||
}
|
||||
} else {
|
||||
m = text.match(regex);
|
||||
matches.push(getMatchIndexes(m, captureGroup));
|
||||
}
|
||||
if (matches.length) {
|
||||
count = matches.length;
|
||||
stepThroughMatches(node, matches, genReplacer(replacementNode));
|
||||
}
|
||||
return count;
|
||||
}
|
||||
var FindReplaceText = { findAndReplaceDOMText: findAndReplaceDOMText };
|
||||
|
||||
var getElmIndex = function (elm) {
|
||||
var value = elm.getAttribute('data-mce-index');
|
||||
if (typeof value === 'number') {
|
||||
return '' + value;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var markAllMatches = function (editor, currentIndexState, regex) {
|
||||
var node, marker;
|
||||
marker = editor.dom.create('span', { 'data-mce-bogus': 1 });
|
||||
marker.className = 'mce-match-marker';
|
||||
node = editor.getBody();
|
||||
done(editor, currentIndexState, false);
|
||||
return FindReplaceText.findAndReplaceDOMText(regex, node, marker, false, editor.schema);
|
||||
};
|
||||
var unwrap = function (node) {
|
||||
var parentNode = node.parentNode;
|
||||
if (node.firstChild) {
|
||||
parentNode.insertBefore(node.firstChild, node);
|
||||
}
|
||||
node.parentNode.removeChild(node);
|
||||
};
|
||||
var findSpansByIndex = function (editor, index) {
|
||||
var nodes;
|
||||
var spans = [];
|
||||
nodes = global$1.toArray(editor.getBody().getElementsByTagName('span'));
|
||||
if (nodes.length) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var nodeIndex = getElmIndex(nodes[i]);
|
||||
if (nodeIndex === null || !nodeIndex.length) {
|
||||
continue;
|
||||
}
|
||||
if (nodeIndex === index.toString()) {
|
||||
spans.push(nodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return spans;
|
||||
};
|
||||
var moveSelection = function (editor, currentIndexState, forward) {
|
||||
var testIndex = currentIndexState.get();
|
||||
var dom = editor.dom;
|
||||
forward = forward !== false;
|
||||
if (forward) {
|
||||
testIndex++;
|
||||
} else {
|
||||
testIndex--;
|
||||
}
|
||||
dom.removeClass(findSpansByIndex(editor, currentIndexState.get()), 'mce-match-marker-selected');
|
||||
var spans = findSpansByIndex(editor, testIndex);
|
||||
if (spans.length) {
|
||||
dom.addClass(findSpansByIndex(editor, testIndex), 'mce-match-marker-selected');
|
||||
editor.selection.scrollIntoView(spans[0]);
|
||||
return testIndex;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
var removeNode = function (dom, node) {
|
||||
var parent = node.parentNode;
|
||||
dom.remove(node);
|
||||
if (dom.isEmpty(parent)) {
|
||||
dom.remove(parent);
|
||||
}
|
||||
};
|
||||
var find = function (editor, currentIndexState, text, matchCase, wholeWord) {
|
||||
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
||||
text = text.replace(/\s/g, '[^\\S\\r\\n]');
|
||||
text = wholeWord ? '\\b' + text + '\\b' : text;
|
||||
var count = markAllMatches(editor, currentIndexState, new RegExp(text, matchCase ? 'g' : 'gi'));
|
||||
if (count) {
|
||||
currentIndexState.set(-1);
|
||||
currentIndexState.set(moveSelection(editor, currentIndexState, true));
|
||||
}
|
||||
return count;
|
||||
};
|
||||
var next = function (editor, currentIndexState) {
|
||||
var index = moveSelection(editor, currentIndexState, true);
|
||||
if (index !== -1) {
|
||||
currentIndexState.set(index);
|
||||
}
|
||||
};
|
||||
var prev = function (editor, currentIndexState) {
|
||||
var index = moveSelection(editor, currentIndexState, false);
|
||||
if (index !== -1) {
|
||||
currentIndexState.set(index);
|
||||
}
|
||||
};
|
||||
var isMatchSpan = function (node) {
|
||||
var matchIndex = getElmIndex(node);
|
||||
return matchIndex !== null && matchIndex.length > 0;
|
||||
};
|
||||
var replace = function (editor, currentIndexState, text, forward, all) {
|
||||
var i, nodes, node, matchIndex, currentMatchIndex, nextIndex = currentIndexState.get(), hasMore;
|
||||
forward = forward !== false;
|
||||
node = editor.getBody();
|
||||
nodes = global$1.grep(global$1.toArray(node.getElementsByTagName('span')), isMatchSpan);
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
var nodeIndex = getElmIndex(nodes[i]);
|
||||
matchIndex = currentMatchIndex = parseInt(nodeIndex, 10);
|
||||
if (all || matchIndex === currentIndexState.get()) {
|
||||
if (text.length) {
|
||||
nodes[i].firstChild.nodeValue = text;
|
||||
unwrap(nodes[i]);
|
||||
} else {
|
||||
removeNode(editor.dom, nodes[i]);
|
||||
}
|
||||
while (nodes[++i]) {
|
||||
matchIndex = parseInt(getElmIndex(nodes[i]), 10);
|
||||
if (matchIndex === currentMatchIndex) {
|
||||
removeNode(editor.dom, nodes[i]);
|
||||
} else {
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (forward) {
|
||||
nextIndex--;
|
||||
}
|
||||
} else if (currentMatchIndex > currentIndexState.get()) {
|
||||
nodes[i].setAttribute('data-mce-index', currentMatchIndex - 1);
|
||||
}
|
||||
}
|
||||
currentIndexState.set(nextIndex);
|
||||
if (forward) {
|
||||
hasMore = hasNext(editor, currentIndexState);
|
||||
next(editor, currentIndexState);
|
||||
} else {
|
||||
hasMore = hasPrev(editor, currentIndexState);
|
||||
prev(editor, currentIndexState);
|
||||
}
|
||||
return !all && hasMore;
|
||||
};
|
||||
var done = function (editor, currentIndexState, keepEditorSelection) {
|
||||
var i, nodes, startContainer, endContainer;
|
||||
nodes = global$1.toArray(editor.getBody().getElementsByTagName('span'));
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
var nodeIndex = getElmIndex(nodes[i]);
|
||||
if (nodeIndex !== null && nodeIndex.length) {
|
||||
if (nodeIndex === currentIndexState.get().toString()) {
|
||||
if (!startContainer) {
|
||||
startContainer = nodes[i].firstChild;
|
||||
}
|
||||
endContainer = nodes[i].firstChild;
|
||||
}
|
||||
unwrap(nodes[i]);
|
||||
}
|
||||
}
|
||||
if (startContainer && endContainer) {
|
||||
var rng = editor.dom.createRng();
|
||||
rng.setStart(startContainer, 0);
|
||||
rng.setEnd(endContainer, endContainer.data.length);
|
||||
if (keepEditorSelection !== false) {
|
||||
editor.selection.setRng(rng);
|
||||
}
|
||||
return rng;
|
||||
}
|
||||
};
|
||||
var hasNext = function (editor, currentIndexState) {
|
||||
return findSpansByIndex(editor, currentIndexState.get() + 1).length > 0;
|
||||
};
|
||||
var hasPrev = function (editor, currentIndexState) {
|
||||
return findSpansByIndex(editor, currentIndexState.get() - 1).length > 0;
|
||||
};
|
||||
var Actions = {
|
||||
done: done,
|
||||
find: find,
|
||||
next: next,
|
||||
prev: prev,
|
||||
replace: replace,
|
||||
hasNext: hasNext,
|
||||
hasPrev: hasPrev
|
||||
};
|
||||
|
||||
var get = function (editor, currentIndexState) {
|
||||
var done = function (keepEditorSelection) {
|
||||
return Actions.done(editor, currentIndexState, keepEditorSelection);
|
||||
};
|
||||
var find = function (text, matchCase, wholeWord) {
|
||||
return Actions.find(editor, currentIndexState, text, matchCase, wholeWord);
|
||||
};
|
||||
var next = function () {
|
||||
return Actions.next(editor, currentIndexState);
|
||||
};
|
||||
var prev = function () {
|
||||
return Actions.prev(editor, currentIndexState);
|
||||
};
|
||||
var replace = function (text, forward, all) {
|
||||
return Actions.replace(editor, currentIndexState, text, forward, all);
|
||||
};
|
||||
return {
|
||||
done: done,
|
||||
find: find,
|
||||
next: next,
|
||||
prev: prev,
|
||||
replace: replace
|
||||
};
|
||||
};
|
||||
var Api = { get: get };
|
||||
|
||||
var open = function (editor, currentIndexState) {
|
||||
var last = {}, selectedText;
|
||||
editor.undoManager.add();
|
||||
selectedText = global$1.trim(editor.selection.getContent({ format: 'text' }));
|
||||
function updateButtonStates() {
|
||||
win.statusbar.find('#next').disabled(Actions.hasNext(editor, currentIndexState) === false);
|
||||
win.statusbar.find('#prev').disabled(Actions.hasPrev(editor, currentIndexState) === false);
|
||||
}
|
||||
function notFoundAlert() {
|
||||
editor.windowManager.alert('Could not find the specified string.', function () {
|
||||
win.find('#find')[0].focus();
|
||||
});
|
||||
}
|
||||
var win = editor.windowManager.open({
|
||||
layout: 'flex',
|
||||
pack: 'center',
|
||||
align: 'center',
|
||||
onClose: function () {
|
||||
editor.focus();
|
||||
Actions.done(editor, currentIndexState);
|
||||
editor.undoManager.add();
|
||||
},
|
||||
onSubmit: function (e) {
|
||||
var count, caseState, text, wholeWord;
|
||||
e.preventDefault();
|
||||
caseState = win.find('#case').checked();
|
||||
wholeWord = win.find('#words').checked();
|
||||
text = win.find('#find').value();
|
||||
if (!text.length) {
|
||||
Actions.done(editor, currentIndexState, false);
|
||||
win.statusbar.items().slice(1).disabled(true);
|
||||
return;
|
||||
}
|
||||
if (last.text === text && last.caseState === caseState && last.wholeWord === wholeWord) {
|
||||
if (!Actions.hasNext(editor, currentIndexState)) {
|
||||
notFoundAlert();
|
||||
return;
|
||||
}
|
||||
Actions.next(editor, currentIndexState);
|
||||
updateButtonStates();
|
||||
return;
|
||||
}
|
||||
count = Actions.find(editor, currentIndexState, text, caseState, wholeWord);
|
||||
if (!count) {
|
||||
notFoundAlert();
|
||||
}
|
||||
win.statusbar.items().slice(1).disabled(count === 0);
|
||||
updateButtonStates();
|
||||
last = {
|
||||
text: text,
|
||||
caseState: caseState,
|
||||
wholeWord: wholeWord
|
||||
};
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: 'Find',
|
||||
subtype: 'primary',
|
||||
onclick: function () {
|
||||
win.submit();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Replace',
|
||||
disabled: true,
|
||||
onclick: function () {
|
||||
if (!Actions.replace(editor, currentIndexState, win.find('#replace').value())) {
|
||||
win.statusbar.items().slice(1).disabled(true);
|
||||
currentIndexState.set(-1);
|
||||
last = {};
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Replace all',
|
||||
disabled: true,
|
||||
onclick: function () {
|
||||
Actions.replace(editor, currentIndexState, win.find('#replace').value(), true, true);
|
||||
win.statusbar.items().slice(1).disabled(true);
|
||||
last = {};
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'spacer',
|
||||
flex: 1
|
||||
},
|
||||
{
|
||||
text: 'Prev',
|
||||
name: 'prev',
|
||||
disabled: true,
|
||||
onclick: function () {
|
||||
Actions.prev(editor, currentIndexState);
|
||||
updateButtonStates();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Next',
|
||||
name: 'next',
|
||||
disabled: true,
|
||||
onclick: function () {
|
||||
Actions.next(editor, currentIndexState);
|
||||
updateButtonStates();
|
||||
}
|
||||
}
|
||||
],
|
||||
title: 'Find and replace',
|
||||
items: {
|
||||
type: 'form',
|
||||
padding: 20,
|
||||
labelGap: 30,
|
||||
spacing: 10,
|
||||
items: [
|
||||
{
|
||||
type: 'textbox',
|
||||
name: 'find',
|
||||
size: 40,
|
||||
label: 'Find',
|
||||
value: selectedText
|
||||
},
|
||||
{
|
||||
type: 'textbox',
|
||||
name: 'replace',
|
||||
size: 40,
|
||||
label: 'Replace with'
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'case',
|
||||
text: 'Match case',
|
||||
label: ' '
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'words',
|
||||
text: 'Whole words',
|
||||
label: ' '
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
};
|
||||
var Dialog = { open: open };
|
||||
|
||||
var register = function (editor, currentIndexState) {
|
||||
editor.addCommand('SearchReplace', function () {
|
||||
Dialog.open(editor, currentIndexState);
|
||||
});
|
||||
};
|
||||
var Commands = { register: register };
|
||||
|
||||
var showDialog = function (editor, currentIndexState) {
|
||||
return function () {
|
||||
Dialog.open(editor, currentIndexState);
|
||||
};
|
||||
};
|
||||
var register$1 = function (editor, currentIndexState) {
|
||||
editor.addMenuItem('searchreplace', {
|
||||
text: 'Find and replace',
|
||||
shortcut: 'Meta+F',
|
||||
onclick: showDialog(editor, currentIndexState),
|
||||
separator: 'before',
|
||||
context: 'edit'
|
||||
});
|
||||
editor.addButton('searchreplace', {
|
||||
tooltip: 'Find and replace',
|
||||
onclick: showDialog(editor, currentIndexState)
|
||||
});
|
||||
editor.shortcuts.add('Meta+F', '', showDialog(editor, currentIndexState));
|
||||
};
|
||||
var Buttons = { register: register$1 };
|
||||
|
||||
global.add('searchreplace', function (editor) {
|
||||
var currentIndexState = Cell(-1);
|
||||
Commands.register(editor, currentIndexState);
|
||||
Buttons.register(editor, currentIndexState);
|
||||
return Api.get(editor, currentIndexState);
|
||||
});
|
||||
function Plugin () {
|
||||
}
|
||||
|
||||
return Plugin;
|
||||
|
||||
}());
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var r=function(e){var t=e,n=function(){return t};return{get:n,set:function(e){t=e},clone:function(){return r(n())}}},e=tinymce.util.Tools.resolve("tinymce.PluginManager"),p=tinymce.util.Tools.resolve("tinymce.util.Tools");function h(e){return e&&1===e.nodeType&&"false"===e.contentEditable}var u={findAndReplaceDOMText:function(t,n,r,a,i){var o,d,m,f,p,g,c=[],l=0;function s(e,t){if(t=t||0,!e[0])throw new Error("findAndReplaceDOMText cannot handle zero-length matches");var n=e.index;if(0<t){var r=e[t];if(!r)throw new Error("Invalid capture group");n+=e[0].indexOf(r),e[0]=r}return[n,n+e[0].length,[e[0]]]}if(m=n.ownerDocument,f=i.getBlockElements(),p=i.getWhiteSpaceElements(),g=i.getShortEndedElements(),d=function e(t){var n;if(3===t.nodeType)return t.data;if(p[t.nodeName]&&!f[t.nodeName])return"";if(n="",h(t))return"\n";if((f[t.nodeName]||g[t.nodeName])&&(n+="\n"),t=t.firstChild)for(;n+=e(t),t=t.nextSibling;);return n}(n)){if(t.global)for(;o=t.exec(d);)c.push(s(o,a));else o=d.match(t),c.push(s(o,a));return c.length&&(l=c.length,function(e,t,n){var r,a,i,o,d=[],c=0,l=e,s=t.shift(),u=0;e:for(;;){if((f[l.nodeName]||g[l.nodeName]||h(l))&&c++,3===l.nodeType&&(!a&&l.length+c>=s[1]?(a=l,o=s[1]-c):r&&d.push(l),!r&&l.length+c>s[0]&&(r=l,i=s[0]-c),c+=l.length),r&&a){if(l=n({startNode:r,startNodeIndex:i,endNode:a,endNodeIndex:o,innerNodes:d,match:s[2],matchIndex:u}),c-=a.length-o,a=r=null,d=[],u++,!(s=t.shift()))break}else if(p[l.nodeName]&&!f[l.nodeName]||!l.firstChild){if(l.nextSibling){l=l.nextSibling;continue}}else if(!h(l)){l=l.firstChild;continue}for(;;){if(l.nextSibling){l=l.nextSibling;break}if(l.parentNode===e)break e;l=l.parentNode}}}(n,c,function(e){var h;if("function"!=typeof e){var r=e.nodeType?e:m.createElement(e);h=function(e,t){var n=r.cloneNode(!1);return n.setAttribute("data-mce-index",t),e&&n.appendChild(m.createTextNode(e)),n}}else h=e;return function(e){var t,n,r,a=e.startNode,i=e.endNode,o=e.matchIndex;if(a===i){var d=a;r=d.parentNode,0<e.startNodeIndex&&(t=m.createTextNode(d.data.substring(0,e.startNodeIndex)),r.insertBefore(t,d));var c=h(e.match[0],o);return r.insertBefore(c,d),e.endNodeIndex<d.length&&(n=m.createTextNode(d.data.substring(e.endNodeIndex)),r.insertBefore(n,d)),d.parentNode.removeChild(d),c}t=m.createTextNode(a.data.substring(0,e.startNodeIndex)),n=m.createTextNode(i.data.substring(e.endNodeIndex));for(var l=h(a.data.substring(e.startNodeIndex),o),s=0,u=e.innerNodes.length;s<u;++s){var f=e.innerNodes[s],p=h(f.data,o);f.parentNode.replaceChild(p,f)}var g=h(i.data.substring(0,e.endNodeIndex),o);return(r=a.parentNode).insertBefore(t,a),r.insertBefore(l,a),r.removeChild(a),(r=i.parentNode).insertBefore(g,i),r.insertBefore(n,i),r.removeChild(i),g}}(r))),l}}},g=function(e){var t=e.getAttribute("data-mce-index");return"number"==typeof t?""+t:t},m=function(e){var t=e.parentNode;e.firstChild&&t.insertBefore(e.firstChild,e),e.parentNode.removeChild(e)},o=function(e,t){var n,r=[];if((n=p.toArray(e.getBody().getElementsByTagName("span"))).length)for(var a=0;a<n.length;a++){var i=g(n[a]);null!==i&&i.length&&i===t.toString()&&r.push(n[a])}return r},f=function(e,t,n){var r=t.get(),a=e.dom;(n=!1!==n)?r++:r--,a.removeClass(o(e,t.get()),"mce-match-marker-selected");var i=o(e,r);return i.length?(a.addClass(o(e,r),"mce-match-marker-selected"),e.selection.scrollIntoView(i[0]),r):-1},v=function(e,t){var n=t.parentNode;e.remove(t),e.isEmpty(n)&&e.remove(n)},x=function(e,t){var n=f(e,t,!0);-1!==n&&t.set(n)},b=function(e,t){var n=f(e,t,!1);-1!==n&&t.set(n)},N=function(e){var t=g(e);return null!==t&&0<t.length},y=function(e,t,n){var r,a,i,o;for(a=p.toArray(e.getBody().getElementsByTagName("span")),r=0;r<a.length;r++){var d=g(a[r]);null!==d&&d.length&&(d===t.get().toString()&&(i||(i=a[r].firstChild),o=a[r].firstChild),m(a[r]))}if(i&&o){var c=e.dom.createRng();return c.setStart(i,0),c.setEnd(o,o.data.length),!1!==n&&e.selection.setRng(c),c}},k=function(e,t){return 0<o(e,t.get()+1).length},C=function(e,t){return 0<o(e,t.get()-1).length},T={done:y,find:function(e,t,n,r,a){n=(n=n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")).replace(/\s/g,"[^\\S\\r\\n]"),n=a?"\\b"+n+"\\b":n;var i,o,d,c,l,s=(i=e,o=t,d=new RegExp(n,r?"g":"gi"),(l=i.dom.create("span",{"data-mce-bogus":1})).className="mce-match-marker",c=i.getBody(),y(i,o,!1),u.findAndReplaceDOMText(d,c,l,!1,i.schema));return s&&(t.set(-1),t.set(f(e,t,!0))),s},next:x,prev:b,replace:function(e,t,n,r,a){var i,o,d,c,l,s,u=t.get();for(r=!1!==r,d=e.getBody(),o=p.grep(p.toArray(d.getElementsByTagName("span")),N),i=0;i<o.length;i++){var f=g(o[i]);if(c=l=parseInt(f,10),a||c===t.get()){for(n.length?(o[i].firstChild.nodeValue=n,m(o[i])):v(e.dom,o[i]);o[++i];){if((c=parseInt(g(o[i]),10))!==l){i--;break}v(e.dom,o[i])}r&&u--}else l>t.get()&&o[i].setAttribute("data-mce-index",l-1)}return t.set(u),r?(s=k(e,t),x(e,t)):(s=C(e,t),b(e,t)),!a&&s},hasNext:k,hasPrev:C},n=function(r,a){return{done:function(e){return T.done(r,a,e)},find:function(e,t,n){retuLine truncated
|
||||
Reference in new issue
Block a user