PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.1.8
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.1.8
3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 All 195 releases
convertkit / resources / backend / js / editor.js

editor.js in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.1.8, at resources/backend/js/editor.js

161 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Handles registration of TinyMCE buttons.
3 *
4 * @since 1.9.6
5 *
6 * @author ConvertKit
7 */
8
9 /* eslint-disable no-unused-vars */
10 /**
11 * Registers the given block as a TinyMCE Plugin, with a button in
12 * the Visual Editor toolbar.
13 *
14 * @since 1.9.6
15 *
16 * @param {Object} block Block
17 */
18 function convertKitTinyMCERegisterPlugin(block) {
19 tinymce.PluginManager.add(
20 'convertkit_' + block.name,
21 function (editor, url) {
22 // Add Button to Visual Editor Toolbar.
23 editor.addButton('convertkit_' + block.name, {
24 title: block.title,
25 image: url + '../../../../' + block.icon,
26 cmd: 'convertkit_' + block.name,
27 });
28
29 // Load View when button clicked.
30 editor.addCommand('convertkit_' + block.name, function () {
31 // Close any existing QuickTags modal.
32 convertKitQuickTagsModal.close();
33
34 // Open the TinyMCE Modal.
35 editor.windowManager.open({
36 id: 'convertkit-modal-body',
37 title: block.title,
38 width: block.modal.width,
39
40 // Set modal height up to a maximum of 580px.
41 // Content will overflow-y to show a scrollbar where necessary.
42 height: block.modal.height < 580 ? block.modal.height : 580,
43 inline: 1,
44 buttons: [
45 {
46 text: 'Cancel',
47 classes: 'cancel',
48 },
49 {
50 text: 'Insert',
51 subtype: 'primary',
52 classes: 'insert',
53 },
54 ],
55 });
56
57 // Perform an AJAX call to load the modal's view.
58 fetch(ajaxurl, {
59 method: 'POST',
60 headers: {
61 'Content-Type': 'application/x-www-form-urlencoded',
62 },
63 body: new URLSearchParams({
64 action: 'convertkit_admin_tinymce_output_modal',
65 nonce: convertkit_admin_tinymce.nonce,
66 editor_type: 'tinymce',
67 shortcode: block.name,
68 }),
69 })
70 .then(function (response) {
71 return response.text();
72 })
73 .then(function (result) {
74 // Inject HTML into modal.
75 document.querySelector(
76 '#convertkit-modal-body-body'
77 ).innerHTML = result;
78
79 // Initialize tabbed interface.
80 convertKitTabsInit();
81
82 // Listen for color input changes.
83 convertKitColorInputInit();
84
85 // Initialize conditional fields.
86 convertKitConditionallyDisplayTinyMCEModalFields();
87
88 // Listen for field changes.
89 convertKitConditionalFieldsInit();
90
91 // Bind refresh resource event listeners.
92 convertKitRefreshResourcesInitEventListeners();
93 })
94 .catch(function (error) {
95 console.error(error);
96 });
97 });
98 }
99 );
100 }
101 /* eslint-enable no-unused-vars */
102
103 /**
104 * Listens for changes to input[type=color] inputs within a TinyMCE or QuickTags modal,
105 * assigning the value to the input's data-value attribute.
106 *
107 * The modal.js will check the data-value for the 'true' value, as any color input will always
108 * send #000000 as the value, even when none is supplied.
109 *
110 * @since 2.4.3
111 */
112 function convertKitColorInputInit() {
113 document
114 .querySelectorAll('.convertkit-option input[type=color]')
115 .forEach(function (colorPicker) {
116 colorPicker.addEventListener('change', function (event) {
117 event.target.dataset.value = event.target.value;
118 });
119 });
120 }
121
122 /**
123 * Initializes the conditional fields functionality.
124 *
125 * @since 3.0.6
126 */
127 function convertKitConditionalFieldsInit() {
128 document
129 .querySelectorAll(
130 'form.convertkit-tinymce-popup select, form.convertkit-tinymce-popup input'
131 )
132 .forEach(function (field) {
133 field.addEventListener('change', function () {
134 convertKitConditionallyDisplayTinyMCEModalFields();
135 });
136 });
137 }
138
139 /**
140 * Conditionally display the TinyMCE modal fields.
141 *
142 * @since 3.0.6
143 */
144 function convertKitConditionallyDisplayTinyMCEModalFields() {
145 document
146 .querySelectorAll('form.convertkit-tinymce-popup [data-display-if]')
147 .forEach(function (field) {
148 // Get field that controls whether this field should be displayed.
149 const controllingField = document.querySelector(
150 `form.convertkit-tinymce-popup select[name="${field.dataset.displayIf}"]`
151 );
152
153 // If the value of the field that should be displayed is the same as the value of the controlling field, show/hide the containing div.
154 const container = field.closest('.convertkit-option');
155 container.style.display =
156 field.dataset.displayIfValue === controllingField.value
157 ? 'grid'
158 : 'none';
159 });
160 }
161