1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Finished breakdown of attachment vue into components

This commit is contained in:
Dan Brown
2020-07-04 16:53:02 +01:00
parent 14b6cd1091
commit d41452f39c
24 changed files with 371 additions and 321 deletions

View File

@ -53,6 +53,14 @@ export function onEnterPress(elements, callback) {
if (!Array.isArray(elements)) {
elements = [elements];
}
const listener = event => {
if (event.key === 'Enter') {
callback(event);
}
}
elements.forEach(e => e.addEventListener('keypress', listener));
}
/**
@ -89,4 +97,13 @@ export function findText(selector, text) {
}
}
return null;
}
/**
* Show a loading indicator in the given element.
* This will effectively clear the element.
* @param {Element} element
*/
export function showLoading(element) {
element.innerHTML = `<div class="loading-container"><div></div><div></div><div></div></div>`;
}

View File

@ -67,11 +67,20 @@ async function dataRequest(method, url, data = null) {
body: data,
};
// Send data as JSON if a plain object
if (typeof data === 'object' && !(data instanceof FormData)) {
options.headers = {'Content-Type': 'application/json'};
options.body = JSON.stringify(data);
}
// Ensure FormData instances are sent over POST
// Since Laravel does not read multipart/form-data from other types
// of request. Hence the addition of the magic _method value.
if (data instanceof FormData && method !== 'post') {
data.append('_method', method);
options.method = 'post';
}
return request(url, options)
}
@ -109,7 +118,7 @@ async function request(url, options = {}) {
const response = await fetch(url, options);
const content = await getResponseContent(response);
return {
const returnData = {
data: content,
headers: response.headers,
redirected: response.redirected,
@ -117,7 +126,13 @@ async function request(url, options = {}) {
statusText: response.statusText,
url: response.url,
original: response,
};
if (!response.ok) {
throw returnData;
}
return returnData;
}
/**