PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.3.8
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.3.8
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 2.3.3 All 194 releases
convertkit / includes / integrations / divi / scripts / builder-bundle.min.js

builder-bundle.min.js in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.3.8, at includes/integrations/divi/scripts/builder-bundle.min.js

265 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * ConvertKit Broadcasts Divi Module.
3 */
4 class ConvertKitDiviBroadcasts extends React.Component {
5 /**
6 * The Divi module name. Must match the slug defined in
7 * the PHP class ConvertKit_Divi_Module_Broadcasts.
8 *
9 * @since 2.5.7
10 */
11 static slug = 'convertkit_broadcasts';
12
13 /**
14 * Renders the frontend output for this module.
15 *
16 * @since 2.5.7
17 */
18 render() {
19 const block = window.ConvertkitDiviBuilderData.broadcasts;
20
21 // If no Access Token has been defined in the Plugin, show a message in the module to tell the user what to do.
22 if (!block.has_access_token) {
23 return ConvertKitDiviNoAccessMessage(block);
24 }
25
26 // If no resources exist in ConvertKit, show a message in the module to tell the user what to do.
27 if (!block.has_resources) {
28 return ConvertKitDiviNoResourcesMessage(block);
29 }
30
31 // Return module with text.
32 return ConvertKitDiviMessage(
33 'Configure this broadcasts module by clicking the settings cog.'
34 );
35 }
36 }
37
38 /**
39 * ConvertKit Form Divi Module.
40 */
41 class ConvertKitDiviForm extends React.Component {
42 /**
43 * The Divi module name. Must match the slug defined in
44 * the PHP class ConvertKit_Divi_Module_Form.
45 *
46 * @since 2.5.6
47 */
48 static slug = 'convertkit_form';
49
50 /**
51 * Renders the frontend output for this module.
52 *
53 * @since 2.5.6
54 */
55 render() {
56 const form =
57 typeof this.props.form !== 'undefined' ? this.props.form : '';
58
59 return ConvertKitDiviRenderResourceModule(
60 window.ConvertkitDiviBuilderData.form,
61 form,
62 form
63 ? window.ConvertkitDiviBuilderData.form.fields.form.data.forms[
64 form
65 ].name
66 : '',
67 window.ConvertkitDiviBuilderData.form.fields.form.label
68 );
69 }
70 }
71
72 /**
73 * ConvertKit Form Trigger Divi Module.
74 */
75 class ConvertKitDiviFormTrigger extends React.Component {
76 /**
77 * The Divi module name. Must match the slug defined in
78 * the PHP class ConvertKit_Divi_Module_Form.
79 *
80 * @since 2.5.7
81 */
82 static slug = 'convertkit_formtrigger';
83
84 /**
85 * Renders the frontend output for this module.
86 *
87 * @since 2.5.7
88 */
89 render() {
90 const form = Number(
91 typeof this.props.form !== 'undefined' ? this.props.form : 0
92 );
93
94 return ConvertKitDiviRenderResourceModule(
95 window.ConvertkitDiviBuilderData.formtrigger,
96 form,
97 form > 0
98 ? window.ConvertkitDiviBuilderData.formtrigger.fields.form
99 .values[form]
100 : '',
101 window.ConvertkitDiviBuilderData.formtrigger.fields.form.label
102 );
103 }
104 }
105
106 /**
107 * ConvertKit Product Divi Module.
108 */
109 class ConvertKitDiviProduct extends React.Component {
110 /**
111 * The Divi module name. Must match the slug defined in
112 * the PHP class ConvertKit_Divi_Module_Product.
113 *
114 * @since 2.5.7
115 */
116 static slug = 'convertkit_product';
117
118 /**
119 * Renders the frontend output for this module.
120 *
121 * @since 2.5.7
122 */
123 render() {
124 const product =
125 typeof this.props.product !== 'undefined' ? this.props.product : '';
126
127 return ConvertKitDiviRenderResourceModule(
128 window.ConvertkitDiviBuilderData.product,
129 product,
130 product
131 ? window.ConvertkitDiviBuilderData.product.fields.product
132 .values[product]
133 : '',
134 window.ConvertkitDiviBuilderData.product.fields.product.label
135 );
136 }
137 }
138
139 /**
140 * Returns the block's notice and instruction text when no access token exists.
141 *
142 * @since 2.5.7
143 *
144 * @param {Object} block Block.
145 */
146 function ConvertKitDiviNoAccessMessage(block) {
147 return React.createElement(
148 'div',
149 {
150 className: 'convertkit-divi-module convertkit-no-content',
151 },
152 [
153 React.createElement('p', {}, block.no_access_token.notice),
154 React.createElement(
155 'p',
156 {},
157 block.no_access_token.instruction_text
158 ),
159 ]
160 );
161 }
162
163 /**
164 * Returns the block's notice and instruction text when no resources
165 * (forms, products etc) exist.
166 *
167 * @since 2.5.7
168 *
169 * @param {Object} block Block.
170 */
171 function ConvertKitDiviNoResourcesMessage(block) {
172 return React.createElement(
173 'div',
174 {
175 className: 'convertkit-divi-module convertkit-no-content',
176 },
177 [
178 React.createElement('p', {}, block.no_resources.notice),
179 React.createElement('p', {}, block.no_resources.instruction_text),
180 ]
181 );
182 }
183
184 /**
185 * Returns the given text.
186 *
187 * @since 2.5.7
188 *
189 * @param {string} message Message to display.
190 */
191 function ConvertKitDiviMessage(message) {
192 return React.createElement(
193 'div',
194 {
195 className: 'convertkit-divi-module',
196 },
197 message
198 );
199 }
200
201 /**
202 * Renders the Divi module for the given ConvertKit block (form, product, broadcast etc).
203 * and message, based on the Plugin and Divi module's configuration.
204 *
205 * @since 2.5.7
206 *
207 * @param {Object} block Block.
208 * @param {string} value Selected value.
209 * @param {string} valueLabel Selected value's label.
210 * @param {string} resourceName Resource name (form,product).
211 */
212 function ConvertKitDiviRenderResourceModule(
213 block,
214 value,
215 valueLabel,
216 resourceName
217 ) {
218 // If no Access Token has been defined in the Plugin, show a message in the module to tell the user what to do.
219 if (!block.has_access_token) {
220 return ConvertKitDiviNoAccessMessage(block);
221 }
222
223 // If no resources exist in ConvertKit, show a message in the module to tell the user what to do.
224 if (!block.has_resources) {
225 return ConvertKitDiviNoResourcesMessage(block);
226 }
227
228 // Show instructions if no resource selected.
229 if (value.length === 0) {
230 return ConvertKitDiviMessage(
231 'Configure this module by clicking the settings cog.'
232 );
233 }
234
235 // Return module with text.
236 return ConvertKitDiviMessage(
237 'Kit ' +
238 resourceName +
239 ' "' +
240 valueLabel +
241 '" selected. View on the frontend site to see the ' +
242 resourceName +
243 '.'
244 );
245 }
246
247 /**
248 * Register Divi modules when the Divi Builder API is ready.
249 *
250 * @since 2.5.6
251 *
252 * @param {Object} event Event.
253 * @param {Object} API Divi Buidler API.
254 */
255 jQuery(window).on('et_builder_api_ready', function (event, API) {
256 // eslint-disable-line no-unused-vars
257 // Register Divi modules.
258 API.registerModules([
259 ConvertKitDiviBroadcasts,
260 ConvertKitDiviForm,
261 ConvertKitDiviFormTrigger,
262 ConvertKitDiviProduct,
263 ]);
264 });
265