From a33c5653655215d3a6496807f15a896d4b85f070 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 24 Feb 2018 18:30:30 +0100 Subject: Webpack / Rewrite all JS to ES6 Syntax --- assets/common/js/picwall.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 assets/common/js/picwall.js (limited to 'assets/common') diff --git a/assets/common/js/picwall.js b/assets/common/js/picwall.js new file mode 100644 index 00000000..87a93fc3 --- /dev/null +++ b/assets/common/js/picwall.js @@ -0,0 +1,10 @@ +import Blazy from 'blazy'; + +(() => { + const picwall = document.getElementById('picwall_container'); + if (picwall != null) { + // Suppress ESLint error because that's how bLazy works + /* eslint-disable no-new */ + new Blazy(); + } +})(); -- cgit v1.2.3 From e85b7a05a177f803ae36ba5c12835313f31177bc Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 11 Nov 2017 14:01:21 +0100 Subject: Update thumbnail integration after rebasing the branch --- assets/common/js/picwall.js | 10 ---------- assets/common/js/thumbnails.js | 7 +++++++ 2 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 assets/common/js/picwall.js create mode 100644 assets/common/js/thumbnails.js (limited to 'assets/common') diff --git a/assets/common/js/picwall.js b/assets/common/js/picwall.js deleted file mode 100644 index 87a93fc3..00000000 --- a/assets/common/js/picwall.js +++ /dev/null @@ -1,10 +0,0 @@ -import Blazy from 'blazy'; - -(() => { - const picwall = document.getElementById('picwall_container'); - if (picwall != null) { - // Suppress ESLint error because that's how bLazy works - /* eslint-disable no-new */ - new Blazy(); - } -})(); diff --git a/assets/common/js/thumbnails.js b/assets/common/js/thumbnails.js new file mode 100644 index 00000000..c28322bb --- /dev/null +++ b/assets/common/js/thumbnails.js @@ -0,0 +1,7 @@ +import Blazy from 'blazy'; + +(() => { + // Suppress ESLint error because that's how bLazy works + /* eslint-disable no-new */ + new Blazy(); +})(); -- cgit v1.2.3 From 28f26524609338316cc6e51c743058e6e8c7b12b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 8 Jun 2018 12:50:49 +0200 Subject: Add a page to update all thumbnails through AJAX requests in both templates --- assets/common/js/thumbnails-update.js | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 assets/common/js/thumbnails-update.js (limited to 'assets/common') diff --git a/assets/common/js/thumbnails-update.js b/assets/common/js/thumbnails-update.js new file mode 100644 index 00000000..b66ca3ae --- /dev/null +++ b/assets/common/js/thumbnails-update.js @@ -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 = ``; + } + 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); +})(); -- cgit v1.2.3