mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
Make jQuery routines into functions and eliminate unhandled exception #348
This commit is contained in:
parent
b1118a9747
commit
6bf87b26d3
@ -850,10 +850,16 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
// 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
|
||||||
if (contentInjectionMode === 'jquery') {
|
if (contentInjectionMode === 'jquery') {
|
||||||
|
parseAnchorsJQuery();
|
||||||
|
loadImagesJQuery();
|
||||||
|
loadCSSJQuery();
|
||||||
|
//JavaScript loading currently disabled
|
||||||
|
//loadJavaScriptJQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAnchorsJQuery() {
|
||||||
var currentProtocol = location.protocol;
|
var currentProtocol = location.protocol;
|
||||||
var currentHost = location.host;
|
var currentHost = location.host;
|
||||||
|
|
||||||
// Convert links into javascript calls
|
|
||||||
$('#articleContent').contents().find('body').find('a').each(function() {
|
$('#articleContent').contents().find('body').find('a').each(function() {
|
||||||
var href = $(this).attr("href");
|
var href = $(this).attr("href");
|
||||||
// Compute current link's url (with its namespace), if applicable
|
// Compute current link's url (with its namespace), if applicable
|
||||||
@ -893,8 +899,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Load images
|
|
||||||
|
function loadImagesJQuery() {
|
||||||
$('#articleContent').contents().find('body').find('img').each(function() {
|
$('#articleContent').contents().find('body').find('img').each(function() {
|
||||||
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
|
||||||
@ -912,8 +919,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Load CSS content
|
function loadCSSJQuery() {
|
||||||
$('#articleContent').contents().find('link[rel=stylesheet]').each(function() {
|
$('#articleContent').contents().find('link[rel=stylesheet]').each(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
// We try to find its name (from an absolute or relative URL)
|
// We try to find its name (from an absolute or relative URL)
|
||||||
@ -940,12 +948,13 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Load Javascript content
|
function loadJavaScriptJQuery() {
|
||||||
$('#articleContent').contents().find('script').each(function() {
|
$('#articleContent').contents().find('script').each(function() {
|
||||||
var script = $(this);
|
var script = $(this);
|
||||||
// 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 srcMatch = script.attr("src").match(regexpMetadataUrl);
|
var srcMatch = script.attr("src") ? script.attr("src").match(regexpMetadataUrl) : null;
|
||||||
// TODO check that the type of the script is text/javascript or application/javascript
|
// TODO check that the type of the script is text/javascript or application/javascript
|
||||||
if (srcMatch) {
|
if (srcMatch) {
|
||||||
// It's a Javascript file contained in the ZIM file
|
// It's a Javascript file contained in the ZIM file
|
||||||
@ -964,8 +973,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user