#104 XMLHttpRequest change to fetch
parent
adca890d17
commit
1abd55a698
|
@ -425,7 +425,7 @@ export default {
|
||||||
const header = document.createElement('h1');
|
const header = document.createElement('h1');
|
||||||
browser.prepend(header);
|
browser.prepend(header);
|
||||||
header.textContent = allLibs;
|
header.textContent = allLibs;
|
||||||
header.setAttribute('style', `position: absolute;top: 0;left: 0;width: 100%;`);
|
header.setAttribute('style', `position: absolute;top: 0px;left: 0px;width: 100%;`);
|
||||||
|
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
|
@ -437,10 +437,10 @@ export default {
|
||||||
button.addEventListener('touchend', function () {
|
button.addEventListener('touchend', function () {
|
||||||
$id("imgbrowse_holder").style.display = 'none';
|
$id("imgbrowse_holder").style.display = 'none';
|
||||||
});
|
});
|
||||||
button.setAttribute('style', `position: absolute;top: 5;right: -10;`);
|
button.setAttribute('style', `position: absolute;top: 5px;right: 10px;`);
|
||||||
|
|
||||||
const leftBlock = document.createElement('span');
|
const leftBlock = document.createElement('span');
|
||||||
leftBlock.setAttribute('style', `position: absolute;top: 5;left: 10;`);
|
leftBlock.setAttribute('style', `position: absolute;top: 5px;left: 10px;display: inline-flex;`);
|
||||||
browser.appendChild(leftBlock);
|
browser.appendChild(leftBlock);
|
||||||
|
|
||||||
const back = document.createElement('button');
|
const back = document.createElement('button');
|
||||||
|
|
|
@ -40,22 +40,15 @@ Array.prototype.forEach.call(atags, function (aEle) {
|
||||||
});
|
});
|
||||||
img.src = href;
|
img.src = href;
|
||||||
} else {
|
} else {
|
||||||
const xhr = new XMLHttpRequest();
|
fetch(href)
|
||||||
xhr.onreadystatechange = function() {
|
.then( (r) => r.text())
|
||||||
if (xhr.readyState == 4) {
|
// eslint-disable-next-line promise/always-return
|
||||||
let data = xhr.responseText;
|
.then( (data) => {
|
||||||
post({ href, data });
|
post({ href, data });
|
||||||
return data;
|
return data;
|
||||||
} else {
|
})
|
||||||
return false;
|
// eslint-disable-next-line no-console
|
||||||
}
|
.catch( (error) => console.log(error));
|
||||||
};
|
|
||||||
xhr.open('GET', href, false);
|
|
||||||
xhr.send(null);
|
|
||||||
// Do ajax request for image's href value
|
|
||||||
/* $.get(href, function (data) {
|
|
||||||
post({ href, data });
|
|
||||||
}, 'html'); */ // 'html' is necessary to keep returned data as a string
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue