1 |
|
2 |
|
3 | window.Dropzone.options.cmsPluginMediaUpload = false;
|
4 |
|
5 | $(function() {
|
6 |
|
7 | $('body').on('click', '.select-image', function(e) {
|
8 | e.preventDefault();
|
9 | $('#select-image-modal').data('target', $(this).closest('.form-image'));
|
10 | $('#select-image-modal').modal('show');
|
11 | window.refreshmodal();
|
12 | return false;
|
13 | });
|
14 |
|
15 | $('body').on('click', '.delete-image', function(e) {
|
16 | e.preventDefault();
|
17 | const target = $(this).closest('.form-image');
|
18 | target.find('input[type=hidden]').val(null);
|
19 | target.find('img.image').attr('src', '/cms/empty.png');
|
20 | $(this).hide();
|
21 | return false;
|
22 | });
|
23 |
|
24 |
|
25 | window.refreshmodal = function() {
|
26 | const adminpath = $('#cms-plugin-redactor').data('adminpath');
|
27 | $.get(adminpath + '/cms/medias/modal', function(html) {
|
28 | $('#select-image-modal .images').html(html);
|
29 | $('#select-image-modal .images img').click(function() {
|
30 | const target = $('#select-image-modal').data('target');
|
31 | ['id', 'uuid', 'filename'].forEach(attr => {
|
32 | target.find(`input[type=hidden].image-${attr}`).val($(this).data(attr));
|
33 | })
|
34 | target.find('img.image').attr('src', $(this).attr('src'));
|
35 | target.find('.delete-image').show();
|
36 | $('#select-image-modal').modal('hide');
|
37 | });
|
38 | });
|
39 | };
|
40 |
|
41 | $('#cms-plugin-media-upload').dropzone({
|
42 | paramName: 'file[]',
|
43 | init: function() {
|
44 | this.on('complete', refreshmodal);
|
45 | },
|
46 | });
|
47 | });
|