mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 12:53:54 -04:00
Fix subtitles and media download
Former-commit-id: 40b838098ce913dd7d285fdfab5c9b4817e7b7ec [formerly 462f9114eeed8cdadf0b8f795cff62efb6f0fe77 [formerly 5191fb4a99aece1d0cd015204cf496a1418f9f45]] Former-commit-id: 74b41d33d653e7ed16d6ab084b99fd5594c33b63 Former-commit-id: 9f6abd5c077893dad3ffbdd6a82f913017c2bd85
This commit is contained in:
parent
3cb56113fc
commit
2d0dd806f1
@ -3228,13 +3228,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
||||
var regexpPath = /^(.*\/)[^\/]+$/;
|
||||
// Pattern to find a ZIM URL (with its namespace) - see https://wiki.openzim.org/wiki/ZIM_file_format#Namespaces
|
||||
var regexpZIMUrlWithNamespace = /^[./]*([-ABCIJMUVWX]\/.+)$/;
|
||||
// Regex below finds images, scripts, stylesheets and tracks with ZIM-type metadata and image namespaces [kiwix-js #378].
|
||||
// Regex below finds images, scripts, stylesheets (not tracks) with ZIM-type metadata and image namespaces [kiwix-js #378].
|
||||
// It first searches for <img, <script, <link, etc., then scans forward to find, on a word boundary, either src=["'] or href=["']
|
||||
// (ignoring any extra whitespace), and it then tests the path of the URL with a non-capturing negative lookahead that excludes
|
||||
// URLs that begin 'http' (i.e. non-relative URLs). It then captures the whole of the URL up until either the opening delimiter
|
||||
// (" or ', which is capture group \3) or a querystring or hash character (? or #). When the regex is used below, it will be further
|
||||
// processed to calculate the ZIM URL from the relative path. This regex can cope with legitimate single quote marks (') in the URL.
|
||||
var regexpTagsWithZimUrl = /(<(?:img|script|link|track)\b[^>]*?\s)(?:src|href)(\s*=\s*(["']))(?!http|app:)(.+?)(?=\3|\?|#)/ig;
|
||||
var regexpTagsWithZimUrl = /(<(?:img|script|link)\b[^>]*?\s)(?:src|href)(\s*=\s*(["']))(?!http|app:)(.+?)(?=\3|\?|#)/ig;
|
||||
// Regex below tests the html of an article for active content [kiwix-js #466]
|
||||
// It inspects every <script> block in the html and matches in the following cases: 1) the script loads a UI application called app.js;
|
||||
// 2) the script block has inline content that does not contain "importScript()", "toggleOpenSection" or an "articleId" assignment
|
||||
@ -3822,7 +3822,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
||||
}
|
||||
var mediaElement = /audio|video/i.test(mediaSource.tagName) ? mediaSource : mediaSource.parentElement;
|
||||
// Create custom subtitle / cc load menu if it doesn't already exist
|
||||
if (!articleDocument.getElementById('kiwixCCMenu')) buildCustomCCMenu(articleDocument, mediaElement, function (ccBlob) {
|
||||
if (!articleWindow.document.getElementById('kiwixCCMenu')) buildCustomCCMenu(articleWindow.document, mediaElement, function (ccBlob) {
|
||||
trackBlob = ccBlob;
|
||||
});
|
||||
// Load media file
|
||||
@ -3838,13 +3838,15 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
||||
if (/track/i.test(mediaSource.tagName)) return;
|
||||
mediaElement.load();
|
||||
// Add a download link in case media source not supported
|
||||
if (articleWindow.kiwixType === 'iframe') {
|
||||
var iframe = document.getElementById('articleContent').contentDocument;
|
||||
document.getElementById('alertBoxFooter').innerHTML =
|
||||
'<div id="downloadAlert" class="alert alert-info alert-dismissible">\n' +
|
||||
' <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>\n' +
|
||||
' <span id="alertMessage"></span>\n' +
|
||||
'</div>\n';
|
||||
var alertMessage = document.getElementById('alertMessage');
|
||||
var filename = articleWindow.title + '_' + dirEntry.url.replace(/^.*\/([^\/]+)$/, '$1');
|
||||
var filename = iframe.title + '_' + dirEntry.url.replace(/^.*\/([^\/]+)$/, '$1');
|
||||
// Make filename safe
|
||||
filename = filename.replace(/[\/\\:*?"<>|]/g, '_');
|
||||
alertMessage.innerHTML = '<a href="#" class="alert-link" id="downloadMedia">Download this file</a> (and any selected subtitles) to play with another app';
|
||||
@ -3892,6 +3894,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
||||
alertMessage.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user