|
1 | 1 | /* eslint-disable prefer-arrow-callback */ |
2 | 2 | (function (tinymce) { |
3 | | - function insertMediaCallback(data, caption, align, cssClass) { |
4 | | - var imageUrl = ''; |
5 | | - if (data.type === 'image') { |
6 | | - if (data.variation_url !== null) { |
7 | | - imageUrl = data.variation_url; |
8 | | - } else if (data.url !== null) { |
9 | | - imageUrl = data.url; |
10 | | - } |
11 | | - } else if (data.type === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { |
12 | | - imageUrl = data.thumbnail_url; |
13 | | - } |
| 3 | + function insertMediaCallback(data, caption, align, cssClass) { |
| 4 | + var imageUrl = ''; |
| 5 | + if (data.mediaType === 'image') { |
| 6 | + if (data.variation_url !== null) { |
| 7 | + imageUrl = data.variation_url; |
| 8 | + } else if (data.url !== null) { |
| 9 | + imageUrl = data.url; |
| 10 | + } |
| 11 | + } else if (data.mediaType === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { |
| 12 | + imageUrl = data.thumbnail_url; |
| 13 | + } |
14 | 14 |
|
15 | | - let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; |
16 | | - let elementClass = "ezoeItemCustomTag ngremotemedia"; |
17 | | - let alignAttr = ''; |
| 15 | + let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; |
| 16 | + let elementClass = "ezoeItemCustomTag ngremotemedia"; |
| 17 | + let alignAttr = ''; |
18 | 18 |
|
19 | | - if (typeof align !== 'undefined' && align !== '') { |
20 | | - elementClass += (' ezoeAlign' + align); |
21 | | - alignAttr = 'align="'+align+'"'; |
22 | | - } |
| 19 | + if (typeof align !== 'undefined' && align !== '') { |
| 20 | + elementClass += (' ezoeAlign' + align); |
| 21 | + alignAttr = 'align="'+align+'"'; |
| 22 | + } |
23 | 23 |
|
24 | | - let html = '<img type="custom" src="'+previewUrl+'"' |
25 | | - + 'data-mce-src="'+previewUrl+'"' |
26 | | - + alignAttr |
27 | | - + 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations) |
28 | | - + 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl |
29 | | - + 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">'; |
| 24 | + let html = '<img type="custom" src="'+previewUrl+'"' |
| 25 | + + 'data-mce-src="'+previewUrl+'"' |
| 26 | + + alignAttr |
| 27 | + + 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations) |
| 28 | + + 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl |
| 29 | + + 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">'; |
30 | 30 |
|
31 | | - tinymce.execCommand('mceInsertContent', false, html); |
32 | | - } |
| 31 | + tinymce.execCommand('mceInsertContent', false, html); |
| 32 | + } |
33 | 33 |
|
34 | | - tinymce.PluginManager.add("ngremotemedia", function (editor) { |
35 | | - const fieldId = editor.settings.ez_attribute_id; |
| 34 | + tinymce.PluginManager.add("ngremotemedia", function (editor) { |
| 35 | + const fieldId = editor.settings.ez_attribute_id; |
36 | 36 |
|
37 | | - window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); |
| 37 | + window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); |
38 | 38 |
|
39 | | - // Add a button that opens a modal |
40 | | - editor.addButton("ngremotemedia", { |
41 | | - title: "Insert remote media", |
42 | | - image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", |
43 | | - onclick() { |
44 | | - let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); |
45 | | - let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); |
46 | | - let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); |
| 39 | + // Add a button that opens a modal |
| 40 | + editor.addButton("ngremotemedia", { |
| 41 | + title: "Insert remote media", |
| 42 | + image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", |
| 43 | + onclick() { |
| 44 | + let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); |
| 45 | + let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); |
| 46 | + let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); |
47 | 47 |
|
48 | | - var data = {}; |
49 | | - if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { |
50 | | - data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); |
51 | | - let attributes = attributeString.split('attribute_separation'); |
| 48 | + var data = {}; |
| 49 | + if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { |
| 50 | + data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); |
| 51 | + let attributes = attributeString.split('attribute_separation'); |
52 | 52 |
|
53 | | - attributes.forEach(function (attribute) { |
54 | | - let attributeKey = attribute.split('|')[0]; |
55 | | - let attributeValue = attribute.split('|')[1]; |
| 53 | + attributes.forEach(function (attribute) { |
| 54 | + let attributeKey = attribute.split('|')[0]; |
| 55 | + let attributeValue = attribute.split('|')[1]; |
56 | 56 |
|
57 | | - if (attributeKey === 'coords' || attributeKey === 'image_variations') { |
58 | | - try { |
59 | | - data['image_variations'] = JSON.parse(attributeValue); |
60 | | - } catch(e) { |
61 | | - data['image_variations'] = {}; |
62 | | - } |
| 57 | + if (attributeKey === 'coords' || attributeKey === 'image_variations') { |
| 58 | + try { |
| 59 | + data['image_variations'] = JSON.parse(attributeValue); |
| 60 | + } catch(e) { |
| 61 | + data['image_variations'] = {}; |
| 62 | + } |
63 | 63 |
|
64 | | - return; |
65 | | - } |
| 64 | + return; |
| 65 | + } |
66 | 66 |
|
67 | | - data[attributeKey] = attributeValue; |
68 | | - }); |
69 | | - } |
| 67 | + data[attributeKey] = attributeValue; |
| 68 | + }); |
| 69 | + } |
70 | 70 |
|
71 | | - window[`remoteMedia` + fieldId].openEditorInsertModal(data); |
72 | | - }, |
73 | | - }); |
| 71 | + window[`remoteMedia` + fieldId].openEditorInsertModal(data); |
| 72 | + }, |
| 73 | + }); |
74 | 74 |
|
| 75 | + return { |
| 76 | + getMetadata() { |
75 | 77 | return { |
76 | | - getMetadata() { |
77 | | - return { |
78 | | - name: "Netgen remote media", |
79 | | - url: "https://github.com/netgen/NetgenRemoteMediaBundle", |
80 | | - }; |
81 | | - }, |
| 78 | + name: "Netgen remote media", |
| 79 | + url: "https://github.com/netgen/NetgenRemoteMediaBundle", |
82 | 80 | }; |
83 | | - }); |
| 81 | + }, |
| 82 | + }; |
| 83 | + }); |
84 | 84 | })(tinymce); |
0 commit comments