// 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)
functionurlEncode(input){
varoutput=[];
for(varn=0;n<input.length;n++){
varhex=Number(input.charCodeAt(n)).toString(16);
output.push('%'+hex);
}
returnoutput.join('');
}
// get all images
varimgs=document.images;
for(vari=0;i<imgs.length;i++){
// get img src
varimg=imgs[i];
varimgSrc=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`
varencodedSrc=urlEncode(imgSrc);
// now decode hex-notation back to regular chars; the JS function will properly decode `%c3%b6` as `ö`
vardecodedSrc=decodeURIComponent(encodedSrc);
if(imgSrc!=decodedSrc){
img.src=decodedSrc;
}
}
}
window.navigate_to=function(href){// XOWA: expose publicly for alertify