Add a setting to retrieve bookmark metadata asynchrounously
- There is a new standalone script (metadata.js) which requests a new controller to get bookmark metadata and fill the form async - This feature is enabled with the new setting: general.enable_async_metadata (enabled by default) - general.retrieve_description is now enabled by default - A small rotating loader animation has a been added to bookmark inputs when metadata is being retrieved (default template) - Custom JS htmlentities has been removed and mathiasbynens/he library is used instead Fixes #1563
This commit is contained in:
parent
f34554c6c2
commit
4cf3564d28
19 changed files with 447 additions and 75 deletions
assets/common/js
39
assets/common/js/metadata.js
Normal file
39
assets/common/js/metadata.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import he from 'he';
|
||||
|
||||
function clearLoaders(loaders) {
|
||||
if (loaders != null && loaders.length > 0) {
|
||||
[...loaders].forEach((loader) => {
|
||||
loader.classList.remove('loading-input');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
(() => {
|
||||
const loaders = document.querySelectorAll('.loading-input');
|
||||
const inputTitle = document.querySelector('input[name="lf_title"]');
|
||||
if (inputTitle != null && inputTitle.value.length > 0) {
|
||||
clearLoaders(loaders);
|
||||
return;
|
||||
}
|
||||
|
||||
const url = document.querySelector('input[name="lf_url"]').value;
|
||||
const basePath = document.querySelector('input[name="js_base_path"]').value;
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', `${basePath}/admin/metadata?url=${encodeURI(url)}`, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
xhr.onload = () => {
|
||||
const result = JSON.parse(xhr.response);
|
||||
Object.keys(result).forEach((key) => {
|
||||
if (result[key] !== null && result[key].length) {
|
||||
const element = document.querySelector(`input[name="lf_${key}"], textarea[name="lf_${key}"]`);
|
||||
if (element != null && element.value.length === 0) {
|
||||
element.value = he.decode(result[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
clearLoaders(loaders);
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue