scinote-web/app/assets/javascripts/sitewide/file_preview.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
/* eslint no-use-before-define: ["error", { "functions": false }]*/
/* eslint-disable no-underscore-dangle */
/* global PdfPreview */
var FilePreviewModal = (function() {
'use strict';
2020-10-22 19:41:17 +08:00
function initPreviewModal() {
2020-10-19 21:23:34 +08:00
$(document).on('click', '.file-preview-link', function(e) {
2020-10-22 19:41:17 +08:00
var params = {};
var galleryViewId = $(this).data('gallery-view-id');
e.preventDefault();
2020-10-22 19:41:17 +08:00
e.stopPropagation();
2020-11-26 22:35:06 +08:00
if ($(this).closest('.attachments').data('preview')) params.preview = true;
2023-10-04 18:49:32 +08:00
params.gallery = Array.from(new Set(
$(`.file-preview-link[data-gallery-view-id=${galleryViewId}]`)
.toArray()
.sort((a, b) => $(a).closest('.asset').css('order') - $(b).closest('.asset').css('order'))
.map(i => i.dataset.id)
));
2020-10-22 19:41:17 +08:00
$.get($(this).data('preview-url'), params, function(result) {
2020-10-19 21:23:34 +08:00
$('#filePreviewModal .modal-content').html(result.html);
$('#filePreviewModal').modal('show');
2020-11-26 22:35:06 +08:00
$('.modal-backdrop').last().css('z-index', $('#filePreviewModal').css('z-index') - 1);
PdfPreview.initCanvas();
2020-10-22 19:41:17 +08:00
});
});
2020-10-22 19:41:17 +08:00
$(document).on('click', '#filePreviewModal .gallery-switcher', function(e) {
e.preventDefault();
e.stopPropagation();
$.get($(this).attr('href'), { gallery: $(this).data('gallery-elements') }, function(result) {
$('#filePreviewModal .modal-content').html(result.html);
PdfPreview.initCanvas();
2019-07-02 19:15:57 +08:00
});
2020-10-22 19:41:17 +08:00
});
}
return Object.freeze({
2020-10-19 21:23:34 +08:00
init: initPreviewModal
});
2020-10-19 21:23:34 +08:00
}());
FilePreviewModal.init();