2019-09-24 03:07:03 +08:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
|
|
|
var ActiveStoragePreviews = (function() {
|
|
|
|
const RETRY_COUNT = 50;
|
|
|
|
const RETRY_DELAY = 5000;
|
|
|
|
|
|
|
|
return Object.freeze({
|
|
|
|
reCheckPreview: function(ev) {
|
|
|
|
var img = ev.target;
|
|
|
|
var src = ev.target.src;
|
|
|
|
|
|
|
|
if (img.length === 0) return;
|
|
|
|
|
|
|
|
if (!img.retryCount) {
|
|
|
|
img.retryCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img.retryCount >= RETRY_COUNT) return;
|
|
|
|
|
2019-10-01 21:20:46 +08:00
|
|
|
if (!$(img).parent().hasClass('processing')) $(img).parent().addClass('processing');
|
|
|
|
|
2019-09-24 03:07:03 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
img.src = src;
|
|
|
|
img.retryCount += 1;
|
|
|
|
}, RETRY_DELAY);
|
|
|
|
},
|
|
|
|
showPreview: function(ev) {
|
|
|
|
$(ev.target).css('opacity', 1);
|
2019-10-01 21:20:46 +08:00
|
|
|
$(ev.target).parent().removeClass('processing');
|
2023-08-14 23:48:00 +08:00
|
|
|
},
|
|
|
|
reloadPreview: function(target) {
|
|
|
|
$(target)
|
|
|
|
.one('error', (event) => this.reCheckPreview(event))
|
|
|
|
.one('load', (event) => this.showPreview(event))
|
|
|
|
.trigger('error');
|
2019-09-24 03:07:03 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
2023-07-20 18:59:45 +08:00
|
|
|
|
|
|
|
$(document).on('turbolinks:load', function() {
|
|
|
|
$('.asset-preview-image')
|
|
|
|
.one('load', (event) => ActiveStoragePreviews.showPreview(event))
|
|
|
|
.one('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
|
|
|
.each(function() {
|
|
|
|
if (this.complete) {
|
2023-08-16 21:28:28 +08:00
|
|
|
$(this).trigger('load');
|
2023-07-20 18:59:45 +08:00
|
|
|
} else if (this.error) {
|
2023-08-16 21:28:28 +08:00
|
|
|
$(this).trigger('error');
|
2023-07-20 18:59:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|