OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
newline
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
ContextSelectors.ts
994 bytes
02/20/2020 05:44:04 AM
rw-r--r--
📄
InsertBlock.ts
16.37 KB
02/20/2020 05:44:04 AM
rw-r--r--
📄
InsertBr.ts
5.95 KB
02/20/2020 05:44:05 AM
rw-r--r--
📄
InsertLi.ts
3.73 KB
02/20/2020 05:44:05 AM
rw-r--r--
📄
InsertNewLine.ts
856 bytes
02/20/2020 05:44:06 AM
rw-r--r--
📄
NewLineAction.ts
3.46 KB
02/20/2020 05:44:06 AM
rw-r--r--
📄
NewLineUtils.ts
3.32 KB
02/20/2020 05:44:07 AM
rw-r--r--
Editing: InsertLi.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import NodeType from '../dom/NodeType'; import NewLineUtils from './NewLineUtils'; import Editor from '../api/Editor'; const hasFirstChild = function (elm, name) { return elm.firstChild && elm.firstChild.nodeName === name; }; const hasParent = function (elm, parentName) { return elm && elm.parentNode && elm.parentNode.nodeName === parentName; }; const isListBlock = function (elm) { return elm && /^(OL|UL|LI)$/.test(elm.nodeName); }; const isNestedList = function (elm) { return isListBlock(elm) && isListBlock(elm.parentNode); }; const getContainerBlock = function (containerBlock) { const containerBlockParent = containerBlock.parentNode; if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) { return containerBlockParent; } return containerBlock; }; const isFirstOrLastLi = function (containerBlock, parentBlock, first) { let node = containerBlock[first ? 'firstChild' : 'lastChild']; // Find first/last element since there might be whitespace there while (node) { if (NodeType.isElement(node)) { break; } node = node[first ? 'nextSibling' : 'previousSibling']; } return node === parentBlock; }; // Inserts a block or br before/after or in the middle of a split list of the LI is empty const insert = function (editor: Editor, createNewBlock, containerBlock, parentBlock, newBlockName) { const dom = editor.dom; const rng = editor.selection.getRng(); if (containerBlock === editor.getBody()) { return; } if (isNestedList(containerBlock)) { newBlockName = 'LI'; } let newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR'); if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) { if (hasParent(containerBlock, 'LI')) { // Nested list is inside a LI dom.insertAfter(newBlock, getContainerBlock(containerBlock)); } else { // Is first and last list item then replace the OL/UL with a text block dom.replace(newBlock, containerBlock); } } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) { if (hasParent(containerBlock, 'LI')) { // List nested in an LI then move the list to a new sibling LI dom.insertAfter(newBlock, getContainerBlock(containerBlock)); newBlock.appendChild(dom.doc.createTextNode(' ')); // Needed for IE so the caret can be placed newBlock.appendChild(containerBlock); } else { // First LI in list then remove LI and add text block before list containerBlock.parentNode.insertBefore(newBlock, containerBlock); } } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) { // Last LI in list then remove LI and add text block after list dom.insertAfter(newBlock, getContainerBlock(containerBlock)); } else { // Middle LI in list the split the list and insert a text block in the middle // Extract after fragment and insert it after the current block containerBlock = getContainerBlock(containerBlock); const tmpRng = rng.cloneRange(); tmpRng.setStartAfter(parentBlock); tmpRng.setEndAfter(containerBlock); const fragment = tmpRng.extractContents(); if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) { newBlock = fragment.firstChild; dom.insertAfter(fragment, containerBlock); } else { dom.insertAfter(fragment, containerBlock); dom.insertAfter(newBlock, containerBlock); } } dom.remove(parentBlock); NewLineUtils.moveToCaretPosition(editor, newBlock); }; export default { insert };