Skip to content

Commit

Permalink
Display image in default language, if in selected one is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfatguy committed Nov 6, 2024
1 parent d1c64cb commit a6c14b5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions engine/paragraph-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ const ParagraphEngine = {
} else if (defaultDescription !== '') {
description = defaultDescription;
} else {
console.log('Description not available for paragraph no "' + paragraph + '" and language "' + language + '".');

description = "No **NOT** found!";
description = 'Description not available for paragraph no "' + paragraph + '" and language "' + language + '".';
}
}

Expand Down Expand Up @@ -120,8 +118,6 @@ const ParagraphEngine = {
}
});
} else {
console.log("No connectors for paragraph no: " + paragraph + " and language: " + language);

return null;
}
},
Expand All @@ -140,24 +136,35 @@ const ParagraphEngine = {
return paragraphObj.image[AutoLoader.defaultLanguage];
}
}
console.log('Image not available for paragraph no "' + paragraph + '" and language "' + language + '".');

return "";
},

loadImage: function(paragraph, language, imgElementId, callback) {
language = TranslationEngine.validateLanguage(language);

const imagePath = 'data/images/' + this.getImage(paragraph, language);
const img = document.getElementById(imgElementId);
let imagePath = 'data/images/' + this.getImage(paragraph, language);

if (img) {
img.onload = function() {
callback(true, imagePath);
};

img.onerror = function() {
callback(false, imagePath);
imagePath = 'data/images/' + ParagraphEngine.getImage(paragraph, AutoLoader.defaultLanguage);

img.onload = function() {
callback(true, imagePath);
};

img.onerror = function() {
callback(false, imagePath);
};

img.src = imagePath;
};

img.src = imagePath;
} else {
callback(false, 'Image element not found');
Expand Down Expand Up @@ -250,12 +257,8 @@ const ParagraphEngine = {
paragraph = this.validateParagraph(paragraph);
language = TranslationEngine.validateLanguage(language);

this.loadImage(paragraph, language, 'paragraph-image', function(exists, imagePath) {
this.loadImage(paragraph, language, 'paragraph-image', function(exists) {
ParagraphEngine.toggleColumns(exists);

if (!exists) {
console.log("Image not found or element not found:", imagePath);
}
});

document.getElementById('paragraph-number').textContent = paragraph.toUpperCase();
Expand Down

0 comments on commit a6c14b5

Please sign in to comment.