mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 07:35:48 +01:00
improvements
This commit is contained in:
parent
c2acc25825
commit
cfef2bb7e2
3 changed files with 88 additions and 80 deletions
|
|
@ -596,10 +596,51 @@ var Dom = function () {
|
|||
|
||||
return nativeInputs.indexOf(target.tagName) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks node if it is empty
|
||||
* It must be node without childNodes
|
||||
* @param {Node} node
|
||||
*
|
||||
* @return {Boolean} true if it is empty
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'checkNodeEmpty',
|
||||
value: function checkNodeEmpty(node) {
|
||||
|
||||
if (this.isElement(node) && this.isNativeInput(node)) {
|
||||
|
||||
node = node.value;
|
||||
|
||||
if (node.trim()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if (node.trim()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* breadth-first search
|
||||
*
|
||||
* Pushes to stack all DOM leafs and checks for emptiness
|
||||
* @param {Node} node
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'isEmpty',
|
||||
value: function isEmpty(node) {
|
||||
var _this = this;
|
||||
|
||||
var treeWalker = [],
|
||||
stack = [];
|
||||
|
|
@ -635,41 +676,7 @@ var Dom = function () {
|
|||
treeWalker.push(node);
|
||||
}
|
||||
|
||||
var isEmpty = true;
|
||||
|
||||
stack.forEach(function (node) {
|
||||
|
||||
if (_this.isElement(node)) {
|
||||
|
||||
if (_this.isNativeInput(node)) {
|
||||
|
||||
node = node.value;
|
||||
|
||||
if (node.trim()) {
|
||||
|
||||
isEmpty = false;
|
||||
}
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if (node.trim()) {
|
||||
|
||||
isEmpty = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if (node.trim()) {
|
||||
|
||||
isEmpty = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return isEmpty;
|
||||
return stack.every(this.checkNodeEmpty);
|
||||
}
|
||||
}]);
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -174,6 +174,49 @@ export default class Dom {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks node if it is empty
|
||||
* It must be node without childNodes
|
||||
* @param {Node} node
|
||||
*
|
||||
* @return {Boolean} true if it is empty
|
||||
*/
|
||||
static checkNodeEmpty(node) {
|
||||
|
||||
if ( this.isElement(node) && this.isNativeInput(node) ) {
|
||||
|
||||
node = node.value;
|
||||
|
||||
if ( node.trim() ) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if ( node.trim() ) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* breadth-first search
|
||||
*
|
||||
* Pushes to stack all DOM leafs and checks for emptiness
|
||||
* @param {Node} node
|
||||
* @return {boolean}
|
||||
*/
|
||||
static isEmpty(node) {
|
||||
|
||||
let treeWalker = [],
|
||||
|
|
@ -214,49 +257,7 @@ export default class Dom {
|
|||
|
||||
}
|
||||
|
||||
let isEmpty = true;
|
||||
|
||||
stack.forEach( (node) => {
|
||||
|
||||
if ( this.isElement(node) ) {
|
||||
|
||||
if ( this.isNativeInput(node) ) {
|
||||
|
||||
node = node.value;
|
||||
|
||||
if ( node.trim() ) {
|
||||
|
||||
isEmpty = false;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if ( node.trim() ) {
|
||||
|
||||
isEmpty = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
node = node.textContent.replace('\u200B', '');
|
||||
|
||||
if ( node.trim() ) {
|
||||
|
||||
isEmpty = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return isEmpty;
|
||||
return stack.every( this.checkNodeEmpty );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue