From 1abd55a6986c99a83050d2436872724d493c5711 Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Thu, 27 May 2021 12:46:01 +0530 Subject: [PATCH] #104 XMLHttpRequest change to fetch --- .../extensions/ext-imagelib/ext-imagelib.js | 6 ++--- src/editor/extensions/ext-imagelib/index.js | 23 +++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js index f49d6b06..6564ed2f 100644 --- a/src/editor/extensions/ext-imagelib/ext-imagelib.js +++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js @@ -425,7 +425,7 @@ export default { const header = document.createElement('h1'); browser.prepend(header); 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'); // eslint-disable-next-line max-len @@ -437,10 +437,10 @@ export default { button.addEventListener('touchend', function () { $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'); - leftBlock.setAttribute('style', `position: absolute;top: 5;left: 10;`); + leftBlock.setAttribute('style', `position: absolute;top: 5px;left: 10px;display: inline-flex;`); browser.appendChild(leftBlock); const back = document.createElement('button'); diff --git a/src/editor/extensions/ext-imagelib/index.js b/src/editor/extensions/ext-imagelib/index.js index b296045b..91bbb0cb 100644 --- a/src/editor/extensions/ext-imagelib/index.js +++ b/src/editor/extensions/ext-imagelib/index.js @@ -40,22 +40,15 @@ Array.prototype.forEach.call(atags, function (aEle) { }); img.src = href; } else { - const xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4) { - let data = xhr.responseText; - post({ href, data }); - return data; - } else { - return false; - } - }; - xhr.open('GET', href, false); - xhr.send(null); - // Do ajax request for image's href value - /* $.get(href, function (data) { + fetch(href) + .then( (r) => r.text()) + // eslint-disable-next-line promise/always-return + .then( (data) => { post({ href, data }); - }, 'html'); */ // 'html' is necessary to keep returned data as a string + return data; + }) + // eslint-disable-next-line no-console + .catch( (error) => console.log(error)); } return false; });