Use XMLHttpRequest (for IE 11 compatibility)
This commit is contained in:
parent
4d36c872ca
commit
7850cece52
1 changed files with 34 additions and 27 deletions
|
@ -60,24 +60,20 @@ function parseUrl(url) {
|
|||
return parser;
|
||||
}
|
||||
|
||||
if (prefillInstance != null) {
|
||||
const url = normalizeUrl(prefillInstance);
|
||||
instance.value = url;
|
||||
add_instance(parseUrl(url).hostname, false, true);
|
||||
function instances_loading_error() {
|
||||
choose_instance.innerHTML = "";
|
||||
add_instance("-- LOADING FAILED! --", true, false, "");
|
||||
console.error('Failed to fetch servers list from joinmastodon.');
|
||||
}
|
||||
|
||||
choose_instance.addEventListener('focus', function (e) {
|
||||
if (choose_instance.children.length < 3) {
|
||||
remove_loading_instance();
|
||||
add_loading_instance();
|
||||
fetch('https://api.joinmastodon.org/servers')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failure response from joinmastodon.');
|
||||
function instances_loaded() {
|
||||
if (this.status !== 200) {
|
||||
instances_loading_error();
|
||||
return;
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(servers => {
|
||||
|
||||
const servers = JSON.parse(this.responseText);
|
||||
|
||||
const chosen_instance = choose_instance.value;
|
||||
const domains = servers.map(obj => obj.domain);
|
||||
if (domains.indexOf(chosen_instance) === -1) {
|
||||
|
@ -91,13 +87,24 @@ choose_instance.addEventListener('focus', function (e) {
|
|||
const selected = (domain === chosen_instance);
|
||||
add_instance(domain, false, selected);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
choose_instance.innerHTML = "";
|
||||
add_instance("-- LOADING FAILED! --", true, false, "");
|
||||
console.error(
|
||||
'Failed to fetch servers list from joinmastodon.', error);
|
||||
});
|
||||
}
|
||||
|
||||
if (prefillInstance != null) {
|
||||
const url = normalizeUrl(prefillInstance);
|
||||
instance.value = url;
|
||||
add_instance(parseUrl(url).hostname, false, true);
|
||||
}
|
||||
|
||||
choose_instance.addEventListener('focus', function (e) {
|
||||
if (choose_instance.children.length < 3) {
|
||||
remove_loading_instance();
|
||||
add_loading_instance();
|
||||
|
||||
const req = new XMLHttpRequest();
|
||||
req.addEventListener('load', instances_loaded);
|
||||
req.addEventListener('error', instances_loading_error);
|
||||
req.open('GET', 'https://api.joinmastodon.org/servers');
|
||||
req.send();
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Reference in a new issue