mirror of
https://github.com/codex-team/editor.js
synced 2024-06-16 04:35:50 +02:00
Upd
This commit is contained in:
parent
0968152570
commit
eb362a6e23
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -71,23 +71,8 @@ module.exports = (function (callbacks) {
|
||||||
*/
|
*/
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
var nativeInputs = editor.content.currentNode.querySelectorAll('textarea, input'),
|
|
||||||
nativeInputsAreEmpty = true,
|
|
||||||
textContentIsEmpty = !editor.content.currentNode.textContent.trim();
|
|
||||||
|
|
||||||
Array.prototype.map.call(nativeInputs, function (input) {
|
if (!editor.core.isBlockEmpty(editor.content.currentNode)) {
|
||||||
|
|
||||||
if (input.type == 'textarea' || input.type == 'text') {
|
|
||||||
|
|
||||||
nativeInputsAreEmpty = nativeInputsAreEmpty && !input.value.trim();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
var blockIsEmpty = textContentIsEmpty && nativeInputsAreEmpty;
|
|
||||||
|
|
||||||
if (!blockIsEmpty) {
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -271,14 +271,14 @@ module.exports = (function (caret) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts node at the caret location
|
* Inserts node at the caret location
|
||||||
* @param node
|
* @param {HTMLElement|DocumentFragment} node
|
||||||
*/
|
*/
|
||||||
caret.insertNode = function (node) {
|
caret.insertNode = function (node) {
|
||||||
|
|
||||||
var selection, range,
|
var selection, range,
|
||||||
lastNode = node;
|
lastNode = node;
|
||||||
|
|
||||||
if (node instanceof window.DocumentFragment) {
|
if (node.nodeType == editor.core.nodeTypes.DOCUMENT_FRAGMENT) {
|
||||||
|
|
||||||
lastNode = node.lastChild;
|
lastNode = node.lastChild;
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,8 @@ module.exports = (function (core) {
|
||||||
core.nodeTypes = {
|
core.nodeTypes = {
|
||||||
TAG : 1,
|
TAG : 1,
|
||||||
TEXT : 3,
|
TEXT : 3,
|
||||||
COMMENT : 8
|
COMMENT : 8,
|
||||||
|
DOCUMENT_FRAGMENT: 11
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,6 +352,35 @@ module.exports = (function (core) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if block is empty
|
||||||
|
* We should check block textContent, child native inputs and some exceptions like IMG and IFRAME
|
||||||
|
*
|
||||||
|
* @param block
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
core.isBlockEmpty = function (block) {
|
||||||
|
|
||||||
|
const EXCEPTION_TAGS = ['IMG', 'IFRAME'];
|
||||||
|
|
||||||
|
var nativeInputs = block.querySelectorAll('textarea, input'),
|
||||||
|
nativeInputsAreEmpty = true,
|
||||||
|
textContentIsEmpty = !block.textContent.trim();
|
||||||
|
|
||||||
|
Array.prototype.forEach.call(nativeInputs, function (input) {
|
||||||
|
|
||||||
|
if (input.type == 'textarea' || input.type == 'text') {
|
||||||
|
|
||||||
|
nativeInputsAreEmpty = nativeInputsAreEmpty && !input.value.trim();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return textContentIsEmpty && nativeInputsAreEmpty && !(EXCEPTION_TAGS.indexOf(block.tagName) + 1);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return core;
|
return core;
|
||||||
|
|
||||||
|
|
|
@ -197,13 +197,12 @@ module.exports = function (paste) {
|
||||||
*/
|
*/
|
||||||
var insertPastedParagraphs = function (paragraphs) {
|
var insertPastedParagraphs = function (paragraphs) {
|
||||||
|
|
||||||
var NEW_BLOCK_TYPE = editor.settings.initialBlockPlugin,
|
var NEW_BLOCK_TYPE = editor.settings.initialBlockPlugin;
|
||||||
currentBlockContent = editor.content.currentNode.firstChild.firstChild;
|
|
||||||
|
|
||||||
paragraphs.forEach(function (paragraph, index) {
|
paragraphs.forEach(function (paragraph, index) {
|
||||||
|
|
||||||
/** Don't allow empty paragraphs */
|
/** Don't allow empty paragraphs */
|
||||||
if (paragraph.innerHTML.trim() === '') {
|
if (editor.core.isBlockEmpty(paragraph)) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -212,13 +211,10 @@ module.exports = function (paste) {
|
||||||
/**
|
/**
|
||||||
* If there was no data in working node, replace it with first paragraph of pasted text
|
* If there was no data in working node, replace it with first paragraph of pasted text
|
||||||
*/
|
*/
|
||||||
if (index == 0 && currentBlockContent.innerHTML.trim() === '') {
|
if (index == 0 && editor.core.isBlockEmpty(editor.content.currentNode)) {
|
||||||
|
|
||||||
editor.content.switchBlock(editor.content.currentNode, editor.tools[NEW_BLOCK_TYPE].render({
|
editor.content.currentNode.remove();
|
||||||
text : paragraph.innerHTML
|
editor.caret.setToPreviousBlock(editor.caret.inputIndex);
|
||||||
}), NEW_BLOCK_TYPE);
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue