Simplify image showing and hiding

Former-commit-id: 21045ffb2cdd43ee1af5e53d44582a57c57bc0dc [formerly c78b1cf4dfc2a38bc3c7f645541ecf7716d0c29c]
Former-commit-id: 8c6719ba3f8aa8e90f6e5d9b4881d0b160a69ffa
This commit is contained in:
Jaifroid 2017-06-25 22:30:32 +01:00
parent 01f8713675
commit b85b749dc7

View File

@ -790,17 +790,13 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
var $body = $(htmlArticle); var $body = $(htmlArticle);
$body.find('img').each(function(){ $body.find('img').each(function(){
var image = $(this); var image = $(this);
// Prevents unnecessary 404's being produced when iframe loads images // Prevents unnecessary 404's being produced when iframe loads images [kiwix-js #272]
$(image).attr("data-src", $(image).attr("src")); $(image).attr("data-src", $(image).attr("src"));
$(image).removeAttr("src"); $(image).removeAttr("src");
$(image).attr("data-height", $(image).attr("height")); $(image).hide(); //Hide images to prevent occupying whitespace
$(image).removeAttr("height"); //Restore hidden images on load
$(image).attr("data-width", $(image).attr("width"));
$(image).removeAttr("width");
//Restore image height and size on image load
$(image).on("load", function (e) { $(image).on("load", function (e) {
this.width = $(image).attr("data-width"); $(this).show();
this.height = $(image).attr("data-height");
}); });
}); });
$('#articleContent').contents().find('body').html($body); $('#articleContent').contents().find('body').html($body);
@ -869,7 +865,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
var image = $(this); var image = $(this);
// It's a standard image contained in the ZIM file // It's a standard image contained in the ZIM file
// We try to find its name (from an absolute or relative URL) // We try to find its name (from an absolute or relative URL)
var imageMatch = image.attr('data-src').match(regexpImageUrl); var imageMatch = image.attr('data-src').match(regexpImageUrl); //kiwix-js #272
if (imageMatch) { if (imageMatch) {
var title = decodeURIComponent(imageMatch[1]); var title = decodeURIComponent(imageMatch[1]);
selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) { selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {