- this.formContainer.addEventListener('ajax-form-success', this.refreshGallery.bind(this));
- this.container.addEventListener('dropzone-success', this.refreshGallery.bind(this));
+ // Rebuild thumbs click
+ onChildEvent(this.formContainer, '#image-manager-rebuild-thumbs', 'click', async (_, button) => {
+ button.disabled = true;
+ if (this.lastSelected) {
+ await this.rebuildThumbnails(this.lastSelected.id);
+ }
+ button.disabled = false;
+ });
+
+ // Edit form submit
+ this.formContainer.addEventListener('ajax-form-success', () => {
+ this.refreshGallery();
+ this.resetEditForm();
+ });
+
+ // Image upload success
+ this.container.addEventListener('dropzone-upload-success', this.refreshGallery.bind(this));
+
+ // Auto load-more on scroll
+ const scrollZone = this.listContainer.parentElement;
+ let scrollEvents = [];
+ scrollZone.addEventListener('wheel', event => {
+ const scrollOffset = Math.ceil(scrollZone.scrollHeight - scrollZone.scrollTop);
+ const bottomedOut = scrollOffset === scrollZone.clientHeight;
+ if (!bottomedOut || event.deltaY < 1) {
+ return;
+ }
+
+ const secondAgo = Date.now() - 1000;
+ scrollEvents.push(Date.now());
+ scrollEvents = scrollEvents.filter(d => d >= secondAgo);
+ if (scrollEvents.length > 5 && this.canLoadMore()) {
+ this.runLoadMore();
+ }
+ });