diff --git a/www/js/app.js b/www/js/app.js index 1b3ec9a3..2362fd0e 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -787,19 +787,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles $("#articleContent").contents().scrollTop(0); // Display the article inside the web page. - var $body = $(htmlArticle); - $body.find('img').each(function(){ - var image = $(this); - // Prevents unnecessary 404's being produced when iframe loads images [kiwix-js #272] - $(image).attr("data-src", $(image).attr("src")); - $(image).removeAttr("src"); - $(image).hide(); //Hide images to prevent occupying whitespace - //Restore hidden images on load - $(image).on("load", function (e) { - $(this).show(); - }); - }); - $('#articleContent').contents().find('body').html($body); + //Fast-replace img with data-img and hide image [kiwix-js #272] + htmlArticle = htmlArticle.replace(/(]*)src(\s*=)/ig, + "$1style=\"display: none;\" onload=\"this.style.display='inline'\" data-kiwixsrc$2"); + + $('#articleContent').contents().find('body').html(htmlArticle); // If the ServiceWorker is not useable, we need to fallback to parse the DOM // to inject math images, and replace some links with javascript calls @@ -865,7 +857,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles var image = $(this); // It's a standard image contained in the ZIM file // We try to find its name (from an absolute or relative URL) - var imageMatch = image.attr('data-src').match(regexpImageUrl); //kiwix-js #272 + var imageMatch = image.attr('data-kiwixsrc').match(regexpImageUrl); //kiwix-js #272 if (imageMatch) { var title = decodeURIComponent(imageMatch[1]); selectedArchive.getDirEntryByTitle(title).then(function(dirEntry) {