forked from sebsauvage/Shaarli
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page to update all thumbnails through AJAX requests in both tem…
…plates
- Loading branch information
1 parent
787faa4
commit 28f2652
Showing
17 changed files
with
487 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Script used in the thumbnails update page. | ||
* | ||
* It retrieves the list of link IDs to update, and execute AJAX requests | ||
* to update their thumbnails, while updating the progress bar. | ||
*/ | ||
|
||
/** | ||
* Update the thumbnail of the link with the current i index in ids. | ||
* It contains a recursive call to retrieve the thumb of the next link when it succeed. | ||
* It also update the progress bar and other visual feedback elements. | ||
* | ||
* @param {array} ids List of LinkID to update | ||
* @param {int} i Current index in ids | ||
* @param {object} elements List of DOM element to avoid retrieving them at each iteration | ||
*/ | ||
function updateThumb(ids, i, elements) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('POST', '?do=ajax_thumb_update'); | ||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | ||
xhr.responseType = 'json'; | ||
xhr.onload = () => { | ||
if (xhr.status !== 200) { | ||
alert(`An error occurred. Return code: ${xhr.status}`); | ||
} else { | ||
const { response } = xhr; | ||
i += 1; | ||
elements.progressBar.style.width = `${(i * 100) / ids.length}%`; | ||
elements.current.innerHTML = i; | ||
elements.title.innerHTML = response.title; | ||
if (response.thumbnail !== false) { | ||
elements.thumbnail.innerHTML = `<img src="${response.thumbnail}">`; | ||
} | ||
if (i < ids.length) { | ||
updateThumb(ids, i, elements); | ||
} | ||
} | ||
}; | ||
xhr.send(`id=${ids[i]}`); | ||
} | ||
|
||
(() => { | ||
const ids = document.getElementsByName('ids')[0].value.split(','); | ||
const elements = { | ||
progressBar: document.querySelector('.progressbar > div'), | ||
current: document.querySelector('.progress-current'), | ||
thumbnail: document.querySelector('.thumbnail-placeholder'), | ||
title: document.querySelector('.thumbnail-link-title'), | ||
}; | ||
updateThumb(ids, 0, elements); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.