Fast-replace img src

Former-commit-id: a06c1c1b520865ecea28573e87a0cc2024c0e434 [formerly 2fa6cf6fdac12a7fde8bf313e5766acc6e41be1b]
Former-commit-id: 38f4bf42ff16f2e0377c6762ee14d7f5dc48f6ad
This commit is contained in:
Jaifroid 2017-07-05 17:34:20 +01:00
parent 74dc3aca89
commit c575caaa00

View File

@ -787,19 +787,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
$("#articleContent").contents().scrollTop(0); $("#articleContent").contents().scrollTop(0);
// Display the article inside the web page. // Display the article inside the web page.
var $body = $(htmlArticle); //Fast-replace img with data-img and hide image [kiwix-js #272]
$body.find('img').each(function(){ htmlArticle = htmlArticle.replace(/(<img\s+[^>]*)src(\s*=)/ig,
var image = $(this); "$1style=\"display: none;\" onload=\"this.style.display='inline'\" data-kiwixsrc$2");
// Prevents unnecessary 404's being produced when iframe loads images [kiwix-js #272]
$(image).attr("data-src", $(image).attr("src")); $('#articleContent').contents().find('body').html(htmlArticle);
$(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);
// If the ServiceWorker is not useable, we need to fallback to parse the DOM // 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 // 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); 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); //kiwix-js #272 var imageMatch = image.attr('data-kiwixsrc').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) {