Skip to content

Commit

Permalink
Merge pull request #787 from Badsender-com/develop
Browse files Browse the repository at this point in the history
Release clever dev
  • Loading branch information
FlorianGille authored Apr 30, 2024
2 parents e140aa1 + db61598 commit f39935f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/css/badsender-editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ body {
}
}

.error-message {
.error-message, .size-warning-message {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
max-width: 700px;
Expand Down
41 changes: 40 additions & 1 deletion packages/editor/src/js/ext/badsender-control-quality.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function isElementEmpty(element) {
}

function getErrorsForControlQuality(viewModel) {
checkAndDisplaySizeWarning(viewModel)
const htmlToExport = viewModel.exportHTML()
const parsedHtml = $.parseHTML(htmlToExport);
const extraItems = [];
Expand Down Expand Up @@ -108,7 +109,45 @@ function displayErrors (errors, viewModel) {
$errorMessageDiv.append($errorMessageTitle, $errorMessageDescription, $errorsDiv);
}

function checkAndDisplaySizeWarning(viewModel) {

const sizeThreshold = 102 * 1024; // 102KB in octets
const htmlToExport = viewModel.exportHTML();
const exportedHtmlSize = new Blob([htmlToExport]).size; // to calculate the size of the exported HTML in octets

if (exportedHtmlSize > sizeThreshold) {
displaySizeWarning(viewModel);
} else {
// Remove any existing size warning message
$('.size-warning-message').remove();
}
}

function displaySizeWarning(viewModel) {
// Remove any existing size warning message
$('.size-warning-message').remove();

// Define the default English messages with keys for translation
const warningTitleKey = 'Excessive Size';
const warningDescriptionKey = 'The exported HTML exceeds 102KB, which may result in clipping email on Gmail.';

// Construct the warning message elements with translation keys
const $warningMessageTitle = $(`<h3>${viewModel.t(warningTitleKey)}</h3>`);
const $warningMessageDescription = $(`<p>${viewModel.t(warningDescriptionKey)}</p>`);

// Create the warning message container with styling
const $warningMessageDiv = $('<div class="size-warning-message"></div>');

// Insert the warning message before the specified body location
$warningMessageDiv.insertBefore('replacedbody');
// Append the title and description to the container
$warningMessageDiv.append($warningMessageTitle, $warningMessageDescription);
}




module.exports = {
getErrorsForControlQuality,
displayErrors
displayErrors,
}
6 changes: 0 additions & 6 deletions packages/editor/src/js/viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,6 @@ function initializeEditor(content, blockDefs, thumbPathConverter, galleryUrl) {
var blackLinesRegex = /^\s*[\r\n]/gm;
content = content.replace(blackLinesRegex, '');

// Remove successif empty indentation and empty spaces if content exceeds 102k
if (content.length > MAX_SIZE) {
content = content.replace(/\n|\t/g, ' ');
content = content.replace(/\s\s+/g, ' ');
}

return content;
};

Expand Down
2 changes: 2 additions & 0 deletions public/lang/mosaico-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
"Select from gallery": "Select from gallery",
"Your email was successfully exported": "Your email was successfully exported",
"We noticed some missing details while executing quality controls:": "We noticed some missing details while executing quality controls:",
"Excessive Size": "Excessive Size",
"The exported HTML exceeds 102KB, which may result in clipping email on Gmail.": "The exported HTML exceeds 102KB, which may result in clipping email on Gmail.",
"Missing link label:": "Missing link on:",
"Missing background image": "Missing background image",
"Picture with no link": "Picture with no link",
Expand Down
2 changes: 2 additions & 0 deletions public/lang/mosaico-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
"Select from gallery": "Sélectionnez dans la galerie",
"Your email was successfully exported": "Votre email a bien été exporté",
"We noticed some missing details while executing quality controls:": "Nous avons détecté quelques oublis lors du contrôle qualité",
"Excessive Size": "Poids trop élevé",
"The exported HTML exceeds 102KB, which may result in clipping email on Gmail.": "Le HTML exporté fait plus de 102ko, cela risque de tronquer le rendu du message sur Gmail.",
"Missing link label:": "Lien manquant sur:",
"Missing background image": "Image de fond manquant",
"Picture with no link": "Image sans lien",
Expand Down

0 comments on commit f39935f

Please sign in to comment.