From c575caaa00b9e1f4776723462600964f45b067f5 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 5 Jul 2017 17:34:20 +0100 Subject: [PATCH] Fast-replace img src Former-commit-id: a06c1c1b520865ecea28573e87a0cc2024c0e434 [formerly 2fa6cf6fdac12a7fde8bf313e5766acc6e41be1b] Former-commit-id: 38f4bf42ff16f2e0377c6762ee14d7f5dc48f6ad --- www/js/app.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) 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) {