List tool validate and sanitise improved

This commit is contained in:
Peter Savchenko 2017-02-20 18:52:41 +03:00
parent 3ba9c85d6a
commit f3c8d44fbd
2 changed files with 27 additions and 10 deletions

View file

@ -203,8 +203,15 @@
},
anchor: 'Update',
},
{
type : 'list',
data : {
type : 'OL',
items : [1,3,4]
},
},
],
count: 2
count: 3
}
});
</script>

View file

@ -129,7 +129,7 @@ var list = (function(list_plugin) {
*/
list_plugin.render = function (data) {
var type = data && data.type == 'ordered' ? 'OL' : 'UL',
var type = data && (data.type == 'ordered' || data.type == 'OL') ? 'OL' : 'UL',
tag = ui.make(type),
newLi;
@ -139,7 +139,7 @@ var list = (function(list_plugin) {
newLi = ui.block('li', elementClasses_.li);
newLi.innerHTML = element;
newLi.innerHTML = element || '';
tag.appendChild(newLi);
@ -159,15 +159,18 @@ var list = (function(list_plugin) {
list_plugin.validate = function(data) {
var items = data.items.every(function(item){
return item.trim() !== '';
var isEmpty = data.items.every(function(item){
return item.trim() === '';
});
if (!items)
if (isEmpty){
return;
}
if (data.type != 'UL' && data.type != 'OL')
if (data.type != 'UL' && data.type != 'OL'){
console.warn('CodeX Editor List-tool: wrong list type passed %o', data.type);
return;
}
return true;
};
@ -180,10 +183,17 @@ var list = (function(list_plugin) {
var data = {
type : null,
items : []
};
},
litsItemContent = '';
for(var index = 0; index < blockContent.childNodes.length; index++)
data.items[index] = blockContent.childNodes[index].textContent;
for (var index = 0; index < blockContent.childNodes.length; index++){
litsItemContent = blockContent.childNodes[index].innerHTML;
if (litsItemContent !== '' && litsItemContent !== '<br>') {
data.items.push(litsItemContent);
}
}
data.type = blockContent.dataset.type;