]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - assets/common/js/thumbnails-update.js
2 * Script used in the thumbnails update page.
4 * It retrieves the list of link IDs to update, and execute AJAX requests
5 * to update their thumbnails, while updating the progress bar.
9 * Update the thumbnail of the link with the current i index in ids.
10 * It contains a recursive call to retrieve the thumb of the next link when it succeed.
11 * It also update the progress bar and other visual feedback elements.
13 * @param {string} basePath Shaarli subfolder for XHR requests
14 * @param {array} ids List of LinkID to update
15 * @param {int} i Current index in ids
16 * @param {object} elements List of DOM element to avoid retrieving them at each iteration
18 function updateThumb(basePath
, ids
, i
, elements
) {
19 const xhr
= new XMLHttpRequest();
20 xhr
.open('POST', `${basePath}/?do=ajax_thumb_update`);
21 xhr
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
22 xhr
.responseType
= 'json';
24 if (xhr
.status
!== 200) {
25 alert(`An error occurred. Return code: ${xhr.status}`);
27 const { response
} = xhr
;
29 elements
.progressBar
.style
.width
= `${(i * 100) / ids.length}%`;
30 elements
.current
.innerHTML
= i
;
31 elements
.title
.innerHTML
= response
.title
;
32 if (response
.thumbnail
!== false) {
33 elements
.thumbnail
.innerHTML
= `<img src="${response.thumbnail}">`;
36 updateThumb(ids
, i
, elements
);
40 xhr
.send(`id=${ids[i]}`);
44 const basePath
= document
.querySelector('input[name="js_base_path"]').value
;
45 const ids
= document
.getElementsByName('ids')[0].value
.split(',');
47 progressBar: document
.querySelector('.progressbar > div'),
48 current: document
.querySelector('.progress-current'),
49 thumbnail: document
.querySelector('.thumbnail-placeholder'),
50 title: document
.querySelector('.thumbnail-link-title'),
52 updateThumb(basePath
, ids
, 0, elements
);