mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Gui: Encode and decode image sources [#829]
This commit is contained in:
parent
4187dc4a76
commit
ff0f92b950
@ -68,6 +68,9 @@ function init () {
|
||||
if (needReference) {
|
||||
xowa.js.load_lib(xowa.root_dir + 'bin/any/xowa/html/res/src/gadgets/reference-tooltips/jquery.reference-tooltips.js', initReferenceTooltips);
|
||||
}
|
||||
|
||||
// 2021-01-11|ISSUE#:829|Fix SWT not encoding non-ASCII characters in image name
|
||||
xowa.js.doc.fixSwtImgEncoding();
|
||||
}
|
||||
init();
|
||||
}, false);
|
@ -77,11 +77,12 @@ if (!window.xowa) {
|
||||
script.setAttribute('src', file);
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
};
|
||||
|
||||
|
||||
xowa.js.jquery.init_callback = function() {
|
||||
jQuery.cookie = xowa.cookie;
|
||||
jQuery.ready(); //fire the ready event
|
||||
};
|
||||
|
||||
xowa.js.jquery.init = function(document) {
|
||||
if (xowa.js.jquery.init_done) return;
|
||||
xowa.js.load_lib(xowa.root_dir + 'bin/any/xowa/html/res/lib/jquery/jquery-1.11.3.min.js', xowa.js.jquery.init_callback);
|
||||
@ -570,6 +571,43 @@ if (!window.xowa) {
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(rng);
|
||||
}
|
||||
|
||||
// 2021-01-11|ISSUE#:829|Fix SWT not encoding non-ASCII characters in image name
|
||||
xowa.js.doc.fixSwtImgEncoding = function() {
|
||||
// only run for GUI mode
|
||||
if (!xowa_global_values.mode_is_gui) return;
|
||||
|
||||
// encodes each character in a string in hex notation (%0F)
|
||||
function urlEncode(input) {
|
||||
var output = [];
|
||||
for (var n = 0; n < input.length; n++) {
|
||||
var hex = Number(input.charCodeAt(n)).toString(16);
|
||||
output.push('%' + hex);
|
||||
}
|
||||
return output.join('');
|
||||
}
|
||||
|
||||
// get all images
|
||||
var imgs = document.images;
|
||||
for (var i = 0; i < imgs.length; i++) {
|
||||
// get img src
|
||||
var img = imgs[i];
|
||||
var imgSrc = img.src;
|
||||
|
||||
// encode each char in img.src using hex-notation; note that this is necessary for encoding bad SWT encodings like such as in `File:Bevölkerungspyramide_Georgien_2016.png`
|
||||
// * real chr: `ö`
|
||||
// * fail SWT: `ö`
|
||||
// * pass hex: `%c3%b6`
|
||||
var encodedSrc = urlEncode(imgSrc);
|
||||
|
||||
// now decode hex-notation back to regular chars; the JS function will properly decode `%c3%b6` as `ö`
|
||||
var decodedSrc = decodeURIComponent(encodedSrc);
|
||||
if (imgSrc != decodedSrc) {
|
||||
img.src = decodedSrc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.navigate_to = function(href) { // XOWA: expose publicly for alertify
|
||||
window.location = href;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user