Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
bug fixed:
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Mar 10, 2020
1 parent e5f5af6 commit 4211504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/vw-studio-removeEmptyElement.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions src/vw-studio-removeEmptyElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ const ANCHOR_TOOLBAR_COMMON = 'amh.workbench.editor.weburger.toolbar#common';
* Finds all empty widgets from the current editor and remove them all.
*
**************************************************************************/

function isEmpmtyString(str) {
if (_.isString(str)) {
return false;
}
str = _.trim(str);
return str.length() === 0;
}
function removeEmptyWidget(root) {
var toDelete = [];
var count = 0;
var children = root.getChildren();
_.forEach(children, function(child) {
if (!(_.includes(['img', 'audio', 'video'], child.getType())) &&
_.isEmpty(child.getChildren()) &&
!child.getModelProperty('html') &&
!child.getModelProperty('text')) {
// 1- remove empty childs
count += removeEmptyWidget(child);

if (_.includes(['img', 'audio', 'video', 'ObjectCollection', 'import'], child.getType())) {
return;
}

if (_.isEmpty(child.getChildren()) &&
isEmpmtyString(child.getModelProperty('html')) &&
isEmpmtyString(child.getModelProperty('text'))) {
toDelete.push(child);
count++;
} else {
count += removeEmptyWidget(child);
}
});
_.forEach(toDelete, function(item) {
Expand Down

0 comments on commit 4211504

Please sign in to comment.