1var shortcodes = []; 2var lists = []; 3var model_fields = []; 4var custom_fields = []; 5var get_aweber_shortcodes_ajax = null; 6var get_aweber_lists_ajax = null; 7var elementor_control_aweber_form_submit_added = false; 8var elementor_control_aweber_widget_added = false; 9var elementor_control_aweber_form_submit_observer = null; 10var elementor_control_aweber_widget_observer = null; 11 12function update_message(panel, message, selector) { 13 cls_selector = 'important_note'; 14 if (typeof selector !== 'undefined') { 15 cls_selector = selector; 16 } 17 panel.$el.find('.elementor-control-' + cls_selector) 18 .find('.elementor-control-raw-html').html(message); 19} 20 21function load_select_option(panel, data, cls, key, val) { 22 for (let i =0; i < data.length; i++) { 23 panel.$el.find(cls +' select') 24 .append(jQuery("<option></option>") 25 .attr("value", data[i][key]).text(data[i][val])); 26 } 27} 28 29function load_signup_dropdown(panel, selected_list_id) { 30 if(selected_list_id == 0) { 31 panel.$el.find('.elementor-control-aweber_form select') 32 .append(jQuery("<option></option>") 33 .attr("value", 0) 34 .text('Please select sign Up form & Split Tests')); 35 } 36 37 let list = shortcodes.filter(obj => obj.list_id == selected_list_id); 38 if (list.length) { 39 load_select_option(panel, list[0].options, 40 '.elementor-control-aweber_form', 'value', 'name') 41 } else { 42 panel.$el.find('.elementor-control-aweber_form select') 43 .append(jQuery("<option></option>") 44 .attr("value", 0).text('No signup form found')); 45 } 46} 47 48function attach_signup_form(panel, model, shortcodes) { 49 let settings = model.get('settings'); 50 panel.$el.find('.elementor-control-important_note').hide(); 51 52 load_select_option(panel, shortcodes, '.elementor-control-aweber_list', 53 'list_id', 'list_name') 54 if ('aweber_list' in settings.attributes) { 55 panel.$el.find('.elementor-control-aweber_list select') 56 .val(settings.attributes['aweber_list']); 57 58 load_signup_dropdown(panel, settings.attributes['aweber_list']); 59 if ('aweber_form' in settings.attributes) { 60 let webform_val = 0; 61 if (settings.attributes['aweber_form'].includes(settings.attributes['aweber_list'])) { 62 webform_val = settings.attributes['aweber_form']; 63 } 64 panel.$el.find('.elementor-control-aweber_form select').val(webform_val); 65 } 66 } 67 68 panel.$el.find('.elementor-control-aweber_list select').change(function(){ 69 panel.$el.find('.elementor-control-aweber_form select').empty(); 70 panel.$el.find('.elementor-control-aweber_form select').val(0); 71 load_signup_dropdown(panel, jQuery(this).val()); 72 }); 73 74 panel.$el.find('.elementor-control-aweber_form select').change(function(){ 75 // Remove the scripts loaded for the forms, so that the next time same form is selected it should load. 76 jQuery('script').each(function () { 77 let $this = jQuery(this); 78 let script_id = jQuery(this).attr('id'); 79 if (typeof script_id !== 'undefined' && 80 script_id.includes('aweber-wjs')) { 81 $this.remove(); 82 } 83 }); 84 }); 85} 86 87function parse_aweber_shortcodes(result) { 88 shortcodes.push({ 89 list_id: 0, 90 list_name: 'Please select list', 91 options: [] 92 }); 93 94 let options = []; 95 options.push({ 96 'name': 'Please select sign Up form & Split Tests', 97 'value': 0 98 }) 99 let currentListId = result.short_codes[0].list_id; 100 let currentListName = result.short_codes[0].list_name; 101 for(let i=0; i < result.short_codes.length; i++) { 102 if (currentListId != result.short_codes[i].list_id) { 103 shortcodes.push({ 104 list_id: currentListId, 105 list_name: currentListName, 106 options: options 107 }); 108 options = []; 109 options.push({ 110 'name': 'Please select signup form', 111 'value': 0 112 }) 113 currentListId = result.short_codes[i].list_id; 114 currentListName = result.short_codes[i].list_name; 115 } 116 option_name = 'Form - ' + result.short_codes[i].text; 117 if(result.short_codes[i].value.includes('split_tests')) { 118 option_name = 'Split - ' + result.short_codes[i].text; 119 } 120 options.push({ 121 'name': option_name, 122 'value': result.short_codes[i].value 123 }); 124 } 125 if (options.length > 0) { 126 shortcodes.push({ 127 'list_id': currentListId, 128 'list_name': currentListName, 129 'options': options 130 }); 131 } 132} 133 134function init_aweber_elements(panel, model, view) { 135 if (panel.$el.find('.elementor-control-aweber_connection_closed_message').length) { 136 return; 137 } 138 139 var settings = model.get('settings'); 140 if (shortcodes.length) { 141 attach_signup_form(panel, model, shortcodes); 142 } else { 143 panel.$el.find('.elementor-control-aweber_list').hide(); 144 panel.$el.find('.elementor-control-aweber_form').hide(); 145 146 if (get_aweber_shortcodes_ajax !== null) { 147 // One ajax request already in pending state. Dont call one more. 148 return; 149 } 150 151 get_aweber_shortcodes_ajax = jQuery.getJSON(php_vars.ajax_url + '?action=get_aweber_webform_shortcodes&nonce=' + php_vars.nonces.get_aweber_webform_shortcodes, function(result){ 152 if (result.status == 'error') { 153 message = result.message; 154 if (result.message.includes('reconnect')) { 155 message = '<p style="text-align: center">' + result.message + '<br>\ 156 <br><a href="' + php_vars.plugin_connect_url + '">Go to Plugin</a></p>'; 157 } 158 update_message(panel, message); 159 } else { 160 parse_aweber_shortcodes(result); 161 162 panel.$el.find('.elementor-control-aweber_list').show(); 163 panel.$el.find('.elementor-control-aweber_form').show(); 164 165 attach_signup_form(panel, model, shortcodes); 166 } 167 // Set it to null. Ajax request completed. 168 get_aweber_shortcodes_ajax = null; 169 }).fail(function(data){ 170 update_message(panel, 'An unexpected error occurred. \ 171 Please check your internet connection and try again'); 172 // Set it to null. Ajax request completed. 173 get_aweber_shortcodes_ajax = null; 174 }); 175 } 176} 177 178function load_aweber_custom_fields(panel, model, list_id) { 179 // Empty the Previous seleted custom fields. 180 custom_fields = []; 181 // Prepare Ajax request data 182 let data = { 183 list_id: list_id, 184 action: 'get_aweber_custom_fields', 185 nonce: php_vars.nonces.get_aweber_custom_fields 186 }; 187 // Show the Custom fields loading Message 188 panel.$el.find(".elementor-control-aweber_custom_fields_message").show(); 189 update_message(panel, 'Loading custom fields', 'aweber_custom_fields_message'); 190 191 // Update the value to None for previous selected fields. 192 panel.$el.find('[class*=elementor-control-aweber_form_custom_dynamic_field_]:visible') 193 .each(function(index){ 194 model.setSetting('aweber_form_custom_dynamic_field_' + index, '0'); 195 }); 196 197 // Hide all the prevoius Custom fields 198 panel.$el.find('[class*=elementor-control-aweber_form_custom_dynamic_field_]').hide(); 199 // If the valid list id is not selceted, then return 200 if (list_id == '0') { 201 panel.$el.find(".elementor-control-aweber_custom_fields_message").hide(); 202 return; 203 } 204 205 // Get the Custom Fields for the selected lists. 206 jQuery.getJSON(php_vars.ajax_url, data, function(result){ 207 if (result.status == 'error') { 208 message = result.message; 209 if (result.message.includes('reconnect')) { 210 message = '<p style="text-align: center">' + result.message + '<br>\ 211 <br><a href="' + php_vars.plugin_connect_url + '">Go to Plugin</a></p>'; 212 } 213 update_message(panel, message, 'aweber_custom_fields_message'); 214 } else { 215 // Hide the custom fields loading Message 216 panel.$el.find(".elementor-control-aweber_custom_fields_message").hide(); 217 // Get the Fields 218 custom_fields = result.custom_fields; 219 if (custom_fields.length > 0) { 220 // IF their are fields for a list 221 show_load_dynamic_custom_fields(panel, model); 222 } 223 } 224 }).fail(function(data){ 225 update_message(panel, 'An unexpected error occurred. \ 226 Please check your internet connection and try again', 'aweber_custom_fields_message'); 227 }); 228} 229 230function update_lists(panel, model) { 231 panel.$el.find('.elementor-control-aweber_form_list select').empty(); 232 load_select_option(panel, lists, '.elementor-control-aweber_form_list', 233 'list_id', 'list_name'); 234 235 // Load the Forms fields in the AWeber static fields dropdown 236 update_field_mapping(panel, model); 237 // Get the selected Lists IF any and update in List dropdown. 238 var settings = model.get('settings'); 239 if ( 'aweber_form_list' in settings.attributes && 240 settings.attributes['aweber_form_list'] != '' && 241 settings.attributes['aweber_form_list'] != '0' ) { 242 // Update the Selected list id. 243 panel.$el.find('.elementor-control-aweber_form_list select') 244 .val(settings.attributes['aweber_form_list']); 245 246 // Load the Custom if there are any for the selected lists. 247 if (custom_fields.length) { 248 show_load_dynamic_custom_fields(panel, model); 249 } else { 250 load_aweber_custom_fields(panel, model, settings.attributes['aweber_form_list']); 251 } 252 } 253 // Once the List are loaded, Hide the Loading Message. 254 panel.$el.find('.elementor-control-important_note').hide(); 255 256 // Once lists are loaded, Show the Lists, tags and Static Fields 257 panel.$el.find(".elementor-control-aweber_form_list").show(); 258 panel.$el.find(".elementor-control-aweber_form_tags").show(); 259 panel.$el.find(".elementor-control-aweber_form_more_options").show(); 260 panel.$el.find(".elementor-control-aweber_form_name_static_field").show(); 261 panel.$el.find(".elementor-control-aweber_form_email_static_field").show(); 262 263 // Add the Change Event to the List Dropdown. 264 panel.$el.find('.elementor-control-aweber_form_list select').off().on('change', function(){ 265 let selected_list_id = jQuery(this).val(); 266 load_aweber_custom_fields(panel, model, selected_list_id); 267 }); 268 269 // Add the change event to the "Email" 270 panel.$el.find('.elementor-control-aweber_form_email_static_field select').off().on('change', function(){ 271 model.setSetting('aweber_form_email_static_field', jQuery(this).val()); 272 }); 273 274 // Add the change event to the "Name" 275 panel.$el.find('.elementor-control-aweber_form_name_static_field select').off().on('change', function(){ 276 model.setSetting('aweber_form_name_static_field', jQuery(this).val()); 277 }); 278} 279 280function show_load_dynamic_custom_fields(panel, model) { 281 panel.$el.find('[class*=elementor-control-aweber_form_custom_dynamic_field_]') 282 .slice(0, custom_fields.length).each(function(index){ 283 // Show the Field. 284 jQuery(this).show(); 285 // Show the Custom field name 286 jQuery(this).find('.elementor-control-title').html(custom_fields[index]); 287 // Load the Fields in the Front end. 288 update_field_mapping(panel, model, ['aweber_form_custom_dynamic_field_'+index]); 289 // Add an event to update the model custom fields value, when altered 290 panel.$el.find('.elementor-control-aweber_form_custom_dynamic_field_'+index+' select').off().on('change', function(){ 291 model.setSetting('aweber_form_custom_dynamic_field_' + index, jQuery(this).val()); 292 }); 293 }); 294} 295 296function get_fields(model) { 297 // Empty the Fields 298 model_fields = []; 299 300 let settings = model.get('settings'); 301 let models = settings.attributes.form_fields['models']; 302 303 model_fields.push({'id': '0', 'label': '- None -'}); 304 for (let i=0; i<models.length; i++) { 305 model_fields.push({ 306 'id': models[i].attributes.custom_id, 307 'label': models[i].attributes.field_label || models[i].attributes.placeholder || 'NA' 308 }); 309 } 310} 311 312function update_field_mapping (panel, model, options) { 313 let settings = model.get('settings'); 314 if (typeof options === 'undefined') { 315 options = ['aweber_form_name_static_field', 'aweber_form_email_static_field']; 316 } 317 for (let op=0; op<options.length; op++) { 318 let local_fields = JSON.parse(JSON.stringify(model_fields)); 319 let selector = '.elementor-control-' + options[op]; 320 let label_name = panel.$el.find(selector) 321 .find('.elementor-control-title') 322 .text(); 323 // Use this only for CustomFields, not the Name and Email Fields.
324 if (options[op] != 'aweber_form_name_static_field' && options[op] != 'aweber_form_email_static_field') { 325 for (let m=1; m < local_fields.length; m++) { 326 local_fields[m]['id'] = local_fields[m]['id']+'-('+label_name+')'; 327 } 328 } 329 panel.$el.find(selector + ' select').empty(); 330 load_select_option(panel, local_fields, selector, 'id', 'label'); 331 // condition check, what value to set in the custom fields dropdown. 332 let option_val = "0"; 333 if (settings.attributes[options[op]]) { 334 if (panel.$el.find(selector + ' option[value="'+settings.attributes[options[op]]+'"]').length != 0) { 335 option_val = settings.attributes[options[op]]; 336 } 337 } 338 panel.$el.find(selector + ' select').val(option_val); 339 } 340} 341 342function load_aweber_list(panel, model) { 343 // If the AWeber Connection is closed 344 if (panel.$el.find('.elementor-control-aweber_connection_closed_message').length) { 345 return; 346 } 347 // Check the AWeber Panel is active. 348 if (panel.$el.find('.elementor-control-aweber_form_list').length == 0) { 349 return; 350 } 351 // Show the Loading message. 352 panel.$el.find('.elementor-control-important_note').show(); 353 354 // Get the Form fields 355 get_fields(model); 356 357 // Hide the AWeber forms, untill the lists are loaded. 358 panel.$el.find(".elementor-control-aweber_form_list").hide(); 359 panel.$el.find(".elementor-control-aweber_form_tags").hide(); 360 panel.$el.find(".elementor-control-aweber_form_more_options").hide(); 361 panel.$el.find(".elementor-control-aweber_form_name_static_field").hide(); 362 panel.$el.find(".elementor-control-aweber_form_email_static_field").hide(); 363 panel.$el.find(".elementor-control-aweber_custom_fields_message").hide(); 364 // Hide the AWeber Dynamic Custom Fields 365 panel.$el.find('[class*=elementor-control-aweber_form_custom_dynamic_field_]').hide(); 366 if (lists.length > 0) { 367 update_lists(panel, model); 368 } else { 369 if (get_aweber_lists_ajax !== null) { 370 // One ajax request already in pending state. Dont call one more. 371 return; 372 } 373 get_aweber_lists_ajax = jQuery.getJSON(php_vars.ajax_url + '?action=get_aweber_lists&nonce=' + php_vars.nonces.get_aweber_lists, function(result){ 374 if (result.status == 'error') { 375 message = result.message; 376 if (result.message.includes('reconnect')) { 377 message = '<p style="text-align: center">' + result.message + '<br>\ 378 <br><a href="' + php_vars.plugin_connect_url + '">Go to Plugin</a></p>'; 379 } 380 update_message(panel, message); 381 } else { 382 lists = result.lists; 383 lists.unshift({'list_id': 0, 'list_name': 'Please select list'}); 384 update_lists(panel, model); 385 } 386 get_aweber_lists_ajax = null; 387 }).fail(function(data){ 388 update_message(panel, 'An unexpected error occurred. \ 389 Please check your internet connection and try again'); 390 get_aweber_lists_ajax = null; 391 }); 392 } 393} 394 395jQuery( window ).on( 'elementor/frontend/init', () => { 396 if (typeof elementor !== 'undefined') { 397 elementor.hooks.addAction( 'panel/open_editor/widget/aweber', function(panel, model, view) { 398 if (elementor_control_aweber_widget_observer) { 399 // Disconnect the observer if already connected. 400 elementor_control_aweber_widget_observer.disconnect(); 401 } 402 elementor_control_aweber_widget_observer = new MutationObserver((mutationList, observer) => { 403 if (panel.$el.hasClass('elementor-control-aweber_form') || panel.$el.find('.elementor-control-aweber_form').length) { 404 if (elementor_control_aweber_widget_added === false) { 405 init_aweber_elements(panel, model, view); 406 elementor_control_aweber_widget_added = true; 407 } 408 } else { 409 elementor_control_aweber_widget_added = false;
410 } 411 412 if (panel.$el.find('#elementor-panel-header-title').text().includes('AWeber') === false) { 413 // AWeber Panel got closed. so disconnect the observer. 414 observer.disconnect(); 415 elementor_control_aweber_widget_observer = null; 416 } 417 }); 418 elementor_control_aweber_widget_observer.observe(panel.$el.find('#elementor-panel-content-wrapper')[0], { attributes: true, childList: true }); 419 }); 420 421 elementor.hooks.addAction( 'panel/open_editor/widget/form', function(panel, model, view) { 422 if (elementor_control_aweber_form_submit_observer) { 423 elementor_control_aweber_form_submit_observer.disconnect(); 424 } 425 // Create an observer instance linked to the callback function 426 elementor_control_aweber_form_submit_observer = new MutationObserver((mutationList, observer) => { 427 if (panel.$el.hasClass('elementor-control-aweber_form_list') || panel.$el.find('.elementor-control-aweber_form_list').length) { 428 // Load the lists if its not added. 429 if (elementor_control_aweber_form_submit_added === false) { 430 load_aweber_list(panel, model); 431 } 432 elementor_control_aweber_form_submit_added = true; 433 } else { 434 elementor_control_aweber_form_submit_added = false; 435 } 436 437 if (panel.$el.find('#elementor-panel-header-title').text().includes('Form') === false) { 438 observer.disconnect(); 439 elementor_control_aweber_form_submit_observer = null; 440 } 441 }); 442 // Start observing the target node for configured mutations 443 elementor_control_aweber_form_submit_observer.observe(panel.$el.find('#elementor-panel-content-wrapper')[0], { attributes: true, childList: true }); 444 }); 445 } 446});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.