Skip to content

Commit

Permalink
fix : Inserted images/videos aren't considred as a content in news - E…
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Aug 9, 2023
1 parent 5ddd3e9 commit 2b55057
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,29 @@ export default {
editMode: function() {
return this.activityId && this.activityId !== '';
},
hasMediaContent() {
const parsedDocument = new DOMParser().parseFromString(this.news.body, 'text/html');
const mediaElements = parsedDocument.querySelectorAll('img, video, iframe');
return mediaElements.length > 0;
},
postDisabled: function () {
return this.uploading || !this.news.title || !this.news.title.trim() || !this.news.body || !new DOMParser().parseFromString(this.news.body, 'text/html').documentElement.textContent.replace(/ /g, '').trim();
return this.uploading || !this.news.title || !this.news.title.trim() || !this.news.body || !new DOMParser().parseFromString(this.news.body, 'text/html').documentElement.textContent.replace(/ /g, '').trim() && !this.hasMediaContent;
},
updateDisabled: function () {
// disable update button while uploading an attachment
if (this.uploading) {
return true;
}
// disable update button if a mandatory field is empty
if (!this.news.title || !this.news.title.trim() || !this.news.body || !this.news.body.replace(/ /g, '').trim()) {
if (!this.news.title || !this.news.title.trim() || !this.news.body || !new DOMParser().parseFromString(this.news.body, 'text/html').documentElement.textContent.replace(/ /g, '').trim() && !this.hasMediaContent) {
return true;
}
// disable update button nothing has changed
if (!this.illustrationChanged && !this.attachmentsChanged
&& this.news.title === this.originalNews.title
&& this.news.summary === this.originalNews.summary
&& this.getString(this.news.body) === this.getString(this.originalNews.body)
&& !this.areMediaContentsChanged(this.originalNews.body, this.news.body)
&& this.news.published === this.originalNews.published
&& this.news.publicationState !== 'draft') {
return true;
Expand Down Expand Up @@ -1121,6 +1127,20 @@ export default {
this.autoSave();
}
}, this.endUplodingFileTimeout);
},
areMediaContentsChanged(originalNewsBody, newsBody) {
const newsBodyParsedDocument = new DOMParser().parseFromString(newsBody, 'text/html');
const originalNewsBodyParsedDocument = new DOMParser().parseFromString(originalNewsBody, 'text/html');
const newsMediaElements = newsBodyParsedDocument.querySelectorAll('img, video, iframe');
const originalNewsmediaElements = originalNewsBodyParsedDocument.querySelectorAll('img, video, iframe');
const newsMediaSources = Array.from(newsMediaElements).map(element => element.src);
const originalNewsMediaSources = Array.from(originalNewsmediaElements).map(element => element.src);
// check if the media element is removed or new element is inserted
if (newsMediaSources.length !== originalNewsMediaSources.length) {
return true;
}
// check if the element is reinserted by the same url or from the existing upload !
return !originalNewsMediaSources.every((element, index) => element === newsMediaSources[index]);
}
}
};
Expand Down

0 comments on commit 2b55057

Please sign in to comment.