mirror of
https://github.com/codex-team/editor.js
synced 2024-06-27 09:50:05 +02:00
code improved after review
This commit is contained in:
parent
7393708d77
commit
869c65f3da
|
@ -88,7 +88,7 @@ var codex =
|
||||||
codex.sanitizer = __webpack_require__(18);
|
codex.sanitizer = __webpack_require__(18);
|
||||||
};
|
};
|
||||||
|
|
||||||
codex.version = ("1.3.10");
|
codex.version = ("1.3.11");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
|
@ -1173,7 +1173,7 @@ var codex =
|
||||||
* Works with DOM
|
* Works with DOM
|
||||||
*
|
*
|
||||||
* @author Codex Team
|
* @author Codex Team
|
||||||
* @version 1.3.8
|
* @version 1.3.11
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var content = function (content) {
|
var content = function (content) {
|
||||||
|
@ -1808,26 +1808,16 @@ var codex =
|
||||||
*/
|
*/
|
||||||
var sibling = node.nextSibling;
|
var sibling = node.nextSibling;
|
||||||
|
|
||||||
// console.log('Погнали проверять соседей ');
|
|
||||||
|
|
||||||
while (sibling) {
|
while (sibling) {
|
||||||
|
|
||||||
// console.log('Опаньки! нашли соседа: %o', sibling);
|
|
||||||
|
|
||||||
if (sibling.textContent.length) {
|
if (sibling.textContent.length) {
|
||||||
|
|
||||||
// console.log('Соседи не пустые, то есть мы не в конце.');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// console.log('Сосед пустой. Возможно мы в конце.');
|
|
||||||
// console.log('Смотрим следующего');
|
|
||||||
|
|
||||||
sibling = sibling.nextSibling;
|
sibling = sibling.nextSibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('Все соседи пустые. -------');
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1837,13 +1827,13 @@ var codex =
|
||||||
* @param [String] htmlString - html content as string
|
* @param [String] htmlString - html content as string
|
||||||
* @return {string} - html content as string
|
* @return {string} - html content as string
|
||||||
*/
|
*/
|
||||||
content.makeParagraphsFromContent = function (htmlString) {
|
content.wrapTextIntoParagraphs = function (htmlString) {
|
||||||
|
|
||||||
var wrapper = document.createElement('DIV'),
|
var wrapper = document.createElement('DIV'),
|
||||||
newWrapper = document.createElement('DIV'),
|
newWrapper = document.createElement('DIV'),
|
||||||
i,
|
i,
|
||||||
paragraph,
|
paragraph,
|
||||||
firstLevelBlocks = ['DIV', 'BLOCKQUOTE', 'SECTION', 'ARTICLE', 'PRE', 'CODE', 'P'],
|
firstLevelBlocks = ['DIV', 'P'],
|
||||||
blockTyped,
|
blockTyped,
|
||||||
node;
|
node;
|
||||||
|
|
||||||
|
@ -1855,19 +1845,10 @@ var codex =
|
||||||
node = wrapper.childNodes[i];
|
node = wrapper.childNodes[i];
|
||||||
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
||||||
|
|
||||||
// console.log("Узел: %o", node);
|
|
||||||
// console.log(blockTyped ? 'Он блочный' : 'Инлайновый');
|
|
||||||
|
|
||||||
if (blockTyped) {
|
if (blockTyped) {
|
||||||
|
|
||||||
// console.log('Проверим, не сформировали ли мы до этого параграф из инлайновых элементов');
|
|
||||||
// console.log('Длина контента параграфа: ', paragraph.textContent.length);
|
|
||||||
|
|
||||||
if (paragraph.childNodes.length) {
|
if (paragraph.childNodes.length) {
|
||||||
|
|
||||||
// console.info('Опа, параграф не пустой. Нужно его добавить и очистить');
|
|
||||||
// console.log('Клонировали, добавили');
|
|
||||||
|
|
||||||
newWrapper.appendChild(paragraph.cloneNode(true));
|
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||||
|
|
||||||
paragraph = null;
|
paragraph = null;
|
||||||
|
@ -1877,16 +1858,10 @@ var codex =
|
||||||
newWrapper.appendChild(node.cloneNode(true));
|
newWrapper.appendChild(node.cloneNode(true));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// console.log('Инлайновые элементы мы добавляем в парагаф');
|
|
||||||
// console.log('Сейчас в нем %o детей', paragraph.childNodes.length);
|
|
||||||
|
|
||||||
paragraph.appendChild(node.cloneNode(true));
|
paragraph.appendChild(node.cloneNode(true));
|
||||||
|
|
||||||
// console.log('А теперь: %o', paragraph.childNodes.length);
|
|
||||||
// console.log('Проверим, не последний ли это элемент. Если да, то параграф нужно добавить в обертку перед выходом из цикла');
|
|
||||||
|
|
||||||
if (i == wrapper.childNodes.length - 1) {
|
if (i == wrapper.childNodes.length - 1) {
|
||||||
newWrapper.appendChild(paragraph);
|
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
||||||
* Works with DOM
|
* Works with DOM
|
||||||
*
|
*
|
||||||
* @author Codex Team
|
* @author Codex Team
|
||||||
* @version 1.3.8
|
* @version 1.3.11
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var content = (function(content) {
|
var content = (function(content) {
|
||||||
|
@ -672,28 +672,18 @@ var content = (function(content) {
|
||||||
*/
|
*/
|
||||||
var sibling = node.nextSibling;
|
var sibling = node.nextSibling;
|
||||||
|
|
||||||
// console.log('Погнали проверять соседей ');
|
|
||||||
|
|
||||||
while ( sibling ) {
|
while ( sibling ) {
|
||||||
|
|
||||||
// console.log('Опаньки! нашли соседа: %o', sibling);
|
|
||||||
|
|
||||||
if (sibling.textContent.length){
|
if (sibling.textContent.length){
|
||||||
|
|
||||||
// console.log('Соседи не пустые, то есть мы не в конце.');
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// console.log('Сосед пустой. Возможно мы в конце.');
|
|
||||||
// console.log('Смотрим следующего');
|
|
||||||
|
|
||||||
sibling = sibling.nextSibling;
|
sibling = sibling.nextSibling;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('Все соседи пустые. -------');
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -704,13 +694,13 @@ var content = (function(content) {
|
||||||
* @param [String] htmlString - html content as string
|
* @param [String] htmlString - html content as string
|
||||||
* @return {string} - html content as string
|
* @return {string} - html content as string
|
||||||
*/
|
*/
|
||||||
content.makeParagraphsFromContent = function(htmlString) {
|
content.wrapTextIntoParagraphs = function(htmlString) {
|
||||||
|
|
||||||
var wrapper = document.createElement('DIV'),
|
var wrapper = document.createElement('DIV'),
|
||||||
newWrapper = document.createElement('DIV'),
|
newWrapper = document.createElement('DIV'),
|
||||||
i,
|
i,
|
||||||
paragraph,
|
paragraph,
|
||||||
firstLevelBlocks = ['DIV', 'BLOCKQUOTE', 'SECTION', 'ARTICLE', 'PRE', 'CODE', 'P'],
|
firstLevelBlocks = ['DIV', 'P'],
|
||||||
blockTyped,
|
blockTyped,
|
||||||
node;
|
node;
|
||||||
|
|
||||||
|
@ -722,19 +712,10 @@ var content = (function(content) {
|
||||||
node = wrapper.childNodes[i];
|
node = wrapper.childNodes[i];
|
||||||
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
||||||
|
|
||||||
// console.log("Узел: %o", node);
|
|
||||||
// console.log(blockTyped ? 'Он блочный' : 'Инлайновый');
|
|
||||||
|
|
||||||
if ( blockTyped ) {
|
if ( blockTyped ) {
|
||||||
|
|
||||||
// console.log('Проверим, не сформировали ли мы до этого параграф из инлайновых элементов');
|
|
||||||
// console.log('Длина контента параграфа: ', paragraph.textContent.length);
|
|
||||||
|
|
||||||
if ( paragraph.childNodes.length ){
|
if ( paragraph.childNodes.length ){
|
||||||
|
|
||||||
// console.info('Опа, параграф не пустой. Нужно его добавить и очистить');
|
|
||||||
// console.log('Клонировали, добавили');
|
|
||||||
|
|
||||||
newWrapper.appendChild(paragraph.cloneNode(true));
|
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||||
|
|
||||||
paragraph = null;
|
paragraph = null;
|
||||||
|
@ -746,16 +727,10 @@ var content = (function(content) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// console.log('Инлайновые элементы мы добавляем в парагаф');
|
|
||||||
// console.log('Сейчас в нем %o детей', paragraph.childNodes.length);
|
|
||||||
|
|
||||||
paragraph.appendChild(node.cloneNode(true));
|
paragraph.appendChild(node.cloneNode(true));
|
||||||
|
|
||||||
// console.log('А теперь: %o', paragraph.childNodes.length);
|
|
||||||
// console.log('Проверим, не последний ли это элемент. Если да, то параграф нужно добавить в обертку перед выходом из цикла');
|
|
||||||
|
|
||||||
if ( i == wrapper.childNodes.length - 1 ){
|
if ( i == wrapper.childNodes.length - 1 ){
|
||||||
newWrapper.appendChild(paragraph);
|
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "codex.editor",
|
"name": "codex.editor",
|
||||||
"version": "1.3.10",
|
"version": "1.3.11",
|
||||||
"description": "Codex Editor. Native JS, based on API and Open Source",
|
"description": "Codex Editor. Native JS, based on API and Open Source",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -445,7 +445,7 @@ var quote = (function(quote) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make paragraphs */
|
/** Make paragraphs */
|
||||||
data.text = codex.content.makeParagraphsFromContent(data.text);
|
data.text = codex.content.wrapTextIntoParagraphs(data.text);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue