1 |
|
2 |
|
3 | require('./object-types');
|
4 | window.Dropzone.options.cmsPluginMediaUpload = false;
|
5 |
|
6 | $(function() {
|
7 |
|
8 | $('.fa-caret-right').click(function() {
|
9 | const target = $(this).data('target');
|
10 | $(target).toggle();
|
11 | $(this).toggleClass('fa-caret-right');
|
12 | $(this).toggleClass('fa-caret-down');
|
13 | })
|
14 |
|
15 | if ($('#cms-plugin-redactor').length < 1) {
|
16 | return ;
|
17 | }
|
18 |
|
19 | const adminpath = $('#cms-plugin-redactor').data('adminpath');
|
20 | $R('#cms-plugin-redactor', {
|
21 | imageUpload: adminpath + '/cms/medias/upload',
|
22 | imageResizable: true,
|
23 | imagePosition: true,
|
24 | plugins: [ 'table', 'alignment', 'video' ]
|
25 | });
|
26 |
|
27 |
|
28 | const refreshmodal = function() {
|
29 | const adminpath = $('#cms-plugin-redactor').data('adminpath');
|
30 | $.get(adminpath + '/cms/medias/modal', function(html) {
|
31 | $('#select-image-modal .images').html(html);
|
32 | $('#select-image-modal .images img').click(function() {
|
33 | const id = $(this).data('id');
|
34 | const target = $('#select-image-modal').data('target');
|
35 | $(`.form-page-sidebar #${target}-id`).val(id);
|
36 | $(`.form-page-sidebar #page-${target}`).attr('src', $(this).attr('src'));
|
37 | $('#select-image-modal').modal('hide');
|
38 | $(`.form-page-sidebar #${target}-id`).parent('.form-group').find('.delete-image').show();
|
39 | });
|
40 | });
|
41 | };
|
42 | $('.select-image').click(function(e) {
|
43 | $('#select-image-modal').data('target', $(this).data('target'));
|
44 | $('#select-image-modal').modal('show');
|
45 | refreshmodal();
|
46 | return false;
|
47 | });
|
48 |
|
49 | $('.delete-image').click(function(e) {
|
50 | const target = $(this).data('target');
|
51 | $(`.form-page-sidebar #${target}-id`).val(null);
|
52 | $(`.form-page-sidebar #page-${target}`).attr('src', '/cms/empty.png');
|
53 | $(this).hide();
|
54 | return false;
|
55 | });
|
56 |
|
57 | $('#cms-plugin-media-upload').dropzone({
|
58 | paramName: 'file[]',
|
59 | init: function() {
|
60 | this.on('complete', refreshmodal);
|
61 | },
|
62 | });
|
63 | });
|