1// This allows us to emit events and move logic out of here to work with stimulus 2try { 3 CAN_JS_EVENT_BRIDGE = window.CanJsEventBridge 4 if (typeof CAN_JS_EVENT_BRIDGE === "undefined") { 5 throw new Error("CanJsEventBridge is not defined"); 6 } 7} catch(error) { 8 console.error("CRITICAL: Error creating CanJsEventBridge: ", error); 9 console.error("CRITICAL: Ensure can-js-event-bridge.js is loaded before can JS", error); 10} 11 12//indexOf polyfill from //stackoverflow.com/questions/8034789/jquery-ie8-object-doesnt-support-this-property-or-method-how-to-fix-this 13 14if (!Array.prototype.indexOf) { 15 Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { 16 "use strict"; 17 if (this === void 0 || this === null) { 18 throw new TypeError(); 19 } 20 var t = Object(this); 21 var len = t.length >>> 0; 22 if (len === 0) { 23 return -1; 24 } 25 var n = 0; 26 if (arguments.length > 0) { 27 n = Number(arguments[1]); 28 if (n !== n) { // shortcut for verifying if it's NaN 29 n = 0; 30 } else if (n !== 0 && n !== Infinity && n !== -Infinity) { 31 n = (n > 0 || -1) * Math.floor(Math.abs(n)); 32 } 33 } 34 if (n >= len) { 35 return -1; 36 } 37 var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); 38 for (; k < len; k++) { 39 if (k in t && t[k] === searchElement) { 40 return k; 41 } 42 } 43 return -1; 44 } 45} 46 47if (typeof console === "undefined"){ 48 console = function(){ 49 this.log = function(){ 50 return; 51 } 52 } 53} 54 55// disable the stylesheets via dom for those browser which don't support the disabled attribute on link tags 56if (document.getElementById('bootstrap-css') != null) { var bootstrap_css = document.getElementById('bootstrap-css').disabled = true; } 57if (document.getElementById('bootstrap-responsive -css') != null) { var bootstrap_responsive_css = document.getElementById('bootstrap-responsive-css').disabled = true; } 58if (document.getElementById('style-forms-css') != null) { var bootstrap_responsive_css = document.getElementById('style-forms-css').disabled = false; } 59 60 61//see https://medium.com/@kristiantolleshaugmrch/fixing-the-double-tap-issue-in-ios-safari-with-javascript-4e72a18a1feb 62function isIosSafari() { 63 var ua = (window.navigator && navigator.userAgent) || ''; 64 var iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i); 65 var webkit = !!ua.match(/WebKit/i); 66 var iOSSafari = iOS && webkit && !ua.match(/CriOS/i); 67 return iOSSafari; 68 } 69 70function removeHoverIosSafari() { 71 //console.log(isIosSafari()); 72 if (!isIosSafari()) return; 73 // Tags of interest: Only process certain interactive elements 74 function shouldPrevent(target) { 75 var tagName = target.tagName.toLowerCase(); 76 var datasetBind = target.dataset.bind; 77 //console.log(datasetBind); 78 //console.log(datasetBind && datasetBind.indexOf('click') > -1); 79 //console.log((datasetBind && datasetBind.indexOf('click') > -1) || (tagName == 'a' || tagName == 'button')); 80 var preventFilter = (datasetBind && datasetBind.indexOf('click') > -1) || (tagName == 'a' || tagName == 'button' || tagName == 'i'); 81 return preventFilter; 82 } 83 var eventSelector = { 84 touchend: function (_, target) { 85 // Reset any flags on touchend 86 target.dataset._clicked_ = ''; 87 target.dataset._mousemove_ = '0'; 88 target.dataset._timeOutId_ = ''; 89 }, 90 mouseover: function (e) { 91 e.preventDefault(); // Prevent default hover behavior 92 }, 93 mousemove: function (e, target) { 94 e.preventDefault(); // Prevent default hover behavior 95 var _mousemoves = +(target.dataset._mousemove_ || '0'); 96 _mousemoves = _mousemoves + 1; 97 console.log('mousemoves: ' + _mousemoves); 98 target.dataset._mousemove_ = _mousemoves; 99 // Trigger click event after enough movement 100 if (_mousemoves > 1 && !target.dataset._timeOutId_) { 101 var id = setTimeout(function () { 102 console.log('double mousemove click fired'); 103 target.click(); // Simulate a click after mouse move 104 }, 80); // Adjust delay to fine-tune the click event timing 105 target.dataset._timeOutId_ = id; 106 } 107 }, 108 click: function (e, target) { 109 // Prevent double click 110 if (target.dataset._clicked_) { 111 // This check prevents interference with valid tracking 112 // and programmatic click events. 113 if (e.isTrusted) { 114 console.log('prevented doubleclick'); 115 e.preventDefault(); 116 } 117 return; 118 } 119 // Prevent timeout click 120 if (target.dataset._timeOutId_) { 121 console.log('cleared timeout'); 122 clearTimeout(+target.dataset._timeOutId_); 123 } 124 // Mark element as clicked 125 target.dataset._clicked_ = 'true'; 126 } 127 }; 128 function preventHover(e) { 129 //console.log(e); 130 var target = e.target; 131 // Skip elements that don't have click handlers or necessary attributes 132 //console.log(target); 133 if (!(target && target.click && target.tagName && target.dataset)) return; 134 //console.log('after first return'); 135 if (!shouldPrevent(target)) return; 136 //console.log('after second return'); 137 var type = e.type; 138 //console.log(type, target); 139 eventSelector[type] && eventSelector[type](e, target); 140 } 141 // Add event listeners for touch and mouse events 142 document.addEventListener('touchend', preventHover, true); 143 document.addEventListener('mouseover', preventHover, true); 144 document.addEventListener('mousemove', preventHover, true); 145 document.addEventListener('click', preventHover, true); 146 147} 148 149removeHoverIosSafari(); 150 151// Global helper function: 152// Get a browser native promise from a JQuery $.ajax call 153// the promise will resolve with the response data if successful, 154// or reject with the most detailed error available if the ajax request fails (eg not a HTTP 200) 155function ajaxPromise(ajaxRequest) { 156 return new Promise(function(resolve, reject) { 157 $.ajax(ajaxRequest) 158 .done(function(data, textStatus, jqXHR) { 159 resolve(data); 160 }) 161 .fail(function(jqXHR, textStatus, errorThrown) { 162 reject(new AjaxError(jqXHR, textStatus, errorThrown, this)); 163 }); 164 }); 165} 166 167// Global helper function that returns a detailed error message. 168function AjaxError(jqXHR, textStatus, errorThrown, jqueryThis) { 169 var errorDetails = errorThrown || "'" + textStatus + "' (status: " + jqXHR.status + ')'; 170 171 this.status = jqXHR.status; 172 this.message = 'Ajax call failed with ' + errorDetails + ': ' + jqueryThis.type + ' ' + jqueryThis.url; 173 this.url = jqueryThis.url; 174 175 this.toString = function(){ 176 return this.message; 177 } 178} 179 180/** Common function to be called when fancybox is closed */ 181function onFancyboxCloseCommon() { 182 $('.js-file_delete_link').css('display', 'inline'); 183 $('.js-edit_confirm_delete').css('display', 'none'); 184 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
185 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 186 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 187 $('body').removeClass('form_builder_edit'); 188} 189 190function listItemMenus() { 191 // Toggle list item menu when menu_trigger is clicked 192 $('body').on('click', '.list_item_menu .menu_trigger', function(e) { 193 e.preventDefault(); 194 e.stopPropagation(); 195 196 var $menuWrapper = $(this).closest('.list_item_menu'); 197 198 // Close all other open menus first 199 $('.list_item_menu').not($menuWrapper).removeClass('menu-active'); 200 201 // Toggle current menu 202 $menuWrapper.toggleClass('menu-active'); 203 }); 204 205 // Close menu when clicking outside 206 $(document).on('click', function(e) { 207 if (!$(e.target).closest('.list_item_menu').length) { 208 $('.list_item_menu').removeClass('menu-active'); 209 } 210 }); 211} 212 213$(document).ready(function() { 214 215 listItemMenus(); 216 217 if (typeof(List) !== 'undefined' && typeof(ListPagination) !== 'undefined' ) { 218 // Network - custom fields 219 var listjs_options46a = { 220 valueNames: [ 'listjs_name' ], 221 page: 25, 222 plugins: [ ListPagination({}) ], 223 item: '<li class="list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 224 }; 225 226 if ($('.js-network_custom_fields-custom ul').length && !$('.js-network_custom_fields-custom ul p').length) { 227 var userList24a = new List('network_custom_fields-custom', listjs_options46a, custom_fields_array); 228 var questions_fancy_function_customs = function() { 229 $(".js-network_custom_fields-custom ul .js-fancylink").each(function() { 230 if (!$(this).data('fancybox')) { 231 $(this).fancybox({ 232 onComplete: function() { 233 $('body').addClass('body_has_modal'); 234 $('#fancybox-content select.js-regexp_type').each(function() { 235 var selected_regex = $(this).parents('.js-custom_regex_modal').find('.js-regex_input').val(); 236 //console.log(selected_regex); 237 if (selected_regex) { 238 var match = false; 239 $(this).find('option').each(function() { 240 //console.log($(this).val()); 241 if ($(this).val() == selected_regex) { 242 $(this).attr('selected', 'selected'); 243 match = true; 244 } 245 }); 246 247 if (!match) { 248 $(this).val('Custom'); 249 } 250 } 251 252 show_hide_custom_regex_options($(this)); 253 254 255 256 }); 257 258 $('#fancybox-content select.js-regexp_type').change(function() { 259 show_hide_custom_regex_options($(this)); 260 if ($(this).val() == "Custom") { 261 $(this).parents('.js-custom_regex_modal').find('.js-regex_input').val(''); 262 $(this).parents('.js-custom_regex_modal').find('.js-regex_description_input').val(''); 263 } 264 }); 265 266 $('#fancybox-content input[type=text], input[type=email], input[type=password], input[type=number], textarea').not('.select2-drop input, .select2-container input, .editable_button_text, .js-search, label + input, label + textarea, textarea.js-redactor, input.js-other_input, .js-no_floatlabel, #replyHiddenForm textarea, #recaptcha_response_field, .js-nofloatlabel').floatlabel(); 267 if ($.isFunction($.fn.customSelect) ) { 268 $("#fancybox-content select.can_select").not('.hasCustomSelect').not("select.can_select.js-form_select2").customSelect({customClass:"can_select"}); 269 } 270 canValidate(); 271 }, 272 onClosed: function() { 273 $('.js-file_delete_link').css('display','inline'); 274 $('.js-edit_confirm_delete').css('display','none'); 275 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 276 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 277 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 278 $('body').removeClass('form_builder_edit'); 279 }, 280 margin: 15, 281 hideOnOverlayClick: false 282 }); 283 284 285 } 286 287 }); 288 289 } 290 291 userList24a.on('paged', questions_fancy_function_customs); 292 userList24a.on('searchComplete', questions_fancy_function_customs); 293 294 $('.js-field_list_massops_sort_toggle').click(function() { 295 toggleSort(this, userList24a, $('.js-field_list_massops_sort_dropdown').val(), true); 296 }); 297
298 $('.js-field_list_massops_sort_dropdown').change(function() { 299 toggleSort($('.js-field_list_massops_sort_toggle'), userList24a, $(this).val(), false); 300 }); 301 //questions_fancy_function(); 302 } 303 } 304 305 //fix autocomplete in chrome 306 if ($('.chrome').length) { 307 $('[autocomplete=off]').attr('autocomplete','really_off'); 308 } 309 310 function getURLParameter(name) { 311 return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; 312 } 313 314 // Check duplicate trigger actions 315 function checkDuplicateTriggerActions(action_permalink) { 316 $('.js-ladder_trigger_warning').remove(); 317 $.ajax({ 318 url: `ladders_check_duplicate_trigger_actions`, 319 method: 'GET', 320 data: { 321 action_permalink: action_permalink 322 } 323 }).done(function(data) { 324 if (data.error) { 325 alert(data.error) 326 } else if (data.ladder) { 327 $('.js-text_to_join').before("<div class='white_box hundredtool js-ladder_trigger_warning mb10'><p class='nomb'><strong>" + an_javascript_translation.note_colon + "</strong> " + data.msg + " <a href='" + data.ladder.url + "' target='_blank'>" + an_javascript_translation.here + "</a>.</div>"); 328 } 329 }) 330 } 331 332 // show hide the searchform 333 334 335 // Float Labels 336 float_labels_init = function() { 337 if ($('input:focus, textarea:focus').length) { 338 var $focused_input = $('input:focus, textarea:focus'); 339 } 340 341 $('input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], textarea').not('.select2-drop input, .select2-container input, .editable_button_text, .js-search, label + input, label + textarea, textarea.js-redactor, input.js-other_input, .js-no_floatlabel, #replyHiddenForm textarea, #recaptcha_response_field, .js-nofloatlabel').floatlabel(); 342 343 $('label + input, label + textarea').each(function() { 344 if ($(this).prev().text() == '') { 345 $(this).floatlabel(); 346 } 347 }); 348 349 if ($focused_input) { 350 $focused_input.focus(); 351 } 352 353 $('body').on('focusin', 'input[type=text]:not(.select2-drop input, .select2-container input, .editable_button_text, .js-search, input.js-other_input, .js-no_floatlabel, #recaptcha_response_field), input[type=email]:not(.select2-drop input, .select2-container input, .editable_button_text, .js-search, .js-no_floatlabel), input[type=password]:not(.select2-drop input, .select2-container input, .editable_button_text, .js-search, .js-no_floatlabel), input[type=number]:not(.select2-drop input, .select2-container input, .editable_button_text, .js-search, .js-no_floatlabel), textarea:not(.redactor-box textarea, .js-no_floatlabel, #replyHiddenForm textarea, .js-nofloatlabel)', function(e) { 354 myvar = $(this); 355 if (!$(this).data().plugin_floatlabel && $(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined && 356 (!$(this).prev().length || 357 ($(this).prev().length && $(this).prev().prop('tagName').toUpperCase() == "LABEL" && $(this).prev().text() == '') || 358 $(this).prev().prop('tagName').toUpperCase() != "LABEL")) 359 { 360 $(this).floatlabel(); 361 var $that = $(this); 362 if ($('.trident').length) { 363 setTimeout(function() { 364 $that.focus(); 365 }, 10); 366 } else { 367 $that.focus(); 368 } 369 370 // 371 } 372 373 }); 374 } 375 376 float_labels_init(); 377 378 379 // Select2 380 //$('select').select2(); 381 if ($.isFunction($.fn.select2)) { 382 $('.action_lang-select_wrap select').select2({ 383 minimumResultsForSearch: Infinity 384 }); 385 } 386 387 //grow the status bar 388 $(".js-action_status_status_bar-grow").delay(1000).animate({ width: "100%" }, 1500 ); 389 $(".js-grow-dot").delay(2600).animate({ width: "10px", height: "10px", top: "-4px", right: "-5px" }, 100 ); 390 $(".js-grow-dot-flash").delay(2600).animate({ opacity: "0" }, 500 ); 391 392 // start organizing/profile menu functions 393 394 // menu drop down menu, only works on non-host an event as part of an event campaign pages 395 if ($('.js-create_host_pitch_form').length & !$('.js-fancy_fake').length) { 396 $('.js-logo_head-wrap, .js-site_footer a, .js-header_login, .js-mega_menu, .js-navatar_wrap, .js-user_nav_trigger, .js-group_quick_switch_bar, .js-group_quick_switch, .js-basejump_icon_trigger').attr('href', 'javascript:void(0);').addClass('disabled');
397 $('.js-header_login').hide(); 398 } 399 400 // file uploads 401 $('body').on('change', '.js-upload_label_box input[type=file]', function () { 402 $(this).siblings('.js-uploaded_file_name').html(this.files[0].name); 403 }); 404 $('body').on('click', '.js-sample_file', function (event) { 405 event.preventDefault(); 406 event.stopPropagation(); 407 window.location.href = this.getAttribute('href'); 408 }); 409 410 // MMS uploads 411 $('body').on('change', '.js-mms_media_upload_input', function () { 412 var $media_url = $(this).parent().find('.js-mms_media_image_url'); 413 var $that = $(this); 414 console.log($media_url); 415 console.log($that); 416 if (typeof($that[0].files[0]) != 'undefined') { 417 if($that[0].files[0].size > 5242880){ 418 alert(an_javascript_translation.your_image_is_too_big_mms_has_a_file_size_limit_of_5mb); 419 $that.val(''); 420 } else { 421 $that.parent().find('.js-mms_media_upload-label').addClass('disabled').text(an_javascript_translation.loading); 422 var formData = new FormData(); 423 formData.append('file', $that[0].files[0]); 424 $.ajax({ 425 url: '/uploads/', 426 data: formData, 427 type: 'POST', 428 contentType: false, 429 processData: false 430 }).done(function(data) { 431 $media_url.val(data.url).trigger('change'); 432 $that.parent().find('.js-mms_media_upload-label').removeClass('disabled').text(an_javascript_translation.upload); 433 }).fail(function() { 434 alert(an_javascript_translation.your_upload_failed_please_try_again); 435 $that.parent().find('.js-mms_media_upload-label').removeClass('disabled').text(an_javascript_translation.upload); 436 }); 437 } 438 439 } 440 441 }); 442 443 $("body").on('change keyup', ".js-mms_media_image_url", function() { 444 //console.log('change'); 445 if ($(this).val() == '') { 446 $(this).parents('.js-mms_fields_wrap').find('.js-mms_media_upload-preview').addClass('hide'); 447 } else { 448 $(this).parents('.js-mms_fields_wrap').find('.js-mms_image').attr('src', $(this).val()); 449 $(this).parents('.js-mms_fields_wrap').find('.js-mms_media_upload-preview').removeClass('hide'); 450 } 451 }); 452 453 $('body, .js-group_quick_switch_bar').mouseup(function(e) { 454 //console.log(e.srcElement); 455 456 //remove all open menus 457 $('.js-menu_tapped, .js-navatar_wrap').removeClass('menu_tapped js-menu_tapped'); 458 459 if (!$('.js-logo_head-wrap.disabled').length) { 460 //detect if we've clicked inside the start organizing menu, and not the close button 461 if ($(e.srcElement).parents('.js-mega_menu').length && !$(e.srcElement).hasClass("js-tap_to_close")) { 462 $(e.srcElement).parents('.js-mega_menu').removeClass("menu_tapped_close js-menu_tapped_close").addClass("menu_tapped js-menu_tapped"); 463 } 464 if ($(e.srcElement).hasClass('js-mega_menu') && !$(e.srcElement).hasClass("js-tap_to_close")) { 465 $(e.srcElement).removeClass("menu_tapped_close js-menu_tapped_close").addClass("menu_tapped js-menu_tapped"); 466 } 467 468 //detect if we've clicked inside the profile menu, and not the close button 469 470 if ($(e.srcElement).parents('.js-user_nav_trigger').length && (!$(e.srcElement).hasClass("js-user_nav_close") && !$(e.srcElement).parents(".js-user_nav_close").length)) { 471 $(e.srcElement).parents('.js-user_nav_trigger').find('.js-navatar_wrap').removeClass("menu_tapped_close js-menu_tapped_close").addClass("menu_tapped js-menu_tapped"); 472 } 473 if ($(e.srcElement).hasClass('js-navatar_wrap')) { 474 $(e.srcElement).removeClass("menu_tapped_close js-menu_tapped_close").addClass("menu_tapped js-menu_tapped"); 475 } 476 } 477 478 }); 479 480 // file uploads 481 482 $('body').on('change', '.js-upload_label_box input[type=file]', function () { 483 $(this).siblings('.js-uploaded_file_name').html(this.files[0].name); 484 }); 485 486 // Data Sharing 487 $(".js-edit_d_sharing_opts").click(function() { 488 $(".js-d_sharing_opts").slideDown(200); 489 $(".js-edit_d_sharing_opts-close").show().css("display", "inline-block"); 490 $(".js-edit_d_sharing_opts").hide(); 491 }); 492 $(".js-edit_d_sharing_opts-close").click(function() { 493 $(".js-d_sharing_opts").slideUp(200); 494 $(".js-edit_d_sharing_opts").show(); 495 $(".js-edit_d_sharing_opts-close").hide(); 496 }); 497 498 //IE11 innerHTML fix 499 $('.comment-reply-link').click(function() { 500 setTimeout(function() { 501 $('#respond textarea').val(''); 502 }, 10); 503 }); 504 505 506 // fundraising section 507 508 // add/remove radio button selected classes for donate and tip jar amounts 509 var add_remove_donate_amount_selected = function($element) { 510 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 511 $('.js-donate_amount input[type="radio"]').parent().removeClass('donate_amount-selected js-donate_amount-selected'); 512 if ($element.parent().hasClass('placeholder_fix_wrap')) { 513 $element.parent().parent().addClass('donate_amount-selected js-donate_amount-selected'); 514 } else { 515 $element.parent().addClass('donate_amount-selected js-donate_amount-selected'); 516 } 517 } else { 518 $('.js-donate_amount input[type="radio"]').parent().removeClass('donate_amount-selected js-donate_amount-selected'); 519 $element.parent().addClass('donate_amount-selected js-donate_amount-selected'); 520 } 521 522 } 523 524 var add_remove_tip_label_selected = function($element) { 525 //console.log('fire'); 526 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 527 $('.js-tip_label input[type="radio"]').parent().removeClass('tip_label-selected js-tip_label-selected'); 528 if ($element.parent().hasClass('placeholder_fix_wrap')) { 529 $element.parent().parent().addClass('tip_label-selected js-tip_label-selected'); 530 } else { 531 $element.parent().addClass('tip_label-selected js-tip_label-selected'); 532 } 533 } else { 534 $('.js-tip_label input[type="radio"]').parent().removeClass('tip_label-selected js-tip_label-selected'); 535 $element.parent().addClass('tip_label-selected js-tip_label-selected'); 536 } 537 } 538 539 // split amounts function 540 var split_amount_function = function($element) { 541 //console.log($element.val()); 542 if ($element.val() == 'other') { 543 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 544 545 if (!isNaN($element.siblings().children().val()) && $element.siblings().children().val() != '') { 546 var split_amount = $('.js-donate_amount .js-other_input').val() / $('.js-donation_info_split').length; 547 if (split_amount % 1 === 0) { 548 $('.js-donation_info_split input').val(split_amount).trigger('change'); 549 } else { 550 $('.js-donation_info_split input').val(split_amount.toFixed(2)).trigger('change'); 551 } 552 553 } else if ($element.siblings().children().val() == '') { 554 $('.js-donation_info_split input').val('').trigger('change'); 555 } 556 } else { 557 if (!isNaN($element.siblings('.js-other_input').val()) && $element.siblings('.js-other_input').val() != '') { 558 var split_amount = $('.js-donate_amount .js-other_input').val() / $('.js-donation_info_split').length; 559 if (split_amount % 1 === 0) { 560 $('.js-donation_info_split input').val(split_amount).trigger('change'); 561 } else { 562 $('.js-donation_info_split input').val(split_amount.toFixed(2)).trigger('change'); 563 } 564 565 } else if ($element.siblings('.js-other_input').val() == '') { 566 $('.js-donation_info_split input').val('').trigger('change'); 567 } 568 } 569 } else if ($element.val() != '') { 570 var split_amount = parseInt($element.val()) / $('.js-donation_info_split').length; 571 if (split_amount % 1 === 0) { 572 $('.js-donation_info_split input').val(split_amount).trigger('change'); 573 } else { 574 $('.js-donation_info_split input').val(split_amount.toFixed(2)).trigger('change'); 575 } 576 } 577 } 578 579 // add required classes 580 var add_required_class_donate_amount = function($element) { 581 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 582 if ($element.siblings().length && $element.is(':checked') && $element.hasClass('required')) { 583 $element.siblings().children().addClass('required'); 584 } else { 585 $element.parent().siblings().children().children().removeClass('required error_input'); 586 } 587 } else { 588 if ($element.siblings('.js-other_input').length && $element.is(':checked') && $element.hasClass('required')) { 589 //console.log('if') 590 $element.siblings('.js-other_input').addClass('required'); 591 } else { 592 //console.log('else') 593 $element.parent().siblings('.js-other_label').children('.js-other_input').removeClass('required error_input'); 594 } 595 } 596 } 597 598 var add_required_class_tip = function($element) { 599 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 600 if ($element.siblings().length && $element.is(':checked')) { 601 $element.siblings().children().addClass('required'); 602 } else { 603 $element.parent().siblings().children().children().removeClass('required error_input'); 604 } 605 } else { 606 if ($element.siblings('.js-other_input').length && $element.is(':checked')) { 607 $element.siblings('.js-other_input').addClass('required'); 608 } else { 609 $element.parent().siblings('.js-other_label').children('.js-other_input').removeClass('required error_input'); 610 } 611 } 612 } 613 614 const resolve_currency_symbol = function(currency_string) { 615 if (typeof currency_string !== 'string' || currency_string.trim() == '') { 616 return '$'; 617 } 618 619 const currency = currency_string.toUpperCase().trim(); 620 if (currency == 'USD') { 621 return '$'; 622 } else if (currency == 'EUR') { 623 return '€'; 624 } else if (currency == 'GBP') { 625 return '£'; 626 } else if (currency == 'ILS') { 627 return '₪'; 628 } else { 629 return currency + ' '; 630 } 631 } 632 633 const reverse_currency_symbol = function(currency_string) { 634 if (typeof currency_string !== 'string' || !currency_string.trim()) { 635 return 'USD'; 636 } 637 638 const currency = currency_string.toUpperCase(); 639 if (currency == '$') { 640 return 'USD'; 641 } else if (currency == '€') { 642 return 'EUR'; 643 } else if (currency == '£') { 644 return 'GBP'; 645 } else if (currency == '₪') { 646 return 'ILS'; 647 } else { 648 return currency; 649 } 650 } 651
652 function updateCurrencySymbols($select, currencies) { 653 const permalink = $select.val(); 654 const currencySymbol = resolve_currency_symbol(currencies[permalink]); 655 656 const bindTargets = $select.data('bind-targets'); 657 let targets = bindTargets ? $(bindTargets) : $('.js-currency-symbol'); 658 659 targets.each(function () { 660 $(this).text(currencySymbol); 661 }); 662 } 663 664 $('select[data-group-currencies]').each(function () { 665 const $this = $(this); 666 const currencies = $this.data('group-currencies'); 667 668 // Initial update 669 updateCurrencySymbols($this, currencies); 670 671 // Update on change 672 $this.on('change', function () { 673 updateCurrencySymbols($(this), currencies); 674 }); 675 }); 676 677 // calculate submit button total 678 var calculate_total = function() { 679 if ($('.js-update_card_form').length) { 680 if ($('.js-recurring_status').val() != 'active') { 681 $('.js-donate_form_button').val(an_javascript_translation.save_card_details_restart_contribution); 682 } 683 } else { 684 //console.log('start'); 685 var total_donation = 0; 686 var total_count = 0; 687 688 // if we're splitting, add up split boxes 689 if ($('.js-donation_info_split').length) { 690 //console.log('true'); 691 $('.js-donation_info_split input').each(function(i,e) { 692 if (!isNaN($(e).val()) && $(e).val() != '') { 693 total_donation = total_donation + parseFloat($(e).val()); 694 //console.log(total_donation); 695 } 696 }); 697 } else if ($('.js-ticket_option').length) { 698 const currency_prefix = resolve_currency_symbol($('.js-currency').val()); 699 if (!isNaN($('.js-ticketed_event_subtotal').html().replace(currency_prefix,''))) { 700 total_donation = total_donation + parseFloat($('.js-ticketed_event_subtotal').html().replace(currency_prefix,'')); 701 } 702 } else { 703 // otherwise, add up radios (and other amounts if the user has checked that 704 if ($('.js-donate_amount.js-donate_amount-selected input[type="radio"]').val() == 'other') { 705 706 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 707 if (!isNaN($('.js-donate_amount.js-donate_amount-selected input[type="radio"]').siblings().children().val()) && $('.js-donate_amount.js-donate_amount-selected input[type="radio"]').siblings().children().val() != '') { 708 total_donation = total_donation + parseFloat($('.js-donate_amount.js-donate_amount-selected input[type="radio"]').siblings().children().val()); 709 } 710 } else { 711 if (!isNaN($('.js-donate_amount input[type="radio"]:checked').siblings('.js-other_input').val()) && $('.js-donate_amount input[type="radio"]:checked').siblings('.js-other_input').val() != '') { 712 total_donation = total_donation + parseFloat($('.js-donate_amount input[type="radio"]:checked').siblings('.js-other_input').val()); 713 } 714 } 715 } else { 716 if ($('.js-donate_amount input[type="radio"]:checked').length) { 717 total_donation = total_donation + parseFloat($('.js-donate_amount input[type="radio"]:checked').val()); 718 } 719 } 720 } 721 722 // add in tip 723 724 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 725 //console.log($('.tip_label.tip_label-selected input[type="radio"]').val()); 726 if ($('.js-tip_label.js-tip_label-selected input[type="radio"]').val() == 'other') { 727 if (!isNaN($('.js-tip_label.js-tip_label-selected input[type="radio"]').siblings().children().val()) && $('.js-tip_label.js-tip_label-selected input[type="radio"]').siblings().children().val() != '') { 728 total_donation = total_donation + parseFloat($('.js-tip_label.js-tip_label-selected input[type="radio"]').siblings().children().val()); 729 } 730 } else { 731 if ($('.js-tip_label input[type="radio"]:checked').val() == '10') { 732 total_donation = total_donation + (total_donation * 0.1); 733 } else if ($('.js-tip_label input[type="radio"]:checked').val() == '20') { 734 total_donation = total_donation + (total_donation * 0.2); 735 } 736 } 737 } else { 738 if ($('.js-tip_label input[type="radio"]:checked').val() == 'other') { 739 if (!isNaN($('.js-tip_label input[type="radio"]:checked').siblings('.js-other_input').val()) && $('.js-tip_label input[type="radio"]:checked').siblings('.js-other_input').val() != '') { 740 total_donation = total_donation + parseFloat($('.js-tip_label input[type="radio"]:checked').siblings('.js-other_input').val()); 741 } 742 } else { 743 if ($('.js-tip_label input[type="radio"]:checked').val() == '10') { 744 total_donation = total_donation + (total_donation * 0.1); 745 } else if ($('.js-tip_label input[type="radio"]:checked').val() == '20') { 746 total_donation = total_donation + (total_donation * 0.2); 747 } 748 } 749 } 750 751 752 // round out numbers and add recurring period to contribute button 753 if (total_donation == 0) { 754 var amount_rounded = ''; 755 } else if (total_donation % 1 === 0) { 756 var amount_rounded = total_donation; 757 } else { 758 var amount_rounded = total_donation.toFixed(2); 759 } 760 761 if ($('.js-donate_amount_recurring').attr('checked') || $('input[type="hidden"][name="donation[recurring]"]').val() == 'true') { 762 if ($('input[type="hidden"][name="donation[recurring_period]"]').val() == "recurring_weekly") { 763 var recurring_period = an_javascript_translation.weekly; 764 } else if ($('input[type="hidden"][name="donation[recurring_period]"]').val() == "recurring_monthly") { 765 var recurring_period = an_javascript_translation.monthly; 766 } else if ($('input[type="hidden"][name="donation[recurring_period]"]').val() == "recurring_three") { 767 var recurring_period = an_javascript_translation.every_3_months; 768 } else if ($('input[type="hidden"][name="donation[recurring_period]"]').val() == "recurring_yearly") { 769 var recurring_period = an_javascript_translation.yearly; 770 } else { 771 var recurring_period = $('.js-donate_recurring_period option:selected').html(); 772 } 773 } else { 774 var recurring_period = ''; 775 } 776 777 if ($('.js-ticket_option').length) { 778 779 $('.js-ticket_option').each(function() { 780 //console.log($(this).find('.js-ticketed_event_ticket_number').val()); 781 if (isInt($(this).find('.js-ticketed_event_ticket_number').val()) && $(this).find('.js-ticketed_event_ticket_number').val() != '' && $(this).find('.js-ticketed_event_ticket_number').val() > 0) { 782 //console.log('true'); 783 total_count = total_count + parseInt($(this).find('.js-ticketed_event_ticket_number').val()); 784 //console.log(total_donation); 785 } 786 }); 787 } 788 789 if (total_donation == 0 || (total_count == 0 && $('.js-ticket_option').length)) { 790 if ($('.js-ticket_option').length || $('.js-add_ticket_option').length) { 791 $('.js-ticketed_event_form_button').val(an_javascript_translation.purchase_tickets); 792 $('input[name="ticket_receipt[total_amount]"]').val(amount_rounded); 793 } else { 794 if ($('.js-donate_form_button').attr('disabled') !== 'disabled') { 795 $('.js-donate_form_button').val(an_javascript_translation.contribute_now); 796 $('input[name="donation[total_amount]"]').val(amount_rounded); 797 } 798 } 799 800 } else { 801 //console.log(); 802 const currency_prefix = resolve_currency_symbol($('.js-currency').val()); 803 804 if ($('.js-ticket_option').length) { 805 if (total_count == 1) { 806 $('.js-ticketed_event_form_button').val(an_javascript_translation.purchase + ' ' + total_count + ' ' + an_javascript_translation.ticket_for + ' ' + currency_prefix + amount_rounded + ' ' + an_javascript_translation.now); 807 } else { 808 $('.js-ticketed_event_form_button').val(an_javascript_translation.purchase + ' ' + total_count + ' ' + an_javascript_translation.tickets_for + ' ' + currency_prefix + amount_rounded + ' ' + an_javascript_translation.now); 809 } 810 $('input[name="ticket_receipt[total_amount]"]').val(total_donation); 811 } else { 812 $('.js-donate_form_button').val(an_javascript_translation.contribute + ' ' + currency_prefix + amount_rounded + ' ' + recurring_period + ' ' + an_javascript_translation.now); 813 $('input[name="donation[total_amount]"]').val(total_donation); 814 } 815 } 816 } 817 818 } 819 820 function isInt(n) { 821 return n % 1 === 0; 822 } 823 824 // calculate ticketed events subtotal 825 var calculate_subtotal = function() { 826 var total_donation = 0; 827 828 const currency_prefix = resolve_currency_symbol($('.js-currency').val()); 829 830 $('.js-ticket_option').each(function() { 831 //console.log($(this).find('.js-ticketed_event_ticket_number').val()); 832 if (isInt($(this).find('.js-ticketed_event_ticket_number').val()) && $(this).find('.js-ticketed_event_ticket_number').val() != '' && $(this).find('.js-ticketed_event_ticket_number').val() > 0) { 833 //console.log('true'); 834 total_donation = total_donation + parseInt($(this).find('.js-ticketed_event_ticket_number').val()) * parseFloat($(this).find('.js-ticketed_event_ticket_amount').html().replace(currency_prefix,'').replace(',','')); 835 //console.log(total_donation); 836 } 837 }); 838 839 // round out numbers 840 if (total_donation == 0) { 841 var amount_rounded = '0.00'; 842 } else { 843 var amount_rounded = total_donation.toFixed(2); 844 } 845 846 847 $('.js-ticketed_event_subtotal').html(currency_prefix + amount_rounded); 848 } 849 850 851 //fundraising errors for grouped inputs 852 var donation_split_errors = function() { 853 var input_full_flag = false;
854 $('.js-donation_info_split input').each(function(i) { 855 if ($(this).val() != '' && !isNaN($(this).val()) && $(this).val() != 0) { 856 input_full_flag = true; 857 } 858 }); 859 860 if (!input_full_flag) { 861 //console.log($(this)); 862 $('.js-donation_info_split input').addClass('error_input'); 863 } else { 864 $('.js-donation_info_split input').removeClass('error_input'); 865 } 866 } 867 868 869 // do url argument stuff 870 var url_parameter_amount = getURLParameter('amount'); 871 var url_parameter_recurring = getURLParameter('recurring'); 872 var url_parameter_recurring_period = getURLParameter('period'); 873 var url_parameter_oneclick = getURLParameter('oneclick'); 874 if (typeof(oneclick_verified) == 'undefined') { 875 oneclick_verified = false; 876 } 877 878 if (url_parameter_amount && !isNaN(url_parameter_amount) && url_parameter_amount > 0) { 879 880 var radio_check_flag = false; 881 $('.js-donate_amount input[type="radio"]').each(function(i) { 882 if ($(this).val() == url_parameter_amount) { 883 $(this).attr('checked','checked'); 884 radio_check_flag = true; 885 } 886 }); 887 888 if (radio_check_flag == false && $('.js-donate_amount.js-other_label').length) { 889 $('.js-donate_amount.js-other_label input[type="radio"]').attr('checked','checked'); 890 $('.js-donate_amount .js-other_input').val(url_parameter_amount); 891 radio_check_flag = true; 892 } else if (radio_check_flag == false && url_parameter_oneclick == 'true' && oneclick_verified == true) { 893 $('.js-donate_amount_wrap').append('<label class="donate_amount js-donate_amount other_label js-other_label">' 894 + '<input type="radio" checked name="donation[amount]" value="other" />' 895 + '<input type="text" name="donation[custom_amount]" value="' + url_parameter_amount + '" size="35" placeholder="$ Other" class="number other_input js-other_input " min="1" />' 896 + '</label>'); 897 radio_check_flag = true; 898 } 899 900 if (url_parameter_oneclick == 'true' && url_parameter_recurring == 'true' && oneclick_verified == true && (url_parameter_recurring_period == 'recurring_weekly' || url_parameter_recurring_period == 'recurring_monthly' || url_parameter_recurring_period == 'recurring_three' || url_parameter_recurring_period == 'recurring_yearly')) { 901 if ($('.js-donate_recurring').length) { 902 $('.js-donate_recurring').remove(); 903 } 904 905 $('.js-donate_amount_wrap').after('<div class="donate_recurring js-donate_recurring mb40 clearfix">' 906 + '<div class="donate_recurring_inner">' 907 + '<label>' 908 + '<input type="checkbox" name="donation[recurring]" class="donate_amount_recurring js-donate_amount_recurring" value="true" />' + an_javascript_translation.make_this_payment_recurring 909 + '</label>' 910 + '<span class="block">' 911 + '<select name="donation[recurring_period]" class="can_select js-donate_recurring_period" id="donate_recurring_period">' 912 + '<option value="recurring_weekly">' + an_javascript_translation.weekly + '</option>' 913 + '<option value="recurring_monthly">' + an_javascript_translation.monthly + '</option>' 914 + '<option value="recurring_three">' + an_javascript_translation.every_3_months + '</option>' 915 + '<option value="recurring_yearly">' + an_javascript_translation.yearly + '</option>' 916 + '</select>' 917 + '</span>' 918 + '</div>' 919 + '</div>'); 920 } 921 } 922 923 if (url_parameter_recurring == 'true') { 924 $('.js-donate_amount_recurring').attr('checked','checked'); 925 } 926 927 if (url_parameter_recurring_period) { 928 $('.js-donate_recurring_period').val(url_parameter_recurring_period).trigger('update'); 929 } 930 931 var cc_info_validation = function($this) { 932 //$('.required_noname').each(function(i) { 933 if ($this.val() == '' || isNaN($this.val())) { 934 //console.log('true'); 935 $this.addClass('error_input_cc js-error_input_cc'); 936 //console.log($this); 937 //console.log($this.siblings('span.can_select').length); 938 if ($this.siblings('span.can_select').length) { 939 $this.siblings('span.can_select').addClass('error_input_cc js-error_input_cc'); 940 $this.parent().addClass('error_input-select_wrap js-error_input-select_wrap'); 941 } 942 943 944 } else { 945 //console.log('false'); 946 $this.removeClass('error_input_cc js-error_input_cc'); 947 if ($this.siblings('span.can_select').length) { 948 $this.siblings('span.can_select').removeClass('error_input_cc js-error_input_cc'); 949 $this.parent().removeClass('error_input-select_wrap js-error_input-select_wrap'); 950 } 951 } 952 953 cc_info_error_number = $('input.js-required_noname.js-error_input_cc, select.js-required_noname.js-error_input_cc').length; 954 //}); 955 } 956 957 cc_info_error_number = 0; 958 959 960 // do fundraising stuff 961 $('.js-donate_amount input[type="radio"]').each(function(i) { 962 //console.log($(this).is(':checked')); 963 //console.log($('.js-other_input').prev().val()); 964 if ($(this).is(':checked')) { 965 966 add_remove_donate_amount_selected($(this)); 967 968 split_amount_function($(this)); 969 970 } 971 972 calculate_total(); 973 974 }); 975 976 $('.js-donate_amount input[type="radio"]').click(function() { 977 if ($(this).is(':checked')) { 978 //console.log('checked'); 979 980 add_remove_donate_amount_selected($(this)); 981 982 split_amount_function($(this)); 983 } 984 985 add_required_class_donate_amount($(this)); 986 987 calculate_total(); 988 989 donation_split_errors(); 990 }); 991 992 $('.js-donate_amount .js-other_input').on('focusin', function() { 993 //console.log('fire'); 994 995 //this won't work when users tab in, not sure why, can't get the below code to work 996 //kludge, but checked doesn't seem to fire before this goes, so it screws up validation 997 /* 998setTimeout(function() { 999 console.log(!$(this).siblings('input[type="radio"]').is(':checked')); 1000 //if (!$(this).siblings('input[type="radio"]').is(':checked')) { 1001 $(this).siblings('input[type="radio"]').attr('checked', 'checked'); 1002 //} 1003 }, 5000); 1004*/ 1005 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 1006 if (!$(this).siblings().is(':checked')) { 1007 $(this).siblings().attr('checked', 'checked'); 1008 1009 } 1010 } else { 1011 if (!$(this).siblings('input[type="radio"]').is(':checked')) { 1012 $(this).siblings('input[type="radio"]').attr('checked', 'checked'); 1013 } 1014 } 1015 1016 $(this).parents(".check_radio_field").find('label').removeClass("error_checkbox"); 1017 1018 add_remove_donate_amount_selected($(this)); 1019 1020 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 1021 split_amount_function($('.js-donate_amount.js-other_label input[value="other"]')); 1022 1023 if ($(this).siblings().hasClass('required')) { 1024 $(this).addClass('required'); 1025 } 1026 } else { 1027 split_amount_function($(this).siblings('input[type="radio"]')); 1028 1029 if ($(this).siblings('input[type="radio"]').hasClass('required')) { 1030 $(this).addClass('required'); 1031 } 1032 } 1033 1034 calculate_total(); 1035 1036 $(this).attr('placeholder', an_javascript_translation.enter_amt); 1037 1038 //console.log($(this).siblings('input[type="radio"]').is(':checked')); 1039 }); 1040 1041 $('.js-donate_amount .js-other_input').on('focusout', function() { 1042 const currency_prefix = resolve_currency_symbol($('.js-currency').val()); 1043 $(this).attr('placeholder', currency_prefix + an_javascript_translation.other); 1044 }); 1045 1046 1047 if (('.js-ticketed_event_subtotal').length) { 1048 calculate_subtotal(); 1049 calculate_total(); 1050 } 1051 1052 $('.js-ticketed_event_ticket_number').on('change keyup', function() { 1053 if ($(this).val() == 0) { 1054 $(this).val(""); 1055 } 1056 calculate_subtotal(); 1057 calculate_total(); 1058 }); 1059 1060 1061 $('.js-tip_label input[type="radio"]').each(function(i) { 1062 if ($(this).is(':checked')) { 1063 add_remove_tip_label_selected($(this)); 1064 } 1065 1066 calculate_total(); 1067 }); 1068 1069 $('.js-tip_label input[type="radio"]').click(function() { 1070 if ($(this).is(':checked')) { 1071 add_remove_tip_label_selected($(this)); 1072 } 1073 1074 add_required_class_tip($(this)); 1075 calculate_total(); 1076 }); 1077 1078 $('.js-tip_label .js-other_input').on('focusin', function() { 1079 1080 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 1081 $(this).siblings().attr('checked','checked'); 1082 } else { 1083 $(this).siblings('input[type="radio"]').attr('checked','checked'); 1084 } 1085 1086 add_remove_tip_label_selected($(this)); 1087 1088 // add required field to other amount option if selected 1089 $(this).addClass('required'); 1090 1091 calculate_total(); 1092 1093 $(this).attr('placeholder', an_javascript_translation.enter_amt); 1094 }); 1095 1096 $('.js-tip_label .js-other_input').on('focusout', function() { 1097 const currency_prefix = resolve_currency_symbol($('.js-currency').val()); 1098 $(this).attr('placeholder', currency_prefix + an_javascript_translation.other); 1099 }); 1100 1101 $('.js-donate_amount_recurring').click(function() { 1102 calculate_total(); 1103 }); 1104 1105 $('.js-donate_recurring_period').change(function() { 1106 calculate_total(); 1107 }); 1108 1109 1110 // add required field to other amount option if selected 1111 $('.js-other_label .js-other_input').each(function(i) { 1112 1113 if (isNaN($(this).val())) { 1114/* 1115 $(this).val( 1116 function(index,value){ 1117 return value.substr(0,value.length-1); 1118 } 1119 ); 1120*/ 1121 $(this).val(''); 1122 } 1123 1124 if ($(this).siblings().is(':checked')) { 1125 1126 $(this).addClass('required'); 1127 1128 } 1129 1130 calculate_total(); 1131 }); 1132 1133 $('.js-tip_label.js-other_label .js-other_input').each(function(i) { 1134 1135 if (isNaN($(this).val())) { 1136/* 1137 $(this).val( 1138 function(index,value){ 1139 return value.substr(0,value.length-1); 1140 } 1141 ); 1142*/ 1143 $(this).val(''); 1144 } 1145 1146 if ($(this).siblings().is(':checked')) { 1147 $(this).addClass('required'); 1148 } 1149 1150 calculate_total(); 1151 }); 1152 1153 //split amounts 1154 $('.js-donate_amount .js-other_input').on('keyup change', function() { 1155 1156 if (isNaN($(this).val())) { 1157/* 1158 $(this).val( 1159 function(index,value){ 1160 return value.substr(0,value.length-1); 1161 } 1162 ); 1163*/ 1164 $(this).val(''); 1165 } 1166 1167 if ($('body.ie_9').length || $('body.ie_7').length || $('body.ie_8').length) { 1168 split_amount_function($('.js-donate_amount.js-other_label input[value="other"]')); 1169 } else { 1170 split_amount_function($(this).siblings('input[type="radio"]')); 1171 } 1172 1173 calculate_total(); 1174 donation_split_errors(); 1175 }); 1176 1177 1178 $('.js-donation_info_split input').on('keyup', function() { 1179 calculate_total(); 1180 }); 1181 1182 //update totals on split boxes 1183 $('.js-donation_info_split input.js-other_input, .js-tip_label_other input.js-other_input, .js-donation_info_split input.js-required_group').on('keyup change', function() { 1184 if (isNaN($(this).val()) || $(this).val() == 0) { 1185/* 1186 $(this).val( 1187 function(index,value){ 1188 return value.substr(0,value.length-1); 1189 } 1190 ); 1191*/ 1192 $(this).val(''); 1193 } 1194 1195 calculate_total(); 1196 }); 1197 1198 // update errors in keyup 1199 $('.js-donation_info_split input').on('keyup', function() { 1200 donation_split_errors(); 1201 }); 1202 1203 /* recurring upsell */ 1204 //show/hide recurring pitch 1205 if (!$('.js-recurring_upsell_check:checked').length) { 1206 $('.js-recurring_pitch_wrapper').hide(); 1207 $('.js-recurring_pitch').removeClass('required'); 1208 } 1209 1210 $('.js-recurring_pitch_label input').change(function() { 1211 $('.js-recurring_pitch_wrapper').slideToggle(); 1212 if ($('.js-recurring_upsell_check:checked').length) { 1213 $('.js-recurring_pitch').addClass('required'); 1214 } else { 1215 $('.js-recurring_pitch').removeClass('required'); 1216 } 1217 }); 1218 1219 // open fancybox on page load 1220 if ($('.js-donate_make_recurring_modal-link').length) { 1221 $(".js-donate_make_recurring_modal-link").fancybox({ 1222 margin: 15, 1223 hideOnOverlayClick: false, 1224 onClosed: function() { 1225 //console.log('close'); 1226 window.setTimeout(function() { 1227 $(".js-donate_auto_modal-link").trigger('click'); 1228 }, 500); 1229 1230 } 1231 }).trigger('click'); 1232 1233 $(".js-donate_auto_modal-link").fancybox({ 1234 margin: 15, 1235 hideOnOverlayClick: false 1236 }); 1237 } else { 1238 $(".js-donate_auto_modal-link").fancybox({ 1239 margin: 15, 1240 hideOnOverlayClick: false 1241 }).trigger('click'); 1242 } 1243 1244 /* ajax for convert function */ 1245 $('.js-convert_to_recurring').click(function() { 1246 $that = $(this); 1247 if (!$that.hasClass('disabled')) { 1248 $that.addClass('disabled').text(an_javascript_translation.processing
1248+ '...'); 1249 $.post($that.data('convert-route'), {} , function(data) { 1250 if (data == true) { 1251 $('.js-donate_make_recurring_modal_wrap').slideUp(function() { 1252 $('.js-success_recurring_wrap').show(); 1253 window.setTimeout(function() { 1254 $.fancybox.close(); 1255 }, 10000); 1256 }); 1257 } else { 1258 alert(an_javascript_translation.recurring_upsell_error); 1259 $that.text($that.data('button-text')); 1260 } 1261 }) 1262 .error(function(e) { 1263 //console.log(e) 1264 alert(an_javascript_translation.recurring_upsell_error); 1265 $that.text($that.data('button-text')); 1266 }) 1267 .complete(function() { 1268 $that.removeClass('disabled'); 1269 }); 1270 } 1271 1272 }); 1273 1274 1275 // $("form.js-create_action_form:not(.js-create_host_pitch_form) .js-view_instructions_button, .js-view_instructions_button_preview").fancybox({ 1276 // margin: 15, 1277 // hideOnOverlayClick: false 1278 // }).trigger('click'); 1279 //$(".create_host_form_step2 #view_instructions_button").fancybox({ modal: true }).trigger('click'); 1280 1281 $('input.js-required_noname').on('keyup', function() { 1282 cc_info_validation($(this)); 1283 }); 1284 1285 $('select.js-required_noname').on('change', function() { 1286 cc_info_validation($(this)); 1287 }); 1288 1289 /* 1290var getGroupRules = function() { 1291 1292 var result = {}; 1293 1294 $('.donation_info_split input').each(function(i) { 1295 result[$(this).attr('name')] = 'require_from_group: [1, ".required_group"]'; 1296 } 1297 1298 console.log(result); 1299 return result; 1300 } 1301*/ 1302 1303 1304 1305 /* fundraising/ticketed events create page */ 1306 1307 /* donors/dollars goal slider */ 1308 var fundraising_goal_donors_dollars_switch = function($select) { 1309 //console.log('fire'); 1310 if ($select.val() == 'dollars') { 1311 $('.js-donate_slider_preview-dollars').css('display','block'); 1312 $('.js-donate_slider_preview-donors').css('display','none'); 1313 $("#manual-goal-setting-key").val('manual_goal_dollars'); 1314 } else { 1315 $('.js-donate_slider_preview-donors').css('display','block'); 1316 $('.js-donate_slider_preview-dollars').css('display','none'); 1317 $("#manual-goal-setting-key").val('manual_goal'); 1318 } 1319 } 1320 1321 var ticketed_goal_donors_dollars_switch = function($select) { 1322 //console.log('fire'); 1323 if ($select.val() == 'ticket_slider-dollars') { 1324 $('.js-ticketed_slider_preview-dollars').css('display','block'); 1325 $('.js-ticketed_slider_preview-tickets').css('display','none'); 1326 } else { 1327 $('.js-ticketed_slider_preview-tickets').css('display','block'); 1328 $('.js-ticketed_slider_preview-dollars').css('display','none'); 1329 } 1330 } 1331 1332 1333 1334 $('.js-donate_slider_type').change(function() { 1335 fundraising_goal_donors_dollars_switch($(this)); 1336 }); 1337 1338 /* donors/dollars goal slider */ 1339 var ticketed_goal_donors_dollars_switch = function($select) { 1340 //console.log('fire'); 1341 if ($select.val() == 'ticket_slider-dollars') { 1342 $('.js-ticketed_slider_preview-dollars').css('display','block'); 1343 $('.js-ticketed_slider_preview-tickets').css('display','none'); 1344 } else { 1345 $('.js-ticketed_slider_preview-tickets').css('display','block'); 1346 $('.js-ticketed_slider_preview-dollars').css('display','none'); 1347 } 1348 } 1349 1350 1351 1352 $('.js-ticketed_slider_type').change(function() { 1353 ticketed_goal_donors_dollars_switch($(this)); 1354 }); 1355 1356 1357 /* amount options */ 1358 var amount_option_empty = function() { 1359 if (!$('.js-donate_amount').length) { 1360 1361 donation_amount_error_flag = true; 1362 1363 } else { 1364 1365 donation_amount_error_flag = false; 1366 1367 } 1368 1369 if (donation_amount_error_flag) { 1370 $('.js-donate_amount_enter').addClass('required'); 1371 //errorCount = errorCount + 1; 1372 } else { 1373 $('.js-donate_amount_enter').removeClass('required'); 1374 $('.js-donate_amount_enter').removeClass('error_input'); 1375 //errorCount = errorCount - 1; 1376 } 1377 } 1378 1379 var donate_amount_remove_function = function() { 1380 $('.js-donate_amount-remove').click(function() { 1381 $(this).parent().remove(); 1382 amount_option_empty(); 1383 donate_options_wrapper_class($('.js-donate_amount').length); 1384 }); 1385 } 1386 1387 var donate_options_wrapper_class = function(donate_amount_length_arg) { 1388 var donate_amount_length = donate_amount_length_arg; 1389 var donate_amount_length_plus1 = donate_amount_length + 1; 1390 var donate_amount_length_minus1 = donate_amount_length - 1; 1391 if (donate_amount_length >= 9) { 1392 $('.js-donate_options_count').removeClass('donate_options8').addClass('donate_options9'); 1393 } else { 1394 $('.js-donate_options_count').removeClass('donate_options' + donate_amount_length_minus1).removeClass('donate_options' + donate_amount_length_plus1).addClass('donate_options' + donate_amount_length); 1395 } 1396 } 1397 1398 var amount_option_append_number = function(amount_option_arg) { 1399 $('.js-donate_amount_wrap').append( 1400 '<label class="donate_amount js-donate_amount">' 1401 + '$' 1402 + amount_option_arg 1403 + '<input type="hidden" name="fundraising[amounts][]" value="' 1404 + amount_option_arg 1405 + '" class="amount_option_hidden_input js-amount_option_hidden_input" />' 1406 + '<a href="javascript:void(0);" class="donate_amount-remove js-donate_amount-remove">' + an_javascript_translation.remove + '</a>' 1407 + '</label>' 1408 ); 1409 1410 set_currency_edit(); 1411 } 1412 1413 var amount_option_append_other = function() { 1414 $('.js-donate_amount_wrap').append( 1415 '<label class="donate_amount js-donate_amount">' 1416 + '$' + an_javascript_translation.other 1417 + '<input type="hidden" name="fundraising[amounts][]" value="other" class="amount_option_hidden_input js-amount_option_hidden_input" />' 1418 + '<a href="javascript:void(0);" class="donate_amount-remove js-donate_amount-remove">' + an_javascript_translation.remove + '</a>' 1419 + '</label>' 1420 ); 1421 1422 set_currency_edit(); 1423 } 1424 1425 1426 $('.js-donate_add_amount_button').click(function() { 1427 //check for dupe amounts 1428 var amount_option_dupe = false;
1429 //console.log(amount_option_dupe); 1430 $('.js-amount_option_hidden_input').each(function() { 1431 //console.log($('#donate_amount_enter').val() + ', ' + $(this).val()); 1432 if ($('.js-donate_amount_enter').val() == '') { 1433 if ($(this).val() == 'other') { 1434 amount_option_dupe = true; 1435 } 1436 } else if ($('.js-donate_amount_enter').val() % 1 === 0) { 1437 if ($(this).val() == parseInt($('.js-donate_amount_enter').val())) { 1438 amount_option_dupe = true; 1439 } 1440 } else { 1441 if ($(this).val() == parseFloat($('.js-donate_amount_enter').val()).toFixed(2)) { 1442 amount_option_dupe = true; 1443 } 1444 } 1445 }); 1446 1447 if (!amount_option_dupe) { 1448 if ($('.js-donate_amount_enter').val() != '' && !isNaN($('.js-donate_amount_enter').val()) && $('.js-donate_amount_enter').val() >= 1) { 1449 1450 if ($('.js-donate_amount_enter').val() % 1 === 0) { 1451 var amount_option_tofixed = parseInt($('.js-donate_amount_enter').val()); 1452 } else { 1453 var amount_option_tofixed = parseFloat($('.js-donate_amount_enter').val()).toFixed(2); 1454 } 1455 1456 if ($('.js-donate_amount').length < 5 && $('.js-donate_amount').length != 0) { 1457 donate_options_wrapper_class($('.js-donate_amount').length + 1); 1458 setTimeout(function() { 1459 amount_option_append_number(amount_option_tofixed); 1460 donate_amount_remove_function(); 1461 amount_option_empty(); 1462 $('.js-donate_amount_enter').val(''); 1463 }, 250); 1464 } else { 1465 donate_options_wrapper_class($('.js-donate_amount').length + 1); 1466 amount_option_append_number(amount_option_tofixed); 1467 donate_amount_remove_function(); 1468 //console.log('this' + donation_amount_error_flag); 1469 amount_option_empty(); 1470 1471 } 1472 1473 } else if ($('.js-donate_amount_enter').val() == '') { 1474 1475 if ($('.js-donate_amount').length < 5 && $('.js-donate_amount').length != 0) { 1476 donate_options_wrapper_class($('.js-donate_amount').length + 1); 1477 setTimeout(function() { 1478 amount_option_append_other(); 1479 donate_amount_remove_function(); 1480 amount_option_empty(); 1481 $('.js-donate_amount_enter').val(''); 1482 }, 250); 1483 } else { 1484 donate_options_wrapper_class($('.js-donate_amount').length + 1); 1485 amount_option_append_other(); 1486 donate_amount_remove_function(); 1487 //console.log('this ' + donation_amount_error_flag); 1488 amount_option_empty(); 1489 } 1490 1491 //canValidate(); 1492 1493 } 1494 1495 } 1496 1497 $('.js-donate_amount_enter').val('').blur(); 1498 1499 1500 }); 1501 1502 1503 /* recipients */ 1504 var currency_selected = '$'; 1505 var old_currency_selected = '$'; 1506 1507 var set_currency_edit = function() { 1508 if ($('.js-single_recipient input[type=hidden]').first().length) { 1509 currency_selected = $('.js-single_recipient input[type=hidden]').first().data('currency').toUpperCase(); 1510 } 1511 1512 currency_selected = resolve_currency_symbol(currency_selected); 1513 if (currency_selected.length == 3) { // for example. HUF 150, but $150 and €150 1514 currency_selected += ' '; 1515 } 1516 1517 var currency_regex_string = '\\' + old_currency_selected + ' *'; 1518 var currency_regex = new RegExp(currency_regex_string,"g"); 1519 var currency_dollar_regex = new RegExp('\\$',"g"); 1520/* 1521 console.log(currency_selected); 1522 console.log(old_currency_selected); 1523 console.log(currency_regex_string); 1524 console.log(currency_regex); 1525 console.log(currency_dollar_regex); 1526*/ 1527 1528 //if (currency_selected != 'USD') { 1529 if ($('.js-single_recipient input[type=text]').length) { 1530 $('.js-single_recipient input[type=text]').each(function() { 1531 $(this).attr('placeholder', currency_selected + ' 0'); 1532 }); 1533 } 1534 1535 //console.log($('.js-donate_amount').length); 1536 if ($('.js-donate_amount').length) { 1537 $('.js-donate_amount').each(function() { 1538 $(this).html($(this).html().replace(currency_regex, currency_selected).replace(currency_dollar_regex, currency_selected)); 1539 }); 1540 } 1541 1542 if ($('.js-donate_slider_preview-dollars').length) { 1543 $('.js-donate_slider_preview-dollars').html($('.js-donate_slider_preview-dollars').html().replace(currency_regex, currency_selected).replace(currency_dollar_regex, currency_selected)); 1544 1545 } 1546 1547 if ($('.js-ticketed_slider_preview-dollars').length) { 1548 $('.js-ticketed_slider_preview-dollars').html($('.js-ticketed_slider_preview-dollars').html().replace(currency_regex, currency_selected).replace(currency_dollar_regex, currency_selected)); 1549 1550 } 1551 1552 if ($('.js-ticketed_event_tickets_price').length) { 1553 $('.js-ticketed_event_tickets_price').each(function() { 1554 const currency_selected_usd = reverse_currency_symbol(currency_selected); 1555 const old_currency_selected_usd = reverse_currency_symbol(old_currency_selected); 1556 1557 var currency_regex_string_usd = '\\' + old_currency_selected_usd; 1558 var currency_regex_usd = new RegExp(currency_regex_string_usd,"g"); 1559 var currency_dollar_regex_usd = new RegExp('\\USD',"g"); 1560 1561 //console.log($(this).attr('placeholder')); 1562 $(this).attr('placeholder',$(this).attr('placeholder').replace(currency_regex_usd, currency_selected_usd).replace(currency_dollar_regex_usd, currency_selected_usd)); 1563 1564 if ($(this).parent().find('label').length) { 1565 $(this).parent().find('label').html($(this).parent().find('label').html().replace(currency_regex_usd, currency_selected_usd).replace(currency_dollar_regex_usd, currency_selected_usd)); 1566 } 1567 1568 }); 1569 1570 } 1571 1572 let placeholder_and_label = currency_selected + ' ' + an_javascript_translation.amount + ' *'; // the original label and placeholder (notice the spaces): '$ Amount *' 1573 $('.js-donate_add_dollar_amount-inner input').attr('placeholder', placeholder_and_label); 1574 $('.js-donate_add_dollar_amount-inner label').text(placeholder_and_label); 1575 //} 1576 1577 old_currency_selected = currency_selected; 1578 donate_amount_remove_function(); 1579 }; 1580 1581 var recipients_empty = function() { 1582 if (!$('.js-single_recipient-create').length) { 1583 $('.js-please_add_recipient').show(); 1584 donation_recipient_error_flag = true; 1585 if (typeof(form_id) != 'undefined') { 1586 $('#' + form_id).valid(); 1587 } 1588 } else { 1589 $('.js-please_add_recipient').hide(); 1590 donation_recipient_error_flag = false;
1591 if (typeof(form_id) != 'undefined') { 1592 $('#' + form_id).valid(); 1593 } 1594 } 1595 1596 $('.js-single_recipient-create').each(function(i) { 1597 $(this).children('.js-donation_info_split').remove(); 1598 }); 1599 1600 if ($('.js-single_recipient-create').length > 1) { 1601 $('.js-single_recipient-create').each(function(i) { 1602 $(this).children('.js-donation_info').after('<div class="donation_info_split js-donation_info_split"><input disabled="" type="text" name="donate_split1" value="" size="35" class="disabled tiny" placeholder="$0"></div>'); 1603 }); 1604 } 1605 } 1606 1607 var remove_recipient_function = function() { 1608 $('.js-remove_recipient').click(function() { 1609 $(this).parent().remove(); 1610 recipients_empty(); 1611 //set_currency_edit(); 1612 if ($('.js-add_ticket_option').length) { 1613 $('.js-add_donation_recipient-link').show(); 1614 $('.js-add_donation_recipient-link').next().show(); 1615 } 1616 }); 1617 }; 1618 1619 var recipient_duplicate_check = function($add_button, $recipient_selection) { 1620 var duplicate_recipient_flag = false; 1621 1622 $('.js-single_recipient input').each(function(i) { 1623 if ( 1624 // if the groups are the same, or... 1625 $(this).val() == $recipient_selection.data('id') || 1626 ( 1627 // if the processor is present and not the same, or... 1628 ( 1629 $(this).data('processor') && 1630 $recipient_selection.data('processor') 1631 ) && 1632 $(this).data('processor') != $recipient_selection.data('processor') 1633 ) || 1634 ( 1635 // if the currency is present and not the same 1636 ( 1637 $(this).data('currency') && 1638 $recipient_selection.data('currency') 1639 ) && 1640 $(this).data('currency') != $recipient_selection.data('currency') 1641 ) 1642 ) { 1643 //then we flag as not add-able to the recipient selection 1644 duplicate_recipient_flag = true; 1645 } 1646 }); 1647 1648 if (duplicate_recipient_flag) { 1649 $add_button.attr('disabled',true); 1650 $add_button.addClass('disabled'); 1651 } else { 1652 $add_button.attr('disabled',false); 1653 $add_button.removeClass('disabled'); 1654 } 1655 }; 1656 1657 var add_recipient = function($recipient_selection) { 1658 if ($('.js-add_ticket_option').length) { 1659 var inputHTML = '<input type="hidden" name="ticketed_event[recipient_id]" value="' + $recipient_selection.data('id') + '" data-processor="' + $recipient_selection.data('processor') + '" data-currency="' + $recipient_selection.data('currency') + '" />' 1660 } else { 1661 var inputHTML = '<input type="hidden" name="donation_recipients[]" value="' + $recipient_selection.data('id') + '" data-processor="' + $recipient_selection.data('processor') + '" data-currency="' + $recipient_selection.data('currency') + '" />' 1662 } 1663 $('.js-add_donation_recipient-link').before( 1664 '<div class="single_recipient js-single_recipient single_recipient-create js-single_recipient-create clearfix">' 1665 + '<a href="' + $recipient_selection.data('link') + '" class="recipient_avatar_link">' 1666 + '<img src="' + $recipient_selection.data('avatar') + '" alt="Username" class="avatar donation_avatar" />' 1667 + '</a>' 1668 + '<div class="donation_info js-donation_info">' 1669 + '<div class="donation_info_user clearfix"><a href="' + $recipient_selection.data('link') + '">' + $recipient_selection.data('name') + '</a></div>' 1670 + '</div>' 1671 + '<a class="remove_recipient js-remove_recipient link_remove_recipient" href="javascript:void(0);"><i class="far fa-times"></i> ' + an_javascript_translation.remove_recipients + '</a>' 1672 + inputHTML 1673 + '</div>' 1674 ); 1675 //} 1676 1677 remove_recipient_function(); 1678 1679 if ($('.js-add_ticket_option').length) { 1680 $('.js-add_donation_recipient-link').hide(); 1681 $('.js-add_donation_recipient-link').next().hide(); 1682 } 1683 1684 $.fancybox.close(); 1685 1686 }; 1687 1688 1689 $('.js-add_donation_recipient-link').click(function() { 1690 recipient_duplicate_check($('.donation_groups_button'), $('.js-donation_groups').find('option:selected')); 1691 $('.js-search_recipient_list ul li').each(function(i) { 1692 recipient_duplicate_check($(this).children('.js-choose_recipient_button'), $(this).children('.js-choose_recipient_button')); 1693 }); 1694 }); 1695 1696 $('.js-donation_groups').change(function() { 1697 recipient_duplicate_check($('.js-donation_groups_button'), $('.
1697js-donation_groups').find('option:selected')); 1698 }); 1699 1700 $('.js-donation_groups_button').click(function() { 1701 if (!$('.js-donation_groups_button').hasClass('disabled')) { 1702 var $recipient_selection = $('.js-donation_groups').find('option:selected'); 1703 if ($recipient_selection.val() != '') { 1704 add_recipient($recipient_selection); 1705 recipients_empty(); 1706 set_currency_edit(); 1707 $.fancybox.close(); 1708 } 1709 1710 } 1711 1712 }); 1713 1714 1715 /* url argument for subscription defaults */ 1716 var url_parameter_subscription_group = getURLParameter('subscription_group'); 1717 var url_parameter_subscription_user = getURLParameter('subscription_user'); 1718 var url_parameter_subscription_referrer = getURLParameter('subscription_referrer'); 1719 var url_parameter_mobile_subscription_group = getURLParameter('mobile_subscription_group'); 1720 var url_parameter_mobile_subscription_user = getURLParameter('mobile_subscription_user'); 1721 var url_parameter_mobile_subscription_referrer = getURLParameter('mobile_subscription_referrer'); 1722 1723 1724 /* url arguments for filling existing form fields from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript */ 1725 1726 var urlParams; 1727 (window.onpopstate = function () { 1728 var match, 1729 pl = /\+/g, // Regex for replacing addition symbol with a space 1730 search = /([^&=]+)=?([^&]*)/g, 1731 decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, 1732 query = window.location.search.substring(1); 1733 1734 urlParams = {}; 1735 while (match = search.exec(query)) 1736 urlParams[decode(match[1])] = decode(match[2]); 1737 })(); 1738 1739 if (!$('.js-login_page').length) { 1740 $.each(urlParams, function(key, value) { 1741 if ($('input[name="' + key + '"]').not('.js-form_builder_other_input, .js-other_option').length) { 1742 if ($('input[name="' + key + '"]').attr('type') == 'radio' || $('input[name="' + key + '"]').attr('type') == 'checkbox') { 1743 $('input[name="' + key + '"]').not('.js-form_builder_other_input, .js-other_option').each(function() { 1744 if ($(this).val() == value) { 1745 $(this).prop("checked", true); 1746 } else { 1747 $(this).prop("checked", false); 1748 } 1749 }); 1750 } else { 1751 $('input[name="' + key + '"]').not('.js-form_builder_other_input, .js-other_option').each(function() { 1752 $(this).val(value).trigger('change'); 1753 }); 1754 } 1755 } else if ($('textarea[name="' + key + '"]').length) { 1756 $('textarea[name="' + key + '"]').val(value).trigger('change'); 1757 } else if ($('select[name="' + key + '"]').length) { 1758 //console.log(key); 1759 $('select[name="' + key + '"] option').not('.js-other_option').each(function(i, e) { 1760 if ($(e).attr('value') == value) { 1761 $(e).attr('selected',true); 1762 } else { 1763 $(e).attr('selected',false); 1764 } 1765 }); 1766 } 1767 }); 1768 } 1769 1770 //console.log(url_parameter_subscription_group); 1771 1772 if (url_parameter_subscription_group === 'false') { 1773 $("input[name='subscription[group]']").attr('checked', false); 1774 } 1775 1776 if (url_parameter_subscription_user === 'false') { 1777 $("input[name='subscription[user]']").attr('checked', false); 1778 } 1779 1780 if (url_parameter_subscription_referrer === 'false') { 1781 $("input[name='subscription[referrer]']").attr('checked', false); 1782 $("input[name='subscription[group_referrer]']").attr('checked', false); 1783 } 1784 1785 if (url_parameter_mobile_subscription_group === 'true') { 1786 $("input[name='subscription[sms_group]']").attr('checked', 'checked'); 1787 } 1788 1789 if (url_parameter_mobile_subscription_user === 'true') { 1790 $("input[name='subscription[sms_user]']").attr('checked', 'checked'); 1791 } 1792 1793 if (url_parameter_mobile_subscription_referrer === 'true') { 1794 $("input[name='subscription[sms_referrer]']").attr('checked', 'checked'); 1795 $("input[name='subscription[sms_group_referrer]']").attr('checked', 'checked'); 1796 } 1797 1798 1799 1800 1801 /* event campaign code */ 1802 1803 // Hosting options - show/hide vetting checkbox on change 1804 $('.js-hosting_option_container input[name="event_campaign[hosting_options]"]').on('change', function() { 1805 $('.js-vetting_checkbox').hide(); // Hide all first 1806 $(this).closest('.js-hosting_option_container').find('.js-vetting_checkbox').show(); // Show only the relevant one 1807 $('.js-vetting_checkbox input').prop('checked', false); 1808}); 1809 1810 // Keep vetting checked state synced between options 1811 $('.js-vetting_checkbox input').on('change', function() { 1812 $('.js-vetting_checkbox input').prop('checked', this.checked); 1813 }); 1814 1815 fundraising_recipient_search_list = 1816 '<ul class="lined js-lined">' 1817 + '<li>' 1818 + '<div class="single_recipient js-single_recipient clearfix">' 1819 + '<a href="#" class="recipient_avatar_link">' 1820 + '<img src="http://www.gravatar.com/avatar/02cdeec360274d7d9f1aa85761f95dc8?d=mm&?s=88" alt="Username" class="avatar donation_avatar" />'
1821 + '</a>' 1822 + '<div class="donation_info js-donation_info">' 1823 + '<div class="donation_info_user"><a href="#">Jason Rosenbaum</a></div>' 1824 + '<div class="donation_info_location">Chicago, IL</div>' 1825 + '</div>' 1826 + '</div>' 1827 + '<input type="submit" value="' + an_javascript_translation.add + '" class="button choose_recipient_button js-choose_recipient_button" data-link="http://jasonrosenbaum.com" data-avatar="http://www.gravatar.com/avatar/02cdeec360274d7d9f1aa85761f95dc8?d=mm&?s=88" data-name="Jason Rosenbaum" data-location="Chicago, IL" data-id="jason-rosenbaum-11" />' 1828 + '</li>' 1829 + '<li>' 1830 + '<div class="single_recipient js-single_recipient clearfix">' 1831 + '<a href="#" class="recipient_avatar_link">' 1832 + '<img src="http://www.gravatar.com/avatar/d4942ad1238149e1868793e4d91bd482?d=mm&?s=88" alt="Username" class="avatar donation_avatar" />' 1833 + '</a>' 1834 + '<div class="donation_info js-donation_info">' 1835 + '<div class="donation_info_user"><a href="#">Progressive Action Now</a></div>' 1836 + '</div>' 1837 + '</div>' 1838 + '<input type="submit" value="' + an_javascript_translation.add + '" class="button choose_recipient_button js-choose_recipient_button" data-link="http://progressiveactionnow.com" data-avatar="http://www.gravatar.com/avatar/d4942ad1238149e1868793e4d91bd482?d=mm&?s=88" data-name="Progressive Action Now" data-location="" data-id="progressive-action-now">' 1839 + '</li>' 1840 + '</ul>'; 1841 1842 fundraising_recipient_search_validate = false; 1843 1844 $('.js-donation_user_search_button').click(function() { 1845 console.log('fire'); 1846 fundraising_recipient_search_validate = true; 1847 if ($('.js-donation_user_search').val() != '') { 1848 $('.js-donation_user_search').removeClass('error_input'); 1849 $('.js-search_recipient_list').html('<div class="centertext">' + an_javascript_translation.searching + '</div>'); 1850 1851 // Add redesign param 1852 var redesignParam = ''; 1853 if (getURLParameter('redesign') == '4') redesignParam = '&redesign=4'; 1854 $.get('/fundraisings/search_recipients' + '?q=' + $('.js-donation_user_search').val() + redesignParam, function(data) { 1855 1856 if (data != '<ul class="lined js-lined">\n</ul>') { 1857 $('.js-search_recipient_list').html(data); 1858 $('.js-search_recipient_list ul li').each(function(i) { 1859 recipient_duplicate_check($(this).children('.js-choose_recipient_button'), $(this).children('.js-choose_recipient_button')); 1860 }); 1861 $('.js-search_recipient_list .js-choose_recipient_button').click(function() { 1862 add_recipient($(this)); 1863 recipients_empty(); 1864 set_currency_edit(); 1865 }); 1866 } else { 1867 $('.js-search_recipient_list').html('<p>'+an_javascript_translation.no_recipients_were_found+'</p>'); 1868 } 1869 1870 }) 1871 .fail(function() { 1872 $('.js-search_recipient_list').html('<p>' + an_javascript_translation.an_error_occurred_please_try_again + '</p>'); 1873 }); 1874 1875 1876 // setTimeout(function() { 1877 // $('#search_recipient_list').html(fundraising_recipient_search_list); 1878 // $('#search_recipient_list ul li').each(function(i) { 1879 // recipient_duplicate_check($(this).children('.choose_recipient_button'), $(this).children('.choose_recipient_button')); 1880 // }); 1881 // $('#search_recipient_list .choose_recipient_button').click(function() { 1882 // add_recipient($(this)); 1883 // recipients_empty(); 1884 // }); 1885 // }, 3000); 1886 } else { 1887 $('.js-donation_user_search').addClass('error_input'); 1888 } 1889 1890 }); 1891 1892 $('.js-donation_user_search').on('keyup', function() { 1893 if (fundraising_recipient_search_validate) { 1894 if ($('.js-donation_user_search').val() != '') { 1895 $('.js-donation_user_search').removeClass('error_input'); 1896 } else { 1897 $('.js-donation_user_search').addClass('error_input'); 1898 } 1899 } 1900 }); 1901 1902 var donate_recurring_type_required = function() { 1903 if ($('.js-donate_recurring_type').val() == 'recurring_type_creator') { 1904 $('.js-donate_recurring_period').addClass('required'); 1905 $('.js-donate_recurring_period').children('option').first().html('-- ' + an_javascript_translation.choose_one + ' --'); 1906 $('.js-donate_recurring_period').trigger('update'); 1907 } else { 1908 $('.js-donate_recurring_period').removeClass('required'); 1909 $('.js-donate_recurring_period').removeClass('error_input'); 1910 $('.js-donate_recurring_period').parent().removeClass('js-error_input-select_wrap error_input-select_wrap'); 1911 $('.js-donate_recurring_period').children('option').first().html(an_javascript_translation.allow_user_to_set_recurring_period); 1912 $('.js-donate_recurring_period').trigger('update'); 1913 } 1914 } 1915 1916 sponsor_recipient_search_validate = false;
1917 $('.js-sponsor_user_search_button').click(function() { 1918 sponsor_recipient_search_validate = true; 1919 if ($('.js-sponsor_user_search').val() != '' && $('.js-sponsor_user_search').val().length > 1) { 1920 $('.js-sponsor_user_search').removeClass('error_input'); 1921 $('.js-search_recipient_list').html('<div class="centertext">' + an_javascript_translation.searching + '</div>'); 1922 1923 $.get('/sponsors/search' + '?q=' + $('.js-sponsor_user_search').val(), function(data) { 1924 1925 if (data != '<ul class="lined js-lined">\n</ul>') { 1926 $('.js-search_recipient_list').html(data); 1927 $('.js-search_recipient_list ul li').each(function(i) { 1928 recipient_duplicate_check($(this).children('.js-choose_recipient_button'), $(this).children('.js-choose_recipient_button')); 1929 }); 1930 $('.js-search_recipient_list .js-choose_recipient_button').click(function() { 1931 add_recipient($(this)); 1932 recipients_empty(); 1933 set_currency_edit(); 1934 }); 1935 } else { 1936 $('.js-search_recipient_list').html('<div class="centertext">'+an_javascript_translation.no_groups_were_found+'</div>'); 1937 } 1938 1939 }) 1940 .fail(function() { 1941 $('.js-search_recipient_list').html('<div class="centertext">'+an_javascript_translation.an_error_occurred_please_try_again+'</div>'); 1942 }); 1943 1944 } else { 1945 $('.js-sponsor_user_search').addClass('error_input'); 1946 } 1947 1948 }); 1949 1950 $('.js-sponsor_user_search').on('keyup', function() { 1951 if (sponsor_recipient_search_validate) { 1952 if ($('.js-sponsor_user_search').val() != '') { 1953 $('.js-sponsor_user_search').removeClass('error_input'); 1954 } else { 1955 $('.js-sponsor_user_search').addClass('error_input'); 1956 } 1957 } 1958 }); 1959 1960 var add_ticket_option = function() { 1961 var ticket_index = $($('.js-select_tickets ul li:not(.js-add_ticket_option_wrap)').slice(-1)[0]).attr('class').split(" ")[0]; 1962 ticket_index++; 1963 $('.js-add_ticket_option_wrap').before('' 1964 + '<li class="' + ticket_index + ' clearfix">' 1965 + '<div class="clearfix">' 1966 + '<div class="twentyfive left">' 1967 + '<input class="required digits" id="ticketed_event_tickets_attributes_' + ticket_index + '_total" min="1" name="ticketed_event[tickets_attributes][' + ticket_index + '][total]" placeholder="# ' + an_javascript_translation.available + ' *" size="" step="1" type="number" value="">' 1968 + '</div>' 1969 + '<div class="fifty left">' 1970 + '<input class="ticket_title required" id="ticketed_event_tickets_attributes_' + ticket_index + '_title" name="ticketed_event[tickets_attributes][' + ticket_index + '][title]" placeholder="' + an_javascript_translation.ticket_name + ' *" size="30" type="text" value="">' 1971 + '</div>' 1972 + '<div class="twentyfive left">' 1973 + '<input class="required number js-ticketed_event_tickets_price" id="ticketed_event_tickets_attributes_' + ticket_index + '_price" min="1" name="ticketed_event[tickets_attributes][' + ticket_index + '][price]" placeholder="' + an_javascript_translation.cost_in_usd + ' *" size="" step="1" type="text" value="">' 1974 + '</div>' 1975 + '</div>' 1976 + '<div class="clearfix mt10">' 1977 + '<input class="ticket_desc" id="ticketed_event_tickets_attributes_' + ticket_index + '_description" name="ticketed_event[tickets_attributes][' + ticket_index + '][description]" placeholder="' + an_javascript_translation.ticket_description_optional + '" size="30" type="text" value="">' 1978 + '</div>' 1979 + '<a href="javascript:void(0);" class="fs-14 righti mt5 js-remove_ticket_option remove_ticket_option" data-index="' + ticket_index + '"><i class="far fa-times"></i> ' + an_javascript_translation.remove + '</a>' 1980 + '</li>' 1981 ); 1982 1983 $('form.js-create_donate_form').trigger('rescan.areYouSure'); 1984 } 1985 1986 var remove_ticket_option = function($this) { 1987 $this.parent().find('.js-ticket_options_id').detach().appendTo($this.parent().parent().parent()); 1988 $this.parent().parent().parent().append('<input type="hidden" name="ticketed_event[tickets_attributes][' + $this.data('index') + '][hidden]" value="true" />'); 1989 $this.parent().remove(); 1990 $('form.js-create_donate_form').trigger('rescan.areYouSure'); 1991 } 1992 1993 if ($('.js-donate_add_dollar_amount').length) { 1994 amount_option_empty(); 1995 donate_amount_remove_function(); 1996 $('.js-donate_amount_enter').val(''); 1997 remove_recipient_function(); 1998 recipients_empty(); 1999 set_currency_edit(); 2000 donate_recurring_type_required(); 2001 fundraising_goal_donors_dollars_switch($('.js-donate_slider_type')); 2002 } 2003 2004 if ($('.js-add_ticket_option').length) { 2005 remove_recipient_function(); 2006 recipients_empty(); 2007 set_currency_edit(); 2008 ticketed_goal_donors_dollars_switch($('.js-ticketed_slider_type')); 2009 $('.js-add_ticket_option').click(function() { 2010 add_ticket_option(); 2011 set_currency_edit(); 2012 }); 2013 2014 $('.js-select_tickets').on('click', '.js-remove_ticket_option', function() { 2015 remove_ticket_option($(this)); 2016 }); 2017 2018 if ($('.js-single_recipient-create').length) { 2019 $('.js-add_donation_recipient-link').hide(); 2020 $('.js-add_donation_recipient-link').next().hide(); 2021 } 2022 } 2023 2024 if ($('.js-ticketed_event_form_button').length) { 2025 if (!$('.js-ticketed_event_ticket_number').length) { 2026 $('.js-ticketed_event_form_button').attr('disabled',true).addClass('disabled').val(an_javascript_translation.this_event_is_sold_out); 2027 } 2028 } 2029 2030 //tooltips 2031 toolTipEvent = $.Event('tooltip_built'); 2032 //Activate tooltips 2033 //var targets = $( '.popover-content .tooltip' ); 2034 $('body').bind( 'tooltip_built', function() 2035 {
2036 var targets = $( '.popover-content .js-tooltip' ); 2037 targets.bind( 'mouseover', function(e) 2038 { 2039 //e.preventDefault(); 2040 tooltipFunction(this); 2041 }); 2042 2043 //validation to make name required on the form builder 2044 $('.popover-content #save').click(function() { 2045 if ($('.popover-content #id').val() == '' || $('.popover-content #name').val() == '') { 2046 $('.popover-content #id, .popover-content #name').addClass('error_input'); 2047 } else { 2048 $('.popover-content #id, .popover-content #name').removeClass('error_input'); 2049 } 2050 }); 2051 2052 $('.popover-content #id, .popover-content #name').on('keyup', function() { 2053 if ($('.popover-content #id').val() == '' || $('.popover-content #name').val() == '') { 2054 $('.popover-content #id, .popover-content #name').addClass('error_input'); 2055 } else { 2056 $('.popover-content #id, .popover-content #name').removeClass('error_input'); 2057 } 2058 }); 2059 2060 $(".popover-content #name, .popover-content #id, .popover-content #checkboxes, .popover-content #options, .popover-content #radios").focusin(function() { 2061 2062 tooltipFunction($(this).prev().children(".js-tooltip"), '.popover-content'); 2063 2064 }).focusout(function () { 2065 2066 remove_tooltip(); 2067 2068 }); 2069 }); 2070 2071 // tooltips 2072 var targets = $( 'body' ), 2073 target = false, 2074 tooltip = false, 2075 title = false; 2076 2077 tooltipFunction = function(element) { 2078 2079 target = $( element ); 2080 tip = target.children( 'span' ).html(); 2081 tooltip = $( '<div id="tooltip" class="tooltip_window js-tooltip_window"></div>' ); 2082 2083 if (target.parents(".js-create_action_toolbox").length) { 2084 append_target = 'body'; 2085 } else if (target.parents(".control-label, .control-group").length) { 2086 append_target = '.js-form_builder_modal'; 2087 } else if (target.parents(".js-dialog__inner").length) { 2088 append_target = '.js-dialog__wrapper'; 2089 } else if (target.parents("#fancybox-content").length) { 2090 append_target = '#fancybox-content'; 2091 } else { 2092 append_target = '.js-content'; 2093 } 2094 2095 if( !tip || tip == '' ) 2096 return false; 2097 2098 tooltip.css( 'opacity', 0 ) 2099 .html( tip ) 2100 .appendTo( append_target ); 2101 2102 var init_tooltip = function() { 2103 if (!document.body.contains(tooltip[0])) return; 2104 2105 // check for dialog first, more specific check 2106 if (target.parents(".js-dialog__inner").length) { 2107 2108 var container = target.parents('dialog')[0]; 2109 var tip = target.children('span').html(); 2110 2111 if (!tip) { 2112 return; 2113 } 2114 2115 tooltip.css({ 2116 opacity: 0, 2117 position: 'absolute', 2118 maxWidth: '340px', 2119 pointerEvents: 'none', 2120 zIndex: 999999 2121 }); 2122 2123 tooltip.html(tip).appendTo(container); 2124 2125 var triggerRect = target[0].getBoundingClientRect(); 2126 var containerRect = container.getBoundingClientRect(); 2127 2128 var left = triggerRect.left - containerRect.left + (triggerRect.width / 2) - (tooltip[0].offsetWidth / 2); 2129 var top = triggerRect.top - containerRect.top - tooltip[0].offsetHeight - 10 + container.scrollTop; 2130 2131 if (top < 0) { 2132 top = triggerRect.top - containerRect.top + triggerRect.height + 10 + container.scrollTop; 2133 tooltip.addClass('top'); 2134 } 2135 2136 tooltip[0].style.left = left + 'px'; 2137 tooltip[0].style.top = top + 'px'; 2138 tooltip[0].style.transition = 'opacity 0.3s'; 2139 tooltip[0].style.opacity = '1'; 2140 2141 target.bind('mouseleave', remove_tooltip); 2142 tooltip.bind('click', remove_tooltip); 2143 return; 2144 } 2145 2146 var targetRect = target[0].getBoundingClientRect(); 2147 2148 if( $( window ).width() < tooltip.outerWidth() * 1.5 ) 2149 tooltip.css( 'max-width', $( window ).width() / 2 ); 2150 else 2151 tooltip.css( 'max-width', 340 ); 2152 2153 var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ) - $(append_target).offset().left, 2154 pos_top = target.offset().top - tooltip.outerHeight() - 10 /* - $(append_target).offset().top */; 2155 2156 if( pos_left < 0 ) 2157 { 2158 pos_left = target.offset().left + target.outerWidth() / 2 - 20 - $(append_target).offset().left; 2159 tooltip.addClass( 'left' ); 2160 } 2161 else 2162 tooltip.removeClass( 'left' ); 2163 2164 if( pos_left + tooltip.outerWidth() > $( window ).width() ) 2165 { 2166 pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20 - $(append_target).offset().left; 2167 tooltip.addClass( 'right' ); 2168 } else if (target.parents('#fancybox-content').length && pos_left + tooltip.outerWidth() > $( target.parents('#fancybox-content') ).width() ) { 2169 pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20 - $(append_target).offset().left; 2170 tooltip.addClass( 'right' ); 2171 } else if (target.parents('.js-dialog__inner').length && pos_left + tooltip.outerWidth() > target.parents('.js-dialog__inner').width() ) { 2172 pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20; 2173 tooltip.addClass( 'right' ); 2174 } else { 2175 tooltip.removeClass( 'right' ); 2176 } 2177 2178 if (target.hasClass('dupl_button')) { 2179 pos_top = target.offset().top + target.outerHeight() + 20; 2180 tooltip.addClass( 'top' ); 2181 } else if( pos_top < 0 && !target.parents('.popover-content').length && !target.parents('.js-dialog__inner').length ) 2182 { 2183 if (append_target === '.js-content' || append_target === 'body') { 2184 pos_top = target.offset().top + target.outerHeight() + 10; 2185 } else { 2186 pos_top = target.offset().top + target.outerHeight() - $(append_target).offset().top + 15 + $('#fancybox-content').scrollTop(); 2187 } 2188 tooltip.addClass( 'top' ); 2189 } else if (target.parents('.js-donate_add_dollar_amount-inner').length) { 2190 var pos_top = target.offset().top + target.outerHeight() + 10; 2191 tooltip.addClass( 'top' ); 2192 } else if (target.parents('#fancybox-content').length) { 2193 if (target.parents('.popover-content').length) { 2194 pos_top = target.offset().top - target.parents('.js-form_builder_modal').offset().top - target.outerHeight() - tooltip.outerHeight(); 2195 } else if (target.parents('.js-ladder_modal').length) { 2196 if (pos_top - tooltip.outerHeight() - 10 > target.parents('#fancybox-content').offset().top) { 2197 pos_top = target.offset().top - target.parents('#fancybox-content').offset().top - target.outerHeight() - tooltip.outerHeight() - 0 + $('#fancybox-content').scrollTop(); 2198 } else { 2199 pos_top = target.offset().top - target.parents('#fancybox-content').offset().top + target.outerHeight() - 0; 2200 tooltip.addClass( 'top' ); 2201 } 2202 } else { 2203 if (pos_top - tooltip.outerHeight() - 10 > target.parents('#fancybox-content').offset().top) { 2204 pos_top = target.offset().top - target.parents('#fancybox-content').offset().top - target.outerHeight() - tooltip.outerHeight() - 35 + $('#fancybox-content').scrollTop(); 2205 } else { 2206 pos_top = target.offset().top - target.parents('#fancybox-content').offset().top + target.outerHeight() - 20; 2207 tooltip.addClass( 'top' ); 2208 } 2209 } 2210 } else { 2211 tooltip.removeClass( 'top' ); 2212 } 2213 2214 if (tooltip.hasClass('top')) { 2215 var top_animate = '-=10'; 2216 } else { 2217 var top_animate = '+=10'; 2218 } 2219 2220 if (target.parents(".control-label, .control-group").length) { 2221 pos_left = target.offset().left - 40; 2222 pos_top = target.offset().top + 5 - target.parents('#fancybox-content').offset().top + $('#fancybox-content').scrollTop() + $('.js-form_builder_modal').parent().scrollTop(); 2223 tooltip.addClass("top left"); 2224 tooltip.css( { left: pos_left, top: pos_top, "z-index": 999999999999999999, 'pointer-events': 'none' } ) 2225 .animate( { top: top_animate, opacity: 1 }, 300 ); 2226 } else { 2227 tooltip.css( { left: pos_left, top: pos_top } ) 2228 .animate( { opacity: 1 }, 300 ); 2229 } 2230
2231 if (append_target == 'body') { 2232 tooltip.css('z-index','9000'); 2233 } 2234 }; 2235 2236 init_tooltip(); 2237 $( window ).resize( init_tooltip ); 2238 2239 target.bind( 'mouseleave', remove_tooltip ); 2240 tooltip.bind( 'click', remove_tooltip ); 2241 } 2242 2243 remove_tooltip = function() 2244 { 2245 if (tooltip) { 2246 if (tooltip.hasClass('top')) { 2247 var top_animate = '+=10'; 2248 } else { 2249 var top_animate = '-=10'; 2250 } 2251 2252 if (at1024flag) { 2253 $('.js-tooltip_window').animate( { opacity: 0 }, 300, function() { 2254 $( this ).remove(); 2255 }); 2256 } else { 2257 $('.js-tooltip_window').animate( { top: top_animate, opacity: 0 }, 300, function() { 2258 $( this ).remove(); 2259 }); 2260 } 2261 } 2262 2263 //target.attr( 'title', tip ); 2264 }; 2265 2266 targets.on( 'mouseover', '.js-tooltip', function(e) 2267 { 2268 //e.preventDefault(); 2269 tooltipFunction(this); 2270 }); 2271 2272 // syntax highlighting 2273 if (typeof(SyntaxHighlighter) != 'undefined') { 2274 SyntaxHighlighter.all(); 2275 } 2276 2277 // Inputs with default value (click to edit) 2278 // var input_with_default_containerClass = '.js-input_with_default'; 2279 // var input_with_default_editButtonClass = '.js-edit_button_input_with_default'; 2280 // var input_with_default_displayModeClass = '.js-display_input_with_default'; 2281 // var input_with_default_editModeClass = '.js-edit_input_with_default'; 2282 // input_with_default_init = function () { 2283 // $(input_with_default_editButtonClass).click(function () { 2284 // var parent = $(this).closest(input_with_default_containerClass); 2285 // parent.find(input_with_default_displayModeClass).hide(); 2286 // parent.find(input_with_default_editModeClass).show(); 2287 // }) 2288 // } 2289 // input_with_default_init(); 2290 2291 2292 // update reply-to default (AN-2230) 2293 // Simple JS to show how the Edit link will display the dropdown for multiple reply-to email address options 2294 input_reply_to_option_init = function () { 2295 $('body').on('click', '.js-edit_button_reply_to', function () { 2296 $(this).parents('.js-input_with_default').find('.js-display_input_reply_to_dropdown').addClass('flex').removeClass('hide'); 2297 $(this).parents('.js-input_with_default').find('.js-display_input_reply_to').hide(); 2298 $(this).hide(); 2299 }) 2300 // show notice if no reply-to emails are set 2301 $('body').on('click', '.js-edit_button_reply_to_blank', function () { 2302 alert(an_javascript_translation.no_verified_reply_to_emails_have_been_sent); 2303 }) 2304 } 2305 input_reply_to_option_init(); 2306 2307 2308 // AN-2240 2309 email_preview_count_init = function () { 2310 const maxChars = 280; // Maximum character count 2311 const noticeThreshold = 90; // When to display the notice 2312 2313 $(document).on('input', '.js-email_preview_count', function () { 2314 const charCount = $(this).val().length; 2315 const $container = $(this).closest('.js-preview_count_container'); 2316 const $countDisplay = $container.find('.js-preview_char_count'); 2317 const $notice = $container.find('.js-preview_count_notice'); 2318 2319 $countDisplay.text(`${charCount}/${maxChars}`); 2320 2321 if (charCount >= noticeThreshold) { 2322 $notice.addClass('warning'); 2323 } else { 2324 $notice.removeClass('warning'); 2325 } 2326 2327 if (charCount >= maxChars) { 2328 $notice.addClass('exceeded'); 2329 } else { 2330 $notice.removeClass('exceeded'); 2331 } 2332 }); 2333 } 2334 if ($('.js-email_preview_count').length > 0) { 2335 email_preview_count_init(); 2336 } 2337 2338 2339 // multiselects 2340 if ($.isFunction($.fn.select2)) { 2341 2342 $('body').on('select2-open', function() { 2343 //weird race somewhere so set focus a bit late 2344 setTimeout(function() { 2345 $('.select2-drop-active .select2-input').focus().select(); 2346 }, 100); 2347 2348 }); 2349 2350 multi_select_init = function() { 2351 $("select.js-multi_select").select2({ 2352 closeOnSelect: false, 2353 matcher: function (term, text, option) { 2354 if (term.length == 0) return true; 2355 2356 if(term.split(" ").length == 1){ 2357 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2358 } 2359 2360 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2361 // `data.text` is the text that is displayed for the data object 2362 // check if data.text contains all of keywords, if some is missing, return null 2363 for (var i = 0; i < keywords.length; i++) { 2364 2365 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2366 // Return `null` if the term should not be displayed 2367 return null; 2368 } 2369 // If here, data.text contains all keywords, so return it. 2370 return text; 2371 } 2372 2373 }); 2374 } 2375 2376 multi_select_init(); 2377 2378 add_tags_select_init = function($element, element_to_add) { 2379 // used to configure select2 dropdown as single select 2380 var isSingleSelectDropdown = $element.hasClass('js-singleselect') 2381 2382 if (isSingleSelectDropdown) { 2383 var select_tags_array_choice = [] 2384 if ($element.hasClass('js-select_tags_random')) { 2385 select_tags_array_choice = window['select_tags_array_' + $element.data('select_tags_random')] 2386 } else { 2387 select_tags_array_choice = select_tags_array; 2388 } 2389 2390 if (typeof(element_to_add) != 'undefined') { 2391 current_values = $element.select2('val'); 2392 $element.select2('destroy'); 2393 } else { 2394 current_values = select_tags_array_choice.filter(function (tag) { return tag.selected == true; }).map(function(tag) { return tag.id }); 2395 } 2396 2397 $element.select2({ 2398 data: select_tags_array_choice, 2399 separator: '@!@', 2400 multiple: !isSingleSelectDropdown, 2401 closeOnSelect: false, 2402 matcher: function (term, text, option) { 2403 if (term.length == 0) return true; 2404 2405 if(term.split(" ").length == 1){ 2406 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2407 } 2408 2409 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2410 // `data.text` is the text that is displayed for the data object 2411 // check if data.text contains all of keywords, if some is missing, return null 2412 for (var i = 0; i < keywords.length; i++) { 2413 2414 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2415 // Return `null` if the term should not be displayed 2416 return null; 2417 2418 } 2419 // If here, data.text contains all keywords, so return it. 2420 return text; 2421 } 2422 2423 }); 2424 2425 if (typeof(element_to_add) != 'undefined') { 2426 current_values = element_to_add 2427 } 2428 2429 $element.select2('val', current_values); 2430 } else { 2431 var select_tags_array_choice = [] 2432 if ($element.hasClass('js-select_tags_random')) { 2433 select_tags_array_choice = window['select_tags_array_' + $element.data('select_tags_random')] 2434 } else { 2435 select_tags_array_choice = select_tags_array; 2436 } 2437 //console.log(typeof(element_to_add)); 2438 if (typeof(element_to_add) != 'undefined') { 2439 current_values = $element.select2('data'); 2440 $element.select2('data',[]); 2441 $element.select2('destroy'); 2442 } else { 2443 current_values = select_tags_array_choice.filter(function (tag) { return tag.selected == true; }).map(function(tag) { return {"id": tag.id, "text": tag.id } }); 2444 } 2445 //console.log(current_values); 2446 //console.log(select_tags_array_choice); 2447 2448 //console.log(select_tags_array_choice); 2449 //debugger; 2450 2451 $element.select2({ 2452 data: select_tags_array_choice, 2453 separator: '@!@', 2454 multiple: !isSingleSelectDropdown, 2455 closeOnSelect: false, 2456 query : function (q) { 2457 // pageSize is number of results to show in dropdown 2458 var pageSize, 2459 results; 2460 pageSize = 500; 2461 results = $.grep(this.data, function (e) { 2462 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 2463 if (q.term.length == 0) return true; 2464 2465 if(q.term.split(" ").length == 1){ 2466 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 2467 } 2468 2469 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 2470 // `data.text` is the text that is displayed for the data object 2471 // check if data.text contains all of keywords, if some is missing, return null 2472 for (var i = 0; i < keywords.length; i++) { 2473 2474 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2475 // Return `null` if the term should not be displayed 2476 return null; 2477 2478 } 2479 // If here, data.text contains all keywords, so return it. 2480 return e; 2481 }); 2482 q.callback({ 2483 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 2484 // retrieve more when user hits bottom 2485 more : results.length >= q.page * pageSize 2486 }); 2487 2488 //console.log(q.term); 2489 //console.log(this.data); 2490 2491 2492 } 2493 2494 2495 }); 2496 2497 //console.log($element.select2('data')); 2498 2499 if (typeof(element_to_add) != 'undefined') { 2500 //console.log(element_to_add); 2501 current_values.push({"id": element_to_add, "text": element_to_add }); 2502 } 2503 //console.log(current_values); 2504 $element.select2('data', current_values); 2505 //console.log($element.select2('data')); 2506 //console.log($element.select2('val')); 2507 } 2508 //debugger; 2509 } 2510 2511 $(".js-add_tags_select").each(function() { 2512 add_tags_select_init($(this)); 2513 }); 2514 2515 2516 //currently unused 2517 $(".js-multi_select_tags").each(function() { 2518 var multi_select_tags = $(this).data('tags'); 2519 $(this).select2({ 2520 closeOnSelect: false, 2521 matcher: function (term, text, option) { 2522 if (term.length == 0) return true; 2523 2524 if(term.split(" ").length == 1){ 2525 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2526 } 2527 2528 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2529 // `data.text` is the text that is displayed for the data object 2530 // check if data.text contains all of keywords, if some is missing, return null 2531 for (var i = 0; i < keywords.length; i++) { 2532 2533 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2534 // Return `null` if the term should not be displayed 2535 return null; 2536 2537 } 2538 // If here, data.text contains all keywords, so return it. 2539 return text; 2540 }, 2541 tags: multi_select_tags, 2542 tokenSeparators: [","] 2543 2544 }); 2545 }); 2546 2547 // add select all search results and show/hide child groups links to select menus 2548 $('body').on('select2-open', '.js-multi_select, .js-dynamic_targeting_select, .js-groups_select, .js-tags_select, .js-letter-select-target', function() { 2549
2550 $('.js-select2-drop_controls-wrapper').remove(); 2551 2552 $('.select2-drop-multi.select2-drop-active').append('<div class="select2-drop_controls-wrapper js-select2-drop_controls-wrapper clearfix"><a href="javascript:void(0);" class="js-select2_select_all disabled" disabled="disabled">' + an_javascript_translation.select_all_search_results + '</a></div>'); 2553 2554 //add show/hide child group actions to correct selects 2555 if (($(this).attr('name') == "include[action][]" || $(this).attr('name') == "exclude[action][]" || $(this).attr('name') == "action") && ($('.js-include-network-li').css('display') == "block" || $('.rule-filter-container select option[value=network_groups]').length)) { 2556 $('.js-select2-drop_controls-wrapper').append('<a href="javascript:void(0);" class="js-multi_select_child_toggle multi_select_child_toggle js-multi_select_child_toggle-shown block">' + an_javascript_translation.hide_actions_from_child_groups + '</a>'); 2557 2558 $('.js-multi_select_child_toggle').click(function() { 2559 if ($(this).hasClass('js-multi_select_child_toggle-shown')) { 2560 $(this).text(an_javascript_translation.show_actions_from_child_groups).removeClass('js-multi_select_child_toggle-shown').addClass('js-multi_select_child_toggle-hidden'); 2561 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result').each(function() { 2562 if ($(this).data('select2Data').child) { 2563 $(this).hide(); 2564 } 2565 }); 2566 } else { 2567 $(this).text(an_javascript_translation.hide_actions_from_child_groups).removeClass('js-multi_select_child_toggle-hidden').addClass('js-multi_select_child_toggle-shown'); 2568 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result:hidden').show(); 2569 } 2570 2571 }); 2572 } 2573 2574 //add show/hide child group emails to correct selects 2575 if ( 2576 ( 2577 $(this).attr('name') == "include[email][]" || 2578 $(this).attr('name') == "exclude[email][]" || 2579 $(this).attr('name') == "email" || 2580 $(this).attr('name') == "include[mobile_message][]" || 2581 $(this).attr('name') == "exclude[email_message][]" || 2582 $(this).attr('name') == "message" || 2583 $(this).attr('name') == "include[email_open][]" || 2584 $(this).attr('name') == "exclude[email_open][]" || 2585 $(this).attr('name') == "email_openers" || 2586 $(this).attr('name') == "include[email_click][]" || 2587 $(this).attr('name') == "exclude[email_click][]" || 2588 $(this).attr('name') == "email_clickers" || 2589 $(this).attr('name') == "include[mobile_message_click][]" || 2590 $(this).attr('name') == "exclude[mobile_message_click][]" || 2591 $(this).attr('name') == "message_clickers" 2592 ) && ( 2593 $('.js-include-network-li').css('display') == "block" || 2594 $('.rule-filter-container select option[value=network_groups]').length 2595 ) 2596 ) { 2597 $('.js-select2-drop_controls-wrapper').append('<a href="javascript:void(0);" class="js-multi_select_child_toggle multi_select_child_toggle js-multi_select_child_toggle-shown block">' + an_javascript_translation.hide_emails_from_child_groups + '</a>'); 2598 2599 $('.js-multi_select_child_toggle').click(function() { 2600 if ($(this).hasClass('js-multi_select_child_toggle-shown')) { 2601 $(this).text(an_javascript_translation.show_emails_from_child_groups).removeClass('js-multi_select_child_toggle-shown').addClass('js-multi_select_child_toggle-hidden'); 2602 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result').each(function() { 2603 if ($(this).data('select2Data').child) { 2604 $(this).hide(); 2605 } 2606 }); 2607 } else { 2608 $(this).text(an_javascript_translation.hide_emails_from_child_groups).removeClass('js-multi_select_child_toggle-hidden').addClass('js-multi_select_child_toggle-shown'); 2609 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result:hidden').show(); 2610 } 2611 2612 }); 2613 } 2614 2615 // AN-2373 Add filter by sent date option to emails, email clickers, and email openers 2616 if ($(this).attr('name') == "include[email][]" || 2617 $(this).attr('name') == "exclude[email][]" || 2618 $(this).attr('name') == "email" || 2619 $(this).attr('name') == "include[email_open][]" || 2620 $(this).attr('name') == "exclude[email_open][]" || 2621 $(this).attr('name') == "email_openers" || 2622 $(this).attr('name') == "include[email_click][]" || 2623 $(this).attr('name') == "exclude[email_click][]" || 2624 $(this).attr('name') == "email_clickers" 2625 ) { 2626 const select2Dropdown = $(this); 2627 const modalContentSelector = '.js-ladder_modal'; 2628 const emailSentDateModalContentClass = 'js-email_sent_date_modal'; 2629 const emailSentDateModalSelector = `.${emailSentDateModalContentClass}`; 2630 const isInModal = select2Dropdown.closest(modalContentSelector).length > 0; 2631 const modalContentElement = select2Dropdown.closest(modalContentSelector); 2632 // Remove any previous modal HTML 2633 $(emailSentDateModalSelector).remove(); 2634 // Modal HTML 2635 const modalHTML = ` 2636 <div class="hide ${emailSentDateModalContentClass}"> 2637 <div id="email_sent_date_modal" class="small_modal"> 2638 <h4 class="entry-title mb20">${an_javascript_translation.select_emails_sent_within_a_date_range}</h4> 2639 <p>${an_javascript_translation.select_a_date_range_to_select_all_the_emails}</p> 2640 <div class="flex d-flex--align-center mb20"> 2641 <input type="date" class="js-email_sent_date_input js-email_sent_date_input_start nomb"> 2642 <div class="mt10 mb10 ml10 mr10 centertext"> ${an_javascript_translation.to} </div> 2643 <input type="date" class="js-email_sent_date_input js-email_sent_date_input_end nomb" value="${new Date().toISOString().split('T')[0]}"> 2644 </div> 2645 <a class="button js-email_sent_date_modal_apply disabled">${an_javascript_translation.choose_a_date_range}</a> 2646 <a class="button button-secondary js-email_sent_date_modal_cancel">${an_javascript_translation.cancel}</a> 2647 </div> 2648 </div> 2649 ` 2650 // Add the link and modal (unless already in modal) 2651 $('.js-select2-drop_controls-wrapper').append(` 2652 <a href="#email_sent_date_modal" class="fancylink js-fancylink js-email_sent_date_modal_link block"> 2653 ${an_javascript_translation.select_emails_sent_within_a_date_range} 2654 </a> 2655 ${isInModal ? '' : modalHTML} 2656 `); 2657 // Get currently selected emails before the dropdown closes 2658 let selectedEmails = select2Dropdown.select2('data') || []; 2659 let newSelections = []; 2660 // Get all options currently displayed in the select2 dropdown, before it closes 2661 const allEmailOpts = $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result').toArray().map(el => $(el).data('select2Data')); 2662 if (isInModal) { 2663 // If in modal, link shows the date filter content within the same modal 2664 modalContentElement.after(modalHTML); 2665 $('.js-email_sent_date_modal_link').on('click', function() { 2666 modalContentElement.hide(); 2667 $(emailSentDateModalSelector).show(); 2668 $('.js-email_sent_date_input_start').trigger('focus'); 2669 select2Dropdown.select2('close'); 2670 2671 // Reset modal if closed 2672 2673 }) 2674 $('.js-email_sent_date_modal_apply').on('click', function() { 2675 // Add new selections 2676 select2Dropdown.select2('data', selectedEmails.concat(newSelections)); 2677 }); 2678 $('.js-email_sent_date_modal_apply, .js-email_sent_date_modal_cancel').on('click', function() { 2679 modalContentElement.show(); 2680 $(emailSentDateModalSelector).hide(); 2681 }); 2682 } 2683 else { 2684 // Link opens modal 2685 $('.js-email_sent_date_modal_link').fancybox({ 2686 hideOnOverlayClick: false, 2687 onComplete: function() { 2688 // Focus the start date input when modal opens 2689 $('.js-email_sent_date_input_start').trigger('focus'); 2690 }, 2691 onClosed: function() { 2692 select2Dropdown.select2('close'); 2693 } 2694 }); 2695 $('.js-email_sent_date_modal_apply').on('click', function(e) { 2696 // Add new selections 2697 select2Dropdown.select2('data', selectedEmails.concat(newSelections)); 2698 $.fancybox.close(); 2699 }); 2700 $('.js-email_sent_date_modal_cancel').on('click', function() { 2701 $.fancybox.close(); 2702 }); 2703 } 2704 2705 $('.js-email_sent_date_modal_link').on('click', function() { 2706 // Get any new selections before closing the dropdown 2707 selectedEmails = select2Dropdown.select2('data') 2708 // Close the dropdown after clicking link 2709 select2Dropdown.select2('close'); 2710 }); 2711 2712 // Add change event to date inputs 2713 $('.js-email_sent_date_input_start, .js-email_sent_date_input_end').on('change', function() { 2714 if ($('.js-email_sent_date_input_start').val() && $('.js-email_sent_date_input_end').val()) { 2715 $('.js-email_sent_date_modal_apply').removeClass('disabled'); 2716 newSelections = []; 2717 const start = $('.js-email_sent_date_input_start').val(); 2718 const end = $('.js-email_sent_date_input_end').val();
2719 allEmailOpts.forEach(opt => { 2720 if (opt.send_date >= start && opt.send_date <= end) { 2721 newSelections.push(opt); 2722 } 2723 }); 2724 2725 $('.js-email_sent_date_modal_apply').html(`${an_javascript_translation.select} ${newSelections.length} ${an_javascript_translation.emails}`); 2726 } else { 2727 $('.js-email_sent_date_modal_apply').html(`${an_javascript_translation.choose_a_date_range}`); 2728 $('.js-email_sent_date_modal_apply').addClass('disabled'); 2729 } 2730 }); 2731 } 2732 2733 if ($('.select2-drop-multi.select2-drop-active').hasClass('select2-drop-above')) { 2734 $('.select2-drop-multi.select2-drop-active.select2-drop-above').css('top', parseInt($('.select2-drop-multi.select2-drop-active.select2-drop-above').css('top')) - $('.select2-drop-multi.select2-drop-active.select2-drop-above .js-select2-drop_controls-wrapper').height() + 1); 2735 } 2736 2737 var that = this; 2738 //console.log(that); 2739 2740 $('.select2-dropdown-open input').on('keyup.select2_search', function() { 2741 //console.log($(this)); 2742 if ($(this).val() != '') { 2743 $('.js-select2_select_all').removeClass('disabled').attr('disabled', false); 2744 if ($('.js-multi_select_child_toggle-hidden').length) { 2745 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result').each(function() { 2746 if ($(this).data('select2Data').child) { 2747 $(this).hide(); 2748 } 2749 }); 2750 } 2751 } else { 2752 $('.js-select2_select_all').addClass('disabled').attr('disabled', 'disabled'); 2753 } 2754 }); 2755 2756 $('.js-select2_select_all').click({that: that}, function(event) { 2757 //console.log(event.data.that); 2758 2759 if (!$(this).hasClass('disabled')) { 2760 $that = $(event.data.that); 2761 2762 var selected_array = $that.select2('data'); 2763 $('.select2-drop-multi.select2-drop-active .select2-results li.select2-result:visible').each(function() { 2764 if ($that.hasClass('js-letter-select-target')) { 2765 selected_array.push({ id: $(this).data('select2Data').id, text: $(this).data('select2Data').text, details: $(this).data('select2Data').details }); 2766 } else { 2767 selected_array.push({ id: $(this).data('select2Data').id, text: $(this).data('select2Data').text }); 2768 } 2769 2770 }); 2771 2772 2773 $that.select2("data", selected_array); 2774 $that.select2("close"); 2775 if ($('.js-single_include_exclude_section').length) { 2776 targeting_set_filters(false); 2777 } 2778 2779 } 2780 2781 2782 2783 }); 2784 }); 2785 2786 $('body').on('select2-open', '.js-multi_select_tags', function() { 2787 $('.js-select2-drop_controls-wrapper').remove(); 2788 2789 $('.select2-drop-multi.select2-drop-active').append('<div class="select2-drop_controls-wrapper js-select2-drop_controls-wrapper clearfix">'+ an_javascript_translation.choose_tags_or_type_a_new_one_to_create +'</div>'); 2790 }); 2791 2792 $('body').on('select2-close', '.js-multi_select, .js-multi_select_tags, .js-dynamic_targeting_select, .js-groups_select, .js-tags_select, .js-letter-select-target', function() { 2793 $('.select2-dropdown-open input').off('keyup.select2_search'); 2794 $('.js-select2_select_all').off('click'); 2795 $('.js-select2-drop_controls-wrapper').remove(); 2796 }); 2797 2798 var close_select2_function = function() { 2799 var close_flag = false; 2800 setTimeout(function() { 2801 2802 $('.select2-drop-active').each(function() { 2803 2804 if ($(this).css('display') == 'block') { 2805 //console.log('true'); 2806 close_flag = true; 2807 } 2808 2809 }); 2810 2811 if (close_flag) { 2812 $('.js-multi_select, .js-add_tags_select, .js-multi_select_tags, .js-targets-target_repository_switcher, .js-report_id, .js-file-file_repository_switcher, .js-email-email_list, .js-profile-form-group, .js-sponsor-group-select, .js-edit_profile_menu_group_homepage_select, .js-group_parent_drop, .js-donation_groups, .js-letter-select-target, .js-form_select2, .js-rung_tags_select, .js-form_select2.js-form_select2_nosearch, .js-dynamic_targeting_select, .js-action_lang_select, .js-question_tag_select, .js-query_import_select, .js-rung_actions_select, .js-rung_emails_select, .js-rung_mobile_select, .js-select_search, .js-append_search, .js-email_campaigns_existing_select, select.js-filter_jump_select, select.js-email_stat_select, .js-ec_bc_edit_host_form, .js-form_select2_uninitialized, .js-basejump_modal_group_select, .js-time_zone_select').each(function() { 2813 $(this).select2('close'); 2814 }); 2815 } 2816 }, 0); 2817 2818 } 2819 $('body').on('click', function() { 2820 close_select2_function(); 2821 }); 2822 2823 } 2824 2825 // Updated select2 init function 2826 select2_init = function($element, allowClear) { 2827 if (typeof($element.select2) != 'undefined') { 2828 $element.select2({ 2829 matcher: function (term, text, option) { 2830 if (term.length == 0) return true; 2831 2832 if(term.split(" ").length == 1){ 2833 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2834 } 2835 2836 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2837 // `data.text` is the text that is displayed for the data object 2838 // check if data.text contains all of keywords, if some is missing, return null 2839 for (var i = 0; i < keywords.length; i++) { 2840 2841 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2842 // Return `null` if the term should not be displayed 2843 return null; 2844 2845 } 2846 // If here, data.text contains all keywords, so return it. 2847 return text; 2848 }, 2849 allowClear: allowClear 2850 }); 2851 } 2852 2853 } 2854 2855 $('select.js-targets-target_repository_switcher, select.js-report_id, select.js-file-file_repository_switcher, select.js-email-email_list, select.js-profile-form-group, select.js-s
2855ponsor-group-select, select.js-edit_profile_menu_group_homepage_select, select.js-group_parent_drop, select.js-donation_groups, select.js-filter_jump_select').each(function(){ 2856 select2_init($(this), false); 2857 }); 2858 2859 2860 $('select.js-select_search').each(function(){ 2861 select2_init($(this), true); 2862 }); 2863 2864 /* ======================= start Tags ======================= */ 2865 //donation_return_flag = false; 2866 //submitClicked = 'add_tag'; 2867 //strip double white space from tag names 2868 $('body').on('change', '.js-tag_name', function() { 2869 $(this).val($(this).val().replace(/\s\s+/g, ' ')); 2870 }); 2871 2872 tags_sanitization = function(edit_or_add, $input) { 2873 //console.log(donation_return_flag); 2874 $input.removeClass('error_input'); 2875 if (edit_or_add == 'edit') { 2876 var pattern = /[!@#\$%\^&\*\(\)\+=\{\}\[\];:'"<>\.\?\/~`\\\|,]/; 2877 } else if (edit_or_add == 'add') { 2878 var pattern = /[!@#\$%\^&\*\(\)\+=\{\}\[\];:'"<>\.\?\/~`\\\|]/ // this one allows commas, the above does not! 2879 } 2880 //console.log($tag_edit.length); 2881 2882 if (pattern.test($input.val())) { 2883 //console.log('test'); 2884 2885 $input.addClass('error_input'); 2886 return false; 2887 } 2888 2889 2890 return true; 2891 } 2892 2893 $('body').on('click', '.js-tag_name_submit', function() { 2894 submitClicked = 'add_tag'; 2895 donation_return_flag = false; 2896 $(this).val($(this).val().replace(/\s\s+/g, ' ')); 2897 var $tag_edit = $(this).parents('form').find('.js-tag_name_edit'); 2898 var $tag_add = $(this).parents('form').find('.js-tag_name_add'); 2899 if ($tag_edit.length) { 2900 var tags_sanitization_result = tags_sanitization('edit', $tag_edit); 2901 } else if ($tag_add.length) { 2902 var tags_sanitization_result = tags_sanitization('add', $tag_add); 2903 } 2904 2905 if (!tags_sanitization_result) { 2906 return false; 2907 } 2908 }); 2909 2910 $('.js-add_tags_select.required').on('change', function() { 2911 if ($(this).val()) { 2912 $(this).removeClass('error_input') 2913 } 2914 }); 2915 2916 $('body').on('click', '.js-edit-syndicate-icon', function(e) { 2917 e.preventDefault; 2918 2919 var $that = $(this); 2920 //console.log($that.data('link')); 2921 $.get($that.data('link'), function(data) { 2922 $('body').append(data); 2923 2924 $that.removeClass('js-edit-syndicate-icon'); 2925 2926 $that.fancybox({ 2927 onComplete: function() { 2928 $modal = $(this.href); 2929 $modal.find('.js-multi_select').not('.select2-offscreen').select2({ 2930 placeholder: an_javascript_translation.click_to_make_your_selections, 2931 closeOnSelect: false, 2932 matcher: function (term, text, option) { 2933 if (term.length == 0) return true; 2934 2935 if(term.split(" ").length == 1){ 2936 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2937 } 2938 2939 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2940 // `data.text` is the text that is displayed for the data object 2941 // check if data.text contains all of keywords, if some is missing, return null 2942 for (var i = 0; i < keywords.length; i++) { 2943 2944 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2945 // Return `null` if the term should not be displayed 2946 return null; 2947 2948 } 2949 // If here, data.text contains all keywords, so return it. 2950 return text; 2951 } 2952 }); 2953 2954 $modal.find("select.js-form_select2").not('.select2-offscreen').select2({ 2955 allowClear: true, 2956 closeOnSelect: false, 2957 matcher: function (term, text, option) { 2958 if (term.length == 0) return true; 2959 2960 if(term.split(" ").length == 1){ 2961 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 2962 } 2963 2964 keywords=(term).split(/ |,|\[|\]|\(|\)/); 2965 // `data.text` is the text that is displayed for the data object 2966 // check if data.text contains all of keywords, if some is missing, return null 2967 for (var i = 0; i < keywords.length; i++) { 2968 2969 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 2970 // Return `null` if the term should not be displayed 2971 return null; 2972 2973 } 2974 // If here, data.text contains all keywords, so return it. 2975 return text; 2976 } 2977 }); 2978 2979 donation_return_flag = false; 2980 submitClicked_init(); 2981 canValidate(); 2982 $modal.find('.js-add_collection_tags').click(function() { 2983 $modal.find('.js-syndicate_tag_modal').fadeOut(function() { 2984 $modal.find('.js-apply_collection_modal').fadeIn(); 2985 }); 2986 }); 2987 2988 $modal.find('.js-tags_collection_add, .js-tags_collection_cancel').click(function() { 2989 $modal.find('.js-apply_collection_modal').fadeOut(function() { 2990 $modal.find('.js-syndicate_tag_modal').fadeIn(); 2991 }); 2992 }); 2993 2994 $modal.find('.js-tags_collection_add').click(function() { 2995 var array = $modal.find('select.js-collection_tags_apply').select2("val").split(',').map(function(e) { return e}).concat($modal.find('select.js-syndicate-select-group').select2("val")); 2996 2997 //console.log(array); 2998 2999 $modal.find('select.js-syndicate-select-group').select2("val", array); 3000 $modal.find('select.js-collection_tags_apply').select2("val", ''); 3001 }); 3002 3003 }, 3004 margin: 15, 3005 hideOnOverlayClick: false 3006 }).trigger('click'); 3007 3008 }); 3009 }); 3010 3011 /* ======================= end Tags ======================= */ 3012 3013 /* fly tags modals */ 3014 $('.js-fly_tags_button').click(function() { 3015 $add_tags_fly_sibling_select = $(this).parent().find('input.js-add_tags_select'); 3016 $(this).parents('.js-has_add_tags_fly_button').fadeOut(100, function() { 3017 $(this).parent().find('.js-add_tags_fly').show(); 3018 $.smoothScroll($(this).parent().find('.js-add_tags_fly').offset().top - 100); 3019 }); 3020 }); 3021 3022 $('.js-cancel_add_tags_fly, .js-save_add_tags_fly').click(function() { 3023 var isSingleSelectDropdown = $(this).hasClass('js-singleselect') 3024 3025 if ($(this).hasClass('js-save_add_tags_fly')) { 3026 var $input = $(this).parents('.js-add_tags_fly').find('.js-tags_fly_value'); 3027 var tags_sanitization_result = tags_sanitization('add', $input); 3028 //console.log(tags_sanitization); 3029 //if (tags_sanitization) { console.log('true')} else { console.log('false');} 3030 if (tags_sanitization_result) { 3031 var $select = $add_tags_fly_sibling_select; 3032 if ($input.val() != '') { 3033 var select_tags_array_choice = [] 3034 if ($select.hasClass('js-select_tags_random')) { 3035 select_tags_array_choice = window['select_tags_array_' + $select.data('select_tags_random')] 3036 } else { 3037 select_tags_array_choice = select_tags_array; 3038 } 3039 var tag_input_array = $input.val().split(',').map(function(x) { return x.trim() }); 3040 3041 $.each(tag_input_array, function(i, e) { 3042 if (select_tags_array_choice.filter(function (tag) { return tag.id == e; }).length) { 3043 //console.log('filter true'); 3044 3045 if (isSingleSelectDropdown) { 3046 var selected_array = $select.select2('val'); 3047 selected_array = e; 3048 $select.select2('val', selected_array); 3049 } else { 3050 var selected_array = $select.select2('data'); 3051 selected_array.push({"id": e, "text": e }); 3052 $select.select2('data', selected_array); 3053 } 3054 3055 3056 3057 } else { 3058 //console.log('filter false'); 3059 //console.log($select); 3060 if (isSingleSelectDropdown) { 3061 select_tags_array_choice.push({ 3062 "id": e, 3063 "text": e, 3064 "selected": true 3065 }); 3066 } 3067 add_tags_select_init($select, e); 3068 3069 } 3070 }); 3071 3072 var groupId = $(this).data("groupId"); 3073 3074 $.ajax({ 3075 url: '/api/groups/' + groupId + '/tags', 3076 method: 'POST', 3077 data: {name: $input.val()} 3078 }); 3079 } 3080 3081 $(this).parents('.js-add_tags_fly').fadeOut(function() { 3082 $(this).parent().find('.js-has_add_tags_fly_button').show(); 3083 $.smoothScroll($(this).parent().find('.js-has_add_tags_fly_button').offset().top - 100); 3084 }); 3085 3086 // if Create New Tag modal is standalone or first in modal sequence, clicking Save should close fancybox 3087 if ($(this).parents('.js-add_tags_fly').hasClass('js-first_in_modal_sequence')) { 3088 $.fancybox.close(); 3089 } 3090 } 3091 } else { 3092 $(this).parents('.js-add_tags_fly').find('.js-tags_fly_value').val(''); 3093 $(this).parents('.js-add_tags_fly').fadeOut(function() { 3094 $(this).parent().find('.js-has_add_tags_fly_button').show(); 3095 $.smoothScroll($(this).parent().find('.js-has_add_tags_fly_button').offset().top - 100); 3096 }); 3097 3098 // if Create New Tag modal is standalone or first in modal sequence, clicking Cancel should close fancybox 3099 if ($(this).parents('.js-add_tags_fly').hasClass('js-first_in_modal_sequence')) { 3100 $.fancybox.close(); 3101 } 3102 } 3103 }); 3104 3105 /* fly custom fields modals */ 3106 $('.js-fly_custom_fields_button').click(function() { 3107 $add_custom_fields_fly_sibling_select = $(this).parent().find('select.js-wait_field, select.js-wait_polling_locations_field, select.js-wait_early_vote_locations_field, select.js-wait_drop_off_locations_field, select.js-actblue_sync_field, select.js-form_testing_class'); 3108 $(this).parents('.js-has_add_custom_fields_fly_button').fadeOut(100, function() { 3109 $(this).parent().find('.js-add_custom_fields_fly').show(); 3110 $.smoothScroll($(this).parent().find('.js-add_custom_fields_fly').offset().top - 100); 3111 }); 3112 3113 }); 3114 3115 $('.js-cancel_add_custom_fields_fly, .js-save_add_custom_fields_fly').click(function() { 3116 3117 $(this).parents('.js-add_custom_fields_fly').fadeOut(function() { 3118 3119 $(this).parent().find('.js-has_add_custom_fields_fly_button').show(); 3120 $.smoothScroll($(this).parent().find('.js-has_add_custom_fields_fly_button').offset().top - 100); 3121 }); 3122 3123 if ($(this).hasClass('js-save_add_custom_fields_fly')) { 3124 var $input = $(this).parents('.js-add_custom_fields_fly').find('.js-cu
3124stom_fields_fly_value'); 3125 var input_val = $.trim($input.val()); 3126 var $select = $add_custom_fields_fly_sibling_select; 3127 if ($input.val() != '') { 3128 if ($select.find('option').filter(function () { return $(this).text().toLowerCase() == input_val.toLowerCase(); }).length) { 3129 $select.find('option').filter(function () { return $(this).text().toLowerCase() == input_val.toLowerCase(); }).attr('selected','true').trigger("change"); 3130 } else { 3131 $select.append('<option selected="true" value="' + input_val + '">' + input_val + '</option>').trigger("change"); 3132 } 3133 var groupId = $(this).data("groupId"); 3134 3135 $.ajax({ 3136 url: '/api/groups/' + groupId + '/custom_fields', 3137 method: 'POST', 3138 data: {field_name: input_val} 3139 }) 3140 } 3141 } 3142 3143 $(this).parents('.js-add_custom_fields_fly').find('.js-custom_fields_fly_value').val(''); 3144 3145 // if Create New Custom Field modal is standalone or first in modal sequence, clicking Cancel or Save should close fancybox 3146 if ($(this).parents('.js-add_custom_fields_fly').hasClass('js-first_in_modal_sequence')) { 3147 $.fancybox.close(); 3148 } 3149 3150 }); 3151 3152 /* fly email campaigns modals */ 3153 $('.js-fly_email_campaigns_button').click(function() { 3154 $add_email_campaigns_fly_sibling_select = $(this).parent().find('select.js-add_email_campaigns_select'); 3155 $(this).parents('.js-has_add_email_campaigns_fly_button').fadeOut(function() { 3156 //console.log($(this)); 3157 $(this).parent().find('.js-add_email_campaigns_fly').show(); 3158 $.smoothScroll($(this).parent().find('.js-add_email_campaigns_fly').offset().top - 100); 3159 }); 3160 3161 }); 3162 3163 $('.js-cancel_add_email_campaigns_fly, .js-save_add_email_campaigns_fly').click(function() { 3164 3165 $(this).parents('.js-add_email_campaigns_fly').fadeOut(function() { 3166 3167 $(this).parent().find('.js-has_add_email_campaigns_fly_button').show(); 3168 $.smoothScroll($(this).parent().find('.js-has_add_email_campaigns_fly_button').offset().top - 100); 3169 }); 3170 3171 if ($(this).hasClass('js-save_add_email_campaigns_fly')) { 3172 var $input = $(this).parents('.js-add_email_campaigns_fly').find('.js-email_campaigns_fly_value'); 3173 var $select = $add_email_campaigns_fly_sibling_select; 3174 if ($input.val() != '') { 3175 if ($select.find('option').filter(function () { return $(this).html() == $input.val(); }).length) { 3176 $select.find('option').filter(function () { return $(this).html() == $input.val(); }).attr('selected','true').trigger("change"); 3177 } else { 3178 $select.append('<option selected="true">' + $input.val() + '</option>').trigger("change"); 3179 } 3180 var groupId = $(this).data("groupId"); 3181 3182 $.ajax({ 3183 url: '/email_campaigns', 3184 method: 'POST', 3185 data: {name: $input.val()} 3186 }) 3187 } 3188 } 3189 3190 $(this).parents('.js-add_email_campaigns_fly').find('.js-email_campaigns_fly_value').val(''); 3191 3192 }); 3193 if ($('.js-email_campaigns_existing_select').length) { 3194 $('.js-email_campaigns_existing_select').select2( { 3195 data: existing_emails_array, 3196 multiple : true, 3197 closeOnSelect: false, 3198 // text for loading more results 3199 //formatLoadMore : 'Loading more...', 3200 query : function (q) { 3201 // pageSize is number of results to show in dropdown 3202 var pageSize, 3203 results; 3204 pageSize = 500; 3205 results = $.grep(this.data, function (e) { 3206 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 3207 if (q.term.length == 0) return true; 3208 3209 if(q.term.split(" ").length == 1){ 3210 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 3211 } 3212 3213 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 3214 // `data.text` is the text that is displayed for the data object 3215 // check if data.text contains all of keywords, if some is missing, return null 3216 for (var i = 0; i < keywords.length; i++) { 3217 3218 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 3219 // Return `null` if the term should not be displayed 3220 return null; 3221 3222 } 3223 // If here, data.text contains all keywords, so return it. 3224 return e; 3225 }); 3226 q.callback({ 3227 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 3228 // retrieve more when user hits bottom 3229 more : results.length >= q.page * pageSize 3230 }); 3231 3232 //console.log(q.term); 3233 //console.log(this.data); 3234 3235 3236 }, 3237 placeholder: an_javascript_translation.select_existing_emails 3238 }); 3239 } 3240 3241 /* Nested tabs init */ 3242 const nested_tabs_init = () => {
3243 $(".js-nested_tab_wrap .js-nested_tab").hide(); 3244 $(".js-nested_tab_wrap").each(function(i, tab) { 3245 $(tab).find(".js-nested_tab").first().show(); 3246 }); 3247 $(".js-tabs_nested a").on("click", function (e) { 3248 if (!$(this).hasClass('disabled')) { 3249 e.preventDefault(); 3250 if ($(this).attr("id") == "current"){ // detection for current tab 3251 return; 3252 } else { 3253 $(".js-nested_tab_wrap .js-nested_tab").hide(); 3254 $(".js-tabs_nested a").attr("id",""); 3255 $(this).attr("id","current"); // Activate this 3256 $($(this).attr('name')).fadeIn(); // Show content for current tab 3257 } 3258 3259 if ($(this).attr("name") == "#tab_stats_main") { 3260 $('.stats-filter__wrap').addClass('test'); 3261 } 3262 } 3263 }); 3264 3265 if (getURLParameter('sub_tab')) { 3266 //console.log($('.js-tabs_nested a[name=#' + getURLParameter('sub_tab') + ']')); 3267 $('.js-tabs_nested a[name=#' + getURLParameter('sub_tab') + ']').trigger('click'); 3268 } 3269 } 3270 3271 3272 3273 3274 // load mobile menu 3275/* 3276 if ($.isFunction($.fn.mobileMenu)) { 3277 $('.js-header_menu').mobileMenu(); 3278 } 3279*/ 3280 3281 $('.js-edit_profile_menu_group_homepage_button').click(function() { 3282 window.location.assign('/groups/' + $('.js-edit_profile_menu_group_homepage_select').find('option:selected').data('link') + '/set_root'); 3283 }); 3284 3285 // redesign 4 mobile menu 3286 $('.js-open-mobile-menu').click(function() { 3287 $('.js-mobile-nav-overlay').fadeIn(); 3288 }); 3289 $('.js-close-mobile-menu').click(function() { 3290 $('.js-mobile-nav-overlay').fadeOut(); 3291 }); 3292 // sub-menu 3293 $('.js-mobile-top-level-nav-link').click(function() { 3294 $(this).parent('.js-mobile-sub-menu').toggleClass('mobile-sub-menu-is-open').children('.sub-menu').slideToggle('200'); 3295 }); 3296 3297/* 3298 if (!$.browser.opera) { 3299 $('select.select-menu').each(function(){ 3300 var title = $(this).attr('title'); 3301 if( $('option:selected', this).val() != '' ) title = $('option:selected',this).text(); 3302 $(this) 3303 .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'}) 3304 .after('<span class="select">' + title + '</span>') 3305 .change(function(){ 3306 val = $('option:selected',this).text(); 3307 $(this).next().text(val); 3308 }) 3309 }); 3310 }; 3311*/ 3312 3313 /* Just smooth scrolling to make stuff awesome */ 3314 if ($.isFunction($.fn.smoothScroll)) { 3315 // Only attach to <a> or <a.button> that do NOT have .js-no_smooth_scroll 3316 $('a').not('.js-zendesk a, .js-no_smooth_scroll, a.js-no_smooth_scroll').smoothScroll(); 3317 $('a.js-scroll_header_offset').not('.js-no_smooth_scroll').smoothScroll({offset: -200}); 3318 } 3319 3320 3321 /* basic search for help page */ 3322 lined_filter_function = function() { 3323 if ($.isFunction($.fn.listfilter)) { 3324 $("ul.js-lined").listfilter({ 3325 'filter': $('input.js-filter') 3326 }); 3327 } 3328 } 3329 3330 lined_filter_function(); 3331 3332 3333 /* close facebook share redirect after share */ 3334 if (getURLParameter('post_id')) { 3335 window.close(); 3336 // if window doesn't close, redirect to direct link page 3337 if ($('.js-fb_after_share_redirect').val()) { 3338 window.location = $('.js-fb_after_share_redirect').val(); 3339 } 3340 } 3341 3342 3343 3344 /* add/remove creator on actions */ 3345 3346 if ($('.js-creator_toggle').val() == '0') { 3347 $('.js-no_creator_box').show(); 3348 $('.js-creator_box').hide(); 3349 $('.js-action_owner-select select').addClass('required'); 3350 } else { 3351 $('.js-no_creator_box').hide(); 3352 $('.js-creator_box').show(); 3353 $('.js-action_owner-select select').removeClass('required'); 3354 } 3355 3356 $('.js-remove_owner').click(function() { 3357 $('.js-creator_box').fadeOut(function() { 3358 $('.js-no_creator_box').fadeIn(); 3359 }); 3360 3361 $('.js-creator_toggle').val('0'); 3362 $('.js-action_owner-select select').addClass('required'); 3363 }); 3364 3365 $('.js-add_owner').click(function() { 3366 $('.js-no_creator_box').fadeOut(function() { 3367 $('.js-creator_box').fadeIn(); 3368 $('.js-custom_creator').val(''); 3369 }); 3370 $('.js-creator_toggle').val('1'); 3371 $('.js-action_owner-select select').removeClass('required error_input'); 3372 $('.js-action_owner-select div.js-error_input-select_wrap').removeClass('js-error_input-select_wrap error_input-select_wrap'); 3373 }); 3374 3375 3376 /* fix double underscore issue */ 3377 $('.js-new_list_title, .js-action_title').on('keyup', function() { 3378 if (/__/.test($(this).val())) { 3379 $(this).val($(this).val().replace('__', '_')); 3380 } 3381 }); 3382 3383 /* New upload modal */ 3384 3385 3386 3387 // Show all options 3388 $('.js-upload_show_uncommon').click(function(){ 3389 $('.js-upload_uncommon_option').removeClass('hide'); 3390 $('.js-upload_show_uncommon').hide(); 3391 }) 3392 3393 /* unpublish scheduling on actions */ 3394 3395 $('.js-clear_schedule_unpublish').click(function (e) { 3396 e.preventDefault(); 3397 $('.js-unpublish_action').attr('checked', false);
3398 $('.js-schedule_unpublish_date').slideUp(150); 3399 $('.js-schedule_unpublish_date input').removeClass('required'); 3400 $('.js-save_unpublish_never').show(); 3401 $('.js-save_unpublish_immediate').hide(); 3402 $('.js-save_unpublish_scheduled').hide(); 3403 }) 3404 3405 // Update UI when radios change 3406 $('.js-unpublish_action').change(function (e) { 3407 var element = e.target; 3408 3409 // Show/hide schedule date 3410 if (element.value == 'unpublish_schedule') { 3411 $('.js-schedule_unpublish_date').slideDown(150); 3412 $('.js-schedule_unpublish_date input').addClass('required'); 3413 } 3414 else { 3415 $('.js-schedule_unpublish_date').slideUp(150); 3416 $('.js-schedule_unpublish_date input').removeClass('required'); 3417 } 3418 3419 // Change action buttons 3420 if (element.value == 'unpublish_never') { 3421 $('.js-save_unpublish_never').show(); 3422 $('.js-save_unpublish_immediate').hide(); 3423 $('.js-save_unpublish_scheduled').hide(); 3424 } 3425 else { 3426 $('.js-save_unpublish_never').hide(); 3427 if (element.value == 'unpublish_schedule') { 3428 $('.js-save_unpublish_immediate').hide(); 3429 $('.js-save_unpublish_scheduled').show(); 3430 } 3431 else { 3432 $('.js-save_unpublish_immediate').show(); 3433 $('.js-save_unpublish_scheduled').hide(); 3434 } 3435 } 3436 }) 3437 3438 3439 /* ======================= Syndication/Collections ============================= */ 3440 3441 /* syndication and collections targets section */ 3442 3443 if ($('.js-syndicate_group_list_wrap').length) { 3444 3445 $('.js-button_target_add').click(function() { 3446 var selection_json = []; 3447 //gotta make sure to carry along all the details through this process 3448 if ($('select.js-syndicate-select-group').val().length) { 3449 $.each($('select.js-syndicate-select-group').val(), function(i, e) { 3450 selection_json.push({ 3451 "name": $('select.js-syndicate-select-group option[value="' + e + '"]').html().replace(/ /g, ''), 3452 "value": e 3453 }); 3454 }); 3455 addToGroupSelection(selection_json); 3456 $('select.js-syndicate-select-group').select2('data', null); 3457 } 3458 3459 }); 3460 3461 $('.js-button_target_all').click(function() { 3462 var selection_json = []; 3463 $.each($('.js-syndicate-select-group option'), function(i, e) { 3464 selection_json.push({ 3465 "name": $(e).html().replace(/ /g, ''), 3466 "value": $(e).val() 3467 }); 3468 }); 3469 addToGroupSelection(selection_json); 3470 }); 3471 3472 $('.js-button_target_clear').click(function() { 3473 //clear out the list 3474 group_syndication_list.clear(); 3475 3476 //if there's nothing left, add default and clear search 3477 if (!group_syndication_list.get().length) { 3478 group_syndication_list.add({ listjs_name: an_javascript_translation.no_groups_are_selected }); 3479 3480 group_syndication_list.search(); 3481 $('.js-list_search_wrap .js-search').val('') 3482 } 3483 3484 //cleanup 3485 if (group_syndication_list.get("listjs_name", an_javascript_translation.no_groups_are_selected).length) { 3486 $('.js-syndicate_group_list li').addClass('empty'); 3487 } 3488 3489 prepForSavingGroups(); 3490 3491 }); 3492 3493 3494 function addToGroupSelection(json) { 3495 //array for holding new items 3496 var listjs_values_group = []; 3497 3498 //if this is the first item, clear out the list 3499 if (group_syndication_list.get("listjs_name", an_javascript_translation.no_groups_are_selected).length) { 3500 group_syndication_list.clear(); 3501 } 3502 3503 //go through each result to add, check if it's already there, and if not add it to the new items array 3504 $.each(json, function(i, json_item) { 3505 if (!group_syndication_list.get("listjs_id", json_item.value).length) { 3506 listjs_values_group.push({ listjs_name: json_item.name, listjs_id: json_item.value }); 3507 3508 } 3509 }); 3510 3511 //if we have new items, add them and resort/search 3512 if (listjs_values_group.length) { 3513 group_syndication_list.add(listjs_values_group); 3514 group_syndication_list.sort('listjs_name', { order: "asc" }); // Sorts the list in abc-order based on names 3515 group_syndication_list.search($('.js-list_search_wrap .js-search').val()); 3516 3517 //add click handlers and cleanup 3518 $('.js-group_remove').off('click').click(function() { 3519 removeFromGroupSelection(this); 3520 }); 3521 } 3522 3523 //if there's nothing left, add default and clear search 3524 if (!group_syndication_list.get().length) { 3525 group_syndication_list.add({ listjs_name: an_javascript_translation.no_groups_are_selected }); 3526 3527 group_syndication_list.search(); 3528 $('.js-list_search_wrap .js-search').val('') 3529 } 3530 3531 //cleanup 3532 if (group_syndication_list.get("listjs_name", an_javascript_translation.no_groups_are_selected).length) { 3533 $('.js-syndicate_group_list li').addClass('empty'); 3534 } 3535 3536 prepForSavingGroups() 3537 } 3538 3539 function removeFromGroupSelection(target) { 3540 3541 //pop from the list 3542 var remove_text = $(target).parent().find('.js-listjs_id').html().toString(); 3543 //console.log(remove_text); 3544 //console.log(group_syndication_list);
3545 group_syndication_list.remove("listjs_id", remove_text); 3546 3547 //if there's nothing left, add default and clear search 3548 if (!group_syndication_list.get().length) { 3549 group_syndication_list.add({ listjs_name: an_javascript_translation.no_groups_are_selected}); 3550 3551 group_syndication_list.search(); 3552 $('.js-list_search_wrap .js-search').val('') 3553 } 3554 3555 //cleanup 3556 if (group_syndication_list.get("listjs_name", an_javascript_translation.no_groups_are_selected).length) { 3557 $('.js-syndicate_group_list li').addClass('empty'); 3558 } 3559 3560 $('.js-group_remove').off('click').click(function() { 3561 removeFromGroupSelection(this); 3562 }); 3563 3564 prepForSavingGroups(); 3565 3566 } 3567 3568 function prepForSavingGroups() { 3569 var group_selection_array = []; 3570 3571 $.each(group_syndication_list.get(), function(i, e) { 3572 group_selection_array.push(e._values.listjs_id); 3573 }); 3574 //console.log(group_selection_array); 3575 3576 $('.js-group_syndication_selection').val(group_selection_array); 3577 3578 if ($('.js-group_syndication_selection').val() == '') { 3579 syndication_targets_error_flag = true; 3580 } else { 3581 $('.js-syndicate_group_list_wrap .empty').removeClass('error_input'); 3582 syndication_targets_error_flag = false; 3583 } 3584 3585 } 3586 3587 var listjs_options_group = { 3588 valueNames: [ 'listjs_name', 'listjs_id' ], 3589 page: 25, 3590 plugins: [ ListPagination({}) ], 3591 item: '<li class="clearfix"><span class="single_group block hundred-140 left"><span class="listjs_name"></span> <span class="listjs_id js-listjs_id"></span></span><a href="javascript:void(0)" class="group_remove js-group_remove fs-14"><i class="far fa-times"></i> ' + an_javascript_translation.remove + '</a></li>' 3592 }; 3593 3594 group_syndication_list = {};
3595 var listjs_initial_values_group = [ { listjs_name: an_javascript_translation.no_groups_are_selected, id: '' } ]; 3596 3597 group_syndication_list = new List('syndicate_group_list_wrap', listjs_options_group, listjs_initial_values_group); 3598 3599 if (group_syndication_list.get("listjs_name", an_javascript_translation.no_groups_are_selected).length) { 3600 $('.js-syndicate_group_list li').addClass('empty'); 3601 } 3602 3603 //add click handler after searching and paging events 3604 var page_function = function() { 3605 $('.js-group_remove').click(function() { 3606 removeFromGroupSelection(this); 3607 }); 3608 } 3609 3610 group_syndication_list.on('paged', page_function); 3611 group_syndication_list.on('searchComplete', page_function); 3612 3613 //load saved targets 3614 if ($('.js-group_syndication_selection').val() != '') { 3615 var selection_json = []; 3616 $.each($('.js-group_syndication_selection').val().split(','), function(i, e) { 3617 selection_json.push({ 3618 "name": $('.js-syndicate-select-group option[value="' + e + '"]').html().replace(/ /g, ''), 3619 "value": e 3620 }); 3621 }); 3622 addToGroupSelection(selection_json); 3623 } 3624 } 3625 3626 3627 // collections JS 3628 3629 // report sub/unsubs and duplicate wrappers collections 3630 $('.js-add_collection_reports').click(function() { 3631 $('.js-report_subscribe_modal').fadeOut(function() { 3632 $('.js-report_subscribe_collection_modal').fadeIn(); 3633 }); 3634 3635 }); 3636 3637 3638 3639 $('.js-report_subscribe_collection_add, .js-report_subscribe_collection_cancel').click(function() { 3640 $('.js-report_subscribe_collection_modal').fadeOut(function() { 3641 $('.js-report_subscribe_modal').fadeIn(); 3642 }); 3643 3644 }); 3645 3646 3647 3648 $('.js-add_collection_reports_unsub').click(function() { 3649 $('.js-report_unsubscribe_modal').fadeOut(function() { 3650 $('.js-report_unsubscribe_collection_modal').fadeIn(); 3651 }); 3652 3653 }); 3654 3655 $('.js-report_unsubscribe_collection_add, .js-report_unsubscribe_collection_cancel').click(function() { 3656 $('.js-report_unsubscribe_collection_modal').fadeOut(function() { 3657 $('.js-report_unsubscribe_modal').fadeIn(); 3658 }); 3659 3660 }); 3661 3662 $('.js-add_collection_duplicate').click(function() { 3663 $('.js-duplicate_modal').fadeOut(function() { 3664 $('.js-duplicate_collection_modal').fadeIn(); 3665 }); 3666 3667 }); 3668 3669 $('.js-duplicate_collection_add, .js-duplicate_collection_cancel').click(function() { 3670 $('.js-duplicate_collection_modal').fadeOut(function() { 3671 $('.js-duplicate_modal').fadeIn(); 3672 }); 3673 3674 }); 3675 3676 3677 3678 $('.js-report_subscribe_collection_add').click(function() { 3679 var array = $(this).parents('.js-subscribe_all_modal_wrap').find('select.js-collections_apply_subscribe').select2("val").split(',').map(function(e) { return "group/" + e}).concat($(this).parents('.js-subscribe_all_modal_wrap').find('select.js-groups_subscribe').select2("val")); 3680 3681 $(this).parents('.js-subscribe_all_modal_wrap').find('select.js-groups_subscribe').select2("val", array); 3682 $(this).parents('.js-subscribe_all_modal_wrap').find('select.js-collections_apply_subscribe').select2("val", ''); 3683 }); 3684 3685 $('.js-report_unsubscribe_collection_add').click(function() { 3686 var array = $(this).parents('.js-unsubscribe_all_modal_wrap').find('select.js-collections_apply_unsubscribe').select2("val").split(',').map(function(e) { return "group/" + e}).concat($(this).parents('.js-unsubscribe_all_modal_wrap').find('select.js-groups_unsubscribe').select2("val")); 3687 3688 $(this).parents('.js-unsubscribe_all_modal_wrap').find('select.js-groups_unsubscribe').select2("val", array); 3689 $(this).parents('.js-unsubscribe_all_modal_wrap').find('select.js-collections_apply_unsubscribe').select2("val", ''); 3690 }); 3691 3692 $('.js-duplicate_collection_add').click(function() { 3693 var array = $(this).parents('.js-duplicate_modal_wrap').find('select.js-collections_apply_duplicate').select2("val").split(',').concat($(this).parents('.js-duplicate_modal_wrap').find('select.js-duplicate_select').select2("val")); 3694 3695 $(this).parents('.js-duplicate_modal_wrap').find('select.js-duplicate_select').select2("val", array); 3696 $(this).parents('.js-duplicate_modal_wrap').find('select.js-collections_apply_duplicate').select2("val", ''); 3697 }); 3698 3699 3700 // ladder sub/unsub 3701 $('.js-add_collection_ladders').click(function() { 3702 $(this).parents('.js-ladder_modal_create').fadeOut(function() { 3703 $('.js-ladders_collection_modal').fadeIn(); 3704 }); 3705 3706 }); 3707 3708 $('.js-ladders_collection_add, .js-ladders_collection_cancel').click(function() { 3709 $('.js-ladders_collection_modal').fadeOut(function() { 3710 $(this).parent().find('.js-ladder_modal_create').fadeIn(); 3711 }); 3712 3713 }); 3714 3715 $('body').on('click', '.js-ladders_collection_add', function() { 3716 var array = $('select.js-collection_ladder_sub_apply').select2("val").split(',').concat($('select.js-groups_select').select2("val")); 3717 3718 $('select.js-groups_select').select2("val", array); 3719 $('select.js-collection_ladder_sub_apply').select2("val", ''); 3720 }); 3721 3722 3723 //queries/ladder queries 3724 var $queries_add_collection_parent = {}; 3725 3726 $('body').on('click', '.js-add_collection', function() { 3727 $queries_add_collection_parent = $(this).siblings('input.js-network_group'); 3728 //console.log($queries_add_collection_parent); 3729 if ($('.js-apply_collection_modal').length && $('.js-ladders-edit').length) { 3730 $('.js-builder').fadeOut(function() { 3731 $('.js-builder').parent().find('.js-apply_collection_modal').fadeIn(); 3732 }); 3733 } 3734 }); 3735 3736 $('body').on('click', '.js-queries_add_collection', function() { 3737 var select2data = $queries_add_collection_parent.data().select2.opts.data; 3738 if ($('select.js-queries_collection_apply').length) { 3739 var array = $('select.js-queries_collection_apply').val().split(',').concat($queries_add_collection_parent.select2("val")); 3740 } else { 3741 var array = $('input.js-queries_collection_apply').val().split(',').concat($queries_add_collection_parent.select2("val")); 3742 } 3743 3744 3745 var recursive_array_selection = function(selected_array) { 3746 $.each(selected_array, function(i, e) { 3747 if (array.indexOf(e.id) != -1) { 3748 e.selected = "true" 3749 } else { 3750 delete e.selected; 3751 } 3752 3753 if (e.children && e.children.length) { 3754 recursive_array_selection(e.children); 3755 } 3756 }); 3757 3758 3759 } 3760 3761 recursive_array_selection(select2data); 3762 3763 var selected_array = []; 3764 3765 var create_selected_array = function(select_data) { 3766 $(select_data).each(function() { 3767 //console.log(this); 3768 if (this.selected == "true") { 3769 //console.log('true'); 3770 selected_array.push({"id": this.id, "text": this.text}); 3771 } else if (this.children && this.children.length) { 3772 create_selected_array(this.children); 3773 } 3774 }); 3775 } 3776 3777 create_selected_array(select2data); 3778 3779 $queries_add_collection_parent.select2("data", selected_array); 3780 $('.js-queries_collection_apply').select2("val", ''); 3781 3782 if ($('.js-apply_collection_modal').length && $('.js-ladders-edit').length) { 3783 $('.js-apply_collection_modal').fadeOut(function() { 3784 $('.js-builder').fadeIn(); 3785 }); 3786 } else { 3787 $.fancybox.close(); 3788 } 3789 }); 3790 3791 $('body').on('click', '.js-queries_collection_cancel', function() { 3792 $('.js-queries_collection_apply').select2("val", ''); 3793 if ($('.js-apply_collection_modal' && $('.js-ladders-edit').length).length) { 3794 $('.js-apply_collection_modal').fadeOut(function() { 3795 $('.js-builder').fadeIn(); 3796 }); 3797 } else { 3798 $.fancybox.close(); 3799 } 3800 }); 3801 3802 3803 //report targeting 3804 $('.js-add_collection').not('.js-ladders-edit .js-add_collection').fancybox({ 3805 onClosed: function() { 3806 $('.js-report_collections_select').each(function() { 3807 $(this).select2("val",''); 3808 }); 3809 }, 3810 margin: 15, 3811 hideOnOverlayClick: false 3812 }); 3813 3814 var recursive_array_selection = function(selected_array, array) { 3815 $.each(selected_array, function(i, e) { 3816 if (array.indexOf(e.id) != -1) { 3817 e.selected = "true" 3818 } else { 3819 delete e.selected; 3820 } 3821 3822 if (e.children && e.children.length) { 3823 recursive_array_selection(e.children, array); 3824 } 3825 }); 3826 3827 3828 } 3829 3830 var create_selected_array = function(select_data) { 3831 var array = []; 3832 $(select_data).each(function() { 3833 //console.log(this); 3834 if (this.selected == "true") { 3835 //console.log('true'); 3836 array.push({"id": this.id, "text": this.text}); 3837 } else if (this.children && this.children.length) { 3838 create_selected_array(this.children); 3839 } 3840 }); 3841 3842 return array; 3843 } 3844 3845 $('.js-report_collections_include_add').click(function() { 3846 var select2data = $('.js-include-network-li input.js-hidden-targeting-select').data().select2.opts.data; 3847 var array = $('input.js-report_collections_include_select').select2("val").split(',').concat($('.js-include-network-li input.js-hidden-targeting-select').select2("val")); 3848 3849 recursive_array_selection(select2data, array); 3850 3851 var selected_array = create_selected_array(select2data); 3852 3853 $('.js-include-network-li input.js-hidden-targeting-select').select2("data", selected_array); 3854 3855 targeting_set_filters(false); 3856 3857 $.fancybox.close(); 3858 }); 3859 3860 $('.js-report_collections_exclude_add').click(function() { 3861 var select2data = $('.js-exclude-network-li input.js-hidden-targeting-select').data().select2.opts.data; 3862 var array = $('input.js-report_collections_exclude_select').select2("val").split(',').concat($('.js-exclude-network-li input.js-hidden-targeting-select').select2("val")); 3863 3864 recursive_array_selection(select2data, array); 3865 3866 var selected_array = create_selected_array(select2data); 3867 3868 $('.js-exclude-network-li input.js-hidden-targeting-select').select2("data", selected_array); 3869 3870 targeting_set_filters(false); 3871 3872 $.fancybox.close(); 3873 }); 3874 3875 $('.js-report_collections_include_open_add').click(function() { 3876 var select2data = $('.js-include-email_open_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3877 var array = $('input.js-report_collections_include_open_select').select2("val").split(',').concat($('.js-include-email_open_children-li input.js-hidden-targeting-select').select2("val")); 3878 3879 recursive_array_selection(select2data, array); 3880 3881 var selected_array = create_selected_array(select2data); 3882 3883 $('.js-include-email_open_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3884 3885 targeting_set_filters(false); 3886 3887 $.fancybox.close(); 3888 }); 3889 3890 $('.js-report_collections_include_click_add').click(function() { 3891 var select2data = $('.js-include-email_click_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3892 var array = $('input.js-report_collections_include_click_select').select2("val").split(',').concat($('.js-include-email_click_children-li input.js-hidden-targeting-select').select2("val")); 3893 3894 recursive_array_selection(select2data, array); 3895 3896 var selected_array = create_selected_array(select2data); 3897 3898 $('.js-include-email_click_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3899 3900 targeting_set_filters(false); 3901 3902 $.fancybox.close(); 3903 }); 3904 3905 $('.js-report_collections_include_received_add').click(function() { 3906 var select2data = $('.js-include-email_received_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3907 var array = $('input.js-report_collections_include_received_select').select2("val").split(',').concat($('.js-include-email_received_children-li input.js-hidden-targeting-select').select2("val")); 3908 3909 recursive_array_selection(select2data, array); 3910 3911 var selected_array = create_selected_array(select2data); 3912 3913 $('.js-include-email_received_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3914 3915 targeting_set_filters(false); 3916 3917 $.fancybox.close(); 3918 }); 3919 3920 $('.js-report_collections_include_mobile_click_add').click(function() { 3921 var select2data = $('.js-include-mobile_message_click_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3922 var array = $('input.js-report_collections_include_mobile_click_select').select2("val").split(',').concat($('.js-include-mobile_message_click_children-li input.js-hidden-targeting-select').select2("val")); 3923 3924 recursive_array_selection(select2data, array); 3925 3926 var selected_array = create_selected_array(select2data); 3927 3928 $('.js-include-mobile_message_click_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3929 3930 targeting_set_filters(false); 3931 3932 $.fancybox.close(); 3933 }); 3934 3935 $('.js-report_collections_exclude_open_add').click(function() { 3936 var select2data = $('.js-exclude-email_open_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3937 var array = $('input.js-report_collections_exclude_open_select').select2("val").split(',').concat($('.js-exclude-email_open_children-li input.js-hidden-targeting-select').select2("val")); 3938 3939 recursive_array_selection(select2data, array); 3940 3941 var selected_array = create_selected_array(select2data); 3942 3943 $('.js-exclude-email_open_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3944 3945 targeting_set_filters(false); 3946 3947 $.fancybox.close(); 3948 }); 3949 3950 $('.js-report_collections_exclude_received_add').click(function() { 3951 var select2data = $('.js-exclude-email_received_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3952 var array = $('input.js-report_collections_exclude_received_select').select2("val").split(',').concat($('.js-exclude-email_received_children-li input.js-hidden-targeting-select').select2("val")); 3953 3954 recursive_array_selection(select2data, array); 3955 3956 var selected_array = create_selected_array(select2data); 3957 3958 $('.js-exclude-email_received_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3959 3960 targeting_set_filters(false); 3961 3962 $.fancybox.close(); 3963 }); 3964 3965 $('.js-report_collections_exclude_click_add').click(function() { 3966 var select2data = $('.js-exclude-email_click_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3967 var array = $('input.js-report_collections_exclude_click_select').select2("val").split(',').concat($('.js-exclude-email_click_children-li input.js-hidden-targeting-select').select2("val")); 3968 3969 recursive_array_selection(select2data, array); 3970 3971 var selected_array = create_selected_array(select2data); 3972 3973 $('.js-exclude-email_click_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3974 3975 targeting_set_filters(false); 3976 3977 $.fancybox.close(); 3978 }); 3979 3980 $('.js-report_collections_exclude_mobile_click_add').click(function() { 3981 var select2data = $('.js-exclude-mobile_message_click_children-li input.js-hidden-targeting-select').data().select2.opts.data; 3982 var array = $('input.js-report_collections_exclude_mobile_click_select').select2("val").split(',').concat($('.js-exclude-mobile_message_click_children-li input.js-hidden-targeting-select').select2("val")); 3983 3984 recursive_array_selection(select2data, array); 3985 3986 var selected_array = create_selected_array(select2data); 3987 3988 $('.js-exclude-mobile_message_click_children-li input.js-hidden-targeting-select').select2("data", selected_array); 3989 3990 targeting_set_filters(false); 3991 3992 $.fancybox.close(); 3993 }); 3994 3995 //syndication groups 3996 3997 $('body').on('click', '.js-syndication_collection_add', function() { 3998 var array = $('select.js-collection_syndication_apply').select2("val").split(',').concat($('select.js-syndicate-select-group').select2("val")); 3999 4000 $('select.js-syndicate-select-group').select2("val", array); 4001 $('select.js-collection_syndication_apply').select2("val", ''); 4002 4003 $.fancybox.close(); 4004 }); 4005 4006 /* ======================= Sponsors Management ======================= */ 4007 4008 4009 $('.js-algorithm_switch_wrap .js-switch-toggle').click(function(e) { 4010 4011 var confirmation = confirm(an_javascript_translation.about_to_change_sharing_modes); 4012 4013 if (confirmation != true) { 4014 e.preventDefault(); 4015 } else { 4016 if ($(this).hasClass('js-switch-enabled')) { 4017 4018 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 4019 var $disabled = $(this).parent().find('.js-switch_disabled_label'); 4020 var $enabled = $(this).parent().find('.js-switch_enabled_label'); 4021 4022 $disabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 4023 $enabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label'); 4024 4025 } else { 4026 4027 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 4028 var $disabled = $(this).parent().find('.js-switch_enabled_label'); 4029 var $enabled = $(this).parent().find('.js-switch_disabled_label'); 4030 4031 $disabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label');
4031 4032 $enabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 4033 4034 } 4035 4036 } 4037 4038 }); 4039 4040 4041 // Activate remove submissions link on activists table 4042 4043 4044 $('.js-checkbox__input--all').click(function(){ 4045 $('.js-checkbox__input').not(this).prop('checked', this.checked); 4046 }); 4047 4048 var remove_submissions_toggle = function() { 4049 if( $('.js-checkbox__input').is(":checked") ) { 4050 $('.js-remove_submissions').prop('disabled', false); 4051 } else { 4052 $('.js-remove_submissions').prop('disabled', true); 4053 } 4054 } 4055 4056 $('.js-checkbox__input, .js-checkbox__input--all').change(function() { 4057 remove_submissions_toggle(); 4058 }); 4059 4060 remove_submissions_toggle(); 4061 4062 4063 4064 4065 /* ======================= Letter Management ======================= */ 4066 4067 // Count steps on letter campaigns and update final breadcrumb number value 4068 var numVersions = $('.js-step--tab-version').length; 4069 4070 $('.js-step--tab-count').text( numVersions + 2 ); 4071 4072 $('.js-test_mode_bar .js-switch-toggle').click(function() { 4073 4074 if ($(this).hasClass('js-switch-enabled')) { 4075 4076 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 4077 $(this).parent().parent().removeClass('in_test_mode js-in_test_mode'); 4078 $(this).siblings('.js-switch_enabled_label').hide(); 4079 $(this).siblings('.js-switch_disabled_label').show(); 4080 4081 } else { 4082 4083 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 4084 $(this).parent().parent().addClass('in_test_mode js-in_test_mode'); 4085 $(this).siblings('.js-switch_disabled_label').hide(); 4086 $(this).siblings('.js-switch_enabled_label').show(); 4087 } 4088 4089 }); 4090 4091 $('.js-modal_captcha_trigger').fancybox({ 4092 modal: true, 4093 margin: 15, 4094 hideOnOverlayClick: false 4095 }); 4096 4097 $('.js-modal_captcha_trigger').trigger('click'); 4098 4099 /* recaptcha image checkbox selection */ 4100 4101 $('.js-recaptcha_checkbox').on('click', function() { 4102 var selected_array = []; 4103 4104 if ($(this).hasClass('js-recaptcha_checkbox_selected')) { 4105 $(this).removeClass('recaptcha_checkbox_selected js-recaptcha_checkbox_selected') 4106 } else { 4107 $(this).addClass('recaptcha_checkbox_selected js-recaptcha_checkbox_selected') 4108 } 4109 4110 $('.js-recaptcha_checkbox_selected').each(function() { 4111 selected_array.push($(this).data('value')); 4112 }); 4113 4114 $('.js-recaptcha_response').val(selected_array.join(',')); 4115 4116 }); 4117 4118 /* letter targets modal */ 4119 4120 if ($('.js-letter_select_targets_modal').length) { 4121 4122 //modal ui 4123 $('.js-letter-select-target').select2({ 4124 multiple: true, 4125 placeholder: an_javascript_translation.search_for_targets_to_add, 4126 minimumInputLength: 1, 4127 closeOnSelect: false, 4128 dropdownAutoWidth: true, 4129 ajax: { // instead of writing the function to execute the request we use Select2's convenient helper 4130 url: permalink, 4131 dataType: 'json', 4132 quietMillis: 500, 4133 data: function (term) { 4134 return { 4135 q: term // search term 4136 }; 4137 }, 4138 results: function (data) { 4139// console.log(data); 4140 var results = []; 4141 $.each(data.results, function(index, item) { 4142 var is_canada = item.country && item.country === 'CA'; 4143 4144 if (item.party != '') { 4145 let position = item.position; 4146 let last_part = item.district; 4147 if (is_canada) { 4148 position = an_javascript_translation.canadian + ' ' + position; 4149 last_part = item.state + ' - ' + item.district; 4150 } 4151 var txt = item.name + ' [' + position + ' - ' + item.party + ' - ' + last_part + ']'; 4152 results.push({ 4153 id: item.id, 4154 details: JSON.stringify(item), 4155 text: txt 4156 }); 4157 } else if (item.state != '' && item.state != null) { 4158 results.push({ 4159 id: item.id, 4160 details: JSON.stringify(item), 4161 text: item.name + ' [' + item.position + ' - ' + item.state + ']' 4162 }); 4163 } else { 4164 results.push({ 4165 id: item.id, 4166 details: JSON.stringify(item), 4167 text: item.name + ' [' + item.position + ']' 4168 }); 4169 } 4170 }); 4171 return { 4172 results: results 4173 }; 4174 } 4175 }, 4176 formatSelection: function(data) {
4177 return '<div data-details="' + encodeURI(data.details) +'" id="' + data.id + '">' + data.text + '</div>'; 4178 } 4179 }); 4180 4181// $('.js-button_target_add').click(function() { 4182// console.log('one'); 4183// var selection_json = []; 4184// //gotta make sure to carry along all the details through this process 4185// if ($('input.js-letter-select-target').val().length) { 4186// $.each($('input.js-letter-select-target').val().split(','), function(i, e) { 4187// selection_json.push(JSON.parse(decodeURI($('#s2id_letter-select-target #' + e).data('details')))); 4188// }); 4189// addToLetterSelection(selection_json); 4190// prepForSavingTargets(false); 4191// $('input.js-letter-select-target').select2('data', null); 4192// } 4193// 4194// }); 4195 4196 4197// $('.js-letter_states').click(function() { 4198// if ($('select.js-letter-select-state').val()) { 4199// $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4200// $.getJSON(permalink + "?state=" + $('select.js-letter-select-state').val().toString().replace(',','+'), function(data) { 4201// addToLetterSelection(data.results); 4202// $('.js-letter_states').removeClass('disabled').val(an_javascript_translation.add_states).attr('disabled',false); 4203// }) 4204// .error(function() { 4205// $('.js-letter_states').removeClass('disabled').val(an_javascript_translation.add_states).attr('disabled',false); 4206// }); 4207// 4208// $('select.js-letter-select-state').select2('data', null); 4209// } 4210// }); 4211 4212 // AN-2041 4213 4214 // Disabling the "Add Selected" button unless a selection is made 4215 var $selects = $('.js-letter_select_targets_modal input.js-letter-select-target, .js-letter_select_targets_modal .js-letter-select-party input, .js-letter_select_targets_modal select.js-letter-select-state'); 4216 var $input = $('.js-letter_select_targets_modal .js-button_target_add'); 4217 4218 $selects.on('change', function () { 4219 var anySelectHasValue = $selects.filter(function () { 4220 return $(this).val() !== ''; 4221 }).length > 0; 4222 4223 if (anySelectHasValue) { 4224 $input.removeClass('disabled'); 4225 } else { 4226 $input.addClass('disabled'); 4227 } 4228 }); 4229 4230 $selects.on('change', function () { 4231 // if we remove a value, disable the button again 4232 var allSelectsAreEmpty = $selects.filter(function () { 4233 return $(this).val() === ''; 4234 }).length === $selects.length; 4235 4236 if (allSelectsAreEmpty) { 4237 $input.addClass('disabled'); 4238 } 4239 }); 4240 4241 $('.js-letter_select_targets_modal .js-button_target_add').click(function() { 4242 //console.log('two'); 4243 var selection_json = []; 4244 //gotta make sure to carry along all the details through this process 4245 if ($('.js-letter_select_targets_modal input.js-letter-select-target').val().length) { 4246 $.each($('.js-letter_select_targets_modal input.js-letter-select-target').val().split(','), function(i, e) { 4247 selection_json.push(JSON.parse(decodeURI($('#s2id_letter-select-target #' + e).data('details')))); 4248 }); 4249 addToLetterSelection(selection_json); 4250 prepForSavingTargets(false); 4251 } 4252 4253 if ($('.js-letter_select_targets_modal select.js-letter-select-state').val() || $('.js-letter_select_targets_modal select.js-letter-select-party').val()) { 4254 //$(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4255 if ($('select.js-letter-select-state').val() != '' && $('select.js-letter-select-state').val() != null) { 4256 var state_query_string = $('select.js-letter-select-state').val().toString(); 4257 } else { 4258 var state_query_string = ""; 4259 } 4260 4261 if ($('select.js-letter-select-party').val() != '' && $('select.js-letter-select-party').val() != null) { 4262 var party_query_string = $('select.js-letter-select-party').val().toString(); 4263 } else { 4264 var party_query_string = ""; 4265 } 4266 4267 var link = permalink 4268 + "?state=" + state_query_string 4269 + "&party=" + party_query_string 4270 4271 var $that = $(this); 4272 $that.addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true) 4273 $.getJSON(link, function(data) { 4274 addToLetterSelection(data.results); 4275 prepForSavingTargets(false); 4276 //console.log($(this)); 4277 $that.removeClass('disabled').val(an_javascript_translation.add_selected).attr('disabled',false); 4278 }) 4279 .error(function() { 4280 $that.removeClass('disabled').val(an_javascript_translation.add_selected).attr('disabled',false); 4281 }); 4282 4283 4284 4285 4286 } 4287
4288 $('.js-letter_select_targets_modal input.js-letter-select-target').select2('data', null); 4289 $('.js-letter_select_targets_modal select.js-letter-select-state').select2('data', null); 4290 $('.js-letter_select_targets_modal select.js-letter-select-party').select2('data', null); 4291 4292 // disable button after adding 4293 //$(this).addClass('disabled'); 4294 4295 }); 4296 4297 // End AN-2041 4298 4299 4300 4301 $('.js-button_target_all').click(function() { 4302 var confirmation = confirm(an_javascript_translation.targets_add_all_confirmation); 4303 4304 if (confirmation != true) { 4305 return false; 4306 } 4307 $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4308 $.getJSON(permalink, function(data) { 4309 addToLetterSelection(data.results); 4310 $('.js-button_target_all').removeClass('disabled').val(an_javascript_translation.add_all).attr('disabled',false); 4311 prepForSavingTargets(false); 4312 }).error(function() { 4313 $('.js-button_target_all').removeClass('disabled').val(an_javascript_translation.add_all).attr('disabled',false); 4314 prepForSavingTargets(false); 4315 }); 4316 4317 4318 }); 4319 4320// $('.js-letter_all-dems').click(function() { 4321// $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4322// $.getJSON(permalink + "?party=democrat", function(data) { 4323// addToLetterSelection(data.results); 4324// $('.js-letter_all-dems').removeClass('disabled').val(an_javascript_translation.democrats).attr('disabled',false); 4325// }).error(function() { 4326// $('.js-letter_all-dems').removeClass('disabled').val(an_javascript_translation.democrats).attr('disabled',false); 4327// }); 4328// }); 4329// 4330// $('.js-letter_all-repubs').click(function() { 4331// $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4332// $.getJSON(permalink + "?party=republican", function(data) { 4333// addToLetterSelection(data.results); 4334// $('.js-letter_all-repubs').removeClass('disabled').val(an_javascript_translation.republicans).attr('disabled',false); 4335// }).error(function() { 4336// $('.js-letter_all-repubs').removeClass('disabled').val(an_javascript_translation.republicans).attr('disabled',false); 4337// }); 4338// }); 4339// 4340// $('.js-letter_all-indies').click(function() { 4341// $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4342// $.getJSON(permalink + "?party=independent", function(data) { 4343// addToLetterSelection(data.results); 4344// $('.js-letter_all-indies').removeClass('disabled').val(an_javascript_translation.independents_other).attr('disabled',false); 4345// }).error(function() { 4346// $('.js-letter_all-indies').removeClass('disabled').val(an_javascript_translation.independents_other).attr('disabled',false); 4347// }); 4348// }); 4349 4350 4351 4352 $('.js-letter_select_targets_modal .js-button_target_clear').click(function() { 4353 4354 var confirmation = confirm(an_javascript_translation.targets_clear_all_confirmation); 4355 4356 if (confirmation != true) { 4357 return false; 4358 } 4359 //clear out the list 4360 target_list.clear(); 4361 4362 var listCount = target_list.get().length; 4363 //console.log(listCount); 4364 // update target count 4365 $('.js-letter_select_targets_modal .js-target_count').text(listCount); 4366 4367 //if there's nothing left, add default and clear search 4368 if (!target_list.get().length) { 4369 target_list.add({ listjs_name: an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets, generic_badge: '' }); 4370 4371 target_list.search(); 4372 $('.js-add_letter_targets_wrap .js-search').val('') 4373 } 4374 4375 4376 4377 //cleanup 4378 4379 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4380 $('.js-letter_target_list li').addClass('empty'); 4381 } 4382 4383 prepForSavingTargets(false); 4384 4385 4386 4387 }); 4388 4389// function getPartyOfficials(party) { 4390// let ref = '.js-letter_all-'+party; 4391// let label = $(ref).val(); 4392// $(ref).on('click', function() { 4393// $(this).addClass('disabled').val(an_javascript_translation.loading).attr('disabled',true); 4394// let URL = permalink + "?party="+party; 4395// $.getJSON(URL, function(data) { 4396// addToLetterSelection(data.results); 4397// $(ref).removeClass('disabled').val(label).attr('disabled',false); 4398// }).error(function() { 4399// $(ref).removeClass('disabled').val(label).attr('disabled',false); 4400// }); 4401// }); 4402// } 4403//
4404// getPartyOfficials('liberal'); 4405// getPartyOfficials('conservative'); 4406// getPartyOfficials('bloc'); 4407// getPartyOfficials('ndp'); 4408// getPartyOfficials('ca_other'); 4409 4410 function addToLetterSelection(json) { 4411 //array for holding new items 4412 var listjs_values_letter = []; 4413 4414 //if this is the first item, clear out the list 4415 4416 //console.log(target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets)); 4417 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4418 target_list.clear(); 4419 } 4420 4421 //go through each result to add, check if it's already there, and if not add it to the new items array 4422 $.each(json, function(i, json_item) { 4423 if (!target_list.get("listjs_id", json_item.id).length) { 4424 let position = json_item.position; 4425 let last_part = json_item.district; 4426 if (json_item.party != '') { 4427 var is_canada = json_item.country && json_item.country === 'CA'; 4428 if (is_canada) { 4429 position = an_javascript_translation.canadian + ' ' + position; 4430 if (json_item.state != '') { 4431 last_part = json_item.state + ' - ' + last_part; 4432 } 4433 } 4434 listjs_values_letter.push({ listjs_name: json_item.name, generic_badge: position + " - " + json_item.party + " - " + last_part, listjs_id: json_item.id }); 4435 } else if (position == null || position == '') { 4436 listjs_values_letter.push({ listjs_name: json_item.name, generic_badge: json_item.state, listjs_id: json_item.id }); 4437 } else if (json_item.state != '' && json_item.state != null) { 4438 listjs_values_letter.push({ listjs_name: json_item.name, generic_badge: position + " - " + json_item.state, listjs_id: json_item.id }); 4439 } else { 4440 listjs_values_letter.push({ listjs_name: json_item.name, generic_badge: position, listjs_id: json_item.id }); 4441 } 4442 } 4443 }); 4444 4445 //if we have new items, add them and resort/search 4446 if (listjs_values_letter.length) { 4447 target_list.add(listjs_values_letter); 4448 target_list.sort('listjs_name', { order: "asc" }); // Sorts the list in abc-order based on names 4449 target_list.search($('.js-add_letter_targets_wrap .js-search').val()); 4450 4451 //add click handlers and cleanup 4452 $('.js-letter_target_remove').off('click').click(function() { 4453 removeFromLetterSelection(this); 4454 }); 4455 } 4456 4457 //if there's nothing left, add default and clear search 4458 if (!target_list.get().length) { 4459 target_list.add({ listjs_name: an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets, generic_badge: '' }); 4460 4461 target_list.search(); 4462 $('.js-add_letter_targets_wrap .js-search').val('') 4463 } 4464 4465 // AN-2041: update count when list items added and remove disabled class from clear button 4466 var listCount = target_list.get().length; 4467 //console.log(listCount); 4468 // update target count 4469 $('.letter_targets_modal--updated .js-target_count').text(listCount); 4470 4471 if (listCount > 0) { 4472 $('.letter_targets_modal--updated .js-button_target_clear').removeClass('disabled'); 4473 } 4474 4475 //cleanup 4476 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4477 $('.js-letter_target_list li').addClass('empty'); 4478 } 4479 4480 4481 } 4482 4483 function removeFromLetterSelection(target) { 4484 4485 //pop from the list 4486 var remove_text = $(target).parent().find('.listjs_id').html().toString(); 4487 target_list.remove("listjs_id", remove_text); 4488 4489 //if there's nothing left, add default and clear search 4490 if (!target_list.get().length) { 4491 target_list.add({ listjs_name: an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets, generic_badge: '' }); 4492 4493 target_list.search(); 4494 $('.js-add_letter_targets_wrap .js-search').val('') 4495 } 4496 4497 // AN-2041: update count when list is cleared 4498 var listCount = target_list.get().length; 4499 // update target count 4500 $('.letter_targets_modal--updated .js-target_count').text(listCount); 4501 4502 if (listCount === 0) { 4503 $('.letter_targets_modal--updated .js-button_target_clear').addClass('disabled'); 4504 } 4505 4506 prepForSavingTargets(false); 4507 4508 //cleanup 4509 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4510 $('.js-letter_target_list li').addClass('empty'); 4511 } 4512 4513 4514
4515 $('.js-letter_target_remove').off('click').click(function() { 4516 removeFromLetterSelection(this); 4517 }); 4518 4519 } 4520 4521 function prepForSavingTargets(first_run) { 4522 //console.log('prep'); 4523 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4524 if (!first_run) { 4525 $('.js-target_count').html('0'); 4526 $('.js-target_count_empty').show(); 4527 $('.js-target_count_full').hide(); 4528 } 4529 } else { 4530 //console.log('if'); 4531 if (!first_run) { 4532 //console.log('2nd if'); 4533 $('.js-target_count').html(target_list.get().length); 4534 $('.js-target_count_empty').hide(); 4535 $('.js-target_count_full').show(); 4536 } 4537 } 4538 4539 if ($('.js-target_selection_input').val() == '') { 4540 letter_targets_error_flag = true; 4541 } else { 4542 $('.js-target_count_wrap').removeClass('error_input'); 4543 letter_targets_error_flag = false; 4544 } 4545 4546 $('.js-create_action_form').trigger('checkform.areYouSure'); 4547 } 4548 4549 if ($('.js-target_count').length) { 4550 if ($('.js-target_count').html() == "0") { 4551 $('.js-target_count_empty').show(); 4552 $('.js-target_count_full').hide(); 4553 } else { 4554 $('.js-target_count_empty').hide(); 4555 $('.js-target_count_full').show(); 4556 } 4557 } 4558 4559 var listjs_options_letter = { 4560 valueNames: [ 'listjs_name', 'generic_badge', 'listjs_id' ], 4561 page: 100, 4562 plugins: [ ListPagination({}) ], 4563 item: '<li class="clear clearfix"><span class="letter_single_target js-letter_single_target"><span class="listjs_name"></span> <span class="generic_badge"></span> <span class="listjs_id"></span></span><a href="javascript:void(0)" class="fs-14 letter_target_remove js-letter_target_remove"><i class="far fa-times"></i> ' + an_javascript_translation.remove + '</a></li>' 4564 }; 4565 4566 target_list = {};
4567 var listjs_initial_values_letter = [ { listjs_name: an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets, generic_badge: '', id: '' } ]; 4568 4569 target_list = new List('add_letter_targets_wrap', listjs_options_letter, listjs_initial_values_letter); 4570 4571 if (target_list.get("listjs_name", an_javascript_translation.no_targets_are_selected_use_the_controls_above_to_add_targets).length) { 4572 $('.js-letter_target_list li').addClass('empty'); 4573 } 4574 4575 //add click handler after searching and paging events 4576 var page_function = function() { 4577 $('.js-letter_target_remove').click(function() { 4578 removeFromLetterSelection(this); 4579 }); 4580 } 4581 4582 target_list.on('paged', page_function); 4583 target_list.on('searchComplete', page_function); 4584 4585 //load saved targets 4586 if (typeof(results) !== 'undefined') { 4587 if (results.results.length) { 4588 addToLetterSelection(results.results); 4589 //$('#create_action_form').trigger('reinitialize.areYouSure'); 4590 prepForSavingTargets(true); 4591 } 4592 } 4593 4594 $('.js-select_targets_modal_button').fancybox({ 4595 onClosed: function() { 4596 var target_selection_array = []; 4597 4598 $.each(target_list.get(), function(i, e) {
4599 target_selection_array.push(e._values.listjs_id); 4600 }); 4601 4602 $('body').removeClass('form_builder_edit'); 4603 4604 $('.js-target_selection_input').val(target_selection_array.toString().replace(/,/g,' ')); 4605 4606 prepForSavingTargets(false); 4607 4608 }, 4609 onComplete: function() { 4610 $('body').addClass('body_has_modal'); 4611 }, 4612 margin: 15, 4613 hideOnOverlayClick: false 4614 }); 4615 4616 if ($('.js-letter_template_editable').length && !$('.js-letter_template_editable:checked').length) { 4617 $('.js-letter_template_subject, .js-letter_template_message').addClass('required'); 4618 $('.js-letter_template_subject').attr('placeholder',$('.js-letter_template_subject').attr('placeholder').replace('('+ an_javascript_translation.optional + ')','*')); 4619 $('.js-letter_template_message').attr('placeholder',$('.js-letter_template_message').attr('placeholder').replace('('+ an_javascript_translation.optional + ')','*')); 4620 } else { 4621 $('.js-letter_template_subject, .js-letter_template_message').removeClass('required'); 4622 } 4623 4624 $('.js-letter_template_subject').parent().find('.floatlabel-label').text($('.js-letter_template_subject').attr('placeholder')); 4625 $('.js-letter_template_message').parent().find('.floatlabel-label').text($('.js-letter_template_message').attr('placeholder')); 4626 4627 $('.js-letter_template_editable').on('change', function() { 4628 if (!$('.js-letter_template_editable:checked').length) { 4629 $('.js-letter_template_subject, .js-letter_template_message').addClass('required'); 4630 $('.js-letter_template_subject').attr('placeholder',$('.js-letter_template_subject').attr('placeholder').replace('('+ an_javascript_translation.optional + ')','*')); 4631 $('.js-letter_template_message').attr('placeholder',$('.js-letter_template_message').attr('placeholder').replace('('+ an_javascript_translation.optional + ')','*')); 4632 } else { 4633 $('.js-letter_template_subject, .js-letter_template_message').removeClass('required'); 4634 $('.js-letter_template_subject').attr('placeholder',$('.js-letter_template_subject').attr('placeholder').replace('*','('+ an_javascript_translation.optional + ')')); 4635 $('.js-letter_template_message').attr('placeholder',$('.js-letter_template_message').attr('placeholder').replace('*','('+ an_javascript_translation.optional + ')')); 4636 4637 4638 } 4639 4640 $('.js-letter_template_subject').parent().find('.floatlabel-label').text($('.js-letter_template_subject').attr('placeholder')); 4641 $('.js-letter_template_message').parent().find('.floatlabel-label').text($('.js-letter_template_message').attr('placeholder')); 4642 }); 4643 } 4644 4645 function targetListAjax(val, user) { 4646 $.ajax({ 4647 url: permalink_target_list + '?source_id=' + val + '&user=' + user, 4648 dataType: 'html', 4649 type: 'GET', 4650 cache: false 4651 }) 4652 .done(function(data) { 4653 var prev_val = $('select.js-letter_target').val(); 4654 $('select.js-letter_target').val(''); 4655 $('select.js-letter_target').html(data); 4656 4657 $('select.js-letter_target option').each(function(i, e) { 4658 $.each(prev_val, function(i2, e2) { 4659 if ($(e).attr('value') == e2) { 4660 $(e).attr('selected',true); 4661 } 4662 }); 4663 }); 4664 4665 //$('.js-action_target .can_selectInner').html($('select.js-letter_target option:selected').html()); 4666 4667 4668 $('select.js-letter_target').trigger('render').select2('val', $('select.js-letter_target').val()); 4669 if (typeof(built_in_target_core_field_toggle_function) != 'undefined') { 4670 built_in_target_core_field_toggle_function($('select.js-letter_target')); 4671 } 4672 }) 4673 .error(function() { 4674 var prev_val = $('select.js-letter_target').val(); 4675 4676 $('select.js-letter_target').html('' 4677 + '<option value="">'+ an_javascript_translation.something_went_wrong_loading_custom_lists + '</option>'); 4678 4679 $('select.js-letter_target option').each(function(i, e) { 4680 if ($(e).attr('value') == prev_val) { 4681 $(e).attr('selected',true); 4682 } else { 4683 $(e).attr('selected',false); 4684 } 4685 }); 4686 4687 //$('.js-action_target .can_selectInner').html($('select.js-letter_target option:selected').html()); 4688 $('select.js-letter_target').trigger('render').select2('val', $('select.js-letter_target').val()); 4689 if (typeof(built_in_target_core_field_toggle_function) != 'undefined') { 4690 built_in_target_core_field_toggle_function($('select.js-letter_target')); 4691 } 4692 }); 4693 } 4694 4695 // step 1 target change test 4696 if ($('select.js-letter_target').length && !$('.js-must_login').length) { 4697 var target_val = $('select.js-letter_target').val(); 4698 var target_text = $('select.js-letter_target option:selected').text(); 4699 //target_change = false;
4700 4701/* 4702 $('select.js-letter_target').on('change', function () { 4703 if ($(this).val() != target_val && target_val != '') { 4704 alert('Changing your target list and saving will clear any targets you have selected on your letter versions. To avoid clearing your targets, either don\'t save this page or set your target list back to "' + target_text + '".'); 4705 } 4706 }); 4707*/ 4708 $('select.js-call_target').on('change', function () { 4709 $.post($('.js-create_action_form').attr('action')+"/save_target_list", $('.js-create_action_form').serialize()); 4710 var html_for_target_list = ''; 4711 var selected_array = $(this).val(); 4712 4713 $('.js-letter-select-targeting-group_ul').html(''); 4714 if (selected_array.length) { 4715 var $selected_options = $('select.js-call_target option').filter(function() { 4716 return selected_array.includes($(this).val()); 4717 }); 4718 4719 //console.log($selected_options); 4720 4721 $selected_options.each(function() { 4722 $('.js-letter-select-targeting-group_ul').append('<li><div class="letter-select-target-group-selected">' + $(this).text() + '</div></li>'); 4723 }); 4724 } 4725 4726 4727 }); 4728 4729 if ($('select.js-call-campaign_call_campaign_phone_number').length) { 4730 if ($('select.js-call-campaign_call_campaign_phone_number option:selected').data('permalink')) { 4731 $('.js-phone_number_in_use-link').attr('href', $('select.js-call-campaign_call_campaign_phone_number option:selected').data('permalink') ).text($('select.js-call-campaign_call_campaign_phone_number option:selected').data('title')); 4732 $('.js-phone_number_in_use-alert').show(); 4733 } else { 4734 $('.js-phone_number_in_use-alert').hide(); 4735 } 4736 4737 $('select.js-call-campaign_call_campaign_phone_number').on('change', function () { 4738 if ($('select.js-call-campaign_call_campaign_phone_number option:selected').data('permalink')) { 4739 $('.js-phone_number_in_use-link').attr('href', $('select.js-call-campaign_call_campaign_phone_number option:selected').data('permalink') ).text($('select.js-call-campaign_call_campaign_phone_number option:selected').data('title')); 4740 $('.js-phone_number_in_use-alert').show(); 4741 4742 } else { 4743 $('.js-phone_number_in_use-alert').hide(); 4744 } 4745 }); 4746 } 4747 4748 4749 4750 if (typeof($('select.js-sponsor-group-select').val()) !== 'undefined') { 4751 var val = $('select.js-sponsor-group-select').val(); 4752 } else { 4753 var val = ''; 4754 } 4755 4756 4757 4758 if ($('.js-creator_toggle').val() == 1){ 4759 var user = 'true'; 4760 } else { 4761 var user = ''; 4762 } 4763 4764 //if (!$('select.js-letter_target').hasClass('syndicated_letter')) { 4765 targetListAjax(val, user); 4766 //} 4767 4768 4769 // step 1 sponsor dropdown ajax load 4770 $('select.js-sponsor-group-select').on('change', function() { 4771 //console.log('change'); 4772 var val = $(this).val(); 4773 4774 if ($('.js-creator_toggle').val() == 1){ 4775 var user = 'true'; 4776 } else { 4777 var user = ''; 4778 } 4779 4780 if (!$('select.js-letter_target').hasClass('js-syndicated_letter')) { 4781 targetListAjax(val, user); 4782 } 4783 4784 4785 }); 4786 4787 $('.js-remove_owner, .js-add_owner').click(function() { 4788 var val = $('select.js-sponsor-group-select').val(); 4789 4790 if ($('.js-creator_toggle').val() == 1){ 4791 var user = 'true'; 4792 } else { 4793 var user = ''; 4794 } 4795 4796 if (!$('select.js-letter_target').hasClass('js-syndicated_letter')) { 4797 targetListAjax(val, user); 4798 } 4799 }); 4800 } 4801 4802 $('.js-letter-form .js-phone').on('keyup', function() { 4803 if ((/\D/g).test($(this).val())) { 4804 $(this).val($(this).val().replace(/\D/g,'')); 4805 } 4806 }); 4807 4808 $('.js-letter-form .js-phone-parens').on('keyup', function() { 4809 //strip non-numeric characters first 4810/* 4811 if ((/\D/g).test($(this).val())) { 4812 $(this).val($(this).val().replace(/\D/g,'')); 4813 } 4814 4815 var start_value = $(this).val(); 4816 var end_value = ''; 4817 4818 $.each(start_value, function(i, e) { 4819 end_value = end_value + e; 4820 //if it's time to insert a - and one does not exist, do it 4821 if (i == 2 || i == 6) { 4822 if (start_value.charAt(3) != '-' && start_value.charAt(3) != '') { 4823 end_value = end_value + '-'; 4824 } else if (start_value.charAt(7) != '-' && start_value.charAt(7) != '') { 4825 end_value = end_value + '-'; 4826 } 4827 } 4828 }); 4829 4830 $(this).val(end_value); 4831*/ 4832 4833 4834/* 4835 4836 if ($(this).val().length == 3) { 4837 $(this).val($(this).val() + '-'); 4838 } else if ($(this).val().length == 7) { 4839 $(this).val($(this).val() + '-'); 4840 } 4841*/ 4842 4843 4844 }); 4845 4846 $('.js-captcha_reload').click(function() { 4847 if ($('.js-recaptcha_response').length) { 4848 $('.js-recaptcha_response').val('[reload]'); 4849 } else { 4850 $('.js-captcha').val('[reload]'); 4851 } 4852 $('.js-letter_submit').trigger('click'); 4853 }); 4854 4855 // Unlayer Email Variant Slider // DROPPING THIS HERE BUT CAN MOVE TO EMAIL SECTION IN THIS FILE 4856 4857/* 4858 $('.js-email_variant_slider').flexslider({ 4859 selector: ".email_variant-slides > .single_variant_slide",
4860 slideshow: false, 4861 smoothHeight: false, 4862 animation: "fade", 4863 controlNav: false, 4864 directionNav: true, 4865 prevText: "<i class='fal fa-long-arrow-left'></i> Previous", 4866 nextText: "Next <i class='fal fa-long-arrow-right'></i>", 4867 touch: false, 4868 keyboard: false, 4869 animationLoop: false, 4870 before: function() { 4871 $('.js-li-add_variant').hide(); 4872 }, 4873 }); 4874*/ 4875 4876 // Letter Variant Slider 4877 4878 if ($('.js-letter_variant_slider').length) { 4879 var variant_count = $('.single_variant_slide').length - 1; 4880 var slider_end = true; 4881 4882 $('.js-letter_variant_slider').flexslider({ 4883 selector: ".letter_variant-slides > .single_variant_slide", 4884 slideshow: false, 4885 smoothHeight: false, 4886 animation: "fade", 4887 controlNav: false, 4888 prevText: "<i class='fas fa-arrow-alt-circle-left'></i> " + an_javascript_translation.previous, 4889 nextText: an_javascript_translation.next + " <i class='fas fa-arrow-alt-circle-right'></i>", 4890 touch: false, 4891 keyboard: false, 4892 animationLoop: false, 4893 before: function() { 4894 $('.js-li-add_variant').hide(); 4895 }, 4896 after: function() { 4897 //console.log('end'); 4898 /* 4899 if ($('.flex-active-slide').data('variant') == 0) { 4900 if($('.flex-active-slide').data('variant') == variant_count) { 4901 $('.js-li-add_variant').fadeIn('fast'); 4902 $(".js-delete_variant").fadeOut('fast'); 4903 } else { 4904 $(".js-delete_variant").fadeOut('fast'); 4905 } 4906 } else { 4907 if($('.flex-active-slide').data('variant') == variant_count) { 4908 //$(".js-add_variant").attr('disabled',false).removeClass('disabled'); 4909 $('.js-li-add_variant').fadeIn('fast'); 4910 $(".js-delete_variant").fadeIn('fast'); 4911 } else { 4912 $(".js-delete_variant").fadeIn('fast'); 4913 } 4914 4915 } 4916 */ 4917 4918 }, 4919 added: function() { 4920 $('.js-letter_variant_slider').data('flexslider').flexslider(variant_count); 4921 } 4922 }); 4923 4924 $('.flex-nav-prev').after('<li class="li-delete_variant"><a href="javascript:void(0);" id="delete_variant" class="nopadding js-delete_variant"><i class="fas fa-times-circle"></i> ' + an_javascript_translation.delete + '</a></li><li class="li-add_variant js-li-add_variant"><a href="javascript:void(0);" id="add_variant" class="nopadding js-add_variant"><i class="fas fa-plus-circle"></i> ' + an_javascript_translation.add_variant + '</a></li>'); 4925 4926 $(".js-delete_variant").hide(); 4927 4928 if (variant_count == 0) { 4929 // 4930 } else { 4931 $('.js-li-add_variant').hide(); 4932 } 4933 4934 var flexslider_button_visibility = function(fade) { 4935 setTimeout(function() { 4936 if ($('.flex-active-slide').data('variant') == 0) { 4937 if($('.flex-active-slide').data('variant') == variant_count) { 4938 if (fade) { 4939 $('.js-li-add_variant').fadeIn('fast'); 4940 $(".js-delete_variant").fadeOut('fast'); 4941 } else { 4942 $('.js-li-add_variant').show('fast'); 4943 $(".js-delete_variant").hide('fast'); 4944 } 4945 } else { 4946 if (fade) { 4947 $(".js-delete_variant").fadeOut('fast'); 4948 } else { 4949 $(".js-delete_variant").hide('fast'); 4950 } 4951 } 4952 } else { 4953 if($('.flex-active-slide').data('variant') == variant_count) { 4954 //$(".js-add_variant").attr('disabled',false).removeClass('disabled'); 4955 if (fade) { 4956 $('.js-li-add_variant').fadeIn('fast'); 4957 $(".js-delete_variant").fadeIn('fast'); 4958 } else { 4959 $('.js-li-add_variant').show('fast'); 4960 $(".js-delete_variant").show('fast'); 4961 } 4962 } else { 4963 if (fade) { 4964 $(".js-delete_variant").fadeIn('fast'); 4965 } else { 4966 $(".js-delete_variant").show('fast'); 4967 } 4968 } 4969 4970 } 4971 }, 200); 4972 } 4973 4974 $(document).on('click touchstart', '.flex-prev', function() { 4975 flexslider_button_visibility(true); 4976 }); 4977 4978 $(document).on('click touchstart', '.flex-next', function() { 4979 flexslider_button_visibility(true); 4980 }); 4981 4982 $(document).on('click touchstart', ".js-add_variant", function(){ 4983 //if (!$(this).hasClass('disabled')) { 4984 variant_count++; 4985 4986 if ($('.js-letter_template_editable').attr('checked') == 'checked') { 4987 var edit_option = ''; 4988 var placeholder = '(' + an_javascript_translation.optional +')'; 4989 } else { 4990 var edit_option = 'required' 4991 var placeholder = '*'; 4992 } 4993 4994 var variant_form = '' 4995 + '<div class="single_variant_slide js-single_variant_slide clearfix" data-variant="' + variant_count + '">' 4996 + '<small class="js-variant_title variant_title"> ' + an_javascript_translation.variant + ' ' + variant_count + '</small>'
4997 + '<div class="mb10 clearfix">' 4998 + '<input class="js-letter_template_subject ' + edit_option + '" id="letter_template_subject_' + variant_count + '" name="variant[variant_' + variant_count + '[subject]]" placeholder="' + an_javascript_translation.default_subject + ' ' + placeholder + '" size="30" type="text">' 4999 + '</div>' 5000 + '<div class="mb10 clearfix">' 5001 + '<textarea class="nogrow js-nogrow js-letter_template_message ' + edit_option + '" cols="40" id="letter_template_message_' + variant_count + '" name="variant[variant_' + variant_count + '[body]]" placeholder="' + an_javascript_translation.default_message_activists_will_send + ' ' + placeholder + '" rows="20" wrap="wrap"></textarea>' 5002 + '</div>' 5003 + '</div>'; 5004 5005 $('.js-letter_variant_slider').data('flexslider').addSlide($(variant_form)); 5006 flexslider_button_visibility(false); 5007 $('.js-create_action_form').trigger('rescan.areYouSure'); 5008 //} 5009 }); 5010 5011 $(document).on('click touchstart', ".js-delete_variant", function(){ 5012 if (!$(this).hasClass('disabled')) { 5013 $('.flex-active-slide').fadeOut('fast', function() { 5014 $('.js-letter_variant_slider').data('flexslider').removeSlide($('.js-letter_variant_slider').data('flexslider').currentSlide); 5015 variant_count--; 5016 5017 var count = 0; 5018 $('.js-single_variant_slide').each(function() { 5019 $(this).data('variant', count); 5020 if (count == 0) { 5021 $(this).find('.js-variant_title').html(an_javascript_translation.primary_letter); 5022 } else { 5023 $(this).find('.js-variant_title').html(an_javascript_translation.variant + ' ' + count); 5024 } 5025 5026 count++; 5027 }); 5028 5029 if (variant_count == 0 || $('.flex-active-slide').data('variant') == 0) { 5030 $(".js-delete_variant").fadeOut('fast'); 5031 } 5032 5033 //console.log($('.flex-active-slide').css('opacity')); 5034 if ($('.flex-active-slide').css('opacity') == 0) { 5035 $('.flex-active-slide').css('opacity','1'); 5036 } 5037 5038 flexslider_button_visibility(false); 5039 $('.js-create_action_form').trigger('rescan.areYouSure'); 5040 }); 5041 5042 } 5043 }); 5044 } 5045 5046 5047 5048 /* ======================= End Letter Management ======================= */ 5049 5050 5051 5052 /* ======================= 2-factor/Twilio Verify ======================= */ 5053 5054 const verificationClassPrefix = "js-verification_method_"; 5055 5056 const getVerificationMethod = () => { 5057 return $('select.js-verification_select option:selected').val(); 5058 } 5059 // Show/hide verification method forms 5060 $('select.js-verification_select').on('change', function() { 5061 $('.js-app_label_select').val('').removeClass('error_input').trigger('change'); 5062 $('.js-custom_app_label, .js-form_phone-verify').val('').removeClass('error_input'); 5063 $('.js-custom_app_label_container').hide(); 5064 const vMethod = getVerificationMethod(); 5065 $(`[class*='${verificationClassPrefix}']:not(${verificationClassPrefix}${vMethod})`).slideUp(); 5066 $(`.${verificationClassPrefix}${vMethod}`).slideDown(); 5067 if($(this).val() == 'sms') { 5068 $('.js-form_phone-verify').addClass('required'); 5069 $('.js-app_label_select, .js-custom_app_label, .js-hardware_key_label').removeClass('required error_input'); 5070 } else if($(this).val() == 'app') { 5071 $('.js-form_phone-verify, .js-hardware_key_label').removeClass('required error_input'); 5072 $('.js-app_label_select').addClass('required'); 5073 } else if($(this).val() == 'hardware') { 5074 $('.js-form_phone-verify, .js-app_label_select, .js-custom_app_label').removeClass('required error_input'); 5075 $('.js-hardware_key_label').addClass('required'); 5076 } 5077 }) 5078 // Newer version with buttons instead of dropdown 5079 const showVerificationForm = (vMethod) => { 5080 $('.js-verification_select').val(vMethod); 5081 $(`[class*='${verificationClassPrefix}']:not(${verificationClassPrefix}${vMethod})`).hide(); 5082 $(`.${verificationClassPrefix}${vMethod}`).show(); 5083 } 5084 $('.js-verification_select_hardware').click(function () { 5085 showVerificationForm('hardware'); 5086 $('.js-form_phone-verify, .js-app_label_select, .js-custom_app_label').removeClass('required error_input'); 5087 $('.js-hardware_key_label').addClass('required'); 5088 }) 5089 $('.js-verification_select_app').click(function () { 5090 showVerificationForm('app'); 5091 $('.js-form_phone-verify, .js-hardware_key_label').removeClass('required error_input'); 5092 $('.js-app_label_select').addClass('required'); 5093 }) 5094 $('.js-verification_select_sms').click(function () { 5095 showVerificationForm('sms'); 5096 $('.js-form_phone-verify').addClass('required');
5097 $('.js-app_label_select, .js-custom_app_label, .js-hardware_key_label').removeClass('required error_input'); 5098 }) 5099 $('.js-change-verification-method').click(() => { 5100 $('.js-verification_select').val(""); 5101 $(`[class*='${verificationClassPrefix}']`).hide(); 5102 $(`.${verificationClassPrefix}`).show(); 5103 }) 5104 5105 // Hardware key (physical device) flow registration 5106 $('.js-prompt_for_hardware').click(function () { 5107 $(this).addClass('disabled'); 5108 var two_factor_id = $("#two_factor_id").val() 5109 $.ajax({ 5110 type: "POST", 5111 url: window.location.pathname + "/webauthn_initiate_create", 5112 data: {"two_factor_id": two_factor_id}, 5113 dataType: 'json', 5114 success: function(options_response){ 5115 if(!webauthnCreate(options_response)) { 5116 $('.js-prompt_for_hardware').hide(); 5117 $('.js-hardware_try_again').show(); 5118 } 5119 }, 5120 error: function(jqXHR, textStatus, errorThrown) { 5121 console.log(jqXHR) 5122 $('.js-2fa_step2_hardware').hide(); 5123 $('.js-2fa_step2_hardware_error_text').show(); 5124 }, 5125 timeout: 120000 5126 }) 5127 }) 5128 5129 $('.js-hardware_try_again').click(function () { 5130 $('.js-prompt_for_hardware').removeClass('disabled'); 5131 $('.js-2fa_step2_hardware_error_text').hide(); 5132 $('.js-2fa_step2_hardware_error').hide(); 5133 $('.js-2fa_step2_hardware').show(); 5134 $('.js-prompt_for_hardware').show(); 5135 }); 5136 5137 function webauthnCreate(options_response) { 5138 options = options_response["options"] 5139 two_fa_label = options_response["two_fa_label"] 5140 // options["rp"]["id"] = "localhost" note: swap out for "localhost" for testing 5141 webauthnJSON.create({ "publicKey": options }).then(function(credential){ 5142 webauthnCreateCallback(credential, two_fa_label) 5143 }) 5144 }; 5145 5146 function webauthnCreateCallback(credential, two_fa_label){ 5147 return $.ajax({ 5148 type: "POST", 5149 url: window.location.pathname + "/webauthn_verify_create", 5150 data: { 5151 "publicKeyCredential": JSON.stringify(credential), 5152 "two_fa_label": two_fa_label 5153 }, 5154 dataType: 'json', 5155 success: function(resp){ 5156 //console.log("webauthn_verify_create response", resp) 5157 $('.js-hardware_try_again').hide(); 5158 $('.js-2fa_step2_hardware').hide(); 5159 $('.js-2fa_step2_hardware_having_trouble').hide(); 5160 $('.js-2fa_step2_hardware_success').show(); 5161 5162 if (typeof(resp.removed_types) != 'undefined' && resp.removed_types.length > 0) { 5163 $('.js-2fa_step2_hardware_success_removed_notice').show(); 5164 $.each(resp.removed_types, function(i, e) { 5165 if (e == 'app') { 5166 $('.js-removed_app').show(); 5167 } 5168 5169 if (e == 'sms') { 5170 $('.js-removed_sms').show(); 5171 } 5172 }); 5173 } 5174 }, 5175 error: function(jqXHR, textStatus, errorThrown) { 5176 console.log(jqXHR) 5177 $('.js-2fa_step2_hardware').hide(); 5178 $('.js-2fa_step2_hardware_error').show(); 5179 $('.js-2fa_step2_hardware_error_text').show(); 5180 } 5181 }) 5182 }; 5183 5184 // webauthn hardware key login 5185 5186 $('.js-hardware_try_again_get').click(function () { 5187 $('.js-prompt_for_hardware_get').removeClass('disabled'); 5188 $('.js-hardware_try_again_get').hide(); 5189 $('.js-prompt_for_hardware_get').show(); 5190 }); 5191 5192 $('.js-prompt_for_hardware_get').click(function () { 5193 $(this).addClass('disabled'); 5194 var options = JSON.parse($("#options").val()) 5195 console.log(options) 5196 if(!webauthnGet(options)) { 5197 $('.js-prompt_for_hardware_get').hide(); 5198 $('.js-hardware_try_again_get').show(); 5199 } 5200 }); 5201 5202 function webauthnGet(options) { 5203 webauthnJSON.get({ "publicKey": options }).then(function(credential){ 5204 console.log(credential) 5205 webauthnAssertionCallback(credential) 5206 }) 5207 }; 5208 5209 function webauthnAssertionCallback(credential){ 5210 $('#public_key_from_params').val(JSON.stringify(credential)); 5211 $('.js-prompt_for_hardware_get').hide(); 5212 $('.js-hardware_try_again_get').hide(); 5213 $('.js-hardware_challenge_submit').show(); 5214 //console.log("before submit") 5215 submitClicked = "authy_form"; 5216 $('#authy_form').submit(); 5217 }; 5218 5219 // 5220 // APP FLOW 5221 // 5222 5223 // Validate app label 5224 const getAppLabel = ()=> { 5225 const appLabel = $('select.js-app_label_select option:selected').val(); 5226 if (appLabel === "other") return $('.js-custom_app_label').val(); 5227 return appLabel; 5228 } 5229 // Show/hide custom app label 5230 $('select.js-app_label_select').on('change', function() { 5231 const appLabel = $('select.js-app_label_select option:selected').val(); 5232 if (appLabel === "other") { 5233 $('.js-custom_app_label_container').slideDown(); 5234 $('.js-custom_app_label').addClass('required'); 5235 } 5236 else { 5237 $('.js-custom_app_label_container').slideUp(); 5238 $('.js-custom_app_label').removeClass('required error_input').val(''); 5239 } 5240 }) 5241 5242 5243 // App - step 2 (scan QR or enter text code) 5244 $('.js-app_step2_continue').click(()=>{ 5245 $('.js-2fa_step2_app').hide(); 5246 $('.js-2fa_step3_app').show(); 5247 }) 5248 // Show app text code 5249 $('.js-2fa_show_app_text_code').click(()=>{ 5250 $('.js-2fa_app_text_code').slideToggle(); 5251 }) 5252 5253 5254 5255 // 5256 // SMS FLOW 5257 // 5258 5259 5260 $(".js-fancylink_2faconfirm").fancybox({ 5261 onStart: function() { 5262 if (!$('form').valid()) { 5263 return false;
5264 } 5265 5266 if ($('.js-form_phone-verify').length && $('select.js-verification_select').val() == 'sms') { 5267 const $phoneInput = $('.js-form_phone-verify'); 5268 if ($phoneInput.intlTelInput('isValidNumber')) { 5269 if ($phoneInput.val() != '') { 5270 //const phoneNumber = $phoneInput.intlTelInput("getNumber", 1); 5271 $phoneInput.val($phoneInput.intlTelInput('getNumber')); 5272 } 5273 } else { 5274 $phoneInput.addClass('error_input'); 5275 return false; 5276 } 5277 } 5278 5279 }, 5280 onComplete: function() { 5281 $('body').addClass('body_has_modal'); 5282 }, 5283 onClosed: function() { 5284 $('.js-file_delete_link').css('display','inline'); 5285 $('.js-edit_confirm_delete').css('display','none'); 5286 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 5287 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 5288 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 5289 $('body').removeClass('form_builder_edit'); 5290 }, 5291 margin: 15, 5292 hideOnOverlayClick: false 5293 }); 5294 5295 5296 /* ======================= end 2-factor/Twilio Verify ======================= */ 5297 5298 5299 /* ======================= Mailstream ======================= */ 5300 5301 mailstream_timeout = ''; 5302 5303 var mark_unsaved = function() { 5304 $('.js-mailstream-form-container').addClass('js-has_unsaved_mailstream_changes'); 5305 $('.js-mailstream-date, .js-clear_mailstream_date').addClass('disabled').attr('disabled','disabled'); 5306 }; 5307 5308 var unmark_unsaved = function() { 5309 $('.js-mailstream-form-container').removeClass('js-has_unsaved_mailstream_changes'); 5310 $('.js-mailstream-date, .js-clear_mailstream_date').removeClass('disabled').attr('disabled',false); 5311 }; 5312 5313 mailstream_emails_changed = function() { 5314 // When number of emails change, update instruction text 5315 var add_emails_instructions = $('.js-add_emails_instructions'); 5316 var sort_instructions = $('.js-sort_instructions'); 5317 if ($('.js-mailstream_sort_container .js-mailstream_item').length > 1) { 5318 add_emails_instructions.hide(); 5319 } else { 5320 add_emails_instructions.show(); 5321 } 5322 if ($('.js-mailstream_locked').is(':hidden')) { 5323 sort_instructions.show(); 5324 } else { 5325 sort_instructions.hide(); 5326 } 5327 } 5328 5329 render_mailstream_emails = function(emails, allow_retarget, has_stream = '', is_adding = false, highlight = false) { 5330 var mailstreamContainer = $('.js-mailstream_sort_container'); 5331 if (!is_adding) { 5332 mailstreamContainer.children().not('.js-targeted_email').remove(); 5333 } 5334 5335 if (has_stream) { 5336 $(".js-mailstream_id").text(has_stream); 5337 } 5338 5339 if (emails) { 5340 emails.forEach(email => { 5341 var template = $('.js-mailstream_email_template .js-mailstream_item').clone(); 5342 if (is_adding) { 5343 template.addClass('js-unsaved_item'); 5344 } 5345 if (email.id) 5346 template.find('.js-email_id').text(email.id); 5347 if (email.admin_title && email.admin_title !== '') 5348 template.find('.js-email_title').text(email.admin_title); 5349 template.find('.js-email_title').attr('href', email.manage_url) 5350 if (email.is_draft) { 5351 template.find('.js-email_status_draft').show(); 5352 template.find('.js-email_status_scheduled').hide(); 5353 template.find('.js-email_status_sent').hide(); 5354 } else if (email.is_scheduled) { 5355 template.find('.js-email_status_draft').hide(); 5356 template.find('.js-email_status_sent').hide(); 5357 template.find('.js-email_status_scheduled').show(); 5358 } else { 5359 template.find('.js-email_status_draft').hide(); 5360 template.find('.js-email_status_scheduled').hide(); 5361 } 5362 5363 if (allow_retarget && email.needs_retargeting) { 5364 template.find('.js-retarget_button').show(); 5365 } else { 5366 template.find('.js-retarget_button').hide(); 5367 } 5368 5369 if (typeof email.targets === 'number') { 5370 template.find('.js-target_count').text(email.targets); 5371 template.find('.js-targeted_label').show(); 5372 } else { 5373 template.find('.js-targeted_label').hide(); 5374 } 5375 5376 var targeting_id = $(".js-targeting_email").data("id"); 5377 if ((highlight || targeting_id == email.id) && !$('.js-mailstream_init').length) { 5378 template.find('.js-current_email').show(); 5379 template.find('.js-current_email').prev('.js-email_title').removeClass('graytext'); 5380 template.find('.js-current_email').parents('.js-mailstream_item').find('.js-retarget_button').find('span').html(an_javascript_translation.recalculate_targets_targeting_page); 5381 } else { 5382 template.find('.js-current_email').hide(); 5383 template.find('.js-current_email').parents('.js-mailstream_item').find('.js-retarget_button').find('span').text(an_javascript_translation.recalculate_targets); 5384 } 5385 5386 mailstreamContainer.append(template); 5387 }); 5388 } 5389 5390 $('.js-show_if_mailstream_date').show(); 5391 $('.js-hide_if_mailstream_date').hide(); 5392 $('.js-loading_mailstream').hide(); 5393 mailstream_emails_changed(); 5394 } 5395 5396 get_mailstream_emails = function(date) { 5397 var parsedDate = parseDate(date); 5398 var group_url = $('.js-mailstream-form-container').data('group_url'); 5399 $.get('/groups/' + group_url + '/mailstreams/' + parsedDate + '.json', function(data) { 5400 if (JSON.stringify(data) === '{}') { 5401 resetMailstream(); 5402 } 5403 var has_stream = false 5404 if (Array.isArray(data.mailstream) && data.mailstream.length > 0) { 5405 has_stream = data.stream 5406 } 5407 if (has_stream && !data.targeting_allowed) { 5408 lockMailstream(); 5409 } else { 5410 unlockMailstream(); 5411 } 5412 render_mailstream_emails(data.mailstream, data.targeting_allowed, has_stream) 5413 }).error(function() { 5414 console.log('Error fetching mailstream'); 5415 }); 5416 } 5417 5418 function lockMailstream() { 5419 $('.js-sort_instructions').hide(); 5420 $('.js-search-to-add-container, .js-save_mailstream_btn').addClass('disabled'); 5421 $('.js-mailstream_locked').show(); 5422 $('.js-retarget_button').hide(); 5423 $('.js-mailstream_item').addClass('retargeting'); 5424 $('.js-mailstream_item .js-retargeting-text').hide(); 5425 mailstream_timeout = setTimeout(function() { 5426 get_mailstream_emails(get_selected_date()); 5427 }, 7000); 5428 } 5429 5430 function unlockMailstream() { 5431 $('.js-sort_instructions').show(); 5432 $('.js-search-to-add-container, .js-save_mailstream_btn').removeClass('disabled'); 5433 $('.js-mailstream_locked').hide(); 5434 //$('.js-retarget_button').show(); 5435 $('.js-mailstream_item').removeClass('retargeting'); 5436 clearTimeout(mailstream_timeout); 5437 } 5438 5439 send_mailstream = function(stream_date) { 5440 var group_url = $('.js-mailstream-form-container').data('group_url'); 5441 var emails_ids = []; 5442 $('.js-email_id').each(function() { 5443 if ($(this).text() !== '') 5444 emails_ids.push($(this).text()); 5445 }); 5446 5447 var has_emails = Array.isArray(emails_ids) && emails_ids.length > 0; 5448 var stream_id = $(".js-mailstream_id").first().text(); 5449 if (has_emails) { 5450 if (stream_id === '') { 5451 var parsedDate = parseDate(stream_date); 5452 var params = { 5453 date: parsedDate, 5454 emails: emails_ids 5455 } 5456 $.post('/groups/' + group_url + '/mailstreams', params, function(data) { 5457 if (data.error) { 5458 alert(an_javascript_translation.error_creating_mailstream + " " + data.error_msg); 5459 } else if (data.message) { 5460 Noty.closeAll(); 5461 new Noty({
5462 theme: 'metroui', 5463 type: 'success', 5464 closeWith: ['button','click'], 5465 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + data.message + "</span>", 5466 timeout: 10000 5467 }).show(); 5468 var updatedMailstream = data.updated_mailstream; 5469 if (updatedMailstream) { 5470 render_mailstream_emails(updatedMailstream.mailstream, updatedMailstream.targeting_allowed, updatedMailstream.stream) 5471 } 5472 } 5473 }).done(function (data) { 5474 $('.js-save_mailstream_btn').removeClass('disabled').attr('disabled',false); 5475 unmark_unsaved(); 5476 //console.log(data.message) 5477 //console.log(data); 5478 }).fail(function(jqXHR, textStatus, errorThrown) { 5479 var response = JSON.parse(jqXHR.responseText) 5480 if (response.error && response.error_msg) { 5481 alert(an_javascript_translation.error_creating_mailstream + " " + response.error_msg); 5482 } 5483 $('.js-save_mailstream_btn').removeClass('disabled').attr('disabled',false); 5484 }); 5485 } else { 5486 $.ajax({ 5487 url: '/groups/' + group_url + '/mailstreams/' + stream_id, 5488 type: 'PUT', 5489 data: { emails: emails_ids }, 5490 }).done(function(data) { 5491 if (data.message) { 5492 new Noty({ 5493 theme: 'metroui', 5494 type: 'success', 5495 closeWith: ['button','click'], 5496 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + data.message + "</span>", 5497 timeout: 10000 5498 }).show(); 5499 } 5500 var updatedMailstream = data.updated_mailstream; 5501 if (updatedMailstream) { 5502 render_mailstream_emails(updatedMailstream.mailstream, updatedMailstream.targeting_allowed, updatedMailstream.stream) 5503 } 5504 $('.js-save_mailstream_btn').removeClass('disabled').attr('disabled',false); 5505 unmark_unsaved(); 5506 }); 5507 } 5508 } else { 5509 if (stream_id !== '') { 5510 deleteMailstream(stream_id); 5511 } 5512 unmark_unsaved(); 5513 $('.js-save_mailstream_btn').removeClass('disabled').attr('disabled',false); 5514 } 5515 5516 } // send_mailstream 5517 5518 function deleteMailstream(stream_id) { 5519 var group_url = $('.js-mailstream-form-container').data('group_url'); 5520 $.post('/groups/' + group_url + '/mailstreams/delete/' + stream_id, {}, function(data) { 5521 if (data.message) { 5522 new Noty({ 5523 theme: 'metroui', 5524 type: 'success', 5525 closeWith: ['button','click'], 5526 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + data.message + "</span>", 5527 timeout: 10000 5528 }).show(); 5529 $('.js-save_mailstream_btn').removeClass('disabled').attr('disabled',false); 5530 resetMailstream(); 5531 unmark_unsaved(); 5532 } 5533 }); 5534 } 5535 5536 function resetMailstream() { 5537 $(".js-mailstream_id").text(''); 5538 } 5539 5540 function parseDate(dateStr) { 5541 return dateStr.toLocaleDateString('en-CA', { 5542 year: 'numeric', month: '2-digit', day: '2-digit' 5543 }).replace(/\//g, '-'); 5544 } 5545 5546 var datepick_change = function(element, clearDateBtn) { 5547 clearTimeout(mailstream_timeout); 5548 var inputVal = $(element).val(); 5549 if (!inputVal || inputVal === '') { 5550 $('.js-show_if_mailstream_date').hide(); 5551 $('.js-hide_if_mailstream_date').show(); 5552 clearDateBtn.addClass('hide'); 5553 return; 5554 } 5555 clearDateBtn.removeClass('hide'); 5556 $('.js-show_if_mailstream_date').hide(); 5557 $('.js-hide_if_mailstream_date').show(); 5558 $('.js-loading_mailstream').show(); 5559 var newDate = new Date(inputVal); 5560 get_mailstream_emails(new Date(newDate)); 5561 }; 5562 5563 mailstream_datepick_days_init = function() { 5564 var dateInput = $('.js-mailstream_date_and_search .js-mailstream-date'); 5565 var clearDateBtn = $('.js-clear_mailstream_date'); 5566 5567 // Initialize datepicker and change handler 5568 dateInput.datetimepicker({ 5569 startDate: new Date(), 5570 format: "MM dd, yyyy", 5571 showMeridian: true, 5572 autoclose: true, 5573 pickerPosition: "bottom-left", 5574 minView: 2 5575 }).on('change', function(e) { 5576 datepick_change(this, clearDateBtn); 5577 //stop change if unsaved! 5578 }); 5579 5580 // Clear date button 5581 clearDateBtn.on('click', function() { 5582 dateInput.val('').trigger('change'); 5583 }); 5584 } 5585 5586 mailstream_init = function() { 5587 mailstream_datepick_days_init(); 5588 var group_url = $('.js-mailstream-form-container').data('group_url'); 5589 5590 // Make mailstream emails draggable 5591 $( ".js-mailstream_sort_container" ).sortable({ 5592 handle: ".fa-grip-vertical", 5593 placeholder: "mailstream-placeholder", 5594 afterMove: function() { 5595 mark_unsaved(); 5596 } 5597 }); 5598 $(".js-mailstream_sort_container").disableSelection(); 5599 5600 // Retarget button 5601 $(document).on('click touchstart', '.js-retarget_button', function() { 5602 //var retarget_button = $(this); 5603 //retarget_button.closest('.js-mailstream_item').addClass('retargeting'); 5604 5605 //$('.js-mailstream_date_and_search, .js-save_mailstream_btn').addClass('disabled'); 5606 var email_id = $(this).closest('.js-mailstream-item-main').find('.js-email_id').text(); 5607 var stream_id = $(this).closest('.js-mailstream_item').find(".js-mailstream_id").text(); 5608 $.post('/groups/' + group_url + '/mailstreams/' + email_id + '/retarget', { stream: stream_id }, function(data) { 5609 if (data.status === "processing" && data.check_id) { 5610 lockMailstream(); 5611 } 5612 }).fail(function(jqXHR, textStatus, errorThrown) { 5613 if (jqXHR.status == 404) { 5614 alert(an_javascript_translation.error_retargeting_email_try_again_later); 5615 } 5616 5617 }); 5618 }); 5619 5620 $(document).on('click', '.js-save_mailstream_btn', function() { 5621 $(this).addClass('disabled').attr('disabled','disabled'); 5622 send_mailstream(get_selected_date()); 5623 }); 5624 5625 $(document).on('click', '.js-add_to_mailstream', function() { 5626 var $selectedEmail = $('select.js-available_emails'); 5627 var selectedEmail = $selectedEmail.val(); 5628 console.log(selectedEmail); 5629 if (selectedEmail) { 5630 var $option = $selectedEmail.find('option:selected'); 5631 var subject = $option.text(); 5632 var formated = subject.split(']')[1].trim(); 5633 var emails = [{ 5634 admin_title: formated, is_draft: $option.data('is-draft'), is_scheduled: $option.data('is-scheduled'), is_sent: $option.data('is-sent'), targets: null, id: selectedEmail 5635 }]; 5636 5637 render_mailstream_emails(emails, false,false, true); 5638 $selectedEmail.find('option:selected').addClass('disabled').attr('disabled','disabled'); 5639 $selectedEmail.val('').trigger('change'); 5640 mark_unsaved(); 5641 } 5642 }); 5643 5644 // Remove email button 5645 $(document).on('click touchstart', '.js-remove_mailstream_email', function() { 5646 $item = $(this).closest('.js-mailstream_item'); 5647 $('select.js-available_emails option[value=' + $item.find('.js-email_id').text() + ']').removeClass('disabled').attr('disabled', false); 5648 if ($('.js-current_email:visible').length) { 5649 $('.js-add_to_mailstream').removeClass('disabled').attr('disabled',false); 5650 } 5651 5652 $item.remove(); 5653 mailstream_emails_changed(); 5654 mark_unsaved(); 5655 5656 }); 5657 5658 get_selected_date = function() { 5659 var date = $('.js-mailstream_date_and_search .js-mailstream-date').val(); 5660 return new Date(date); 5661 } 5662 5663 if ($('.js-mailstream-date').val() != '') { 5664 $('.js-mailstream-date').trigger('change'); 5665 } 5666 5667 } // mailstream_init 5668 5669 5670 /* ======================= End Mailstream ======================= */ 5671 5672 if ($('.js-reportResults').val()) { 5673 reportResults(JSON.parse($('.js-reportResults').val())); 5674 } 5675 5676 /* ======================= Tab Ajax ======================= */ 5677 if ($('.js-tab_ajax').length) { 5678 $(document).on('tabMove', function(event, element) { 5679 var $tab_content = $(element); 5680 if ($tab_content.hasClass('js-tab_ajax') && !$tab_content.hasClass('js-tab_ajax_loaded')) { 5681 $tab_content.addClass('js-tab_ajax_loaded'); 5682 $tab_content.html('<small>' + an_javascript_translation.loading + '</small>'); 5683 5684 var admin_search_param = getURLParameter('admin_search'); 5685 if (admin_search_param) { 5686 admin_search_param = '?admin_search=' + admin_search_param; 5687 } else { 5688 admin_search_param = ''; 5689 } 5690 5691 $.get(window.location.pathname + '/' + element.replace('#','') + admin_search_param, function(data) { 5692 //console.log(data); 5693 $tab_content.html(data); 5694 window["ajax_tab_callback_" + element.replace('#','')](); 5695 }).fail(function() { 5696 $tab_content.removeClass('js-tab_ajax_loaded'); 5697 $tab_content.html('<small>' + an_javascript_translation.an_error_occurred + '</small>'); 5698 }); 5699 } 5700 }); 5701 5702 emails_tabs_init = function() { 5703 $(".js-emails_tabs").on("click",function(e) { 5704 e.preventDefault() 5705 target_tab = e.currentTarget.closest('a').name 5706 $(".js-emails_tabs_div").hide() 5707 $(".js-emails_tabs").attr("id","") 5708 $(`${target_tab}`).fadeIn() 5709 $(`a[name='${target_tab}']`).attr("id", "current") 5710 }) 5711 $(document).on('tabMove', function(event, element) { 5712 if (element == "#tab_email") { 5713 $("a[name='#all_tab']").attr("id", "current"); 5714 $('.js-emails_tabs_div').hide(); 5715 $(".js-emails_all_tab").fadeIn() 5716 } 5717 }) 5718 5719 // AN-1877 5720 email_stats_init(); 5721 5722 // AN-2199 Mailstream 5723 mailstream_init(); 5724 5725 } 5726 5727 mobile_tabs_init = function() { 5728 $(".js-mobile_tabs").on("click",function(e) { 5729 e.preventDefault() 5730 target_tab = e.currentTarget.closest('a').name 5731 $(".js-mobile_tabs_div").hide() 5732 $(".js-mobile_tabs").attr("id","") 5733 $(`${target_tab}`).fadeIn() 5734 $(`a[name='${target_tab}']`).attr("id", "current") 5735 }) 5736 $(document).on('tabMove', function(event, element) { 5737 if (element == "#tab_mobile") { 5738 $("a[name='#all_mobile_tab']").attr("id", "current") 5739 $('.js-mobile_tabs_div').hide(); 5740 $(".js-mobile_all_tab").fadeIn() 5741 } 5742 }) 5743 } 5744 5745 email_stats_init = function () {
5746 $('.js-hide_email_stats').click(function () { 5747 $('.js-email_stats').slideUp(); 5748 $('.js-show_email_stats').fadeIn(); 5749 }); 5750 $('.js-show_email_stats').click(function () { 5751 $('.js-email_stats').slideDown(); 5752 $('.js-show_email_stats').fadeOut(); 5753 }); 5754 5755 if ($('.js-deliverability_emailStats').val()) { 5756 var deliverability_emailStats = JSON.parse($('.js-deliverability_emailStats').val()); 5757 deliverability_emailStats.forEach((stat) => { 5758 // Initial display of stats on Email page 5759 var stat_template = $('.js-email_stat_items').find('.js-deliverability_email_stats_' + stat.type); 5760 if (stat_template.length) { 5761 formatStat(stat, stat_template); 5762 } 5763 }); 5764 } 5765 5766 function formatStatDropdown({id, text}) { 5767 const stat = deliverability_emailStats.find(stat => stat.type==id); 5768 if (!stat) return text; 5769 var stat_template = $('.js-email_stat_select').find('.js-deliverability_email_stats_select_' + stat.type); 5770 //console.log(stat_template); 5771 var node = $(` 5772 <div class="js-deliverability_email_stats_select_${stat.type} email_stat_template"> 5773 <i class="${stat.icon}"></i> 5774 <div class="d-flex">${stat.label}</div> 5775 <div class="right-side hide">${$('.js-deliverability_email_stats_' + stat.type).find('.js-deliverability_value').text()}</div> 5776 <svg width="40" height="20" stroke-width="1"></svg> 5777 </div>`); 5778 formatStat(stat, node); 5779 return node; 5780 } 5781 5782 $("select.js-email_stat_select").select2({ 5783 formatSelection: formatStatDropdown, 5784 formatResult: formatStatDropdown, 5785 dropdownCssClass: 'email_stat_select', 5786 allowClear: true, 5787 closeOnSelect: false, 5788 minimumResultsForSearch: 20, 5789 matcher: function (term, text, option) { 5790 if (term.length == 0) return true; 5791 5792 if(term.split(" ").length == 1){ 5793 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 5794 } 5795 5796 keywords=(term).split(/ |,|\[|\]|\(|\)/); 5797 // `data.text` is the text that is displayed for the data object 5798 // check if data.text contains all of keywords, if some is missing, return null 5799 for (var i = 0; i < keywords.length; i++) { 5800 5801 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 5802 // Return `null` if the term should not be displayed 5803 return null; 5804 5805 } 5806 // If here, data.text contains all keywords, so return it. 5807 return text; 5808 } 5809 }); 5810 5811 5812 5813 // Inspired by https://github.com/fnando/sparkline/blob/main/src/sparkline.js 5814 5815 function sparklineSVG(svg, entries, options) { 5816 5817 function getY(max, height, diff, value) { 5818 if (max === 0) return height * 1.0 5819 return parseFloat((height - (value * height / max) + diff).toFixed(2)); 5820 } 5821 5822 function removeChildren(svg) { 5823 [...svg.querySelectorAll("*")].forEach(element => svg.removeChild(element)); 5824 } 5825 5826 function defaultFetch(entry) { 5827 return entry.value; 5828 } 5829 5830 function buildElement(tag, attrs) { 5831 const element = document.createElementNS("http://www.w3.org/2000/svg", tag); 5832 5833 for (let name in attrs) { 5834 element.setAttribute(name, attrs[name]); 5835 } 5836 5837 return element; 5838 } 5839 5840 removeChildren(svg); 5841 5842 if (entries.length <= 1) { 5843 return; 5844 } 5845 5846 options = options || {}; 5847 5848 if (typeof(entries[0]) === "number") { 5849 entries = entries.map(entry => { 5850 return {value: entry}; 5851 }); 5852 } 5853 const spotRadius = 2; 5854 const spotDiameter = spotRadius * 2; 5855 const strokeWidth = 0.5; 5856 const fetch = options.fetch || defaultFetch; 5857 const values = entries.map(entry => fetch(entry)); 5858 const width = parseFloat(svg.attributes.width.value) - spotDiameter * 2; 5859 const fullHeight = parseFloat(svg.attributes.height.value); 5860 const height = fullHeight - (strokeWidth * 2) - spotDiameter; 5861 const max = Math.max(...values); 5862 const lastItemIndex = values.length - 1; 5863 const offset = width / lastItemIndex; 5864 const datapoints = []; 5865 5866 // Hold the line coordinates. 5867 const pathY = getY(max, height, strokeWidth + spotRadius, values[0]); 5868 let pathCoords = `M${spotDiameter} ${pathY}`; 5869
5870 values.forEach((value, index) => { 5871 const x = index * offset + spotDiameter; 5872 const y = getY(max, height, strokeWidth + spotRadius, value); 5873 5874 datapoints.push(Object.assign({}, entries[index], { 5875 index: index, 5876 x: x, 5877 y: y 5878 })); 5879 5880 pathCoords += ` L ${x} ${y}`; 5881 }); 5882 5883 const path = buildElement("path", { 5884 class: "sparkline--line", 5885 d: pathCoords, 5886 fill: "none", 5887 stroke: "currentColor" 5888 }); 5889 svg.appendChild(path); 5890 } 5891 5892 function formatStat(stat, stat_template) { 5893 const svg = $(stat_template).find('svg'); 5894 sparklineSVG(svg[0], stat.lineData); 5895 5896 } 5897 5898 var deliverability_ajax = false; 5899 5900 var get_deliverability_stats = function() { 5901 if (deliverability_ajax) { 5902 deliverability_ajax.abort(); 5903 } 5904 5905 $('.js-deliverability_email_graph, .js-deliverability_email_graph_error, .js-deliverability_email_graph_nosent').hide(); 5906 $('.js-deliverability_email_graph_loading').show(); 5907 var url = $('.js-deliverability_graph_modal').data('url') 5908 + '?domain=' + $('select.js-email_domain_select').val() 5909 + '&start_date=' + $('.js-ladder_stat_start').val() 5910 + '&end_date=' + $('.js-ladder_stat_end').val() 5911 5912 5913 deliverability_ajax = $.get(url, function(data) { 5914 deliverability_ajax = false; 5915 5916 $('.js-deliverability_email_graph_loading, .js-deliverability_email_graph_error').hide(); 5917 5918 deliverability_emailStats = data; 5919 5920 $('select.js-email_stat_select').trigger('change'); 5921 5922 }).fail(function() { 5923 $('.js-deliverability_email_graph_loading, .js-deliverability_email_graph_nosent').hide(); 5924 $('.js-deliverability_email_graph_error').show(); 5925 deliverability_ajax = false; 5926 }); 5927 } 5928 5929 //get_deliverability_stats(); 5930 5931 $('.js-deliverability_input').on('change', function() { 5932 get_deliverability_stats(); 5933 }); 5934 5935 $('.js-deliverability_date_clear').click(function() { 5936 $('.js-datepick-days-past-week-only').val('').trigger('change'); 5937 }); 5938 5939 $('.js-fancylink_deliverability').fancybox({ 5940 onComplete: function() { 5941 $('body').addClass('body_has_modal'); 5942 $('select.js-email_stat_select').val($(this.orig[0]).data('stat')).trigger('change'); 5943 $('select.js-email_domain_select').val('').trigger('change'); 5944 }, 5945 onClosed: function() { 5946 $('.js-file_delete_link').css('display','inline'); 5947 $('.js-edit_confirm_delete').css('display','none'); 5948 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 5949 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 5950 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 5951 $('body').removeClass('form_builder_edit'); 5952 }, 5953 margin: 15, 5954 hideOnOverlayClick: false 5955 }); 5956 5957 5958 $('select.js-email_stat_select').on('change', function() { 5959 deliverability_draw_selected_stat_graph($(this).val()); 5960 }); 5961 5962 var deliverability_draw_selected_stat_graph = function(selected_stat) { 5963 if (Math.max(...deliverability_emailStats[0].lineData) == 0) { 5964 $('.js-deliverability_email_graph_nosent').show(); 5965 } else { 5966 $('.js-deliverability_email_graph_nosent').hide(); 5967 $('.js-deliverability_email_graph').show(); 5968 $.each(deliverability_emailStats, function(i, e) { 5969 if (selected_stat == e.type) { 5970 drawEmailGraphInModal(e); 5971 } 5972 }); 5973 } 5974 5975 $('.js-deliverability_tip').hide(); 5976 $('.js-deliverability_tip_' + selected_stat).show(); 5977 5978 } 5979 5980 function get_plot_bands(stat_type) { 5981 //console.log(stat_type); 5982 plot_lines = [{ 5983 from: 40, 5984 to: 100, 5985 color: '#e8fed6' 5986 }, { 5987 from: 15, 5988 to: 40, 5989 color: '#FEF9E7' 5990 }, { 5991 from: 0, 5992 to: 15, 5993 color: '#FBEEE6' 5994 }]; 5995 5996 if (stat_type == 'open') { 5997 plot_lines = [{ 5998 from: 40, 5999 to: 100, 6000 color: '#e8fed6' 6001 }, { 6002 from: 15, 6003 to: 40, 6004 color: '#FEF9E7' 6005 }, { 6006 from: 0, 6007 to: 15, 6008 color: '#FBEEE6' 6009 }]; 6010 } else if (stat_type == 'click') { 6011 plot_lines = [{ 6012 from: 4, 6013 to: 100, 6014 color: '#e8fed6' 6015 }, { 6016 from: 1, 6017 to: 4, 6018 color: '#FEF9E7' 6019 }, {
6020 from: 0, 6021 to: 1, 6022 color: '#FBEEE6' 6023 }]; 6024 } else if (stat_type == 'unsubscribe') { 6025 plot_lines = [{ 6026 from: 1, 6027 to: 100, 6028 color: '#FBEEE6' 6029 }, { 6030 from: 0.4, 6031 to: 1, 6032 color: '#FEF9E7' 6033 }, { 6034 from: 0, 6035 to: 0.4, 6036 color: '#e8fed6' 6037 }]; 6038 } else if (stat_type == 'bounce') { 6039 plot_lines = [{ 6040 from: 2, 6041 to: 100, 6042 color: '#FBEEE6' 6043 }, { 6044 from: 0.6, 6045 to: 2, 6046 color: '#FEF9E7' 6047 }, { 6048 from: 0, 6049 to: 0.6, 6050 color: '#e8fed6' 6051 }]; 6052 } else if (stat_type == 'spam') { 6053 plot_lines = [{ 6054 from: 0.19, 6055 to: 100, 6056 color: '#FBEEE6' 6057 }, { 6058 from: 0.09, 6059 to: 0.19, 6060 color: '#FEF9E7' 6061 }, { 6062 from: 0, 6063 to: 0.09, 6064 color: '#e8fed6' 6065 }]; 6066 } 6067 //console.log(plot_lines); 6068 return plot_lines 6069 6070 } 6071 6072 function calculate_y_max(data_array) { 6073 var array_max = Math.max(...data_array) 6074 var padding = array_max * .1 //add 10% as padding 6075 var potential_max = array_max + padding; 6076 6077 if (potential_max > 100) { 6078 return 100 6079 } else { 6080 return potential_max 6081 } 6082 } 6083 6084 function drawEmailGraphInModal(stat) { 6085 $('.js-deliverability_email_graph').highcharts({ 6086 credits: { 6087 enabled: false 6088 }, 6089 chart: { 6090 alignTicks: false 6091 }, 6092 title: { 6093 text: '', 6094 align: 'center' 6095 }, 6096 xAxis: [{ 6097 type: 'datetime', 6098 labels: { 6099 rotation: -45, 6100 y: 30, 6101 format: '{value:%b %e}', 6102 style: { 6103 color: '#434343' 6104 } 6105 }, 6106 minPadding: 0, 6107 maxPadding: 0, 6108 startOnTick: true, 6109 endOnTick: false, 6110 startOfWeek: 0, 6111 tickInterval: 24 * 3600 * 1000 * 7, 6112 minorTickInterval: 24 * 3600 * 1000 * 7, 6113 minorGridLineWidth: 0 6114 }], 6115 yAxis: [{ // Primary yAxis 6116 max: calculate_y_max(stat.lineData), 6117 //tickPositions: [0, 20, 40, 100], 6118 labels: { 6119 format: '{value}%', 6120 style: { 6121 color: '#434343' 6122 } 6123 }, 6124 title: { 6125 text: `${stat.label} ${an_javascript_translation.rate}`, 6126 style: { 6127 color: '#0095da' 6128 }, 6129 margin: 10 6130 }, 6131 plotBands: get_plot_bands(stat.type) 6132 }, { // Secondary yAxis 6133 showFirstLabel: true, 6134 showLastLabel: true, 6135 title: { 6136 text: null 6137 }, 6138 labels: { 6139 style: { 6140 color: '#b0b0b0' 6141 }, 6142 formatter: function () { 6143 if ((this.isFirst == true) || (this.isLast == true)) { 6144 return this.value; 6145 } 6146 }, 6147 rotation: 45 6148 }, 6149 gridLineWidth: 0, 6150 title: { 6151 text: an_javascript_translation.total_sent, 6152 style: { 6153 color: '#b0b0b0' 6154 }, 6155 margin: 10 6156 }, 6157 opposite: true, 6158 min: 0 6159 }], 6160 tooltip: { 6161 backgroundColor: '#ffffff', 6162 xDateFormat: '%b %e' 6163 }, 6164 legend: { 6165 enabled: false, 6166 align: 'center', 6167 verticalAlign: 'top', 6168 y: 10, 6169 floating: true, 6170 }, 6171 plotOptions: { 6172 series: { 6173 pointStart: new Date(stat.startDate).getTime(), 6174 pointInterval: 24 * 3600 * 1000 * 7, // One week 6175 marker: { 6176 enabled: false, 6177 }, 6178 findNearestPointBy: "xy" 6179 }, 6180 areaspline: { 6181 fillOpacity: 0.5, 6182 findNearestPointBy: "xy" 6183 } 6184 }, 6185 series: [{ 6186 name: an_javascript_translation.total_sent, 6187 yAxis: 1, 6188 type: 'spline', 6189 lineWidth: 1, 6190 color: '#b0b0b0', 6191 data: deliverability_emailStats[0].lineData, 6192 tooltip: { 6193 valueSuffix: ' ' + an_javascript_translation.emails 6194 }, 6195 marker: { 6196 symbol: 'circle', 6197 states: { 6198 hover: { 6199 radius: 3, 6200 symbol: 'circle' 6201 } 6202 }, 6203 enabled: true 6204 }, 6205 index: 2 6206 }, { 6207 name: stat.label, 6208 type: 'areaspline', 6209 color: '#0095da', 6210 data: stat.lineData, 6211 tooltip: { 6212 valueSuffix: '%' 6213 }, 6214 marker: { 6215 states: { 6216 hover: { 6217 radius: 3, 6218 symbol: 'circle' 6219 } 6220 }, 6221 enabled: true 6222 }, 6223 index: 1 6224 }] 6225 }); 6226 6227 $('.js-deliverability_email_graph svg').on('click', function() { 6228 close_select2_function(); 6229 }); 6230 } 6231 6232 6233 6234 6235 6236 } 6237 6238 group_admin_init = function() { 6239 nested_tabs_init(); 6240
6241 $('.js-show_inheritance_on').each(function() { 6242 if ((/true/).test($(this).find('input').first().val())) { 6243 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_off').show(); 6244 $(this).hide(); 6245 } else { 6246 $(this).show(); 6247 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_off').hide(); 6248 } 6249 }); 6250 6251 $('body').on('click', '.js-disable_inheritance', function () { 6252 console.log($(this)); 6253 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_on').hide(); 6254 $(this).parents('.js-inheritance_wrap').find(".js-disable_inheritance_checkbox > input").last().prop( "value", true ); 6255 $(".js-noninherited").prop("value",true); 6256 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_off').show(); 6257 }) 6258 $('body').on('click', '.js-enable_inheritance', function () { 6259 console.log($(this)); 6260 $(this).parents('.js-inheritance_wrap').find(".js-disable_inheritance_checkbox > input").last().prop( "value", false ); 6261 $(".js-noninherited").prop("value",false); 6262 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_off').hide(); 6263 $(this).parents('.js-inheritance_wrap').find('.js-show_inheritance_on').show(); 6264 }) 6265 } 6266 6267 6268 window["ajax_tab_callback_tab_actions"] = function() { 6269 // Group Manage - Actions 6270 group_manage_actions_list_js_init(); 6271 float_labels_init(); 6272 lined_filter_function(); 6273 submitClicked_init(); 6274 } 6275 6276 window["ajax_tab_callback_tab_email"] = function() { 6277 // Group Manage - Emails 6278 group_manage_emails_list_js_init(); 6279 group_manage_stats_expand_init(); 6280 datepick_days_past_init(); 6281 datepick_days_past_week_only_init(); 6282 float_labels_init(); 6283 lined_filter_function(); 6284 fancy_link_general_init(); 6285 can_select_init(); 6286 submitClicked_init(); 6287 emails_tabs_init(); 6288 form_select2_init(); 6289 } 6290 6291 window["ajax_tab_callback_tab_mobile"] = function() { 6292 // Group Manage - Mobile 6293 group_manage_mobile_list_js_init(); 6294 group_manage_stats_expand_init(); 6295 datepick_days_past_init(); 6296 float_labels_init(); 6297 lined_filter_function(); 6298 fancy_link_general_init(); 6299 submitClicked_init(); 6300 mobile_tabs_init(); 6301 } 6302 6303 window["ajax_tab_callback_tab_reports"] = function() { 6304 // Group Manage - Reports
6305 group_manage_report_list_js_init(); 6306 lined_filter_function(); 6307 } 6308 6309 window["ajax_tab_callback_tab_statistics"] = function() { 6310 // Group Manage - Statistics 6311 group_manage_growth_chart_init(); 6312 fancy_link_general_init(); 6313 datepick_days_past_init(); 6314 multi_select_init(); 6315 submitClicked_init(); 6316 } 6317 6318 window["ajax_tab_callback_tab_activists"] = function() { 6319 // Group Manage - Activists 6320 float_labels_init(); 6321 multi_select_init(); 6322 form_select2_init(); 6323 can_select_init(); 6324 submitClicked_init(); 6325 view_query_init(); 6326 if ($('.js-reportResults').val()) { 6327 reportResults(JSON.parse($('.js-reportResults').val())); 6328 } 6329 6330 } 6331 6332 6333 6334 window["ajax_tab_callback_tab_admin"] = function() { 6335 // Group Manage - Administrators 6336 fancy_link_general_init(); 6337 group_admin_list_init(); 6338 lined_filter_function(); 6339 float_labels_init(); 6340 admin_modal_init(); 6341 bulk_permissions_modal_init(); 6342 submitClicked_init(); 6343 group_admin_init(); 6344 } 6345 6346 window["ajax_tab_callback_tab_settings"] = function() { 6347 // Group Manage - Settings 6348 group_manage_settings_init(); 6349 float_labels_init(); 6350 are_you_sure_dirty_init(); 6351 settings_checkbox_init(); 6352 form_select2_init(); 6353 can_select_init(); 6354 data_processing_init(); 6355 redactor_init_function(); 6356 mobile_reply_init(); 6357 fancy_link_general_init(); 6358 form_submit_init(); 6359 submitClicked_init(); 6360 //input_with_default_init(); 6361 donation_return_flag = false; 6362 no_email_entry_init(); 6363 } 6364 6365 window["ajax_tab_callback_tab_network"] = function() { 6366 // Group Manage - Network 6367 fancy_link_general_init(); 6368 lined_filter_function(); 6369 float_labels_init(); 6370 datepick_days_past_init(); 6371 group_manage_network_tab_init(); 6372 submitClicked_init(); 6373 } 6374 6375 window["ajax_tab_callback_tab_syndication"] = function() { 6376 // Group Manage - Syndication 6377 //no-op for now, no js 6378 } 6379 } 6380 6381 /* ======================= End Tab Ajax ======================= */ 6382 6383 var no_email_entry_init = function() { 6384 $('.js-noemailaddress').change(function() { 6385 if ($(this).val().includes('@')) { 6386 $(this).val($(this).val().replaceAll("@","")); 6387 } 6388 }); 6389 } 6390 6391 /* ======================= Group Management ======================= */ 6392 6393/* 6394 $('.js-dashboard_fundraiser_quicklinks small div').on('mouseenter', function() { 6395 $('.js-legacy_subscribers').fadeIn('fast'); 6396 }); 6397 6398 6399 $('.js-dashboard_fundraiser_quicklinks small div').on('mouseleave', function() { 6400 $('.js-legacy_subscribers').fadeOut('fast'); 6401 }); 6402*/ 6403 6404 /* ====== toggle pinned ========= */ 6405 $('body').on('click', '.js-toggle_pinned', function(e) { 6406 e.preventDefault(); 6407 var $that = $(this); 6408 $.post($that.attr('href'), {} , function(data) { 6409 if (data.success == true) { 6410 //console.log($that); 6411 location.reload(); 6412 } 6413 }); 6414 }); 6415 6416 pinned_items_init = function() { 6417 if (getCookie($('.js-edit_highlights').data('group_url') + '_pinned_report_visible') == 'false') { 6418 $('.js-pinned_container_report').hide(); 6419 $('.js-show_pinned_link[data-pinned-type="report"]').show(); 6420 } 6421 6422 if (getCookie($('.js-edit_highlights').data('group_url') + '_pinned_email_visible') == 'false') { 6423 $('.js-pinned_container_email').hide(); 6424 $('.js-show_pinned_link[data-pinned-type="email"]').show(); 6425 } 6426 6427 if (getCookie($('.js-edit_highlights').data('group_url') + '_pinned_mobile_visible') == 'false') { 6428 $('.js-pinned_container_mobile').hide(); 6429 $('.js-show_pinned_link[data-pinned-type="mobile"]').show(); 6430 } 6431 6432 $('.js-pinned_toggle_link').off('click').click(function(){ 6433 var pinnedType = $(this).data('pinned-type'); 6434 var pinnedContainer = $('.js-pinned_container[data-pinned-type="' + pinnedType + '"]'); 6435 6436 pinnedContainer.slideToggle(function() { 6437 $('.js-show_pinned_link[data-pinned-type="' + pinnedType + '"]').toggle(); 6438 6439 setCookie($('.js-edit_highlights').data('group_url') + '_pinned_' + pinnedType + '_visible', pinnedContainer.is(':visible')); 6440 }); 6441 }); 6442 } 6443 6444 6445 6446 function highlightedReportsModalOpen(event) { 6447 event.preventDefault(); 6448 let $select = $('select.js-highlight_select').first(); 6449 6450 if ($select.find('option').length == 1) { 6451 $('.js-edit_highlights_content, .js-edit_highlights_error').hide(); 6452 $('.js-edit_highlights_loading').show(); 6453 6454 $.get("/groups/" + $('.js-edit_highlights').data('group_url') + "/report_highlights/mount_options", function(data) { 6455 // prevents adding options multiple times 6456 var options = data; 6457 6458 //populates first select 6459 options.forEach(option => { 6460 let optionElement = document.createElement("option"); 6461 optionElement.value = option.id; 6462 optionElement.innerText = option.name; 6463 $select.append(optionElement.cloneNode(true)); 6464 }); 6465 6466 let selectedReportId = $select.data('selected-report-id'); 6467 6468 if (selectedReportId) { 6469 $select.val(selectedReportId).trigger("change"); 6470 } 6471 6472 let highlightsSelectsIterator = Array(6).fill(1).map( (_, i) => i+1 ) 6473 6474 //populates other selects copying options from first select 6475 highlightsSelectsIterator.forEach(i => { 6476 if(i == 0){ return } 6477 let $optionsCloned = $select.find('option:not(:first)'); 6478 6479 let $otherselect = $($('select.js-highlight_select')[i]); 6480 6481 $optionsCloned.each(function() { 6482 $otherselect.append(this.cloneNode(true)); 6483 }); 6484 6485 let selectedReportId = $otherselect.data('selected-report-id'); 6486 6487 if (selectedReportId) { 6488 $otherselect.val(selectedReportId).trigger("change"); 6489 } 6490 }); 6491 6492 $('.js-edit_highlights_loading, .js-edit_highlights_error').hide(); 6493 $('.js-edit_highlights_content').fadeIn(); 6494 }).error(function() { 6495 $('.js-edit_highlights_loading, .js-edit_highlights_content').hide(); 6496 $('.js-edit_highlights_error').show(); 6497 }); 6498 } else { 6499 $('.js-edit_highlights_loading, .js-edit_highlights_error').hide(); 6500 $('.js-edit_highlights_content').show(); 6501 } 6502 6503 } 6504 6505 $(".js-edit-highlights-button, .js-highlights-list-button").on("click", function(event) { 6506 highlightedReportsModalOpen(event) 6507 }); 6508 6509 $('.js-highlights_pagination a').click(e => {
6510 $('.js-highlights_pagination li').removeClass('active'); 6511 $(e.target).parent().addClass('active'); 6512 if ($(e.target).attr('name') == 'highlights_page_2') { 6513 $('.js-highlights').addClass('highlights_page_2'); 6514 } 6515 else { 6516 $('.js-highlights').removeClass('highlights_page_2'); 6517 } 6518 }) 6519 /* ======================= End Group Management ======================= */ 6520 6521 /* ======================= Group Management - Networks ======================= */ 6522 group_manage_network_tab_init = function() { 6523 $('#network_tree .list > li > .network_name_span .fa').addClass('fa-chevron-circle-down').removeClass('fa-chevron-circle-right').parent().parent().parent().addClass('js-network_accord_is_open'); 6524 $('.js-network_accord').click(function(){ 6525 $(this).children().toggleClass('fa-chevron-circle-down'); 6526 $(this).children().toggleClass('fa-chevron-circle-up'); 6527 $(this).parent().parent('li').toggleClass('js-network_accord_is_open').children('ul.lined').slideToggle(150); 6528 }); 6529 6530 /* custom searching for networks */ 6531 var deBouncer = function($,cf,of, interval){
6532 // deBouncer by hnldesign.nl 6533 // based on code by Paul Irish and the original debouncing function from John Hann 6534 // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ 6535 var debounce = function (func, threshold, execAsap) { 6536 var timeout; 6537 return function debounced () { 6538 var obj = this, args = arguments; 6539 function delayed () { 6540 if (!execAsap) 6541 func.apply(obj, args); 6542 timeout = null; 6543 } 6544 if (timeout) 6545 clearTimeout(timeout); 6546 else if (execAsap) 6547 func.apply(obj, args); 6548 timeout = setTimeout(delayed, threshold || interval); 6549 }; 6550 }; 6551 jQuery.fn[cf] = function(fn){ return fn ? this.bind(of, debounce(fn)) : this.trigger(cf); }; 6552 }; 6553 6554 deBouncer($,'debounced_keyup','keyup',150); 6555 6556 // Searching does NOT filter the in-DOM tree (toggling hundreds of nested rows reflows 6557 // the whole thing — slow, and worst on a 1-letter term that matches almost everything). 6558 // Instead we hide the tree as a single block and render only the matched groups into a 6559 // flat results list, cloned from an HTML <template> and injected in one pass. 6560 function searchList() { 6561 var RESULT_CAP = 150; // bound the broad-term render 6562 var $tree = $('.js-network_tree'); 6563 var treeWrap = $tree.find('.js-network_tree_wrap')[0]; 6564 var $resWrap = $tree.find('.js-network_search_results_wrap'); 6565 var resList = $resWrap.find('.js-network_search_results')[0]; 6566 var $empty = $resWrap.find('.js-network_search_empty'); 6567 var tpl = $tree.find('.js-network_result_tpl')[0]; 6568 6569 if (!treeWrap || !resList || !tpl || !tpl.content) { return; } 6570 6571 // Build a flat index ONCE from the already-rendered rows (no server, no re-render). 6572 // Rows are visited in document order, so a parent is always indexed before its children; 6573 // we tag each li with its index position to link children back to their parent entry. 6574 var index = []; 6575 $tree.find('li.js-network_branch_li').each(function() { 6576 var link = this.querySelector('.js-network_branch_name'); 6577 var name = link ? link.textContent.replace(/\s+/g, ' ').replace(/^\s|\s$/g, '') : ''; 6578 // A row with an accordion toggle has children; a leaf shows a minus (see _network_branch.erb). 6579 var iconDiv = this.querySelector('.list-item__icon'); 6580 var hasChildren = !!(iconDiv && iconDiv.querySelector('.js-network_accord')); 6581 6582 var actionsDiv = this.querySelector('.list-item__actions'); 6583 var permLink = actionsDiv ? actionsDiv.querySelector('.js-fancylink_group_permissions') : null; 6584 var parentLi = $(this).parent().closest('li.js-network_branch_li')[0]; 6585 var parent = parentLi ? parentLi._an_network_index : -1; 6586 this._an_network_index = index.length; 6587 index.push({ 6588 nameUpper: name.toUpperCase(), 6589 name: name, 6590 url: link ? link.getAttribute('href') : '#', 6591 hasChildren: hasChildren, 6592 permLink: permLink, 6593 parent: parent, 6594 depth: parent < 0 ? 0 : index[parent].depth + 1 6595 }); 6596 }); 6597 6598 $tree.find('.js-search').debounced_keyup(function() { 6599 var term = $(this).val().toUpperCase().replace(/^\s+|\s+$/g, ''); 6600 6601 if (term === '') { // restore the browse view (tree keeps its expand/collapse state) 6602 resList.innerHTML = ''; 6603 $resWrap.addClass('hide'); 6604 $(treeWrap).removeClass('hide'); 6605 return; 6606 } 6607 6608 // Pass 1: mark matches (capped) plus their ancestor chains, so results keep the 6609 // tree context — the top group and any parents of a match stay visible, as before. 6610 var include = [], matched = 0, i, j, item; 6611 for (i = 0; i < index.length && matched < RESULT_CAP; i++) { 6612 if (index[i].nameUpper.indexOf(term) < 0) { continue; } 6613 matched++; 6614 for (j = i; j >= 0 && !include[j]; j = index[j].parent) { include[j] = true; } 6615 } 6616 6617 // Pass 2: render the included rows in tree order, indented by their depth. 6618 var frag = document.createDocumentFragment(); 6619 var row, li, nameEl, manageEl, iconEl, permEl; 6620 for (i = 0; i < index.length; i++) { 6621 if (!include[i]) { continue; } 6622 item = index[i]; 6623 row = tpl.content.cloneNode(true); 6624 li = row.querySelector('li'); 6625 nameEl = row.querySelector('.js-name'); 6626 manageEl = row.querySelector('.js-manage'); 6627 iconEl = row.querySelector('.js-icon'); 6628 nameEl.textContent = item.name; 6629 nameEl.setAttribute('href', item.url); 6630 manageEl.setAttribute('href', item.url); 6631 if (item.permLink) { // copy the row's permissions shield; clicks proxy to the original (see handler below) 6632 permEl = item.permLink.cloneNode(true); 6633 permEl._an_network_index = i; 6634 manageEl.parentNode.insertBefore(permEl, manageEl); 6635 } 6636 // Match the tree's leading icon: circle-chevron for groups with children, minus for leaves. 6637 iconEl.className = 'far ' + (item.hasChildren ? 'fa-chevron-circle-up' : 'fa-minus'); 6638 // Same per-level indent the nested tree gets from `#network_tree ul ul { padding-left: 26px }`. 6639 if (item.depth > 0) { li.style.paddingLeft = (item.depth * 26) + 'px'; } 6640 frag.appendChild(row); 6641 } 6642 6643 // Single DOM write for the whole result set, then swap tree <-> results. 6644 resList.innerHTML = ''; 6645 resList.appendChild(frag); 6646 $empty.toggleClass('hide', matched > 0); 6647 $(treeWrap).addClass('hide'); 6648 $resWrap.removeClass('hide'); 6649 }); 6650 6651 // The cloned shields aren't fancybox-bound (that binding ran at init, on the tree's 6652 // links) — delegate clicks back to the original link, which opens the modal. 6653 $(resList).on('click', '.js-fancylink_group_permissions', function(e) { 6654 e.preventDefault(); 6655 var item = index[this._an_network_index]; 6656 if (item && item.permLink) { $(item.permLink).trigger('click'); } 6657 }); 6658 } 6659 6660 6661 searchList(); 6662 6663 6664 6665 $('.js-fancylink_group_permissions').fancybox({ 6666 onComplete: function() { 6667 //console.log(this); 6668 //console.log(this.href); 6669 //console.log($(this.href)); 6670 var $div = $(this.href) 6671 var permalink = $div.data('permalink'); 6672 var modalType = $div.data('modal-type'); 6673 $('body').addClass('body_has_modal'); 6674 function repositionModal() { 6675 var wrapHeight = $('#fancybox-wrap').outerHeight(); 6676 var winHeight = $(window).height(); 6677 var topOffset = $(window).width() < 768 ? 0 : 15; 6678 var top = wrapHeight >= winHeight 6679 ? topOffset + $(window).scrollTop() 6680 : Math.max(topOffset, (winHeight - wrapHeight) / 2 + $(window).scrollTop()); 6681 $('#fancybox-wrap').css('top', top + 'px'); 6682 } 6683 $.get(`/child_permissions/${permalink}?modal_type=${modalType}`, function(data) { 6684 $div.html(data); 6685 repositionModal(); 6686 // Show child permissions confirm modal 6687 $div.find('.js-show_child_permissions_confirm').on('click', function() { 6688 $div.find('.js-child_permissions_form').hide(); 6689 $div.find('.js-child_permissions_confirm').show(); 6690 $('#fancybox-wrap').scrollTop(0); 6691 repositionModal(); 6692 }); 6693 // Hide child permissions confirm modal (go back) 6694 $div.find('.js-hide_child_permissions_confirm').on('click', function() { 6695 $div.find('.js-child_permissions_confirm').hide(); 6696 $div.find('.js-child_permissions_form').show(); 6697 $('#fancybox-wrap').scrollTop(0); 6698 repositionModal(); 6699 }); 6700 }).fail(function() { 6701 $div.html('<small>'+an_javascript_translation.an_error_occurred_please_try_again+'</small>'); 6702 }); 6703 }, 6704 onClosed: function() { 6705 $('.js-file_delete_link').css('display','inline'); 6706 $('.js-edit_confirm_delete').css('display','none'); 6707 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
6708 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 6709 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 6710 $('body').removeClass('form_builder_edit'); 6711 }, 6712 margin: 15, 6713 hideOnOverlayClick: false 6714 }); 6715 } 6716 6717 group_manage_network_tab_init(); 6718 6719 6720 /* ======================= END Group Management - Networks ======================= */ 6721 6722 /* ======================= START Discussions ======================= */ 6723 6724 $('.js-tab_discussion .js-switch-toggle').click(function() { 6725 6726 if ($(this).hasClass('js-switch-enabled')) { 6727 6728 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 6729 $(this).siblings('.js-switch_enabled_label').hide(); 6730 $(this).siblings('.js-switch_disabled_label').show(); 6731 $(this).parent().siblings().not(".js-entry-title").delay(300).slideUp(200); 6732 6733 } else { 6734 6735 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 6736 $(this).siblings('.js-switch_disabled_label').hide(); 6737 $(this).siblings('.js-switch_enabled_label').show(); 6738 $(this).parent().siblings().delay(300).slideDown(300); 6739 6740 } 6741 6742 }); 6743 6744 /* ======================= END Discussions ======================= */ 6745 6746 /* ======================= START Profile Edit ======================= */ 6747 6748 $(".js-edit_profile_save_changes").fancybox({ 6749 onStart: function() { 6750 if (!$('.js-edit_profile_form').valid()) { 6751 return false; 6752 } 6753 }, 6754 onComplete: function() { 6755 $('body').addClass('body_has_modal'); 6756 }, 6757 onClosed: function() { 6758 $('.js-file_delete_link').css('display','inline'); 6759 $('.js-edit_confirm_delete').css('display','none'); 6760 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 6761 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 6762 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 6763 $('body').removeClass('form_builder_edit'); 6764 }, 6765 margin: 15, 6766 hideOnOverlayClick: false 6767 }); 6768 6769 $('.js-show_two_factor_security_warning').click(()=>{ 6770 $('.js-two_factor_security_warning').slideToggle(); 6771 }) 6772 6773 $('.js-save_profile_confirm_button').click(function(e) { 6774 //console.log('click'); 6775 e.preventDefault(); 6776 if ($('.js-save_profile_confirm_form').valid()) { 6777 $('.js-edit_profile_form, .js-edit_two_factor').append('<input name="user[current_password]" class="js-save_profile_confirm_password_output" type="hidden" value="' + $('.js-save_profile_confirm_password_input').val() + '">'); 6778 submitClicked = "edit_profile_form"; 6779 $('.js-edit_profile_form, .js-edit_two_factor').submit(); 6780 } 6781 }); 6782 6783 /* ======================= END Profile Edit ======================= */ 6784 6785 6786 /* ======================= START Power Query Toggle ======================= */ 6787 6788 $('.js-power_toggle .js-switch-toggle').click(function() { 6789 6790 if ($(this).hasClass('js-switch-enabled')) { 6791 6792 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 6793 $(this).siblings('.js-switch_enabled_label').hide(); 6794 $(this).siblings('.js-switch_disabled_label').show(); 6795 6796 } else { 6797 6798 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 6799 $(this).siblings('.js-switch_disabled_label').hide(); 6800 $(this).siblings('.js-switch_enabled_label').show(); 6801 6802 } 6803 6804 }); 6805 6806 $('.js-single_power_toggle .js-switch-toggle').not('.js-email_writing_wrap .js-switch-toggle').click(function() { 6807 6808 var confirmation = confirm(an_javascript_translation.query_mode_toggle); 6809 6810 if (confirmation != true) { 6811 return false; 6812 } 6813 //test this!!!! 6814 $('form.js-create_email2_form').trigger('reinitialize.areYouSure'); 6815 6816 if ($(this).hasClass('js-switch-enabled')) { 6817 6818 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 6819 $(this).parent('.js-single_power_toggle').removeClass('single_power_toggle-on js-single_power_toggle-on').addClass('single_power_toggle-off js-single_power_toggle-off'); 6820 $(this).parent('.js-single_power_toggle').siblings('.js-query_import').slideUp(100); 6821
6822 $('.js-include_exclude_wrap').slideUp(); 6823 6824 6825 } else { 6826 6827 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 6828 $(this).parent('.js-single_power_toggle').removeClass('single_power_toggle-off js-single_power_toggle-off').addClass('single_power_toggle-on js-single_power_toggle-on'); 6829 $(this).parent('.js-single_power_toggle').siblings('.js-query_import').slideDown(100); 6830 $('.js-include_exclude_wrap').slideUp(); 6831 6832 } 6833 6834 }); 6835 6836 /* ======================= END Power Query Toggle ======================= */ 6837 6838 /* ======================= START Redactor/Unlayer ======================= */ 6839 6840 // alternate subjects, froms, and bodies 6841 6842 $('.js-subject_email_line').on('click', '.js-circle_add', function() { 6843 $('.js-subject_email_line .js-circle_add').remove(); 6844 $('.js-subject_email_line').append('' 6845 + '<div class="alternate_subject_wrap clear">' 6846 + '<input type="text" id="email-subject-alternate" class="create_action-editable js-create_action-editable js-email-subject-alternate hundredtool" placeholder="' + an_javascript_translation.alternate_subject + '" name="alternate_subjects[]" autocomplete="off" />' 6847 + '<a class="circle_add js-circle_add righti"><i class="fas fa-plus-circle"></i></a>' 6848 + '</div>' 6849 + ''); 6850 remove_tooltip(); 6851 }); 6852 6853 $('.js-from_email_line').on('click', '.js-circle_add', function() { 6854 $('.js-from_email_line .js-circle_add').remove(); 6855 $('.js-from_email_line').append('' 6856 + '<div class="alternate_subject_wrap clear">' 6857 + '<input type="text" id="email-from-alternate" class="create_action-editable js-create_action-editable js-email-from-alternate js-noemailaddress hundredtool" placeholder="' + an_javascript_translation.alternate_from + '" name="alternate_froms[]" autocomplete="off" />' 6858 + '<a class="circle_add js-circle_add righti"><i class="fas fa-plus-circle"></i></a>' 6859 + '</div>' 6860 + ''); 6861 remove_tooltip(); 6862 }); 6863 6864 $('.js-email_preview_line').on('click', '.js-circle_add', function() { 6865 $('.js-email_preview_line .js-circle_add').remove(); 6866 $('.js-email_preview_line').append(` 6867 <div class="alternate_subject_wrap js-preview_count_container clear"> 6868 <input 6869 type="text" 6870 id="email-preview-alternate" 6871 class="js-email_preview_count create_action-editable js-create_action-editable js-noemailaddress hundredtool" 6872 placeholder="${an_javascript_translation.alternate_preview}" 6873 name="alternate_pre_headers[]" 6874 autocomplete="off" 6875 /> 6876 <a class="circle_add js-circle_add righti"> 6877 <i class="fas fa-plus-circle"></i> 6878 </a> 6879 <div class="js-preview_count left hundred clearfix mb20 mt-20 line-height-normal "> 6880 <span class="inlineblock"><strong><small><span class="js-preview_char_count ">0/280 </span> ${an_javascript_translation.characters}</small></strong></span> 6881 <span class="js-preview_count_notice character_count inline-block"><small>(${an_javascript_translation.we_recommend_keeping_this_to_90_characters_or_less})</small></span> 6882 </div> 6883 </div> 6884 `); 6885 remove_tooltip(); 6886 }); 6887 6888 if ($('.js-email_bodies_wrap').length && $('.js-unlayer_editor').length) { 6889 unlayer_body_active = 0; // 0 indexed! 6890 if ($('.js-error_liquid_wrap').length) { 6891 var show_liquid_errors = false; 6892 $('.js-error_liquid_wrap .js-liquid_errors_body_title').each(function(i, e) { 6893 if ($(this).text() == "original") { 6894 show_liquid_errors = true; 6895 } 6896 }); 6897 6898 if (show_liquid_errors) { 6899 $('.js-unlayer_editor').addClass('error_liquid'); 6900 } else { 6901 $('.js-unlayer_editor').removeClass('error_liquid'); 6902 } 6903 } 6904 6905 if ($('.js-email_builder_html').length > 1) { 6906 $('.js-next_body').show(); 6907 $('.js-email_bodies_wrap .js-circle_add').hide(); 6908 } 6909 6910 $('.js-builder_body_title_text').addClass('disabled'); 6911 } 6912 6913 if ($('.js-unlayer_editor_layout').length) { 6914 unlayer_body_active = 0; // 0 indexed! stub for wrappers 6915 } 6916 6917 6918 6919 6920 mobile_reply_init = function() { 6921 if ($('.js-mobile_reply_body').length) { 6922 $(".js-mobile_reply_body").each(function() { 6923 $(this).charCount({ 6924 allowed: 160, 6925 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 6926 wrapperSelector: '.js-mobile_reply_wrapper', 6927 link_shortening: false 6928 }); 6929 }); 6930 } 6931 6932 if ($('.js-mobile_template_body').length) { 6933 $(".js-mobile_template_body").each(function() { 6934 $(this).charCount({ 6935 allowed: 160, 6936 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 6937 wrapperSelector: '.js-mobile_reply_wrapper', 6938 hostname: $('.js-mobile_custom_shortlink').val(), 6939 regex: "url_strict" 6940 }); 6941 }); 6942 } 6943 } 6944 mobile_reply_init(); 6945 6946 6947 6948 //console.log($('.js-message_body')); 6949 if ($('.js-message_body').length) { 6950 $(".js-message_body").each(function() { 6951 $(this).charCount({ 6952 allowed: 160, 6953 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 6954 wrapperSelector: '.js-ladder_action_sms_write', 6955 hostname: $('.js-mobile_custom_shortlink').val(), 6956 regex: "url_strict" 6957 }); 6958 }); 6959 } 6960 6961 if ($('.js-sms_auto_reply').length) { 6962 $(".js-sms_auto_reply").each(function() { 6963 $(this).charCount({ 6964 allowed: 160, 6965 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 6966 wrapperSelector: '.js-append_text_message', 6967 link_shortening: false 6968 }); 6969 }); 6970 } 6971 6972 if ($('.js-inbox_send_message').length) { 6973 $(".js-inbox_send_message").each(function() { 6974 $(this).charCount({ 6975 allowed: 160, 6976 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 6977 wrapperSelector: '.js-inbox_footer', 6978 link_shortening: false 6979 }); 6980 }); 6981 } 6982 6983 // Emoji Picker 6984 if ($('.js-sms_add-emoji').length) { 6985 // Add Emoji Picker to new body 6986 var newEmojiPicker = $('.js-sms_add-emoji'); 6987 6988 // Emoji Picker 6989 newEmojiPicker.emojioneArea({ 6990 standalone: true, 6991 autocomplete: false, 6992 pickerPosition: "bottom", 6993 search: false, 6994 hideSource: false 6995 }); 6996 6997 emojiPickerInit = function(picker) { 6998 //console.log(picker); 6999 var $el = $(picker); 7000 //console.log($el); 7001 7002 var $emojionearea = $el[0].emojioneArea; 7003 // Grab next button to assign as trigger 7004 var $emojiTrigger = $el.parent().find('.js-sms_add-emoji-btn'); 7005 //console.log($emojiTrigger); 7006 7007 $emojiTrigger.on('click', function(e) { 7008 //console.log('click'); 7009 e.preventDefault(); 7010 $emojionearea.showPicker(); 7011 }) 7012 7013 $emojiTrigger.on('blur', function(e) { 7014 $emojionearea.hidePicker(); 7015 }) 7016 7017 $emojionearea.setText(''); 7018 7019 $emojionearea.on('picker.show', function () { 7020 // Check if outside of window bounds, adjust if necessary 7021 const rect = $emojionearea.picker[0].getBoundingClientRect(); 7022 if (rect.left < 0) { 7023 const offset = rect.left * -1 + 15; 7024 // Move into bounds 7025 $emojionearea.picker.css('transform', `translateX(${offset}px)`) 7026 // Adjust caret position - pseudo element requires inline style 7027 function getSelectorForElement(element) { 7028 const $element = $(element); 7029 const selectorParts = []; 7030 7031 $element.parents().each(function() { 7032 const $this = $(this); 7033 const tagName = this.tagName.toLowerCase(); 7034 const id = this.id ? `#${this.id}` : ''; 7035 const classes = this.className ? `.${this.className.replace(/\s+/g, '.')}` : ''; 7036 7037 selectorParts.unshift(tagName + id + classes); 7038 }); 7039 7040 return selectorParts.join(' > '); 7041 } 7042 var inlineStyle = $emojionearea.picker.find('style'); 7043 if (inlineStyle.length == 0) { 7044 $emojionearea.picker.append('<style></style>'); 7045 inlineStyle = $emojionearea.picker.find('style'); 7046 } 7047 inlineStyle.text(` 7048 ${getSelectorForElement($emojionearea.picker)} .emojionearea-wrapper:after { 7049 right: ${23 + (offset)}px; 7050 } 7051 `); 7052 } 7053 }) 7054 7055 $emojionearea.on('picker.hide', function() { 7056 var $emoji = $el.data("emojioneArea").getText(); 7057 $emojionearea.setText(''); 7058 7059 if($emoji) { 7060 if (typeof($mobile_textarea_with_focus) != 'undefined' && $mobile_textarea_with_focus.hasClass('CodeMirror')) { 7061 console.log($emoji); 7062 $mobile_textarea_with_focus[0].CodeMirror.doc.replaceSelection($emoji); 7063 $.fancybox.close(); 7064 7065 } else { 7066 var $textarea = $el.closest('.js-sms_body_textarea, .js-ladder_action_sms_write').find('.js-mobile_message_body, .js-message_body');
7067 var cursorPos = $textarea.prop('selectionStart'); 7068 var v = $textarea.val(); 7069 var textBefore = v.substring(0, cursorPos); 7070 var textAfter = v.substring(cursorPos, v.length); 7071 var textInsert = $emoji; 7072 7073 $textarea.val(textBefore + textInsert + textAfter).trigger('change'); 7074 7075 } 7076 7077 } 7078 }); 7079 // Reset any previous adjustments 7080 setTimeout(function () { 7081 if ($emojionearea && $emojionearea.picker) { 7082 $emojionearea.picker.css('transform', 'none'); 7083 $emojionearea.picker.find('style').remove(); 7084 } 7085 }, 250) 7086 } 7087 7088 $.each(newEmojiPicker, function() { 7089 emojiPickerInit(this); 7090 }); 7091 } 7092 7093 7094 // Add additional MMS images 7095 $('.js-media_upload_url').on('click', '.js-circle_add', function() { 7096 $('.js-media_upload_url .js-circle_add').remove(); 7097 var random_id = Math.floor((1 + Math.random()) * 0x10000).toString(16); 7098 if ($('html').attr('id') === 'style4') { 7099 $('.js-media_upload_url').append('' 7100 + '<div style="flex-basis: 100%;" class="flex-break"></div>' 7101 + '<div class="mms_input__wrap alternate_image_field_wrap clear">' 7102 + ' <input type="text" id="admin-mms_media_image_url-alternate" name="alternate_images[][image]" class="mms_media_image_url js-mms_media_image_url create_action-editable js-create_action-editable nomb" placeholder="' + an_javascript_translation.url_to_your_image_starts_with_http + '" />' 7103 + ' <input type="file" id="mms_media_upload_input-alternate_' + random_id + '" class="hide js-mms_media_upload_input" hidden />' 7104 + ' <label for="mms_media_upload_input-alternate_' + random_id + '" class="button js-mms_media_upload-label" id="mms_media_upload-label">'+ an_javascript_translation.upload +'</label> ' 7105 + '<a class="circle_add js-circle_add righti js-tooltip hiddentooltip"><i class="fas fa-plus-circle"></i> <span>'+ an_javascript_translation.enter_the_url_of_your_image_to_be_used_for_mms_messaging +'</span></a>' 7106 + '</div>' 7107 + ''); 7108 } else { 7109 $('.js-media_upload_url').append('' 7110 + '<div style="flex-basis: 100%;" class="flex-break"></div>' 7111 + '<div class="mms_input__wrap alternate_image_field_wrap clear">' 7112 + ' <input type="text" id="admin-mms_media_image_url-alternate" name="alternate_images[][image]" class="mms_media_image_url js-mms_media_image_url create_action-editable js-create_action-editable" placeholder="' + an_javascript_translation.url_to_your_image_starts_with_http + '" />' 7113 + ' <input type="file" id="mms_media_upload_input-alternate_' + random_id + '" class="hide js-mms_media_upload_input" hidden />' 7114 + ' <label for="mms_media_upload_input-alternate_' + random_id + '" class="button js-mms_media_upload-label" id="mms_media_upload-label">'+ an_javascript_translation.upload +'</label> ' 7115 + '<a class="circle_add js-circle_add righti js-tooltip hiddentooltip"><i class="fas fa-plus-circle"></i> <span>'+ an_javascript_translation.enter_the_url_of_your_image_to_be_used_for_mms_messaging +'</span></a>' 7116 + '</div>' 7117 + ''); 7118 } 7119 }); 7120 7121 $('.js-email_bodies_wrap').on('click', '.js-circle_add', function() { 7122 //console.log('click'); 7123 if ($('.js-unlayer_editor').length) { 7124 //var unlayer_id_random = Math.floor((1 + Math.random()) * 0x10000).toString(16); 7125// $('.js-add_new_body').remove(); 7126 if (!$('.js-email_bodies_wrap').hasClass('js-unlayer_loading')) { 7127 7128 if ($('.js-builder_body_title_text').val() == '') { 7129 $('.js-builder_body_title_text').addClass('error_input'); 7130 } else { 7131 $('.js-email_bodies_wrap').addClass('js-unlayer_loading'); 7132 $('.js-builder_body_title_text').removeClass('error_input'); 7133 if (!$(this).hasClass('disabled')) { 7134 //console.log('click'); 7135 $(this).addClass('disabled'); 7136 var $button = $(this); 7137 unlayer.exportHtml(function(data) { 7138 $('.js-email_builder_json').eq(unlayer_body_active).val(JSON.stringify(data.design)); 7139 $('.js-email_builder_html').eq(unlayer_body_active).val(data.html.replace(/'/g,"'").replace(/"/g,'"').replace(/&#039;/g,"'").replace(/&quot;/g,'"')); 7140 $('.js-email_builder_title_hidden').eq(unlayer_body_active).val($('.js-builder_body_title_text').val()); 7141 7142 $('.js-email_variant_slider').append('' 7143 + '<div class="unlayer_write single_variant_slide js-single_variant_slide clearfix">' 7144 + '<input type="hidden" name="alternate_bodies[][title]" value="" class="js-email_builder_title_hidden">' 7145 + '<input type="hidden" name="alternate_bodies[][builder_html]" value="" class="js-email_builder_html">' 7146 + '<input type="hidden" name="alternate_bodies[][builder_json]" value="" class="js-email_builder_json">' 7147 + '</div>' 7148 + ''); 7149 7150 unlayer_body_active = unlayer_body_active + 1; 7151 7152 $('.js-unlayer_editor').removeClass('error_liquid'); 7153 7154 7155 $('.js-prev_body, .js-delete_body').show(); 7156 7157 var $target = $('.js-unlayer_editor').prev(); 7158 $('.js-unlayer_editor').fadeOut(function() { 7159 $(this).remove(); 7160 $target.after('<div id="editor-container" class="js-unlayer_editor editor-container"></div>'); 7161 7162 $('.js-email_builder_json').eq(unlayer_body_active).val($('.js-email_builder_json').first().val()); 7163 $('.js-email_builder_html').eq(unlayer_body_active).val($('.js-email_builder_html').first().val()); 7164 7165 unlayer_init($('.js-unlayer_editor'), true); 7166 7167 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 7168 7169 $button.removeClass('disabled'); 7170 7171 $('.js-builder_body_title_text').removeClass('disabled').attr('disabled', false).val(''); 7172 }); 7173 7174 }); 7175 } 7176 } 7177 } 7178 7179 } else if ($('.js-mobile_wrapper').length) { 7180 $(this).remove(); 7181 if ($('.js-switch-enabled').length) { 7182 var hide_character = "hide"; 7183 } else { 7184 var hide_character = ""; 7185 } 7186 // this is checking for the v4 ID so that button classes get applied properly 7187 if ($('html').attr('id') === 'style4') { 7188 var that = $('.js-email_bodies_wrap').append('' 7189 + '<div class="clearfix sms_body_textarea js-sms_body_textarea">' 7190 + '<div>' 7191 + '<div class="alternate_body_title_wrap js-alternate_body_title_wrap clearfix test">' 7192 + '<input type="text" class="hundredtool js-create_action-editable" name="alternate_bodies[][title]" value="" placeholder="' + an_javascript_translation.alternate_body_title + '" autocomplete="off">' 7193 + '<a class="tooltip js-tooltip right mt5 js-tooltip_redactor_ignore"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_title_description + '</span></a>' 7194 + '</div>' 7195 + '</div>' 7196 + '<div>' 7197 + '<a class="tooltip js-tooltip right"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.short_and_to_the_point_is_good_and_dont_forget_to_links_to_take_action + '</span></a>' 7198 + '<div class="mobile-add-buttons hundred-35">' 7199 + '<a class="sms_add-clips right mb10 fs-14 fancylink js-fancylink js-sms_add-clips" href="#clipsmodal"><i class="far fa-tags"></i> ' + an_javascript_translation.add_clips + '</a>' 7200 + '<a class="sms_add-snippet right mb10 fs-14 fancylink js-fancylink js-sms_add-snippet mr20" href="#clipsmodal_snippets_mobile"><i class="far fa-cut"></i> ' + an_javascript_translation.add_snippet + '</a>' 7201 + '<a class="sms_add-emoji right mb10 fs-14 js-sms_add-emoji" href="#"><i class="far fa-smile"></i></a>' 7202 + '<a class="sms_add-emoji right mb10 mr20 fs-14 js-sms_add-emoji-btn test" href="#"><i class="far fa-smile"></i> ' + an_javascript_translation.add_emoji + '</a>' 7203 + '</div>' 7204 + '<textarea autocomplete="off" class="create_action-editable js-create_action-editable js-mobile_message_body js-mobile-codemirror-textarea mobile-codemirror-textarea" cols="40" id="mobile-message-body" name="alternate_bodies[][text]" placeholder="' + an_javascript_translation.alternate_body_content + '" rows="20">' 7205 + $('.js-email_bodies_wrap textarea').first().val() // copy from first version 7206 + '</textarea>' 7207 + '</div>' 7208 + '<div id="character_count" class="js-character_count left clearfix ' + hide_character + '">' 7209 + '<strong><small>' + an_javascript_translation.one_hundred_and_sixty_characters_left + '</small></strong>' 7210 + '<a class="tooltip js-tooltip right ml10"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.mobile_messages_over_the_character_limit_will_be_automatically_split_up_into_multiple_messages + '</span></a>' 7211 + '</div>' 7212 + '</div>' 7213 + '<div class="add_new_body js-add_new_body mb5 mt20">' 7214 + '<a class="button button-secondary outline circle_add js-circle_add">' 7215 + ' <i class="fas fa-plus-circle"></i>' 7216 + '<small class="uppercase ml5">' + an_javascript_translation.add_alternate_body + '</small>' 7217 + '</a>' 7218 + '</div>' 7219 + '</div>' 7220 + ''); 7221 //console.log(that); 7222 } else { 7223 var that = $('.js-email_bodies_wrap').append('' 7224 + '<div class="clearfix sms_body_textarea js-sms_body_textarea">' 7225 + '<div>' 7226 + '<div class="alternate_body_title_wrap js-alternate_body_title_wrap clearfix test">' 7227 + '<input type="text" class="hundredtool js-create_action-editable" name="alternate_bodies[][title]" value="" placeholder="' + an_javascript_translation.alternate_body_title + '" autocomplete="off">' 7228 + '<a class="tooltip js-tooltip right mt5 js-tooltip_redactor_ignore"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_title_description + '</span></a>' 7229 + '</div>' 7230 + '</div>' 7231 + '<div>' 7232 + '<a class="tooltip js-tooltip right"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.short_and_to_the_point_is_good_and_dont_forget_to_links_to_take_action + '</span></a>' 7233 + '<div class="mobile-add-buttons hundred-35">' 7234 + '<a class="sms_add-clips right mb10 fs-14 fancylink js-fancylink js-sms_add-clips" href="#clipsmodal"><i class="far fa-tags"></i> ' + an_javascript_translation.add_clips + '</a>' 7235 + '<a class="sms_add-snippet right mb10 fs-14 fancylink js-fancylink js-sms_add-snippet mr20" href="#clipsmodal_snippets_mobile"><i class="far fa-cut"></i> ' + an_javascript_translation.add_snippet + '</a>' 7236 + '<a class="sms_add-emoji right mb10 fs-14 js-sms_add-emoji" href="#"><i class="far fa-smile"></i></a>' 7237 + '<a class="sms_add-emoji right mb10 mr20 fs-14 js-sms_add-emoji-btn test" href="#"><i class="far fa-smile"></i> ' + an_javascript_translation.add_emoji + '</a>' 7238 + '</div>' 7239 + '<textarea autocomplete="off" class="create_action-editable js-create_action-editable js-mobile_message_body js-mobile-codemirror-textarea mobile-codemirror-textarea" cols="40" id="mobile-message-body" name="alternate_bodies[][text]" placeholder="' + an_javascript_translation.alternate_body_content + '" rows="20">' 7240 + $('.js-email_bodies_wrap textarea').first().val() // copy from first version 7241 + '</textarea>' 7242 + '</div>' 7243 + '<div id="character_count" class="js-character_count left clearfix ' + hide_character + '">' 7244 + '<strong><small>' + an_javascript_translation.one_hundred_and_sixty_characters_left + '</small></strong>' 7245 + '<a class="tooltip js-tooltip right ml10"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.mobile_messages_over_the_character_limit_will_be_automatically_split_up_into_multiple_messages + '</span></a>' 7246 + '</div>' 7247 + '</div>' 7248 + '<div class="add_new_body js-add_new_body mb5 mt5">' 7249 + '<a class="circle_add js-circle_add">' 7250 + ' <i class="fas fa-plus-circle"></i>' 7251 + '<small class="uppercase ml5">' + an_javascript_translation.add_alternate_body + '</small>' 7252 + '</a>' 7253 + '</div>' 7254 + '</div>' 7255 + ''); 7256 //console.log(that); 7257 } 7258
7259 $('.js-mobile_message_body').not('.floatlabel-input').floatlabel(); 7260 $(".js-email_bodies_wrap .js-sms_add-clips, .js-email_bodies_wrap .js-sms_add-snippet").fancybox({ 7261 onComplete: function() { 7262 $('body').addClass('body_has_modal'); 7263 }, 7264 onClosed: function() { 7265 $('.js-file_delete_link').css('display','inline'); 7266 $('.js-edit_confirm_delete').css('display','none'); 7267 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 7268 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 7269 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 7270 $('body').removeClass('form_builder_edit'); 7271 }, 7272 margin: 15, 7273 hideOnOverlayClick: false 7274 }); 7275 7276 $(".js-mobile_message_body").each(function() { 7277 $(this).charCount({ 7278 allowed: 160, 7279 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 7280 wrapperSelector: '.js-sms_body_textarea', 7281 hostname: $('.js-mobile_custom_shortlink').val(), 7282 regex: "url_strict" 7283 }); 7284 }); 7285 7286 var context = {}; 7287 var scope = {}; 7288 $('.js-redactor_clip').each(function() { 7289 //console.log($(this).data('dropkiq-context')); 7290 //console.log($(this).data('dropkiq-scope')); 7291 $.extend(context, $(this).data('dropkiq-context')); 7292 $.extend(scope, $(this).data('dropkiq-scope')); 7293 }); 7294 //console.log(context); 7295 //console.log(scope); 7296 7297 //console.log($(that).find('.js-mobile_message_body').last()); 7298 var textArea = $(that).find('.js-mobile_message_body').last()[0]; 7299 var options = {}; 7300 if (typeof(window.DropkiqUI) != "undefined") { 7301 var dropkiqUI = new window.DropkiqUI(textArea, {}, context, scope, "4fee6b50-29d5-0138-0a6d-4a36325215e0", options); 7302 dropkiqUI.registerFilter('no_profanity', function(){ 7303 return $('.js-dropkiq-no_profanity').data('dropkiq-no_profanity') 7304 }, "no_profanity", [], an_javascript_translation.output_blank_if_text_matches_profanity_list); 7305 dropkiqUI.registerFilter('title_case', function(){ 7306 return $('.js-dropkiq-titlecase').data('dropkiq-titlecase') 7307 }, "title_case", [], an_javascript_translation.output_string_with_first_letters_capitalized); 7308 dropkiqUI.registerFilter('us_state_full', function(){ 7309 return $('.js-dropkiq-us_state_full').data('dropkiq-us_state_full') 7310 }, "us_state_full", [], an_javascript_translation.only_output_a_state_full_name_if_the_value); 7311 } 7312 7313 $('.js-mobile_message_body').parents('form').trigger('checkform.areYouSure'); 7314 7315 // Add Emoji Picker to new body 7316 var newEmojiPicker = $($(that).find('.js-sms_add-emoji').last()); 7317 7318 // Emoji Picker 7319 newEmojiPicker.emojioneArea({ 7320 standalone: true, 7321 autocomplete: false, 7322 pickerPosition: "bottom", 7323 search: false, 7324 hideSource: false 7325 }); 7326 7327 7328 7329 $.each(newEmojiPicker, function() { 7330 emojiPickerInit(this); 7331 }); 7332 7333 init_codemirror(that.find('textarea.js-mobile-codemirror-textarea').last()[0]); 7334 7335 } else { 7336// $('.js-add_new_body').remove(); 7337 $(this).remove(); 7338 // this is checking for the v4 ID so that button classes get applied properly 7339 if ($('html').attr('id') === 'style4') { 7340 $('.js-email_bodies_wrap').append('' 7341 + '<div id="email_redactor_wrap" class="email_redactor_wrap js-email_redactor_wrap clearfix">' 7342 + '<div class="alternate_body_title_wrap js-alternate_body_title_wrap clearfix">' 7343 + '<input type="text" class="hundredtool" name="alternate_bodies[][title]" value="" placeholder="' + an_javascript_translation.alternate_body_title + '" autocomplete="off">' 7344 + '<a class="tooltip js-tooltip right mt5 js-tooltip_redactor_ignore"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_title_description + '</span></a>' 7345 + '</div>' 7346 + '<textarea class="redactor js-redactor withclips js-withcl
7346ips create_action-editable js-create_action-editable hundredtool" cols="40" id="email-text" name="alternate_bodies[][text]" placeholder="' + an_javascript_translation.alternate_body_content + '" rows="20" data-group_link="' + $('textarea.js-redactor').data('group_link') + '">' 7347 + $('.js-email_bodies_wrap textarea.js-redactor').first().val() // copy from first version 7348 + '</textarea>' 7349 + '<a class="tooltip js-tooltip right"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_content_description + '</span></a>' 7350 + '</div>' 7351 + '<div class="add_new_body js-add_new_body mb5 mt20">' 7352 + '<a class="button button-secondary outline circle_add js-circle_add">' 7353 + '<i class="fas fa-plus-circle"></i>' 7354 + '<small class="uppercase ml5">' + an_javascript_translation.add_alternate_body + '</small>' 7355 + '</a></div>' 7356 + ''); 7357 } else { 7358 $('.js-email_bodies_wrap').append('' 7359 + '<div id="email_redactor_wrap" class="email_redactor_wrap js-email_redactor_wrap clearfix">' 7360 + '<div class="alternate_body_title_wrap js-alternate_body_title_wrap clearfix">' 7361 + '<input type="text" class="hundredtool" name="alternate_bodies[][title]" value="" placeholder="' + an_javascript_translation.alternate_body_title + '" autocomplete="off">' 7362 + '<a class="tooltip js-tooltip right mt5 js-tooltip_redactor_ignore"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_title_description + '</span></a>' 7363 + '</div>' 7364 + '<textarea class="redactor js-redactor withclips js-withcl
7364ips create_action-editable js-create_action-editable hundredtool" cols="40" id="email-text" name="alternate_bodies[][text]" placeholder="' + an_javascript_translation.alternate_body_content + '" rows="20" data-group_link="' + $('textarea.js-redactor').data('group_link') + '">' 7365 + $('.js-email_bodies_wrap textarea.js-redactor').first().val() // copy from first version 7366 + '</textarea>' 7367 + '<a class="tooltip js-tooltip right"><div class="fa-stack fa-2x"><i class="fas fa-circle fa-stack-2x"></i><i class="fas fa-question fa-stack-1x fa-inverse"></i></div><span>' + an_javascript_translation.alternate_body_content_description + '</span></a>' 7368 + '</div>' 7369 + '<div class="add_new_body js-add_new_body mb5 mt5">' 7370 + '<a class="circle_add js-circle_add">' 7371 + '<i class="fas fa-plus-circle"></i>' 7372 + '<small class="uppercase ml5">' + an_javascript_translation.add_alternate_body + '</small>' 7373 + '</a></div>' 7374 + ''); 7375 } 7376 7377 var with_clips, donate_form; 7378 7379 $('.js-email_bodies_wrap .js-redactor').each(function() { 7380 if (!$(this).parent().hasClass('redactor-box')) { 7381 if ($(this).hasClass('withclips')) { 7382 with_clips = true; 7383 } else { 7384 with_clips = false; 7385 } 7386 7387 if ($('.js-create_donate_form').length) { 7388 donate_form = true; 7389 } else { 7390 donate_form = false; 7391 } 7392 //console.log($(this)); 7393 redactorLoad($(this), $('.js-content > .js-container').width(), with_clips, donate_form); 7394 } 7395 7396 }); 7397 } 7398 7399 }); 7400 7401 $('.js-email_bodies_wrap .js-prev_body').click(function() { 7402 if (!$('.js-email_bodies_wrap').hasClass('js-unlayer_loading')) { 7403 7404 if ($('.js-builder_body_title_text').val() == '') { 7405 $('.js-builder_body_title_text').addClass('error_input'); 7406 } else { 7407 $('.js-builder_body_title_text').removeClass('error_input'); 7408 $('.js-email_bodies_wrap').addClass('js-unlayer_loading'); 7409 if (!$(this).hasClass('disabled')) { 7410 $(this).addClass('disabled'); 7411 var $button = $(this); 7412 unlayer.exportHtml(function(data) { 7413 $('.js-email_builder_json').eq(unlayer_body_active).val(JSON.stringify(data.design)); 7414 $('.js-email_builder_html').eq(unlayer_body_active).val(data.html.replace(/'/g,"'").replace(/"/g,'"').replace(/&#039;/g,"'").replace(/&quot;/g,'"')); 7415 $('.js-email_builder_title_hidden').eq(unlayer_body_active).val($('.js-builder_body_title_text').val()); 7416 7417 unlayer_body_active = unlayer_body_active - 1; 7418 7419 var $target = $('.js-unlayer_editor').prev(); 7420 $('.js-unlayer_editor').fadeOut(function() { 7421 $(this).remove(); 7422 7423 $target.after('<div id="editor-container" class="js-unlayer_editor editor-container"></div>'); 7424 7425 unlayer_init($('.js-unlayer_editor'), false); 7426 7427 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 7428 7429 $button.removeClass('disabled'); 7430 7431 $('.js-next_body').show(); 7432 $('.js-email_bodies_wrap .js-circle_add').hide(); 7433 7434 if (unlayer_body_active == 0) { 7435 $('.js-prev_body, .js-delete_body').hide(); 7436 $('.js-builder_body_title_text').addClass('disabled').attr('disabled', 'disabled'); 7437 } else { 7438 $('.js-builder_body_title_text').removeClass('disabled').attr('disabled', false); 7439 } 7440 7441 $('.js-builder_body_title_text').val($('.js-email_builder_title_hidden').eq(unlayer_body_active).val()); 7442 if ($('.js-error_liquid_wrap').length) { 7443 var show_liquid_errors = false; 7444 $('.js-error_liquid_wrap .js-liquid_errors_body_title').each(function(i, e) { 7445 if ($(this).text().toLowerCase() == $('.js-builder_body_title_text').val().toLowerCase()) { 7446 show_liquid_errors = true; 7447 } 7448 }); 7449 7450 if (show_liquid_errors) { 7451 $('.js-unlayer_editor').addClass('error_liquid'); 7452 } else { 7453 $('.js-unlayer_editor').removeClass('error_liquid'); 7454 } 7455 } 7456 }); 7457 7458 }); 7459 } 7460 } 7461 } 7462 }); 7463 7464 $('.js-email_bodies_wrap .js-next_body').click(function() { 7465 if (!$('.js-email_bodies_wrap').hasClass('js-unlayer_loading')) { 7466 7467 if ($('.js-builder_body_title_text').val() == '') { 7468 $('.js-builder_body_title_text').addClass('error_input'); 7469 } else { 7470 $('.js-builder_body_title_text').removeClass('error_input'); 7471 $('.js-email_bodies_wrap').addClass('js-unlayer_loading'); 7472 if (!$(this).hasClass('disabled')) { 7473 //console.log('click'); 7474 $(this).addClass('disabled'); 7475 var $button = $(this); 7476 unlayer.exportHtml(function(data) { 7477 $('.js-email_builder_json').eq(unlayer_body_active).val(JSON.stringify(data.design)); 7478 $('.js-email_builder_html').eq(unlayer_body_active).val(data.html.replace(/'/g,"'").replace(/"/g,'"').replace(/&#039;/g,"'").replace(/&quot;/g,'"')); 7479 $('.js-email_builder_title_hidden').eq(unlayer_body_active).val($('.js-builder_body_title_text').val()); 7480 7481 unlayer_body_active = unlayer_body_active + 1; 7482 7483 var $target = $('.js-unlayer_editor').prev(); 7484 $('.js-unlayer_editor').fadeOut(function() { 7485 $(this).remove(); 7486 7487 $target.after('<div id="editor-container" class="js-unlayer_editor editor-container"></div>'); 7488 //console.log('init start'); 7489 unlayer_init($('.js-unlayer_editor'), false); 7490 //console.log('after init'); 7491 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 7492 7493 $button.removeClass('disabled'); 7494 7495 $('.js-prev_body, .js-delete_body').show(); 7496 7497 if (unlayer_body_active == $('.js-single_variant_slide').length - 1 ) { // 0 indexed! 7498 $('.js-next_body').hide(); 7499 $('.js-email_bodies_wrap .js-circle_add').show(); 7500 } 7501 7502 $('.js-builder_body_title_text').removeClass('disabled').attr('disabled', false); 7503 7504 $('.js-builder_body_title_text').val($('.js-email_builder_title_hidden').eq(unlayer_body_active).val()); 7505 if ($('.js-error_liquid_wrap').length) { 7506 var show_liquid_errors = false;
7507 $('.js-error_liquid_wrap .js-liquid_errors_body_title').each(function(i, e) { 7508 if ($(this).text().toLowerCase() == $('.js-builder_body_title_text').val().toLowerCase()) { 7509 show_liquid_errors = true; 7510 } 7511 }); 7512 7513 if (show_liquid_errors) { 7514 $('.js-unlayer_editor').addClass('error_liquid'); 7515 } else { 7516 $('.js-unlayer_editor').removeClass('error_liquid'); 7517 } 7518 } 7519 }) 7520 7521 }); 7522 } 7523 } 7524 } 7525 }); 7526 7527 $('.js-email_bodies_wrap .js-delete_body').click(function() { 7528 if (!$('.js-email_bodies_wrap').hasClass('js-unlayer_loading')) { 7529 $('.js-email_bodies_wrap').addClass('js-unlayer_loading'); 7530 $('.js-single_variant_slide').eq(unlayer_body_active).remove(); 7531 7532 unlayer_body_active = unlayer_body_active - 1; 7533 7534 var $target = $('.js-unlayer_editor').prev(); 7535 $('.js-unlayer_editor').fadeOut(function() { 7536 $(this).remove(); 7537 $target.after('<div id="editor-container" class="js-unlayer_editor editor-container"></div>'); 7538 7539 unlayer_init($('.js-unlayer_editor'), false); 7540 7541 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 7542 7543 if ($('.js-single_variant_slide').length > 1) { 7544 $('.js-next_body').show(); 7545 } 7546 7547 if (unlayer_body_active == $('.js-single_variant_slide').length - 1 ) { // 0 indexed! 7548 $('.js-next_body').hide(); 7549 $('.js-prev_body, .js-delete_body, .js-email_bodies_wrap .js-circle_add').show(); 7550 } 7551 7552 if (unlayer_body_active == 0) { 7553 $('.js-prev_body, .js-delete_body').hide(); 7554 $('.js-builder_body_title_text').addClass('disabled').attr('disabled', 'disabled'); 7555 } else { 7556 $('.js-builder_body_title_text').removeClass('disabled').attr('disabled', false); 7557 } 7558 7559 $('.js-builder_body_title_text').val($('.js-email_builder_title_hidden').eq(unlayer_body_active).val()); 7560 7561 if ($('.js-error_liquid_wrap').length) { 7562 var show_liquid_errors = false; 7563 $('.js-error_liquid_wrap .js-liquid_errors_body_title').each(function(i, e) { 7564 if ($(this).text().toLowerCase() == $('.js-builder_body_title_text').val().toLowerCase()) { 7565 show_liquid_errors = true; 7566 } 7567 }); 7568 7569 if (show_liquid_errors) { 7570 $('.js-unlayer_editor').addClass('error_liquid'); 7571 } else { 7572 $('.js-unlayer_editor').removeClass('error_liquid'); 7573 } 7574 } 7575 7576 }); 7577 } 7578 7579 7580 }); 7581 7582 7583 $('.js-email_writing_wrap .js-switch-toggle').click(function(e) { 7584 7585 7586 var confirmation = confirm(an_javascript_translation.switch_email_write_mode); 7587 7588 if (confirmation != true) { 7589 e.preventDefault(); 7590 } else { 7591 if ($(this).hasClass('js-switch-enabled')) { 7592 7593 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 7594 var $disabled = $(this).parent().find('.js-switch_disabled_label'); 7595 var $enabled = $(this).parent().find('.js-switch_enabled_label'); 7596 7597 $disabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 7598 $enabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label'); 7599 7600 } else { 7601 7602 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 7603 var $disabled = $(this).parent().find('.js-switch_enabled_label'); 7604 var $enabled = $(this).parent().find('.js-switch_disabled_label'); 7605 7606 $disabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label'); 7607 $enabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 7608 7609 } 7610 } 7611 7612 }); 7613 7614 $('.js-sms_writing_wrap .js-switch-toggle').click(function(e) { 7615 e.preventDefault(); 7616 7617 if ($(this).hasClass('js-switch-enabled')) { 7618 7619 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 7620 var $disabled = $(this).parent().find('.js-switch_disabled_label'); 7621 var $enabled = $(this).parent().find('.js-switch_enabled_label'); 7622 7623 $disabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 7624 $enabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label'); 7625 $('.js-switch-option-sms').addClass('active'); 7626 $('.js-switch-option-mms').removeClass('active'); 7627 $('.js-force_mms_toggle').val("");
7628 $('.js-mms_fields_wrap, .js-mms_warning').addClass('hide'); 7629 $('.js-mms_media_image_url').val('').trigger('change'); 7630 $('.js-character_count').show(); 7631 7632 } else { 7633 7634 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 7635 var $disabled = $(this).parent().find('.js-switch_enabled_label'); 7636 var $enabled = $(this).parent().find('.js-switch_disabled_label'); 7637 7638 $disabled.removeClass('switch-enabled js-switch-enabled').addClass('switch_disabled_label js-switch_disabled_label'); 7639 $enabled.removeClass('switch_disabled_label js-switch_disabled_label').addClass('switch_enabled_label js-switch_enabled_label'); 7640 $('.js-switch-option-sms').removeClass('active'); 7641 $('.js-switch-option-mms').addClass('active'); 7642 $('.js-force_mms_toggle').val(true); 7643 $('.js-mms_fields_wrap, .js-mms_warning').removeClass('hide'); 7644 $('.js-character_count').hide(); 7645 } 7646 7647 }); 7648 7649 // Medialess MMS modal buttons 7650 medialessMMSModalButtonHandler = function() { 7651 $('.js-send_as_mms, .js-send_as_sms').addClass('disabled'); 7652 } 7653 $('body').on('click', '.js-send_as_mms', function() { 7654 //console.log('mms',mmsForm); 7655 $('.js-submit_mms_no_media').removeClass('js-submit_mms_no_media').addClass('js-submit_mms_no_media_confirmed') 7656 medialessMMSModalButtonHandler(); 7657 $.fancybox.close(); 7658 }); 7659 $('body').on('click', '.js-send_as_sms', function() { 7660 // console.log('sms',mmsForm); 7661 medialessMMSModalButtonHandler(); 7662 $('.js-preview_force_mms_value').val("false") 7663 $.fancybox.close(); 7664 }); 7665 7666 7667 if ($('.js-unlayer_editor, .js-unlayer_editor_layout').length) { 7668 //load merge tags 7669 default_unlayer_layout = 0 7670 if ($('.js-email_layout_select').val() && $('.js-email_layout_select').val() != 0) { 7671 default_unlayer_layout = $('.js-email_layout_select').val(); 7672 } 7673 var unlayer_init = function($that, use_default) { 7674 if (typeof(unlayer_merge_tags_start) !== 'undefined') { 7675 var merge_tags = $.extend({}, unlayer_merge_tags_start, unlayer_merge_tags_letters, unlayer_merge_tags_call_campaigns, unlayer_merge_tags_event_campaign, unlayer_merge_tags_event_campaign_rsvp, unlayer_merge_tags_end); 7676 } 7677 var unlayer_id = $that.attr('id'); 7678 7679 var unlayer_init_object = { 7680 id: unlayer_id, 7681 projectId: 714, 7682 minHeight: 500, 7683 displayMode: 'email', 7684 mergeTagsConfig: { 7685 sort: false 7686 }, 7687 translations: { 7688 'en-US': { 7689 "labels.merge_tags": "Clips" 7690 } 7691 }, 7692 user: { 7693 id: $('.js-unlayer_unique_id').data('unlayer-group-permalink-user-email') 7694 }, 7695 customCSS: [ 7696 "body {\ 7697 background-color: transparent;\ 7698 }\ 7699 .blockbuilder-preview {\ 7700 background:white;\ 7701 margin-right: 0;\ 7702 box-sizing: content-box;\ 7703 margin-right: 0;\ 7704 overflow: auto;\ 7705 height: calc(100% - 40px);\ 7706 }\ 7707 .blockbuilder-preferences {\ 7708 border-left: 1px solid #e0e0e0;\ 7709 }\ 7710 #u_body {\ 7711 min-height: calc(100vh - 55px) !important;\ 7712 }\ 7713 .blockbuilder-preferences .blockbuilder-tools-panel .blockbuilder-content-tool,\ 7714 .blockbuilder-preferences .blockbuilder-tools-panel .blockbuilder-row-tool {\ 7715 border-radius: 1px;\ 7716 box-shadow: none;\ 7717 transition: all .1s linear;\ 7718 }\ 7719 .blockbuilder-preferences .blockbuilder-tools-panel .blockbuilder-content-tool:hover,\ 7720 .blockbuilder-preferences .blockbuilder-tools-panel .blockbuilder-row-tool:hover {\ 7721 box-shadow: none;\ 7722 border-color: #0096DB;\ 7723 }\ 7724 .blockbuilder-preferences .blockbuilder-tools-panel .blockbuilder-content-tool:nth-child(3n) {\ 7725 margin-right:0;\ 7726 }\ 7727 .blockbuilder-preferences .btn-primary {\ 7728 border-radius:0;\ 7729 text-transform: uppercase;\ 7730 background-color: #0096DB !important;\ 7731 border:none !important;\ 7732 }\ 7733 .blockbuilder-preferences .btn-primary:hover {\ 7734 box-shadow: 0 2px 4px 2px rgba(0, 0, 0, 0.15);\ 7735 }\ 7736 .blockbuilder-preferences .blockbuilder-tools-panel .nav-tabs .nav-item {\ 7737 min-width: 33.33%;\ 7738 max-width: 33.33%;\ 7739 }\ 7740 .blockbuilder-preferences .blockbuilder-tools-panel .nav-tabs .nav-item:nth-child(2) {\ 7741 min-width: 33.34%;\ 7742 max-width: 33.34%;\ 7743 }\ 7744 .blockbuilder-page-layout {\ 7745 width: calc(100% - 2px);\ 7746 }" 7747 ], 7748 tools: { 7749 button: { 7750 properties: { 7751 buttonColors: { 7752 value: { 7753 backgroundColor: $('.js-email_button_color').val() || '#3aaee0', 7754 color: $('.js-email_button_text_color').val() || '#ffffff' 7755 } 7756 } 7757 } 7758 }, 7759 text: { 7760 properties: { 7761 color: { 7762 value: $('.js-email_typeface_color').val() || '#505050' 7763 } 7764 7765 } 7766 } 7767 }, 7768 features: { 7769 ai: false, 7770 textEditor: { 7771 spellChecker: true, 7772 tables: true, 7773 cleanPaste: false 7774 }, 7775 smartMergeTags: false 7776 } 7777 }; 7778 7779 //console.log(unlayer_init_object); 7780 7781 7782 if ($('.js-unlayer_editor_layout').length) { 7783 unlayer_init_object.designMode = 'edit'; 7784 7785 if ($('.js-email_builder_layout_button_color').val() != '') { 7786 unlayer_init_object.tools.button.properties.buttonColors.value.backgroundColor = $('.js-email_builder_layout_button_color').val(); 7787 } 7788 7789 if ($('.js-email_builder_layout_button_text_color').val() != '') { 7790 unlayer_init_object.tools.button.properties.buttonColors.value.color = $('.js-email_builder_layout_button_text_color').val(); 7791 } 7792 7793 if ($('.js-email_builder_layout_typeface_color').val() != '') { 7794 unlayer_init_object.tools.text.properties.color.value = $('.js-email_builder_layout_typeface_color').val(); 7795 } 7796 } 7797 7798 //load unlayer 7799 unlayer.init(unlayer_init_object); 7800 7801 //loads default background, colors, fonts, etc... 7802 var initial_design = JSON.parse('{"counters":{"u_column":1,"u_row":1,"u_content_text":3,"u_content_image":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"columns":false,"backgroundColor":"","columnsBackgroun
7802dColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideMobile":false,"noStackMobile":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"deletable":true}}],"values":{"backgroundColor":"#ffffff","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"600px","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}}}'); 7803 unlayer.loadDesign(initial_design); 7804 7805 var get_layout = function(layout_value) { 7806 //console.log(); 7807 $.get(layout_value, function(data) { 7808 if (data.button_color != '') { 7809 unlayer_init_object.tools.button.properties.buttonColors.value.backgroundColor = data.button_color; 7810 $('.js-email_button_color').val(data.button_color); 7811 } 7812 7813 if (data.button_text_color != '') { 7814 unlayer_init_object.tools.button.properties.buttonColors.value.color = data.button_text_color; 7815 $('.js-email_button_text_color').val(data.button_text_color); 7816 } 7817 7818 if (data.typeface_color != '') { 7819 unlayer_init_object.tools.text.properties.color.value = data.typeface_color; 7820 $('.js-email_typeface_color').val(data.typeface_color); 7821 } 7822 var $target = $that.prev(); 7823 //console.log($that); 7824 //console.log($target); 7825 $that.remove(); 7826 $target.after('<div id="' + unlayer_id + '" class="js-unlayer_editor editor-container"></div>'); 7827 unlayer.init(unlayer_init_object); 7828 unlayer.loadDesign(JSON.parse(data.json)); 7829 unlayer.setMergeTags(merge_tags); 7830 unlayer_listener(); 7831 $('.js-email_layout_select').val('').trigger('change'); 7832 }).fail(function() { 7833 alert(an_javascript_translation.something_went_wrong_loading_your_layout); 7834 $('.js-email_layout_select').val('').trigger('change'); 7835 }); 7836 } 7837 7838 //load design if previously saved 7839 //console.log($that); 7840 if ($('.js-email_builder_json').eq(unlayer_body_active).val() != '') { 7841 unlayer.loadDesign(JSON.parse($('.js-email_builder_json').eq(unlayer_body_active).val())); 7842 $('.js-email_layout_select').val('').trigger('change'); 7843 } else { 7844 //if we have a default layout, load it in 7845 //console.log(default_unlayer_layout); 7846 //console.log(use_default); 7847 if (default_unlayer_layout != 0 && use_default) { 7848 get_layout(default_unlayer_layout); 7849 } else if ($('.js-email_layout_select').val() != 0 && !use_default) { 7850 get_layout($('.js-email_layout_select').val()); 7851 } 7852 } 7853 7854 //deal with merge tags -- code repeated above in the custom JS section 7855 unlayer.setMergeTags(merge_tags); 7856 7857 //deal with merge tags find/replace for letter/event campaign links 7858 var regex_letters = new RegExp('\\|letter}}'); 7859 var regex_call_campaigns = new RegExp('\\|call_campaign}}'); 7860 var regex_event_campaigns = new RegExp('\\| event_campaign}}'); 7861 var regex_event_campaigns_rsvp = new RegExp('\\| event_campaign_rsvp}}'); 7862 7863 var unlayer_listener = function() { 7864 //console.log('listener'); 7865 unlayer.addEventListener('design:updated', function(data) { 7866 //console.log(data.changes); 7867 unlayer.exportHtml(function(data) { 7868 7869// //console.log(regex_letters.test(data.html)); 7870// var letters_array = unlayer_merge_tags_letters, 7871// call_campaigns_array = unlayer_merge_tags_call_campaigns, 7872// event_campaigns_array = unlayer_merge_tags_event_campaign, 7873// event_campaigns_rsvp_array = unlayer_merge_tags_event_campaign_rsvp; 7874// 7875// if (regex_letters.test(data.html)) { 7876// letters_array = unlayer_merge_tags_letters_nolink; 7877// } 7878// //console.log('start'); 7879// //clogconsole.log(data.html); 7880// if (regex_call_campaigns.test(data.html)) { 7881// //console.log('test'); 7882// call_campaigns_array = unlayer_merge_tags_call_campaigns_nolink; 7883// } 7884// 7885// if (regex_event_campaigns.test(data.html)) { 7886// event_campaigns_array = unlayer_merge_tags_event_campaign_nolink; 7887// } 7888// 7889// if (regex_event_campaigns_rsvp.test(data.html)) { 7890// event_campaigns_rsvp_array = unlayer_merge_tags_event_campaign_rsvp_nolink; 7891// } 7892// // console.log(unlayer_merge_tags_start); 7893// // console.log(letters_array); 7894// // console.log(call_campaigns_array); 7895// // console.log(event_campaigns_array); 7896// // console.log(event_campaigns_rsvp_array); 7897// // console.log(unlayer_merge_tags_end); 7898// var merge_tags = $.extend({}, unlayer_merge_tags_start, letters_array, call_campaigns_array, event_campaigns_array, event_campaigns_rsvp_array, unlayer_merge_tags_end); 7899// //console.log(merge_tags); 7900// unlayer.setMergeTags(merge_tags); 7901 //console.log($that); 7902 if (JSON.stringify(data.design) != '' && typeof(JSON.stringify(data.design)) != 'undefined') { 7903 $('.js-email_builder_json').eq(unlayer_body_active).val(JSON.stringify(data.design)); 7904 $('.js-email_builder_html').eq(unlayer_body_active).val(data.html.replace(/'/g,"'").replace(/"/g,'"').replace(/&#039;/g,"'").replace(/&quot;/g,'"')); 7905 $('.js-email_builder_title_hidden').eq(unlayer_body_active).val($('.js-builder_body_title_text').val()); 7906 } 7907 7908 7909 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 7910 7911 }); 7912 }); 7913 7914 unlayer.addEventListener('design:loaded', function() { 7915 //console.log('loaded'); 7916 //console.log(data.changes); 7917 //unlayer.exportHtml(function(data) { 7918 7919 $('.js-email_bodies_wrap').removeClass('js-unlayer_loading'); 7920 7921 //}); 7922 }); 7923 } 7924 7925 unlayer_listener(); 7926 7927 //init areyousure 7928 $('.js-unlayer_editor, .js-unlayer_editor_layout').parents('form').areYouSure({'addRemoveFieldsMarksDirty':true} ); 7929 } 7930 7931 $('.js-unlayer_editor, .js-unlayer_editor_layout').each(function() { 7932 unlayer_init($(this), true); 7933 }); 7934 7935 7936 //apply layouts and defaults to builder 7937 $('.js-layout_apply').click(function() { 7938 if ($('.js-email_layout_select').val()) { 7939 var confirmation = confirm(an_javascript_translation.apply_body_warning); 7940 7941 if (confirmation == true) { 7942 if ($('.js-email_layout_select').val() == "0") { 7943 //set to blank if default layout chosen 7944 //unlayer_init_object.tools.button.properties.buttonColors.value.backgroundColor = '#3aaee
79440'; 7945 $('.js-email_button_color').val('#3aaee0'); 7946 //unlayer_init_object.tools.button.properties.buttonColors.value.color = '#ffffff'; 7947 $('.js-email_button_text_color').val('#ffffff'); 7948 //unlayer_init_object.tools.text.properties.color.value = '#505050'; 7949 $('.js-email_typeface_color').val('#505050'); 7950 7951/* 7952 unlayer.init(unlayer_init_object); 7953 unlayer.loadDesign(initial_design); 7954 unlayer.setMergeTags(merge_tags); 7955 unlayer_listener(); 7956*/ 7957 $('.js-email_layout_select').val('').trigger('change'); 7958 } 7959 7960 $('.js-email_builder_json').eq(unlayer_body_active).val(''); 7961 $('.js-email_builder_html').eq(unlayer_body_active).val(''); 7962 7963 var $target = $('.js-unlayer_editor').prev(); 7964 7965 $('.js-unlayer_editor').remove(); 7966 $target.after('<div id="editor-container" class="js-unlayer_editor editor-container"></div>'); 7967 unlayer_init($('.js-unlayer_editor'), false); 7968 } 7969 } 7970 7971 7972 }); 7973 7974 7975 if ($('.js-editor_mode_switch').length && typeof(hopscotch) != "undefined") { 7976 //if we're new, show the tour 7977 if (!getCookie('seen_editor_tour')) { 7978 var width; 7979 var group_width; 7980 var organizing_menu; 7981 var profile_menu; 7982 var organizing_width; 7983 7984 if (under1024Flag) { 7985 width = 200; 7986 } else { 7987 width = 280; 7988 } 7989 7990 var tour = { 7991 id: "editor-tour", 7992 steps: [ 7993 { 7994 title: an_javascript_translation.we_have_a_new_way_to_write_email, 7995 content: "<p>"+ an_javascript_translation.you_can_now_use_a_drag_and_drop_editor_description +"</p><p>"+ an_javascript_translation.you_can_set_a_default_editor_mode_by_editing_your_profile_description +"</p>", 7996 target: document.querySelector(".js-single_power_toggle"), 7997 placement: "bottom", 7998 width: width 7999 } 8000 ], 8001 i18n: { 8002 nextBtn: an_javascript_translation.next, 8003 doneBtn: an_javascript_translation.done 8004 } 8005 }; 8006 hopscotch.endTour(true); 8007 hopscotch.startTour(tour); 8008 } 8009 //getCookie('seen_ladder_manage_tour') 8010 setCookie('seen_editor_tour','1'); 8011 //getCookie('seen_ladder_manage_tour') 8012 } 8013 8014 8015 } 8016 8017 8018 /* ======================= END Redactor/Unlayer ======================= */ 8019 8020 /* ======================= START stats by domain toggle ======================= */ 8021 8022 $('select.js-stats-domain-filter').change(function() { 8023 var domain = $(this).val(); 8024 $('.js_domain_stats').fadeOut(function() { 8025 $('.js_domain_stats-' + domain).show(); 8026 }); 8027 }); 8028 8029 /* ======================= END stats by domain toggle ======================= */ 8030 8031 $( '.js-accordion' ).accordion({ 8032 active: false, 8033 heightStyle: 'content', 8034 collapsible: true, 8035 }); 8036 8037 /* ======================= START api and sync VAN connection ======================= */ 8038 8039 if ($('.js-event_type').length) { 8040 8041 $(".js-van_continue2").click(function() { 8042 if ($('select.js-event_type').val()) { 8043 $('span.js-event_type').removeClass('error_input'); 8044 $(this).hide(); 8045 $('.js-van_step3').show(); 8046 } else { 8047 $('span.js-event_type').addClass('error_input'); 8048 } 8049 8050 }); 8051 8052 8053 8054 var load_van_shift_role = function(initial_load) { 8055 var event_data = $('select.js-event_type').find('option:selected').data('event'); 8056 if (event_data) { 8057 $('span.js-event_type').removeClass('error_input'); 8058 var event_status_val = $('select.js-event_status').val(); 8059 var event_role_val = $('select.js-event_role').val(); 8060 $('select.js-event_status, select.js-event_role').html(''); 8061 8062 $('select.js-event_status').append(`<option value=""> ${an_javascript_translation.choose_default_status} *</option>`); 8063 $('select.js-event_role').append(`<option value=""> ${an_javascript_translation.choose_default_role} *</option>`); 8064 8065 8066 $.each(event_data.statuses, function(i,e) { 8067 var selected = ''; 8068 if (e.statusId == event_status_val && initial_load) { 8069 selected = 'selected'; 8070 } 8071 $('select.js-event_status').append(`<option value="${e.statusId}" ${selected}> ${an_javascript_translation.status}: ${e.name}</option>`); 8072 }); 8073 8074 $.each(event_data.roles, function(i,e) { 8075 var selected = ''; 8076 if (e.roleId == event_role_val && initial_load) { 8077 selected = 'selected'; 8078 } 8079 $('select.js-event_role').append(`<option value="${e.roleId}" ${selected}> ${an_javascript_translation.role}: ${e.name}</option>`); 8080 }); 8081 8082 $('select.js-event_status, select.js-event_role').trigger('render'); 8083 } else { 8084 $('span.js-event_type').addClass('error_input'); 8085 $('.js-van_step3').hide(); 8086 $(".js-van_continue2").show(); 8087 } 8088 } 8089 8090 if ($('select.js-event_type').val()) { 8091 $('.js-van_step3').show(); 8092 $(".js-van_continue2").hide(); 8093 load_van_shift_role(true); 8094 } 8095 8096 $('select.js-event_type').change(function() { 8097 load_van_shift_role(false); 8098 }); 8099 } 8100 8101 8102 /* ======================= END api and sync VAN connection ======================= */ 8103 8104 /* ======================= start api and sync briteverify connection ======================= */ 8105 $('.js-briteverify_toggle').click(function() { 8106 if ($(this).hasClass('js-briteverify_prompt_for_backfill')) { 8107 var confirmation = confirm(an_javascript_translation.do_you_want_to_backfill); 8108 8109 if (confirmation == true) { 8110 var url = $('.js-briteverify_toggle_backfill').attr("href") 8111 window.location = url; 8112 } else { 8113 var url = $('.js-briteverify_toggle_nobackfill').attr("href") 8114 window.location = url; 8115 } 8116 } else { 8117 var url = $('.js-briteverify_toggle_nobackfill').attr("href") 8118 window.location = url; 8119 } 8120 8121 }); 8122 8123 $('.js-briteverify_form').submit(function(e) { 8124 //e.preventDefault(); 8125 //return false;
8126 if ($('.js-briteverify_activate').length) { 8127 var confirmation = confirm(an_javascript_translation.do_you_want_to_backfill); 8128 8129 if (confirmation == true) { 8130 $('.js-briteverify_backfill').val('true'); 8131 } else { 8132 $('.js-briteverify_backfill').val('false'); 8133 } 8134 } 8135 8136 }); 8137 /* ======================= END api and sync briteverify connection ======================= */ 8138 8139 /* ======================= START CORE FIELDS TOGGLE ======================= */ 8140 8141 // Bulk 8142 $('.js-synd_core_toggle_box .js-switch-toggle').click(function(e) { 8143 8144 8145 if ($(this).hasClass('js-switch-enabled')) { 8146 8147 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 8148 $(this).siblings('.js-switch_enabled_label').hide(); 8149 $(this).siblings('.js-switch_disabled_label').show(); 8150 $(this).parents('.js-network_core_field_box').removeClass('js-is_syndicated is_syndicated'); 8151 8152 } else { 8153 8154 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 8155 $(this).siblings('.js-switch_disabled_label').hide(); 8156 $(this).siblings('.js-switch_enabled_label').show(); 8157 $(this).parents('.js-network_core_field_box').addClass('js-is_syndicated is_syndicated'); 8158 8159 } 8160 8161 }); 8162 8163 // Single 8164 $('.js-single_core_required').click(function() { 8165 8166 if ($(this).parents('.js-single_core_toggle').find('.js-core_field_required').val() === "1") { 8167 8168 $(this).removeClass('single_core_required-on js-single_core_required-on').addClass('single_core_required-off js-single_core_required-off'); 8169 $(this).parents('.js-single_core_toggle').removeClass('single_core_toggle-on js-single_core_toggle-on'); 8170 $(this).parents('.js-core_field_wrap').find('.js-core_field_input').attr('placeholder', $(this).parents('.js-core_field_wrap').find('.js-core_field_input').attr('placeholder').replace(' *','')); 8171 $(this).parents('.js-single_core_toggle').find('.js-core_field_required').val('0'); 8172 8173 } else { 8174 8175 $(this).removeClass('single_core_required-off js-single_core_required-off').addClass('single_core_required-on js-single_core_required-on'); 8176 $(this).parents('.js-single_core_toggle').addClass('single_core_toggle-on js-single_core_toggle-on'); 8177 8178 $(this).parents('.js-core_field_wrap').find('.js-core_field_input').attr('placeholder', $(this).parents('.js-core_field_wrap').find('.js-core_field_input').attr('placeholder') + ' *'); 8179 $(this).parents('.js-single_core_toggle').find('.js-core_field_required').val('1'); 8180 } 8181 8182 $('form.js-create_action_form').trigger('rescan.areYouSure'); 8183 8184 }); 8185 8186 $('.js-disable_core_field').click(function() { 8187 $(this).parents('.js-core_field_wrap').addClass('add_core_field'); 8188 $(this).parents('.js-core_field_toggles').hide(); 8189 $(this).parents('.js-core_field_wrap').find('.js-core_field_input, .js-core_field_sample').slideUp('fast', function() { 8190 $(this).parents('.js-core_field_wrap').find('.js-enable_core_field').show(); 8191 }); 8192 $(this).parents('.js-single_core_toggle').find('.js-core_field_present').val('0'); 8193 8194 $('form.js-create_action_form').trigger('rescan.areYouSure'); 8195 }); 8196 8197 $('.js-enable_core_field').click(function() { 8198 $(this).slideUp('fast', function() { 8199 $(this).parents('.js-core_field_wrap').removeClass('add_core_field'); 8200 $(this).parents('.js-core_field_wrap').find('.js-core_field_input, .js-core_field_sample').show(); 8201 //$(this).parents('.js-core_field_wrap').find('.js-enable_core_field').show(); 8202 $(this).parents('.js-core_field_wrap').find('.js-core_field_toggles').show(); 8203 8204 }); 8205 $(this).parents('.js-core_field_wrap').find('.js-core_field_present').val('1'); 8206 8207 $('form.js-create_action_form').trigger('rescan.areYouSure'); 8208 }); 8209 8210 8211 8212 if ($('.js-letter_target').length) { 8213 8214 8215 $('.js-letter_target').on('change', function () { 8216 if (typeof(built_in_target_core_field_toggle_function) != 'undefined') 8217 built_in_target_core_field_toggle_function($(this)); 8218 }); 8219 } 8220 8221 /* ======================= END CORE FIELDS TOGGLE ======================= */ 8222 8223 /* ========================= START SHORTLINKS ========================= */ 8224 8225 $('.js-copy_to_clipboard').click(function() { 8226 navigator.clipboard.writeText($(this).data('shortlink')); 8227 Noty.closeAll(); 8228 new Noty({
8229 theme: 'metroui', 8230 type: 'success', 8231 closeWith: ['button','click'], 8232 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + an_javascript_translation.shortlink_copied_to_clipboard + "</span>", 8233 timeout: 10000 8234 }).show(); 8235 }); 8236 8237 8238 /* ========================= END SHORTLINKS ========================= */ 8239 8240 8241 /* ========================= START SMS INBOX ========================= */ 8242 8243 if ($('.js-conversation').length) { 8244 const inbox_search_results = $('.js-sms_inbox_search_match'); 8245 var search_index = inbox_search_results.length - 1; 8246 var current_search_result = null; 8247 8248 $('.js-conversation_search_next').on('click', function() { 8249 if (search_index < inbox_search_results.length - 1) { 8250 ++search_index; 8251 conversation_search_highlight(); 8252 } 8253 }); 8254 8255 $('.js-conversation_search_prev').on('click', function() { 8256 if (search_index > 0) { 8257 --search_index; 8258 conversation_search_highlight(); 8259 } 8260 }); 8261 8262 function conversation_search_highlight() { 8263 if (inbox_search_results.length) { 8264 if (current_search_result !== null) { 8265 current_search_result.removeClass('message_result_highlighted'); 8266 } 8267 const conversation_offset = $('.js-conversation').offset().top; 8268 const conversation_height = $('.js-conversation').height(); 8269 current_search_result = inbox_search_results.eq(search_index) 8270 current_search_result.addClass('message_result_highlighted'); 8271 const search_result_offset = current_search_result.offset().top; 8272 const center_offset = (conversation_height / 2) - 50; 8273 $(".js-conversation").scrollTop(search_result_offset - conversation_offset - center_offset + $('.js-conversation').scrollTop()); 8274 } else { 8275 $(".js-conversation").scrollTop($(".js-conversation")[0].scrollHeight); 8276 } 8277 }; 8278 8279 if (inbox_search_results.length > 1) { 8280 $('.js-conversation_search_navigation').show(); 8281 } 8282 8283 conversation_search_highlight(); 8284 } 8285 8286 // Open mobile conversation 8287 var viewportWidth = $(window).width(); 8288 8289 if (viewportWidth < 901) { 8290 $(".close-message").click(function (e) { 8291 $('.js-sms-inbox__inbox').removeClass('active'); 8292 $('body').removeClass('body-lock'); 8293 e.preventDefault(); 8294 }); 8295 8296 if ( $('.js-sms-inbox__inbox').hasClass('active') && getURLParameter('load_conversation') ) { 8297 $('body').addClass('body-lock'); 8298 } 8299 8300 if ( $('.js-sms-inbox__inbox').hasClass('js-sms-inbox__organizer') ) { 8301 $('body').removeClass('body-lock'); 8302 } 8303 } 8304 8305 if ($('.js-leave_inbox_link').length) { 8306 // Organizer View Timeout modal 8307 var openTimeoutModal = function() { 8308 $('.js-open_timeout_modal').click(); 8309 } 8310 setTimeout(openTimeoutModal, 240000); // 4 min 8311 8312 var leaveInboxTimeout = function() { 8313 window.location.href = $('.js-leave_inbox_link').attr('href'); 8314 } 8315 setTimeout(leaveInboxTimeout, 300000); // 5 min 8316 } 8317 8318 8319 8320 // Open "Add New Saved Response" dialog inside of "Manage Saved Response" modal 8321 8322 $('.js-new_response_btn').on('click', function() { 8323 $(this).parent().closest('.js-saved_response_wrap').addClass('hide'); 8324 $('.js-add_response_wrap').removeClass('hide'); 8325 $.smoothScroll($('.js-add_response_wrap').offset().top - 200); 8326 }); 8327 8328 $('.js-cancel_new_response').on('click', function() { 8329 $('.js-saved_response_wrap').removeClass('hide'); 8330 $('.js-add_response_wrap').addClass('hide'); 8331 $.smoothScroll($('.js-saved_response_wrap').offset().top - 200); 8332 }); 8333 8334 // Copy content from canned_responses to message_editor and calls charCount 8335 $('.js-canned_responses_select').on('change', function(event) { 8336 const selected = event.added; 8337 8338 if (selected && selected.id) { 8339 $(".js-inbox_send_message").each(function() { 8340 $(this).val(selected.id); 8341 $(this).charCount({ 8342 allowed: 160, 8343 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 8344 wrapperSelector: '.js-inbox_footer', 8345 link_shortening: false 8346 }); 8347 }); 8348 setTimeout(function() { $('.js-canned_responses_select').val('').trigger('change'); }, 5); 8349 } 8350 }); 8351 8352 // Shows the form for selected canned response 8353 $('.js-canned_response_edit').on('click', function(e) { 8354 const cannedResponseId = $(e.target).parents('.list-item__actions').find('.js-canned_response_edit').attr('id').replace(/[^0-9]/g, ''); 8355 if (!cannedResponseId) { return; } 8356 8357 $(this).parent().closest('.js-saved_response_wrap').addClass('hide'); 8358 $(`.js-edit_response_wrap_${cannedResponseId}`).removeClass('hide'); 8359 setTimeout(function() { 8360 $.smoothScroll($(`.js-edit_response_wrap_${cannedResponseId}`).offset().top - 200); 8361 }, 1); 8362 8363 }); 8364 8365 // Closes canned response edit modal 8366 $('.js-cancel_edit_response').on('click', function() { 8367 $('.js-saved_response_wrap').removeClass('hide'); 8368 $('.js-edit_response_wrap').addClass('hide'); 8369 $.smoothScroll($('.js-saved_response_wrap').offset().top - 200); 8370 }); 8371 8372 // delete confirmation 8373 $('.js-removed-canned-response').click(function() { 8374 var confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_delete_this_saved_response); 8375 8376 if (confirmation != true) { 8377 return false;
8378 e.preventDefault(); 8379 } 8380 }); 8381 8382 8383 /* ========================= END SMS INBOX ========================= */ 8384 8385 /* ======================= START WEBHOOKS ======================= */ 8386 8387/* 8388 $('.js-webhook_button_toggle').click(function() { 8389 if ($(this).hasClass('js-webhook_button_toggle-closed')) { 8390 $(this).switchClass( 'js-webhook_button_toggle-closed', 'js-webhook_button_toggle-open'); 8391 $(this).parent().siblings('.webhook_button_wrap').slideDown(200); 8392 8393 } else { 8394 $(this).switchClass( 'js-webhook_button_toggle-open', 'js-webhook_button_toggle-closed'); 8395 $(this).parent().siblings('.webhook_button_wrap').slideUp(200); 8396 } 8397 }); 8398*/ 8399// displaying actions for webhooks 8400if ($('.js-select_actions input.js-webhook_actions_select').length) { 8401$('.js-select_actions input.js-webhook_actions_select').select2({ 8402data: trigger_action_json_data, 8403multiple : false, 8404separator: '@!@', 8405closeOnSelect: false, 8406// text for loading more results 8407//formatLoadMore : 'Loading more...', 8408query : function (q) { 8409// pageSize is number of results to show in dropdown 8410 var pageSize, 8411 results; 8412 pageSize = 500; 8413 results = $.grep(this.data, function (e) { 8414 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 8415 if (typeof(q.term) !== 'undefined') { 8416 if (q.term.length == 0) return true; 8417 8418 if(q.term.split(" ").length == 1){ 8419 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 8420 } 8421 8422 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 8423 // `data.text` is the text that is displayed for the data object 8424 // check if data.text contains all of keywords, if some is missing, return null 8425 for (var i = 0; i < keywords.length; i++) { 8426 8427 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 8428 // Return `null` if the term should not be displayed 8429 return null; 8430 8431 } 8432 } 8433 // If here, data.text contains all keywords, so return it. 8434 return e; 8435 }); 8436 q.callback({ 8437 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 8438 // retrieve more when user hits bottom 8439 more : results.length >= q.page * pageSize 8440 }); 8441 8442 // console.log(q.term); 8443// console.log(this.data); 8444 8445 8446 }, 8447 placeholder: an_javascript_translation.choose_action 8448 8449})}; 8450 8451$('select.js-webhook_trigger_select').change(function() { 8452 if ($('select.js-webhook_trigger_select').val() == 'took_action_specific') { 8453 $('div.js-select_actions').removeClass('hide') 8454 $('input.js-webhook_actions_select').addClass('required') 8455 } else { 8456 $('div.js-select_actions').addClass('hide') 8457 $('input.js-webhook_actions_select').removeClass('required'); 8458 } 8459}); 8460 8461 8462 8463 /* ======================= END WEBHOOKS ======================= */ 8464 8465 /* ======================= START EVENTS ======================= */ 8466 if ($('.js-auto_checkin_submit').length) { 8467 $('.js-auto_checkin_submit').trigger('click'); 8468 } 8469 8470 /* ======================= END EVENTS ======================= */ 8471 8472 /* ======================= Query Builder JS ============================ */ 8473 8474 if ($('#builder, .js-ladder').length) { 8475 $('#builder').on('click touchstart', '.btn-group input', function() { 8476 //console.log($(this).val()); 8477 if ($(this).val() == 'AND') { 8478 $(this).parent().parent().parent().parent().removeClass('query-builder-or-group'); 8479 $(this).parent().removeClass('query-builder-or-button'); 8480 } else { 8481 $(this).parent().parent().parent().parent().addClass('query-builder-or-group'); 8482 $(this).parent().addClass('query-builder-or-button'); 8483 } 8484 }); 8485 8486 $('#builder').on('focusin', '.rule-value-container input[type=text]', function() { 8487 $('.rules-group-container, .rule-container').attr('draggable','false'); 8488 }); 8489 8490 $('#builder').on('focusout', '.rule-value-container input[type=text]', function() { 8491 $('.rules-group-container, .rule-container').attr('draggable','true'); 8492 }); 8493 } 8494 8495 /* ======================= End Query Builder JS ============================ */ 8496 8497 /* Make It Stick */ 8498 if ( $('.js-content > .js-container').width() > 960) { 8499/* 8500 if ($.isFunction($.fn.sticky) ) { 8501 $(".js-pre_header").sticky({ 8502 topSpacing: 0 8503 }); 8504 $(".js-header").sticky({ 8505 topSpacing: 71 8506 }); 8507 } 8508*/ 8509/* 8510 8511 if ($('.js-donate_sidebar').length) { 8512 $('.js-sticky_sidebar').superSticky({ 8513 padding_top : 130, 8514 padding_bottom : 160, 8515 wrapper: '.js-content' 8516 }); 8517 } else { 8518 if ($('.js-sticky_sidebar').length) { 8519 $('.js-sticky_sidebar').superSticky({ 8520 padding_top : 60, 8521 padding_bottom : 60, 8522 wrapper: '.js-content .js-container' 8523 }); 8524 } 8525 } 8526 8527 8528 if ($('.js-sticky_sidebar_120').length) { 8529 $('.js-sticky_sidebar_120').superSticky({ 8530 padding_top : 120, 8531 padding_bottom : 60, 8532 wrapper: '.js-content' 8533 }); 8534 } 8535 8536 if ($('.js-sticky_sidebar_event_search').length) { 8537 $('.js-sticky_sidebar_event_search').superSticky({ 8538 padding_top : 120, 8539 padding_bottom : 60, 8540 wrapper: '.js-action_head' 8541 }); 8542 } 8543*/ 8544 8545/* 8546 if ($('.js-sticky_sidebar_c4').length) { 8547 $('.js-sticky_sidebar_c4').superSticky({ 8548 padding_top : 60, 8549 wrapper: '.js-sticky_wrapper' 8550 }); 8551 } 8552*/ 8553 8554 } 8555 8556 /* move form sidebar for mobile */ 8557 8558 var under1024Flag = false;
8559 var under768Flag = false; 8560 var under720Flag = false; 8561 var at1024flag = false; 8562 8563 var responsiveSidebar1024 = function() { 8564 if ( $('.js-content > .js-container').width() < 748 ) { 8565 // with the gutters screen width is 768px 8566 8567 if (!under1024Flag) { 8568 var $sidebars = $('.js-sidebar'); 8569 if ($sidebars.length > 1) { 8570 $sidebars.not(':first').remove(); 8571 } 8572 var $sidebar = $('.js-sidebar').first(); 8573 8574 if ($('.js-group_admin_page').length) { // group manage pages 8575 $('.js-ty_head').after($sidebar); 8576 } else if ($('.js-ty_head').length) { // thank you pages 8577 $('.js-ty_head').after($sidebar); 8578 } else if ($('.js-action_target').length) { // petitions 8579 $('.js-action_target').after($sidebar); 8580 } else if ($('.js-event_info').length) { // events 8581 $('.js-event_info').after($sidebar); 8582 } else if ($('.js-group_location').length) { // groups 8583 $('.js-group_location').after($sidebar); 8584 } else if ($('.js-group_zip').length) { // groups 8585 $('.js-group_zip').parent().siblings('.tooltip').after($sidebar); 8586 } else if ($('.js-campaign_actions').length) { // campaign pages 8587 $('h2.js-entry-title').after($sidebar); 8588 } else if ($('.js-user_subscriptions').length) { // unsub page 8589 $('.js-main_col').append($sidebar); 8590 } else if ($('.js-create_donate_form').length) { // fundraising create page 8591 $('.js-action_head .js-entry-title').first().after($sidebar); 8592 } else if (!$('.toolset').length && !$('.partnerships').length && !$('.js-docs').length && !$('.js-syndicate_group_list_wrap').length) { // no moving on a few pages 8593 $('.js-entry-title').after($sidebar); 8594 } 8595 } 8596 8597 under1024Flag = true; 8598 //$('body').addClass('under1024'); 8599 8600 } else { 8601 if (under1024Flag) { 8602 var $sidebars = $('.js-sidebar'); 8603 if ($sidebars.length > 1) { 8604 $sidebars.not(':first').remove(); 8605 } 8606 var $sidebar = $('.js-sidebar').first(); 8607 8608 // Only proceed if sidebar exists 8609 if ($('.js-group_admin_page').length) { // group manage pages 8610 $('#tab_wrap').after($sidebar); 8611 } else if ($('.js-ty_head').length) { // thank you pages 8612 $('.js-ty_head').before($sidebar); 8613 } else if ($('.js-action_target').length) { // petitions 8614 $('.js-action_head').before($sidebar); 8615 } else if ($('.js-event_info').length) { // events 8616 $('.js-action_head').after($sidebar); 8617 } else if ($('.js-group_location').length){ // groups 8618 $('.js-main_col').after($sidebar); 8619 } else if ($('.js-group_zip').length){ // groups 8620 $('.js-main_col').after($sidebar); 8621 } else if ($('.js-event_search_sidebar').length) { // event campaigns 8622 $('.js-main_col').after($sidebar); 8623 } else if ($('.js-campaign_actions').length) { // campaign pages 8624 $('.js-main_col').after($sidebar); 8625 } else if ($('.js-user_subscriptions').length) { // unsub page 8626 $('.js-main_col').after($sidebar); 8627 } else if (!$('.toolset').length && !$('.js-docs').length && !$('.js-syndicate_group_list_wrap').length) { // no moving on a few pages 8628 $('.js-action_head').before($sidebar); 8629 } 8630 } 8631 8632 under1024Flag = false; 8633 //$('body').removeClass('under1024'); 8634 } 8635 8636 if ($('.js-content > .js-container').width() <= 960 ) { 8637 at1024flag = true; 8638 } else { 8639 at1024flag = false; 8640 } 8641 }; 8642 8643 var responsiveSidebar768 = function() { 8644 if ( $('.js-content > .js-container').width() < 700 ) { 8645 8646 if (!under768Flag) { 8647 if ($('.js-the_dashboard').length) { // dashboard 8648 //$('#dashboard_email_chart').after($('.white_box').parent()); 8649 } 8650 } 8651 8652 under768Flag = true; 8653 //$('body').addClass('under1024'); 8654 8655 } else { 8656 if (under768Flag) { 8657 if ($('.js-the_dashboard').length) { // dashboard 8658 //$('#dashboard_groups').after($('.white_box').parent()); 8659 } 8660 } 8661 8662 under768Flag = false; 8663 //$('body').removeClass('under1024'); 8664 } 8665 }; 8666 8667 $.fn.reverse = [].reverse; 8668 8669 var responsiveSidebar720 = function() { 8670 if ( $('.js-content > .js-container').width() < 700 ) { 8671 under720Flag = true; 8672 //$('body').addClass('under1024'); 8673 } else { 8674 under720Flag = false; 8675 //$('body').removeClass('under1024'); 8676 } 8677 }; 8678 8679 responsiveSidebar1024(); 8680 responsiveSidebar768(); 8681 responsiveSidebar720(); 8682 8683 8684 $('.js-content > .js-container').mutate('width', function() { 8685 responsiveSidebar1024(); 8686 responsiveSidebar768(); 8687 responsiveSidebar720(); 8688 }); 8689 8690 8691 /* Start the datepicker */ 8692 if ($.isFunction($.fn.datetimepicker) ) { 8693 $(".js-datepick").datetimepicker({ 8694 format: "MM dd, yyyy - HH:ii P", 8695 showMeridian: true, 8696 autoclose: true, 8697 pickerPosition: "bottom-left", 8698 minuteStep: 15, 8699 }).on('hide', function(ev) { 8700 if (typeof(form_id) !== 'undefined') { 8701 $('#' + form_id).valid(); 8702 } 8703 }); 8704 8705 $(".js-datepick-timezone").datetimepicker({ 8706 format: "HH:ii P", 8707 showMeridian: true, 8708 autoclose: true, 8709 pickerPosition: "bottom-left", 8710 minuteStep: 15, 8711 maxView: 1, 8712 minView: 0, 8713 startView: 1, 8714 }).on('hide', function(ev) { 8715 if (typeof(form_id) !== 'undefined') { 8716 $('#' + form_id).valid(); 8717 } 8718 $('.table-condensed th').show(); 8719 }).on('show', function(ev) { 8720 $('.table-condensed th').hide(); 8721 }); 8722 8723 $('.js-email-confirm-send-timezone').click(function() { 8724 var date = new Date(Date.now()).toDateString().split(' '); 8725 date.shift(); 8726 date = date.toString().replace(/,/g,' '); 8727 $('.js-email-schedule-timezone').val(date + ' - ' + $('.js-email-schedule-timezone').val()); 8728 }); 8729 8730 $(".js-timepick-hours").datetimepicker({ 8731 format: "HH:ii P", 8732 showMeridian: true, 8733 autoclose: true, 8734 minView: 1, 8735 maxView: 1, 8736 startView: 1, 8737 pickerPosition: "bottom-left", 8738 }).on('hide', function(ev) { 8739 if (typeof(form_id) !== 'undefined') { 8740 $('#' + form_id).valid(); 8741 } 8742 }).on('changeDate', function(ev){ 8743 ev.date.setMinutes(0); 8744 }); 8745 8746 $(".js-timepick-hours").on('show', function() { 8747 $('.datetimepicker-hours thead').hide(); 8748 }); 8749 8750 $(".js-datepick-future").datetimepicker({ 8751 format: "MM dd, yyyy - HH:ii P", 8752 showMeridian: true, 8753 autoclose: true, 8754 pickerPosition: "bottom-left", 8755 minuteStep: 15, 8756 startDate: new Date(new Date().getTime()), 8757 }).on('hide', function(ev) { 8758 if (typeof(form_id) !== 'undefined') { 8759 $('#' + form_id).valid(); 8760 } 8761 }); 8762 8763 $(".js-datepick-future-hours").datetimepicker({ 8764 format: "MM dd, yyyy - HH:ii P", 8765 showMeridian: true, 8766 autoclose: true, 8767 pickerPosition: "bottom-left", 8768 minView: 1, 8769 startDate: new Date(new Date().getTime()), 8770 }).on('hide', function(ev) { 8771 if (typeof(form_id) !== 'undefined') { 8772 $('#' + form_id).valid(); 8773 } 8774 }).on('changeDate', function(ev){ 8775 ev.date.setMinutes(0); 8776 }); 8777 8778 $(".js-datepick-days").datetimepicker({ 8779 format: "MM dd, yyyy", 8780 showMeridian: true, 8781 autoclose: true, 8782 pickerPosition: "bottom-left", 8783 startDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), 8784 minView: 2 8785 }).on('hide', function(ev) { 8786 if (typeof(form_id) !== 'undefined') { 8787 $('#' + form_id).valid(); 8788 } 8789 }); 8790 8791 // ladders skip day start and end 8792 8793 $(".js-ladders_add_skip_days_start").datetimepicker({ 8794 format: "MM dd", 8795 showMeridian: true, 8796 autoclose: true, 8797 pickerPosition: "bottom-left", 8798 startDate: new Date(new Date().getFullYear(), 0, 1), 8799 // endDate: new Date((new Date().getFullYear() + 1),"12","31"), 8800 minView: 2 8801 }).on('changeDate', function(ev) { 8802 ladder_skip_month_start = ev.date.toLocaleDateString('default', { month: 'numeric'}) 8803 ladder_skip_day_start = ev.date.toLocaleDateString('default', { day: 'numeric'}) 8804 d = new (Date) 8805 current_year = d.getFullYear() 8806 if (!$('.js-ladders_add_skip_days_end').val()) { 8807 skip_end_date_max = `${current_year}-12-31` 8808 $(".js-ladders_add_skip_days_end").datetimepicker('setStartDate', `${current_year}-${ladder_skip_month_start}-${ladder_skip_day_start}`) 8809 $(".js-ladders_add_skip_days_end").datetimepicker('setEndDate', skip_end_date_max) 8810 } 8811 }) 8812 .on('hide', function(ev) { 8813 if (typeof(form_id) !== 'undefined') { 8814 $('#' + form_id).valid(); 8815 } 8816 }); 8817 8818 8819 $(".js-ladders_add_skip_days_end").datetimepicker({ 8820 format: "MM dd", 8821 showMeridian: true, 8822 autoclose: true, 8823 pickerPosition: "bottom-left", 8824 startDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), 8825 minView: 2 8826 }).on('changeDate', function(ev) { 8827 if (!$('.js-ladders_add_skip_days_start').val()) { 8828 ladder_skip_month_end = ev.date.toLocaleDateString('default', { month: 'numeric'}) 8829 ladder_skip_day_end = ev.date.toLocaleDateString('default', { day: 'numeric'}) 8830 d = new (Date) 8831 current_year = d.getFullYear() 8832 skip_start_date_min = `${current_year}-1-1` 8833 skip_start_date_max = `${current_year +1 }-${ladder_skip_month_end}-${ladder_skip_day_end}` 8834 $(".js-ladders_add_skip_days_start").datetimepicker('setStartDate', skip_start_date_min) 8835 $(".js-ladders_add_skip_days_start").datetimepicker('setEndDate', skip_start_date_max) 8836 } 8837 }).on('hide', function(ev) { 8838 if (typeof(form_id) !== 'undefined') { 8839 $('#' + form_id).valid(); 8840 } 8841 }); 8842 8843 8844 datepick_days_past_init = function() { 8845 $(".js-datepick-days-past").datetimepicker({ 8846 format: "MM dd, yyyy", 8847 showMeridian: true, 8848 autoclose: true, 8849 pickerPosition: "bottom-left", 8850 endDate: new Date(), 8851 minView: 2 8852 }).on('hide', function(ev) { 8853 if (typeof(form_id) !== 'undefined') { 8854 $('#' + form_id).valid(); 8855 } 8856 }); 8857 } 8858 8859 datepick_days_past_init(); 8860 8861 datepick_days_past_week_only_init = function() { 8862 $(".js-datepick-days-past-week-only").datetimepicker({ 8863 format: "MM dd, yyyy", 8864 showMeridian: true, 8865 autoclose: true, 8866 pickerPosition: "bottom-left", 8867 endDate: new Date(), 8868 minView: 2, 8869 startDate: '2022-10-30', 8870 keyboardNavigation: false 8871 }).on('hide', function(ev) { 8872 if (typeof(form_id) !== 'undefined') { 8873 $('#' + form_id).valid(); 8874 } 8875 }).on('change', function(ev) { 8876 if ($(".js-datepick-days-past-week-only-sunday").val() == '') { 8877 $(".js-datepick-days-past-week-only-saturday").val(''); 8878 $(".js-datepick-days-past-week-only-saturday").datetimepicker('setStartDate', '2022-10-30'); 8879 } else { 8880 $(".js-datepick-days-past-week-only-saturday").datetimepicker('setStartDate', $(".js-datepick-days-past-week-only-sunday").val()); 8881 } 8882 }); 8883 8884 $(".js-datepick-days-past-week-only-sunday").datetimepicker('setDaysOfWeekDisabled', [1,2,3,4,5,6]); 8885 $(".js-datepick-days-past-week-only-saturday").datetimepicker('setDaysOfWeekDisabled', [0,1,2,3,4,5]); 8886 } 8887 8888 datepick_days_past_week_only_init(); 8889 8890 8891 8892 $(".js-datepick-days-all").datetimepicker({ 8893 format: "MM dd, yyyy", 8894 showMeridian: true, 8895 autoclose: true, 8896 pickerPosition: "bottom-left", 8897 minView: 2 8898 }).on('hide', function(ev) { 8899 if (typeof(form_id) !== 'undefined') { 8900 $('#' + form_id).valid(); 8901 } 8902 }); 8903 8904 8905/* 8906 $('.js-clear_ladder_date').click(function() { 8907 $(this).parents('form').submit(); 8908 }); 8909*/ 8910 8911 8912 $(".js-days_ago-datepick-hidden").each(function() { 8913 var parent_id = $(this).prev().attr('id'); 8914 $(this).datetimepicker({ 8915 format: "MM dd, yyyy", 8916 showMeridian: true, 8917 autoclose: true, 8918 pickerPosition: "bottom-left", 8919 minView: 2, 8920 endDate: new Date(), 8921 widgetParent: parent_id 8922 }).on('change', function(ev) { 8923 var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds 8924 var start = new Date($(ev.currentTarget).val()); 8925 var end = new Date(); 8926 end.setHours(0); 8927 end.setMinutes(0); 8928 end.setSeconds(0); 8929 end.setMilliseconds(0); 8930 var diffDays = Math.round(Math.abs((start.getTime() - end.getTime())/(oneDay))); 8931 if ($(ev.currentTarget).prev().hasClass('js-days_ago-datepick-date')) { 8932 $(ev.currentTarget).prev().val($(ev.currentTarget).val()); 8933 } else { 8934 $(ev.currentTarget).prev().val(diffDays); 8935 } 8936 8937 }); 8938 }); 8939 8940 $('body').on('focus click touchstart', '.js-days_ago-datepick', function() { 8941 //console.log('click'); 8942 if ($(this).hasClass('js-days_ago-datepick-date')) { 8943 $(this).next().datetimepicker('show'); 8944 if ($(this).val() != '') { 8945 $(this).next().val($(this).val()); 8946 $(this).next().datetimepicker('update'); 8947 } 8948 } else { 8949 $(this).next().datetimepicker('show'); 8950 if ($(this).val() != '') { 8951 var days_ago = $(this).val(); 8952 if (parseInt(days_ago) == days_ago) { 8953 //console.log(days_ago); 8954 var today = new Date(); 8955 //console.log(today); 8956 today.setHours(0); 8957 today.setMinutes(0); 8958 today.setSeconds(0); 8959 //today.setMilliseconds(0); 8960 //console.log(today); 8961 var date_ago = new Date(); 8962 date_ago.setDate(today.getDate() - days_ago); 8963 //console.log(date_ago); 8964 $(this).next().val(date_ago.toLocaleDateString('en-US').replace(/[^ -~]/g,'')); 8965 $(this).next().datetimepicker('update'); 8966 } 8967 } 8968 } 8969 8970 8971 }); 8972 8973 $('body').on('keyup', '.js-days_ago-datepick', function(e) { 8974 if ($(this).hasClass('js-days_ago-datepick-date')) { 8975 if ($(this).val() != '') { 8976 $(this).next().val($(this).val()); 8977 $(this).next().datetimepicker('update'); 8978 } 8979 } else { 8980 var days_ago = $(this).val(); 8981 if (parseInt(days_ago) == days_ago) { 8982 var today = new Date(); 8983 today.setHours(0); 8984 today.setMinutes(0); 8985 today.setSeconds(0); 8986 today.setMilliseconds(0); 8987 var date_ago = new Date(); 8988 date_ago.setDate(today.getDate() - days_ago); 8989 $(this).next().val(date_ago.toLocaleDateString('en-US').replace(/[^ -~]/g,'')); 8990 $(this).next().datetimepicker('update'); 8991 } 8992 } 8993 8994 8995 }); 8996 8997 $('body').on('keydown', '.js-days_ago-datepick', function(e) { 8998 var keyCode = e.keyCode || e.which; 8999 //console.log(keyCode); 9000 if (keyCode == 9) { //If it's the tab key 9001 $(this).next().datetimepicker('hide'); 9002 } 9003 }); 9004 } 9005 9006 // Limiting date range on network report 9007 $('input.js-network_report-datepicker-start').change(function() { 9008 if ($('input.js-network_report-datepicker-start').val() && $('input.js-network_report-datepicker-end').val()) { 9009 (networkReportDateEvaluator($('input.js-network_report-datepicker-start').val(), $('input.js-network_report-datepicker-end').val()) ? $('input.js-network_report-datepicker-start').val("") : $('input.js-network_report-datepicker-start').val() 9010) 9011 } 9012 }) 9013 9014 $('input.js-network_report-datepicker-end').change(function() { 9015 if ($('input.js-network_report-datepicker-start').val() && $('input.js-network_report-datepicker-end').val()) { 9016 (networkReportDateEvaluator($('input.js-network_report-datepicker-start').val(), $('input.js-network_report-datepicker-end').val()) ? $('input.js-network_report-datepicker-end').val("") : $('input.js-network_report-datepicker-end').val()) 9017 } 9018 }) 9019 9020 function networkReportDateEvaluator(start, end) { 9021 var startDate = new Date(start) 9022 var endDate = new Date(end) 9023 if (endDate - startDate > (90 * 24 * 60 * 60 * 1000)) { 9024 alert(an_javascript_translation.network_report_date_warning) 9025 return true 9026 } 9027 else { 9028 return false 9029 } 9030 } 9031 9032 9033 // Donor date picker or day picker toggle 9034 $('input.js-days_ago-datepick_toggleable').not('.js-filter_date_range-future').each(function() { 9035 //console.log($(this).val()); 9036 //console.log($.isNumeric( $(this).val() )); 9037 var $wrapParent = $(this).parents('.js-filter_toggle_wrap'); 9038 9039 if ($(this).val() != '' && !$.isNumeric( $(this).val() )) { 9040 //console.log('true'); 9041 $wrapParent.find(".js-toggle-picker-days").show(); 9042 $wrapParent.find(".js-filter_toggle_date_link").hide(); 9043 $wrapParent.find('.js-donor_switcher_days').hide(); 9044 $wrapParent.find('.js-donor_switcher_date').show(); 9045 $wrapParent.find('.js-filter_toggle_date_range').show(); 9046 $wrapParent.find('.js-filter_toggle_days').hide(); 9047 $wrapParent.find('.js-days_ago-datepick').attr('maxlength','').addClass('mini-date js-days_ago-datepick-date').removeClass('digits'); 9048 $wrapParent.find('.js-filter_toggle_date_range-block').css('display','block'); 9049 $wrapParent.find('.js-filter_toggle_date_range').addClass('mobile-block'); 9050 9051 if ($wrapParent.find('.js-filter_date_range-future').val() != '') { 9052 $wrapParent.find('.js-filter_date_range-future').show(); 9053 $wrapParent.find('.js-toggle_date_range_label').show(); 9054 $wrapParent.find('.js-donor_switcher_date').hide(); 9055 $wrapParent.find('.js-filter_toggle_date_range').hide(); 9056 $wrapParent.find('.js-toggle_date_range_wrap').addClass('d-flex d-flex--mobile-wrap mt5'); 9057 } 9058 } 9059 }); 9060 9061 // Toggle email opener options 9062 $('body').on('click','.js-target_ope
9062ners_link', function () { 9063 $(this).closest('.js-target_openers_container').find('.js-target_openers_select').show(); 9064 $(this).hide(); 9065 }) 9066 9067 // targeting open verification type 9068 // $('.js-target_opener_verification_type_select').change(function() { 9069 // var opener_verification_type = $(this).val(); 9070 // console.log(opener_verification_type); 9071 // $(this).find('option').each(function(){ 9072 // $(this).removeAttr('selected') 9073 // }) 9074 // $(this).find(`option[value="${opener_verification_type}"]`).attr('selected', 'selected'); 9075 // }); 9076 9077 // Toggle "date" options 9078 $('.js-filter_toggle_wrap').on('click', '.js-filter_toggle_date_link', function() { 9079 // ID of js-filter_toggle_days link 9080 var $linkID = $(this).data('trigger'); 9081 // Parent wrapper 9082 var $wrapParent = $(this).parents('.js-filter_toggle_wrap'); 9083 // ID of parent wrapper 9084 var $wrapID = $(this).parents('.js-filter_toggle_wrap').attr('ID'); 9085 9086 // If the link ID matches the parent wrap ID, run the toggle 9087 if ( $linkID === $wrapID ) { 9088 // Hide this link 9089 $(this).hide(); 9090 // Show days link 9091 $($wrapParent).find('.js-filter_toggle_days_link').show(); 9092 // Hide the "days" text 9093 $($wrapParent).find('.js-filter_toggle_days').hide(); 9094 // Show the "date" text 9095 $($wrapParent).find('.js-filter_toggle_date').show(); 9096 9097 $($wrapParent).find('.js-days_ago-datepick').val('').attr('maxlength','').addClass('mini-date js-days_ago-datepick-date').removeClass('digits'); 9098 9099 $($wrapParent).find('.js-days_ago-datepick-hidden').val(''); 9100 9101 $($wrapParent).find('.js-filter_toggle_date_range-block').css('display','block'); 9102 9103 $($wrapParent).find('.js-filter_toggle_date_range').addClass('mobile-block'); 9104 } 9105 }); 9106 9107 // Toggle "days" options 9108 $('.js-filter_toggle_wrap').on('click', '.js-filter_toggle_days_link', function() { 9109 // ID of js-filter_toggle_days link 9110 var $linkID = $(this).data('trigger'); 9111 // Parent wrapper 9112 var $wrapParent = $(this).parents('.js-filter_toggle_wrap'); 9113 // ID of parent wrapper 9114 var $wrapID = $(this).parents('.js-filter_toggle_wrap').attr('ID'); 9115 9116 // If the link ID matches the parent wrap ID, run the toggle 9117 if ( $linkID === $wrapID ) { 9118 $(this).hide(); 9119 // Show date link 9120 $($wrapParent).find('.js-filter_toggle_date_link').show(); 9121 // Hide the "date" text 9122 $($wrapParent).find('.js-filter_toggle_date').hide(); 9123 // Show the "days" text 9124 $($wrapParent).find('.js-filter_toggle_days').show(); 9125 9126 $($wrapParent).find('.js-days_ago-datepick').val('').attr('maxlength','5').removeClass('mini-date js-days_ago-datepick-date').addClass('digits'); 9127 9128 $($wrapParent).find('.js-days_ago-datepick-hidden').val(''); 9129 9130 $($wrapParent).find('.js-filter_date_range-future').hide(); 9131 $($wrapParent).find('.js-toggle_date_range_label').hide(); 9132 $($wrapParent).find('.js-toggle_date_range_wrap').removeClass('d-flex d-flex--mobile-wrap mt5'); 9133 } 9134 }); 9135 9136 // Toggle "date range" options 9137 $('.js-filter_toggle_wrap').on('click', '.js-filter_toggle_date_range', function() { 9138 // ID of js-filter_toggle_days link 9139 var $linkID = $(this).data('trigger'); 9140 // Parent wrapper 9141 var $wrapParent = $(this).parents('.js-filter_toggle_wrap'); 9142 // ID of parent wrapper 9143 var $wrapID = $(this).parents('.js-filter_toggle_wrap').attr('ID'); 9144 9145 // If the link ID matches the parent wrap ID, run the toggle 9146 if ( $linkID === $wrapID ) { 9147 $(this).hide(); 9148 $(this).removeClass('mobile-block'); 9149 $($wrapParent).find('.js-filter_date_range-future').show(); 9150 $($wrapParent).find('.js-toggle_date_range_label').css('display','block'); 9151 $($wrapParent).find('.js-filter_toggle_since').hide(); 9152 $($wrapParent).find('.js-toggle_date_range_wrap').addClass('d-flex d-flex--mobile-wrap mt5'); 9153 } 9154 }); 9155 9156 if ($.isFunction($.fn.pajinate) ) { 9157 if ($('.js-campaign_actions .js-campaign-content div').length) { 9158 $('.js-campaign_actions').pajinate({ 9159 nav_label_prev: '«', 9160 nav_label_next: '»', 9161 show_first_last: false, 9162 items_per_page: 4 9163 }); 9164 } 9165 } 9166 9167 /* administrative titles */ 9168 9169 $('.js-admin_title_delete').click(function() { 9170 $('.js-admin_title_value').val('').removeClass('required'); 9171 submitClicked = 'admin_title_delete'; 9172 $(this).parent().parent().parent().submit(); 9173 }); 9174 9175 $('.js-admin_title_hidden').val($('.js-admin_title_entry').val()); 9176 9177 $('.js-admin_title_entry').on('keyup change', function() { 9178 $('.js-admin_title_hidden').val($(this).val()); 9179 }); 9180 9181 $('.js-admin_title_hidden').val($('.js-admin_title_entry').val()); 9182 9183 9184 $('.js-survey_page_admin_title_entry').on('keyup change', function() { 9185 $('.js-survey_page_admin_title_hidden').val($(this).val()); 9186 }); 9187
9188 /* sharing/thank you/response page options */ 9189 9190 $('.js-autoresponder_modal_publish_link').click(function(e) { 9191 e.preventDefault(); 9192 var inputs = []; 9193 var has_error = false; 9194 9195 $('.js-autoresponder_modal').find('select, input, textarea').each(function() { 9196 if ($(this).attr('type') == "checkbox") { 9197 inputs.push( 9198 $('<input type="hidden" name="' + $(this).attr('name') + '" value="" />').val( ($(this).is(':checked') ? 1 : 0) ) 9199 ); 9200 } else { 9201 if ($(this).hasClass('required') && $(this).val() == '') { 9202 if ($(this).hasClass('js-redactor')) { 9203 $(this).parent().addClass('error_input'); 9204 } else { 9205 $(this).addClass('error_input'); 9206 } 9207 9208 has_error = true; 9209 } else { 9210 $(this).removeClass('error_input'); 9211 inputs.push( 9212 $('<input type="hidden" name="' + $(this).attr('name') + '" value="" />').val( $(this).val() ) 9213 ); 9214 } 9215 9216 } 9217 9218 }); 9219 9220 if (!has_error) { 9221 $('.fancybox-inline-tmp').append(inputs); 9222 $('.js-publish_link_button_for_modal').click(); 9223 } 9224 }); 9225 9226 if ($('.js-tab_response').length) { 9227 9228 // More general function for toggling email wrapper with checkbox 9229 // Use <label class="js-email_checkbox_label"> 9230 $('.js-email_checkbox_label input').on('change', function () { 9231 const parentTab = $(this).closest('.js-nested_tab'); 9232 const wrapperEl = parentTab.find('.js-email_wrapper'); 9233 if ($(this).is(':checked')) wrapperEl.slideDown(); 9234 else wrapperEl.slideUp(); 9235 }); 9236 9237 if ($('.js-response_option_label input:checked').length) { 9238 $('.js-response_option_label').addClass('response_option_label-selected js-response_option_label-selected'); 9239 $('.js-email_wrapper').removeClass('email_wrapper-off js-email_wrapper-off'); 9240 $('.js-email_wrapper').slideDown('fast'); 9241 if (!$('.js-event_campaign_step_6').length) { 9242 $('.js-email_wrapper input, .js-email_wrapper textarea.js-redactor').not('.js-redactor_image_upload_group_id, .js-email-bcc, .js-share_option_include_bcc_field').addClass('required'); 9243 } 9244 } else { 9245 $('.js-response_option_label').removeClass('response_option_label-selected js-response_option_label-selected'); 9246 $('.js-email_wrapper').addClass('email_wrapper-off js-email_wrapper-off'); 9247 $('.js-email_wrapper').slideUp('fast'); 9248 if (!$('.js-event_campaign_step_6').length) { 9249 $('.js-email_wrapper input, .js-email_wrapper textarea.js-redactor, .js-email_wrapper .redactor-box, .js-email_wrapper .redactor-box').removeClass('required error_input'); 9250 } 9251 $('.js-a-tab_response').removeClass('error_tab js-error_tab'); 9252 $('.js-a-tab_response').siblings('.js-error_icon').remove(); 9253 } 9254 9255 // Auto-reply Email toggle - now handled by event-autoresponse-toggle Stimulus controller 9256 9257 // Self check-in checkbox shows/hides check-in options 9258 if ($('.js-self_check_in_checkbox').length) { 9259 function toggleCheckInTab() { 9260 const check_in_opts = $('.js-checkin_tab_label, .js-checkin_opts_wrapper'); 9261 if ($('.js-self_check_in_checkbox').is(':checked')) { 9262 check_in_opts.show(); 9263 } else { 9264 check_in_opts.hide(); 9265 // If check-in tab is active, switch to first tab 9266 if ($('.js-checkin_tab_label a').prop('id') == 'current') { 9267 $('.js-checkin_tab_label').closest('.js-tabs_nested').find('a').first().trigger('click'); 9268 } 9269 } 9270 } 9271 toggleCheckInTab(); 9272 $('.js-self_check_in_checkbox').on('change', toggleCheckInTab); 9273 } 9274 9275 // Copy check-in URL 9276 if ($('.js-copy_checkin_url').length) { 9277 $('.js-copy_checkin_url').on('click', function(e) { 9278 e.preventDefault(); 9279 var directLink = $(this).attr('href'); 9280 9281 navigator.clipboard.writeText(directLink).then(function() { 9282 Noty.closeAll(); 9283 new Noty({ 9284 theme: 'metroui', 9285 type: 'success', 9286 closeWith: ['button','click'], 9287 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + an_javascript_translation.link_copied_to_clipboard + "</span>", 9288 timeout: 10000 9289 }).show(); 9290 }).catch(function(err) { 9291 console.error('Failed to copy: ', err); 9292 }); 9293 }); 9294 } 9295 9296 if($('.js-response_option_label_call').length) { 9297 $('.js-response_option_label_call input').each(function() { 9298 //console.log(this); 9299 if ($(this).is(':checked')) { 9300 9301 9302 //console.log('true'); 9303 9304 $(this).addClass('response_option_label-selected js-response_option_label-selected_call'); 9305 $(this).parents('.js-response_option_call').find('.js-create_action-editable').addClass('required'); 9306 } else { 9307 $(this).removeClass('response_option_label-selected js-response_option_label-selected_call'); 9308 $(this).parents('.js-response_option_call').find('.js-create_action-editable').removeClass('required error_input').parents('.js-append_text_message, .js-append_text_message-wrap').hide(); 9309 } 9310 }); 9311
9312 $('.js-response_option_label_call input').change(function() { 9313 if ($(this).is(':checked')) { 9314 $(this).addClass('response_option_label-selected js-response_option_label-selected_call'); 9315 $(this).parents('.js-response_option_call').find('.js-create_action-editable').addClass('required').parents('.js-append_text_message, .js-append_text_message-wrap').slideDown('fast'); 9316 } else { 9317 $(this).removeClass('response_option_label-selected js-response_option_label-selected_call'); 9318 $(this).parents('.js-response_option_call').find('.js-create_action-editable').removeClass('required error_input').parents('.js-append_text_message, .js-append_text_message-wrap').slideUp('fast'); 9319 } 9320 }); 9321 } 9322 9323 //mobile response 9324 9325 $('.js-response_option_label_mobile input').change(function() { 9326 //console.log('fire'); 9327 if ($(this).parent().hasClass('js-response_option_label_mobile-selected')) { 9328 $(this).parent().removeClass('response_option_label_mobile-selected js-response_option_label_mobile-selected'); 9329 $('.js-sms_bodies_wrap').addClass('sms_bodies_wrap-off js-sms_bodies_wrap-off'); 9330 $('.js-sms_bodies_wrap').slideUp('fast'); 9331 $('.js-mobile_message_body').removeClass('required error_input'); 9332 $('.js-a-tab_response').removeClass('error_tab js-error_tab'); 9333 $('.js-a-tab_response').siblings('.js-error_icon').remove(); 9334 } else { 9335 $(this).parent().addClass('response_option_label_mobile-selected js-response_option_label_mobile-selected'); 9336 $('.js-sms_bodies_wrap').removeClass('sms_bodies_wrap-off js-sms_bodies_wrap-off'); 9337 $('.js-sms_bodies_wrap').slideDown('fast'); 9338 $('.js-mobile_message_body').addClass('required'); 9339 } 9340 }); 9341 9342 // 24-hour Reminder toggle - now handled by event-autoresponse-toggle Stimulus controller 9343 9344 $('.js-include_bcc_option_label input').change(function () { 9345 const wrapperEl = $('.js-include_bcc_option_wrapper'); 9346 const bccInputEl = wrapperEl.find('.js-email-bcc'); 9347 if ($(this).is(':checked')) { 9348 wrapperEl.fadeIn('100'); 9349 } 9350 else { 9351 wrapperEl.hide(); 9352 bccInputEl.val(''); 9353 } 9354 }); 9355 } 9356 9357 9358 group_manage_settings_init = function () { 9359 if ($('.js-tab_settings').length) { 9360 9361 // Group Settings Tabs 9362 $('.js-tabs-settings a').click(function (e) { 9363 e.preventDefault(); 9364 target_tab = e.currentTarget.closest('a').name 9365 $(".js-settings_tabs_div").hide() 9366 $(".js-tabs-settings a").attr("id", "") 9367 $(`${target_tab}`).fadeIn() 9368 $(`a[name='${target_tab}']`).attr("id", "current") 9369 if ($(`${target_tab}`).find('.redactor-toolbar').length) { 9370 $(`${target_tab}`).find('.floatlabel-redactor').css('margin-top', ($(`${target_tab}`).find('.redactor-toolbar').outerHeight() - 5)); 9371 } 9372 }); 9373 $(document).on('tabMove', function(event, element) { 9374 if (element == "#tab_settings") { 9375 $("a[name='#tab_general']").attr("id", "current"); 9376 $('.js-settings_tabs_div').hide(); 9377 $(".js-settings_general_tab").show(); 9378 9379 } 9380 }) 9381 9382 9383 // Legacy notification_option_label styling - now handled by event-autoresponse-toggle Stimulus controller 9384 9385 /* data collective js ***********************************************/ 9386 9387 $('.js-adc_opt_out_checkbox').change(function() { 9388 //console.log($('.js-adc_opt_out_checkbox:checked')); 9389 if ($('.js-adc_opt_out_checkbox:checked').length) { 9390 $('.js-data_collective_opt_out').removeClass('disabled'); 9391 } else { 9392 $('.js-data_collective_opt_out').addClass('disabled'); 9393 } 9394 }); 9395 9396 // AN-2196 9397 $('.js-power_toggle .js-switch-toggle').click(function() { 9398 9399 if ($(this).hasClass('js-switch-enabled')) { 9400 9401 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 9402 $(this).siblings('.js-switch_enabled_label').hide(); 9403 $(this).siblings('.js-switch_disabled_label').show(); 9404 $(this).siblings('.js-ab_test_settings_wrap').slideUp(); 9405 9406 } else { 9407 9408 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 9409 $(this).siblings('.js-switch_disabled_label').hide(); 9410 $(this).siblings('.js-switch_enabled_label').show(); 9411 $(this).siblings('.js-ab_test_settings_wrap').slideDown(); 9412 9413 } 9414 9415 }); 9416 9417 } 9418 9419 if ($('.js-tab_sharing').length || $('.js-tab_settings').length || $('.js-share_option_wrapper').length) { 9420 if ($(".js-facebook_image_modal_button_step2").length) { 9421 $(".js-facebook_image_modal_button").click(function() { 9422 $('.js-share_option_wrapper, .js-step2_sharing_save').fadeOut(function() { 9423 $('.js-facebook_image_modal').show(); 9424 }); 9425 9426 9427 }); 9428 9429 9430 $(".js-save_image_modal").click(function() { 9431 $('.js-facebook_image_modal').fadeOut(function() { 9432 $('.js-share_option_wrapper, .js-step2_sharing_save').show(); 9433 $('.js-facebook_share_box .js-share_image_preview, .js-tab_settings .js-share_image_preview').html('<strong>' + an_javascript_translation.save_this_page_to_update_the_image_preview + '</strong>'); 9434 }); 9435 9436 9437 }); 9438 9439 $('.js-image_delete_link_facebook_share_step2').click(function() { 9440 $(this).parent().fadeOut('fast'); 9441 $('form').append('<input name="remove_image_facebook" value="true" class="js-id_remove_image_facebook" id="id_remove_image_facebook" type="hidden" />'); 9442 $('.js-facebook_share_box .js-share_image_preview, .js-tab_settings .js-share_image_preview').html('<strong>' + an_javascript_translation.save_this_page_to_update_the_image_preview + '</strong>'); 9443 $('.js-facebook_image_modal .js-action_photo_upload').val(''); 9444 $('.js-facebook_image_modal').fadeOut(function() { 9445 $('.js-share_option_wrapper, .js-step2_sharing_save').show(); 9446 }); 9447 9448 }); 9449 9450 $('.js-step2_sharing_save').click(function() { 9451 var errors = false;
9452 $(this).parent().find('.required').each(function() { 9453 if ($(this).val() == '') { 9454 $(this).addClass('error_input'); 9455 errors = true; 9456 } else { 9457 $(this).removeClass('error_input'); 9458 } 9459 }); 9460 if (!errors) { 9461 $.fancybox.close(); 9462 9463 } 9464 }); 9465 } else { 9466 $(".js-facebook_image_modal_button").fancybox({ 9467 onClosed: function() { 9468 if ($('.js-facebook_image_modal .js-action_photo_upload').val() != '' || $('.js-id_remove_image_facebook').val() == 'true') { 9469 $('.js-facebook_share_box .js-share_image_preview, .js-tab_settings .js-share_image_preview').html('<strong>' + an_javascript_translation.save_this_page_to_update_the_image_preview + '</strong>'); 9470 if ($('.js-facebook_image_modal .js-action_photo_upload').val() != '') { 9471 $('.js-id_remove_image_facebook').val(''); 9472 } 9473 } 9474 9475 }, 9476 margin: 15, 9477 hideOnOverlayClick: false 9478 }); 9479 } 9480 9481 // speechifai campaign select 9482 9483 $('.js-speechifai_select_campaign').change(function() { 9484 if (event.target.value.length) { 9485 $('.js-extra_sharing_options').slideUp(400) 9486 } 9487 else { 9488 // $('.js-extra_sharing_options').removeClass("hide") 9489 $('.js-extra_sharing_options').slideDown(400) 9490 } 9491 }) 9492 9493 if ($('.js-speechifai_select_campaign').find(":selected").val() === '' || typeof($('.js-speechifai_select_campaign').find(":selected").val()) == 'undefined') { 9494 $('.js-extra_sharing_options').show() 9495 9496 } 9497 else { 9498 $('.js-extra_sharing_options').hide() 9499 } 9500 9501 9502 9503 // end speechifai 9504 9505 9506 $(".js-twitter_message").each(function() { 9507 $(this).charCount({ 9508 allowed: 280, 9509 counterText: ' ' + an_javascript_translation.characters_left, 9510 wrapperSelector: '.share_box', 9511 twitter: true 9512 }); 9513 9514 }); 9515 9516 $('.js-image_delete_link_facebook_share').click(function() { 9517 $(this).parent().fadeOut('fast'); 9518 $('form.edit_share_option, form.js-network_settings_defaults').append('<input name="remove_image_facebook" value="true" class="js-id_remove_image_facebook" id="id_remove_image_facebook" type="hidden" />'); 9519 $('.js-facebook_share_box .js-share_image_preview, .js-tab_settings .js-share_image_preview').html('<strong>' + an_javascript_translation.save_this_page_to_update_the_image_preview + '</strong>'); 9520 $('.js-facebook_image_modal .js-action_photo_upload').val(''); 9521 $.fancybox.close(); 9522 }); 9523 9524 $('.js-facebook_image_modal .js-action_photo_upload').change(function() { 9525 $('.js-id_remove_image_facebook').remove(); 9526 $('.js-image_delete_link_facebook_share').parent().fadeIn('fast'); 9527 }); 9528 } 9529 9530 if ($('select.js-group_require_2fa').val() == 'true' || $('select.js-group_require_2fa').val() == 'children_included' || $('select.js-group_require_2fa').val() == 'Enabled (from network parent)') { 9531 $('.js-two_factor_type').show(); 9532 } else { 9533 $('.js-two_factor_type').hide(); 9534 } 9535 9536 $('.js-group_require_2fa').on('change', function() { 9537 var val = $(this).val(); 9538 if ( val == 'true' || val == 'children_included' ) { 9539 $('.js-two_factor_type').slideDown(300); 9540 } else { 9541 $('.js-two_factor_type').slideUp(300); 9542 } 9543 }); 9544 9545 // AN-2230 9546 // accordion slide for new email address 9547 $('.js-new_reply_to').click(function(e) { 9548 e.preventDefault(); 9549 $('.js-new_reply_to_wrap').slideDown(300); 9550 }); 9551 9552 } 9553 group_manage_settings_init(); 9554 9555 /* thank you page sidebar */ 9556 9557 $('.js-remove_ty_sidebar_button').click(function() { 9558 setTimeout(function() { 9559 9560 $('.js-sidebar').fadeOut(250); 9561 9562 setTimeout(function() { 9563 $('.js-ty_head').removeClass('main_col').addClass('full_head'); 9564 $('.js-ty_body').removeClass('main_col'); 9565 }, 300); 9566 9567 $('.js-sub-heading').delay(600).slideUp(300); 9568 9569 if( $('.js-add_ty_sidebar_button').hasClass('v4')) { 9570 $('.js-add_ty_sidebar_button.v4').delay(600).show(); 9571 } else { 9572 $('.js-add_ty_sidebar_button').delay(600).slideDown(); 9573 } 9574 9575 }, 75); 9576 9577 $('.js-display_sharing_options_input').val('0'); 9578 }); 9579 9580 $('.js-add_ty_sidebar_button').click(function() { 9581 $(this).hide(); 9582 $('.js-sub-heading').slideDown(300); 9583 9584 setTimeout(function() { 9585 $('.js-ty_head').removeClass('full_head').addClass('main_col'); 9586 $('.js-ty_body').addClass('main_col'); 9587 }, 350); 9588 9589 $('.js-sidebar').delay(700).fadeIn(); 9590 9591 $('.js-display_sharing_options_input').val('1'); 9592 9593 }); 9594 9595 9596 if ($('.js-display_sharing_options_input').length) { 9597 if ($('.js-display_sharing_options_input').val() == 1) { 9598 $('.js-add_ty_sidebar_button').hide(); 9599 $('.js-sub-heading').show(); 9600 9601 //setTimeout(function() { 9602 $('.js-ty_head').removeClass('full_head').addClass('main_col'); 9603 $('.js-ty_body').addClass('main_col'); 9604 //}, 350); 9605
9606 $('.js-sidebar').show(); 9607 } else { 9608 $('.js-sidebar').hide(); 9609 9610 //setTimeout(function() { 9611 $('.js-ty_head').removeClass('main_col').addClass('full_head'); 9612 $('.js-ty_body').removeClass('main_col'); 9613 //}, 300); 9614 9615 $('.js-sub-heading').hide(); 9616 $('.js-add_ty_sidebar_button').show(); 9617 } 9618 } 9619 9620 /* remove image link */ 9621 $('body').on('click', '.js-image_delete_link', function() { 9622 $(this).hide(); 9623 $(this).siblings('.js-file_upload_icon').show(); 9624 $('form').append('<input name="remove_image" value="true" id="id_remove_image" class="js-id_remove_image" type="hidden" />'); 9625 $('.js-action_photo_upload').val(''); 9626 $('.js-action_photo_upload').siblings('.js-uploaded_file_name').html(an_javascript_translation.browse_file_or_drag_and_drop); 9627 $('.js-upload_logo_modal-link').html(an_javascript_translation.add_banner_image) 9628 }); 9629 9630 $('.js-action_photo_upload, .js_audiofile_upload').change(function() { 9631 $('.js-id_remove_image').remove(); 9632 $('.js-image_delete_link').show(); 9633 $('.js-image_delete_link').siblings('.js-file_upload_icon').hide(); 9634 $('.js-upload_logo_modal-link').html(an_javascript_translation.edit_banner_image) 9635 }); 9636 9637 /* campaign page creation add actions functionality */ 9638 9639 var add_action_click_handler = function() { 9640 $('.js-action_col_available .js-add_action_link').bind('click.add_action', function() { 9641 //console.log('click'); 9642 $('.js-action_col_added .js-lined').append($(this).parent()); 9643 $(this).removeClass('add_action_link js-add_action_link').addClass('remove_action_link js-remove_action_link'); 9644 $(this).find('.far').removeClass('fa-plus-circle').addClass('fa-minus-circle'); 9645 $(this).unbind('click.add_action'); 9646 remove_action_click_handler(); 9647 }); 9648 } 9649 9650 var remove_action_click_handler = function() { 9651 $('.js-action_col_added .js-remove_action_link').bind('click.remove_action', function() { 9652 //console.log('click'); 9653 $('.js-action_col_available .js-lined').append($(this).parent()); 9654 $(this).removeClass('remove_action_link js-remove_action_link').addClass('add_action_link js-add_action_link'); 9655 $(this).find('.far').removeClass('fa-minus-circle').addClass('fa-plus-circle'); 9656 $(this).unbind('click.remove_action'); 9657 add_action_click_handler(); 9658 }); 9659 } 9660 9661 add_action_click_handler(); 9662 remove_action_click_handler(); 9663 9664 if ($('.js-new_action_col_reorder').length) { 9665 if ($.isFunction($.fn.sortable) ) { 9666 //mouseX = false; 9667 9668 $(document).on('mousemove', function(e) { 9669 //console.log(e.pageY); 9670 mouseY = e.pageY; 9671 mouseX = e.pageX; 9672 9673 //mouseX = e.pageX - mouseXclick; 9674 }); 9675 9676 9677 var oldContainer; 9678 var group = $(".js-action_col_added ul.js-lined").sortable({ 9679 //group: 'file_browser_reorder', 9680 handle: 'li', 9681 9682 onDrag: function ($item, position, _super) { 9683 //console.log($item); 9684 position.top = mouseY - $('#fancybox-wrap').offset().top - parseInt($('#fancybox-wrap').css('paddingTop').replace("px", "")) - parseInt($('#fancybox-wrap').css('marginTop').replace("px", "")) - parseInt($('#fancybox-content').css('border-top-width').replace("px", "")) - parseInt($('.js-add_new_action_modal').css('paddingTop').replace("px", "")); 9685 position.left = mouseX - mouseXorig + 370; 9686 //position.left = mouseX; 9687 //console.log(position); 9688 $item.css(position); 9689 }, 9690 9691 // Called after the drag has been started, 9692 // that is the mouse button is beeing held down and 9693 // the mouse is moving. 9694 // The container is the closest initialized container. 9695 // Therefore it might not be the container, that actually contains the item. 9696 onDragStart: function ($item, container, _super) { 9697 $item.css({ 9698 height: $item.height(), 9699 width: $item.width() 9700 }) 9701 9702 $item.addClass("dragged") 9703 $("body").addClass("dragging") 9704 }, 9705 9706 onDrop: function ($item, container, _super) { 9707 //console.log($(container).attr('id')); 9708 $item.removeClass("dragged").removeAttr("style"); 9709 $("body").removeClass("dragging"); 9710 }, 9711 9712 afterMove: function (placeholder, container) { 9713 //if ($('.admin_can_reorder ul.nested li').first().attr('class') == 'level_up') { 9714 if(oldContainer != container){ 9715 if(oldContainer) 9716 oldContainer.el.removeClass("active") 9717 container.el.addClass("active") 9718 9719 oldContainer = container 9720 } 9721 //} 9722 }, 9723 9724 onMousedown: function($item, event, _super) { 9725 //console.log('mousedown'); 9726 //if (mouseX == false) { 9727 mouseXorig = event.pageX; 9728 //console.log(mouseX); 9729 //} 9730 event.preventDefault() 9731 }, 9732 9733 }); 9734 } 9735 9736 } 9737 9738 if ($.isFunction($.fn.fancybox) ) { 9739 $("a.js-campaign_modal_open").fancybox({ 9740 onClosed: function() { 9741 $('.js-campaign_actions .js-campaign-content').html(''); 9742 var html = ''; 9743 var actions_array = []; 9744 9745 $('.js-campaign_actions_hidden').remove(); 9746 9747 $('.js-action_col_added .js-lined li').each(function(i, element) { 9748 html += '<div class="our_single_action_campaign js-our_single_action_campaign flex_vert clearfix" id="display_' + $(element).attr('id') + '"><a href="#" class="block col5of12"><img src="' + $(element).data('image') + '" class="our_single_image js-our_single_image" /></a><h6 class="col7of12"><a href="#">
9748' + $(element).data('title') + '</a></h6></div>'; 9749 9750 actions_array.push($(element).attr('id')); 9751 $('.js-create_action_form').append('<input type="hidden" name="actions[]" class="campaign_actions_hidden js-campaign_actions_hidden" value="' + $(element).attr('id') + '" />'); 9752 }); 9753 9754 $('.js-campaign_actions .js-campaign-content').html(html); 9755 $('.js-campaign_actions_input').val(actions_array); 9756 9757 if ($.isFunction($.fn.pajinate) ) { 9758 if ($('.js-campaign_actions .js-campaign-content div').length) { 9759 $('.js-campaign_actions').pajinate({ 9760 nav_label_prev: '«', 9761 nav_label_next: '»', 9762 show_first_last: false, 9763 items_per_page: 4 9764 }); 9765 } 9766 } 9767 9768 }, 9769 margin: 15, 9770 hideOnOverlayClick: false 9771 }); 9772 } 9773 9774 9775 form_select2_init = function() { 9776 if ($.isFunction($.fn.select2)) { 9777 $("select.js-form_select2").select2({ 9778 allowClear: true, 9779 closeOnSelect: false, 9780 matcher: function (term, text, option) { 9781 if (term.length == 0) return true; 9782 9783 if(term.split(" ").length == 1){ 9784 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 9785 } 9786 9787 keywords=(term).split(/ |,|\[|\]|\(|\)/); 9788 // `data.text` is the text that is displayed for the data object 9789 // check if data.text contains all of keywords, if some is missing, return null 9790 for (var i = 0; i < keywords.length; i++) { 9791 9792 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 9793 // Return `null` if the term should not be displayed 9794 return null; 9795 9796 } 9797 // If here, data.text contains all keywords, so return it. 9798 return text; 9799 } 9800 }); 9801 $("select.js-form_select2.js-form_select2_nosearch").select2({ allowClear: true, minimumResultsForSearch: Infinity }); 9802 9803 9804 } 9805 } 9806 form_select2_init(); 9807 9808 if ($("input.js-rung_tags_select").length) { 9809 $("input.js-rung_tags_select").select2({ 9810 data: select_tags_array, 9811 allowClear: true, 9812 closeOnSelect: false, 9813 matcher: function (term, text, option) { 9814 if (term.length == 0) return true; 9815 9816 if(term.split(" ").length == 1){ 9817 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 9818 } 9819 9820 keywords=(term).split(/ |,|\[|\]|\(|\)/); 9821 // `data.text` is the text that is displayed for the data object 9822 // check if data.text contains all of keywords, if some is missing, return null 9823 for (var i = 0; i < keywords.length; i++) { 9824 9825 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 9826 // Return `null` if the term should not be displayed 9827 return null; 9828 9829 } 9830 // If here, data.text contains all keywords, so return it. 9831 return text; 9832 } 9833 }); 9834 9835 9836 $("input.js-tags_select").select2({ 9837 data: select_tags_action_array, 9838 multiple: true, 9839 separator: '@!@', 9840 allowClear: true, 9841 closeOnSelect: false, 9842 matcher: function (term, text, option) { 9843 if (term.length == 0) return true; 9844 9845 if(term.split(" ").length == 1){ 9846 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 9847 } 9848 9849 keywords=(term).split(/ |,|\[|\]|\(|\)/); 9850 // `data.text` is the text that is displayed for the data object 9851 // check if data.text contains all of keywords, if some is missing, return null 9852 for (var i = 0; i < keywords.length; i++) { 9853 9854 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 9855 // Return `null` if the term should not be displayed 9856 return null; 9857 9858 } 9859 // If here, data.text contains all keywords, so return it. 9860 return text; 9861 } 9862 }); 9863 } 9864 9865 9866 9867 var inbox_url = new URL(window.location.href); 9868 if (inbox_url.searchParams.get('show_unread') == 'true') { 9869 $('.js-sms-inbox__filter-conversations').val('unread').trigger('change'); 9870 } else { 9871 $('.js-sms-inbox__filter-conversations').val('all').trigger('change'); 9872 } 9873 9874 $('.js-sms-inbox__filter-conversations').change(function(){ 9875 var url = new URL(window.location.href); 9876 if ($(this).val() == 'all') { 9877 url.searchParams.delete('show_unread'); 9878 window.location.href = url; 9879 } else { 9880 url.searchParams.append('show_unread','true'); 9881 window.location.href = url; 9882 } 9883 }); 9884 /* 9885 $('.js-sms-inbox__filter-tabs').change(function(){ 9886 var url = new URL(window.location.href); 9887 if ($(this).hasClass('active') == 'all') { 9888 url.searchParams.delete('show_unread'); 9889 window.location.href = url; 9890 } else { 9891 url.searchParams.append('show_unread','true'); 9892 window.location.href = url; 9893 } 9894 }); 9895 */ 9896 9897 // select validation 9898 $("select").change(function() { 9899 if (typeof(form_id) !== 'undefined') { 9900 if ($(this).val() == "") { 9901 $(this).parent().addClass('error_input-select_wrap js-error_input-select_wrap'); 9902 } else { 9903 $(this).parent().removeClass('error_input-select_wrap js-error_input-select_wrap'); 9904 } 9905 9906 $('#' + form_id).valid(); 9907 } 9908 }); 9909 9910 9911 //widget embed advanced options 9912 if ($(".js-embed_textarea").hasClass('disabled')) { 9913 $(".js-embed_textarea").val(an_javascript_translation.publish_your_action_to_generate_your_embed_code); 9914 } else { 9915 $(".js-embed_textarea").val(embedForm('100%')); 9916 } 9917 9918 $('.js-embedSize').change(function() { 9919 var value = $('.js-embedSize:checked').val(); 9920 9921 switch(value) { 9922 case "size1": 9923 $(".js-embed_textarea").val(embedForm("300px")) 9924 break; 9925 case "size2": 9926 $(".js-embed_textarea").val(embedForm("600px")) 9927 break; 9928 case "embed-custom": 9929 $(".js-embed_textarea").val(embedForm($('.js-embed_custom_box_input').val())); 9930 break; 9931 } 9932 }); 9933 9934 $('.js-embed_custom_box_input').on('keyup', function() { 9935 var value = $(this).val(); 9936 9937 if ($('.js-embed_custom').is(':checked')) { 9938 $(".js-embed_textarea").val(embedForm(value)); 9939 } 9940 }); 9941 9942 $('select.js-embed-style-type').change(function() { 9943 $(".js-embed_textarea").val(embedForm()); 9944 }); 9945 9946 $('select.js-embed-layout-type').change(function() { 9947 $(".js-embed_textarea").val(embedForm()); 9948 }); 9949 9950 function embedForm(size) { 9951 if (size == undefined) { 9952 var size = $('.js-embedSize:checked').val(); 9953 9954 switch(size) { 9955 case "size1": 9956 size = "300px" 9957 break; 9958 case "size2": 9959 size = "600px" 9960 break; 9961 case "embed-custom": 9962 size = $('.js-embed_custom_box_input').val() 9963 break; 9964 case undefined: 9965 size = '100%' 9966 break; 9967 } 9968 } 9969 9970 var form_url = $(".js-hidden-url").val(); 9971 var form_name = $(".js-hidden-name").val(); 9972 var form_referer = $(".js-hidden-referrer").val(); 9973 9974 if ($.isFunction($.fn.select2)) { 9975 if ($('.js-referrer_code_select').length && $('.js-referrer_code_select').select2('val')) { 9976 form_referer = form_referer + '&referrer=' + $('.js-referrer_code_select').select2('val'); 9977 } 9978 } 9979 var form_type = $('.js-hidden-type').val(); 9980 9981 var widgetText = ""; 9982 9983 var css = $("select.js-embed-style-type").val(); 9984 9985 var layout = $("select.js-embed-layout-type").val(); 9986 9987/* 9988 var version = "v2"; 9989 var version_css = ""; 9990 if (getURLParameter('version') == "v3") { 9991*/ 9992 version = "v6"; 9993 version_css = "-v3"; 9994 //} 9995 9996 if ($('.js-fundraising-embed').length) { 9997 9998 if (css == 'embed-style-standard') { 9999 var styles = ''; 10000 } else if (css == 'embed-style-layout') { 10001 var styles = '&css=whitelabel'; 10002 } else { 10003 var styles = '&css=false'; 10004 } 10005 10006 if (layout == 'embed-layout-standard') { 10007 widgetText += "<script src='https://"+form_url+"/widgets/" + version + "/" + form_type + "/"+form_name+"?format=js"+form_referer+styles+"'></script>"; 10008 } else { 10009 widgetText += "<script src='https://"+form_url+"/widgets/" + version + "/" + form_type + "/"+form_name+"?format=js"+form_referer+styles+"&style=full'></script>"; 10010 } 10011
10012 widgetText += "<div id='can-" + form_type + "-area-"+form_name+"' style='width: "+size+"'><!-- this div is the target for our HTML insertion --></div>"; 10013 10014 } else { 10015 10016 if (css == 'embed-style-standard') { 10017 widgetText += "<link href='https://"+form_url+"/css/style-embed" + version_css + ".css' rel='stylesheet' type='text/css' />"; 10018 } else if (css == 'embed-style-layout') { 10019 widgetText += "<link href='https://"+form_url+"/css/style-embed-whitelabel" + version_css + ".css' rel='stylesheet' type='text/css' />"; 10020 } 10021 10022 10023 if (layout == 'embed-layout-standard') { 10024 widgetText += "<script src='https://"+form_url+"/widgets/" + version + "/" + form_type + "/"+form_name+"?format=js"+form_referer+"'></script>"; 10025 } else { 10026 widgetText += "<script src='https://"+form_url+"/widgets/" + version + "/" + form_type + "/"+form_name+"?format=js"+form_referer+"&style=full'></script>"; 10027 } 10028 10029 widgetText += "<div id='can-" + form_type + "-area-"+form_name+"' style='width: "+size+"'><!-- this div is the target for our HTML insertion --></div>"; 10030 10031 } 10032 10033 return widgetText 10034 } 10035 10036 if ($.isFunction(autosize) ) { 10037 autosize($("textarea:not(.js-nogrow)")); // grow the textareas as you type in them 10038 } 10039 //autosize(document.querySelectorAll('textarea')); 10040 10041 // referrer code select functions 10042 if ($('.js-referrer_code_select').length) { 10043 if ($('.js-direct_link').hasClass('disabled')) { 10044 $('.js-referrer_code_select').addClass('disabled').select2('disable'); 10045 } else { 10046 10047 $('.js-referrer_code_select').on('change', function() { 10048 //change embed code 10049 $(".js-embed_textarea").val(embedForm()); 10050 10051 if ($('.js-referrer_code_select').select2('val')) { 10052 $('.js-direct_link').val($('.js-direct_link_hidden').val() + 'referrer=' + $('.js-referrer_code_select').select2('val')); 10053 10054 $('.js-facebook_link').attr('href', $('.js-facebook_link_hidden').val().replace(/(source%3D.+%26)/gi, "$1referrer%3D" + $('.js-referrer_code_select').select2('val'))); 10055 10056 $('.js-twitter_link').attr('href', $('.js-twitter_link_hidden').val().replace(/(source%3D.+%26)/gi, "$1referrer%3D" + $('.js-referrer_code_select').select2('val'))); 10057 10058 $('.js-gplus_link').attr('href', $('.js-gplus_link_hidden').val().replace(/(source=.+&)/gi, "$1referrer=" + $('.js-referrer_code_select').select2('val'))); 10059 10060 $('.js-share_email').val($('.js-share_email_hidden').val().replace(/(source=.+&)/gi, "$1referrer=" + $('.js-referrer_code_select').select2('val'))); 10061 } else { 10062 $('.js-direct_link').val($('.js-direct_link_hidden').val()); 10063 10064 $('.js-facebook_link').attr('href', $('.js-facebook_link_hidden').val()); 10065 10066 $('.js-twitter_link').attr('href', $('.js-twitter_link_hidden').val()); 10067 10068 $('.js-gplus_link').attr('href', $('.js-gplus_link_hidden').val()); 10069 10070 $('.js-share_email').val($('.js-share_email_hidden').val()); 10071 } 10072 10073 }); 10074 } 10075 } 10076 10077 /* AN-2261 */ 10078 if ($('.js-direct_link').length && !$('.js-direct_link').hasClass('disabled')) { 10079 /* Copy direct link in action sidebar */ 10080 $('.js-copy_direct_link').click(function(e) { 10081 e.preventDefault(); 10082 var directLink = $('.js-direct_link').val(); 10083 10084 navigator.clipboard.writeText(directLink).then(function() { 10085 Noty.closeAll(); 10086 new Noty({ 10087 theme: 'metroui', 10088 type: 'success', 10089 closeWith: ['button','click'], 10090 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + an_javascript_translation.link_copied_to_clipboard + "</span>", 10091 timeout: 10000 10092 }).show(); 10093 }).catch(function(err) { 10094 console.error('Failed to copy: ', err); 10095 }); 10096 }); 10097 10098 10099 /* Copy sample email text in email modal */ 10100 $('.js-share_via_email').click(function(e) { 10101 e.preventDefault(); 10102 var emailSample = $('.js-share_email').val(); 10103 10104 $.fancybox.close(); 10105 10106 navigator.clipboard.writeText(emailSample).then(function() { 10107 new Noty({ 10108 theme: 'metroui', 10109 type: 'success', 10110 closeWith: ['button','click'], 10111 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + an_javascript_translation.email_sample_text_copied_to_clipboard + "</span>", 10112 timeout: 10000 10113 }).show(); 10114 }).catch(function(err) { 10115 console.error('Failed to copy: ', err); 10116 }); 10117 }); 10118 10119 /* Copy embed code in action sidebar */ 10120 $('.js-copy_embed_code').click(function(e) { 10121 e.preventDefault(); 10122 var embedCode = $('.js-embed_textarea').val(); 10123 10124 navigator.clipboard.writeText(embedCode).then(function() { 10125 new Noty({
10126 theme: 'metroui', 10127 type: 'success', 10128 closeWith: ['button','click'], 10129 text: "<span class='noty_icon'><i class='far fa-check-circle'></i></span> <span class='noty_content'>" + an_javascript_translation.embed_code_copied_to_clipboard + "</span>", 10130 timeout: 10000 10131 }).show(); 10132 }).catch(function(err) { 10133 console.error('Failed to copy: ', err); 10134 }); 10135 }); 10136 } 10137 10138 /* Add a class to the parent when inputs are focused */ 10139 $(".js-email_line input").focus(function(){ 10140 $(this).parent().addClass("active_line js-active_line"); 10141 }).blur(function(){ 10142 $(this).parent().removeClass("active_line js-active_line"); 10143 }); 10144 10145 /* inline email validation */ 10146 if ($.isFunction($.fn.mailcheck)) { 10147 $('input#form-email[type="email"], input#form-email[type="text"], input#ipt-login[type="text"], input#ipt-email[type="text"], input#invite_email[type="email"], input#invite_email[type="text"], input#search_user_field[type="text"], input#user_email[type="text"], input#email-title[type="email"], input#email-title[type="text"], input#email-title[type="text"], input#group_email_replyto[type="text", input[name="user[email]"][type="email"], input#email-title-24hour[type="text"], input[name="group[donation_receipt_email][replyto]"], input[name="group[donation_failed_email][replyto]"], input#group_email_replyto[type="text"]').on('blur', function() { 10148 //console.log('start'); 10149 $(this).mailcheck({ 10150 topLevelDomains: ["com","com.au","com.tw","ca","co.nz","co.uk","de","fr","it","ru","net","org","edu","gov","jp","nl","kr","se","eu","ie","co.il","us","at","be","dk","hk","es","gr","ch","no","cz","in","net","net.au","info","biz","mil","co.jp","sg","hu","uk",'org.uk', 'coop', 'ac.uk', 'me.uk'], 10151 suggested: function(element, suggestion) { 10152 element.parents('.core_field, .col6of12, .login-email, .new_account_email, .email_invite_form, .search_cell, .hundred, .email_line, .js-single_user_view-info, .mb20, .hundredtool').find('.js-email_validation').remove(); 10153 element.parents('.core_field, .col6of12, .login-email, .new_account_email, .email_invite_form, .search_cell, .hundred, .email_line, .js-single_user_view-info, .mb20, .hundredtool').first().append('<li class="email_validation js-email_validation"><em>'+ an_javascript_translation.did_you_mean + '</em> ' + suggestion.full + '<em>?</em></li>'); 10154 $('.js-email_validation').click(function() { 10155 $(this).parents('.core_field, .col6of12, .login-email, .new_account_email, .email_invite_form, .search_cell, .hundred, .email_line, .js-single_user_view-info, .mb20, .hundredtool').find('input#form-email[type="email"], input#form-email[type="text"], input#ipt-login[type="text"], input#invite_email[type="email"], input#invite_email[type="text"], input#search_user_field[type="text"], input#user_email[type="text"], input#email-title[type="email"], input[name=email][type="email"], input#email-title[type="text"], input#email-title[type="text"], input#group_email_replyto[type="text"], input#ipt-fp-email[type="email"], input#email-title-24hour[type="text"], input[name="group[donation_receipt_email][replyto]"], input[name="group[donation_failed_email][replyto]"], input#group_email_replyto[type="text"]').val(suggestion.full); 10156 $(this).remove(); 10157 }); 10158 //console.log('suggested'); 10159 //console.log(element); 10160 //console.log(suggestion); 10161 }, 10162 empty: function(element) { 10163 element.parents('.core_field, .col6of12, .login-email, .new_account_email, .email_invite_form, .search_cell, .hundred, .email_line, .js-single_user_view-info, .mb20, .hundredtool').find('.js-email_validation').remove(); 10164 //console.log('empty'); 10165 //console.log(element); 10166 } 10167 }); 10168 }); 10169 } 10170 10171 10172 /* Show the tooltips on input focus */ 10173 $(document).on('focusin',".js-create_action-editable, .js-petition-group-select, .js-create_email2_form input:not(.js-report_name, .js-skip_tooltip_autoopen), .js-create_email2_form select, .js-create_email2_form textarea, .js-custom_html_textarea, .js-disclaimer_textarea, .js-network_settings_defaults input, .js-syndication_title, .js-syndication_description, .js-notification_setting_third_parties_emails, .js-cu
10173stom_creator, .js-letter_template_message, .js-letter_template_subject, .js-ladder_modal input:not(.js-ladder_modal .js-builder input)", function() { 10174 10175 if ($(this).hasClass('js-letter_template_message') || $(this).hasClass('js-letter_template_subject') ) { 10176 //console.log($(this).parents('.js-sticky_sidebar').find("h5 .js-tooltip")); 10177 tooltipFunction($(this).parents('.js-letter_sidebar').find("h5 .js-tooltip"), '.js-content'); 10178 } else if ($(this).parents('.js-single_user_view').length) { 10179 tooltipFunction($(this).parent().next('.js-tooltip'), '.js-content'); 10180 } else if ($(this).hasClass('js-event-location') || $(this).hasClass('js-event-address') || $(this).hasClass('js-event-city') || $(this).hasClass('js-event-zip') || $(this).hasClass('js-user_zip_code')) { 10181 // Moved to event_form_controller.js 10182 //console.log(under768Flag); 10183 // moved to stimulus event-form controller 10184 // if (!(under768Flag && $(this).hasClass('js-event-location'))) { 10185 // if ($('.js-event_physical_location_toggle-enabled').length) { 10186 // if ($(this).parent().hasClass('floatlabel-wrapper')) { 10187 // tooltipFunction($(this).parent().parent().parent().find(".js-tooltip"), '.js-content'); 10188 // } else { 10189 // tooltipFunction($(this).parent().find(".js-tooltip"), '.js-content'); 10190 // } 10191 // } else { 10192 // if ($(this).parent().hasClass('floatlabel-wrapper')) { 10193 // tooltipFunction($(this).parent().parent().parent().parent().find(".js-tooltip"), '.js-content'); 10194 // } else { 10195 // tooltipFunction($(this).parent().find(".js-tooltip"), '.js-content'); 10196 // } 10197 // } 10198 // } 10199 10200 10201 } else if (!$(this).hasClass('js-event-address') && !$(this).hasClass('js-event-city') && !$(this).hasClass('js-event-zip') && !$(this).hasClass('js-user_zip_code')) { 10202 //console.log($(this).attr('id')); 10203 //$(this).parent().find(".tooltip span").animate({opacity:".95"}, { duration: 300, queue: false }).addClass("ie_tool"); 10204 //$(this).parent().find(".tooltip span").animate({bottom:"40px"}, { duration: 300, queue: false }).addClass("ie_tool"); 10205 if ($(this).parent().hasClass('floatlabel-wrapper')) { 10206 tooltipFunction($(this).parent().parent().find(".js-tooltip"), '.js-content'); 10207 } else { 10208 tooltipFunction($(this).parent().find(".js-tooltip"), '.js-content'); 10209 } 10210 10211 10212 } 10213 }).on('focusout', ".js-create_action-editable, .js-petition-group-select, .js-create_email2_form input:not(.js-report_name), .js-create_email2_form select, .js-create_email2_form textarea, .js-custom_html_textarea, .js-disclaimer_textarea, .js-network_settings_defaults input, .js-syndication_title, .js-syndication_description, .js-notification_setting_third_parties_emails, .js-custom_creator, .js-letter_template_message, .js-letter_template_subject, .js-ladder_modal input", function () { 10214 //console.log($(this).attr('id')); 10215 //if (!$(this).hasClass('js-event-address') && !$(this).hasClass('js-event-city') && !$(this).hasClass('js-event-zip')) { 10216 //$(this).parent().find(".tooltip span").animate({opacity:"0"}, { duration: 300, queue: false }).removeClass("ie_tool"); 10217 //$(this).parent().find(".tooltip span").animate({bottom:"60px"}, { duration: 300, queue: false }).removeClass("ie_tool"); 10218 remove_tooltip(); 10219 //} 10220 }); 10221 10222 $('.js-subject_email_line').on('focusin', '.js-email-subject-alternate', function() { 10223 tooltipFunction($('.js-email-subject').parent().find(".js-tooltip"), '.js-content'); 10224 }).on('focusout', '.js-email-subject-alternate', function() { 10225 remove_tooltip(); 10226 }); 10227 10228 $('.js-from_email_line').on('focusin', '.js-email-from-alternate', function() { 10229 tooltipFunction($('.js-email-from').parent().find(".js-tooltip"), '.js-content'); 10230 }).on('focusout', '.js-email-from-alternate', function() { 10231 remove_tooltip(); 10232 }); 10233 10234 $('.js-multi_select:not(.js-report_fields_select, .js-letter-select-party), .js-dynamic_targeting_select').on('select2-focus', function() { 10235 tooltipFunction($(this).parent().find(".js-tooltip")); 10236 }); 10237 10238 $('.js-multi_select, .js-dynamic_targeting_select').on('select2-blur', function() { 10239 remove_tooltip(); 10240 }); 10241 10242 $('body').on('focusin','.js-regex_input_tooltip', function() { 10243 tooltipFunction($(this).parent().parent().parent().find(".js-tooltip")); 10244 }).on('focusout', function() { 10245 remove_tooltip(); 10246 }); 10247 10248 10249 /* Animate the status bar */ 10250/* 10251 REMOVED FOR 3.0 10252 $(".js-action_status_status_bar-grow").delay(1000).animate({ width: "100%" }, 1500 ); 10253 $(".js-action_status_status_bar-grow").queue(function(next) { 10254 $(this).animate({ top: "50" }, {easing: "linear",duration:1500} ).animate({ top: "0" }, 0 ); 10255 $(this).queue(arguments.callee); 10256 next(); 10257 }); 10258 10259*/ 10260 10261 //group twilio settings 10262 $('.js-twilio_toggle_number_management').click(function() { 10263 $('.js-twilio_number_management').slideToggle(); 10264 }); 10265 10266 //phone numbers 10267 if ($.isFunction($.fn.intlTelInput)) { 10268 if ($("#form-phone").length) { 10269 var phone_placeholder = $("#form-phone").attr('placeholder').trim(); 10270 try { 10271 $("#form-phone").intlTelInput({ 10272 utilsScript: "/includes/js/intl-tel-input/js/utils.js", 10273 allowDropdown: false, 10274 customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { 10275 return phone_placeholder + ', ' + selectedCountryPlaceholder; 10276 }, 10277 initialCountry: $('.js-form-country').val(), 10278 autoPlaceholder: "aggressive" 10279 }); 10280 } catch (error) { 10281 $("#form-phone").intlTelInput({ 10282 utilsScript: "/includes/js/intl-tel-input/js/utils.js", 10283 allowDropdown: false, 10284 customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { 10285 return phone_placeholder + ', ' + selectedCountryPlaceholder; 10286 }, 10287 initialCountry: "US", 10288 autoPlaceholder: "aggressive" 10289 }); 10290 } 10291 10292 if ($('.js-single_user_view').length) { 10293 $('.js-country_drop_wrap select').on('change', function() { 10294 try { $("#form-phone").intlTelInput('setCountry',$('.js-country_drop_wrap select').val()); } catch(err) {}; 10295 }); 10296 } else { 10297 $('select.js-form-country').on('change', function() { 10298 try { $("#form-phone").intlTelInput('setCountry',$('select.js-form-country').val()); } catch(err) {}; 10299 }); 10300 } 10301 10302 } 10303 10304 10305 if ($(".js-form_phone, .js-form_phone-verify").length) { 10306 $('.js-form_phone, .js-form_phone-verify').each(function() { 10307 var phone_placeholder = $(this).attr('placeholder').trim();
10308 try { 10309 $(this).intlTelInput({ 10310 utilsScript: "/includes/js/intl-tel-input/js/utils.js", 10311 allowDropdown: false, 10312 customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { 10313 return phone_placeholder + ', ' + selectedCountryPlaceholder; 10314 }, 10315 initialCountry: $('.js-form-country').val(), 10316 autoPlaceholder: "aggressive" 10317 }); 10318 } catch (error) { 10319 $(this).intlTelInput({ 10320 utilsScript: "/includes/js/intl-tel-input/js/utils.js", 10321 allowDropdown: false, 10322 customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { 10323 return phone_placeholder + ', ' + selectedCountryPlaceholder; 10324 }, 10325 initialCountry: "US", 10326 autoPlaceholder: "aggressive" 10327 }); 10328 } 10329 }); 10330 10331 $('.js-mobile_send_as_another_user_save').click(function() { 10332 $phone_input = $(this).parents('.js-mobile_send_as_another_user-modal').find(".js-form_phone"); 10333 if ($phone_input.val() == '' || $phone_input.intlTelInput('isValidNumber')) { 10334 $phone_input.removeClass('error_input'); 10335 $($phone_input).val($($phone_input).intlTelInput('getNumber')); 10336 $.fancybox.close(); 10337 } else { 10338 $phone_input.addClass('error_input'); 10339 } 10340 }); 10341 } 10342 10343/* see form submit below for why this is taken out 10344 if ($('.js-search_user_field').length) { 10345 var phone_placeholder = $(".js-search_user_field").attr('placeholder').trim(); 10346 $(".js-search_user_field").intlTelInput({ 10347 utilsScript: "/includes/js/intl-tel-input/js/utils.js", 10348 allowDropdown: false, 10349 initialCountry: $('.js-search_user_field').data('default-country').toLowerCase(), 10350 autoPlaceholder: "off" 10351 }); 10352 } 10353*/ 10354 } 10355 10356 //phone number display 10357 if (typeof(window.intlTelInputGlobals) !== 'undefined' && $('.js-mobile_phone_display').length) { 10358 //if (typeof(intlTelInputUtils) === 'undefined') { 10359 window.intlTelInputGlobals.loadUtils("/includes/js/intl-tel-input/js/utils.js").then(function() { 10360 $('.js-mobile_phone_display').each(function() { 10361 if ($('.js-merge_user_form').length) { 10362 var country = $(this).parents('.js-single_user_view').find('.js-mobile_phone_country').text().toLowerCase().trim(); 10363 } else if ($(this).parents('.js-single_user_view').length) { 10364 var country = $('.js-single_user_view .js-mobile_phone_country').text().toLowerCase(); 10365 } else { 10366 var country = $(this).parents('.js-single_user_result').find('.js-mobile_phone_country').text().toLowerCase(); 10367 } 10368 10369 10370 $(this).text(intlTelInputUtils.formatNumber($(this).text(),country,'2')); 10371 }); 10372 }); 10373 } 10374 10375 10376 10377 10378 // Data Sharing 10379 $(".js-edit_d_sharing_opts").click(function() { 10380 $(".js-d_sharing_opts").slideDown(200); 10381 $(".js-edit_d_sharing_opts-close").show().css("display", "inline-block"); 10382 $(".js-edit_d_sharing_opts").hide(); 10383 }); 10384 $(".js-edit_d_sharing_opts-close").click(function() { 10385 $(".js-d_sharing_opts").slideUp(200); 10386 $(".js-edit_d_sharing_opts").show(); 10387 $(".js-edit_d_sharing_opts-close").hide(); 10388 }); 10389 10390 // Show/hide email scheduling 10391 $(".js-email-schedule_trigger").click(function() { 10392 $(".js-email_buttons-one").fadeOut(500).parent().find(".js-email_buttons-schedule_type").delay(500).fadeIn(500); 10393 }); 10394 $(".js-email-schedule_single_trigger").click(function() { 10395 $(".js-email_buttons-schedule_type").fadeOut(500).parent().find(".js-email_buttons-two").delay(500).fadeIn(500); 10396 $(".js-email-schedule-time").addClass("required"); 10397 }); 10398 $(".js-email-schedule_zones_trigger").click(function() { 10399 $(".js-email_buttons-schedule_type").fadeOut(500).parent().find(".js-email_buttons-three").delay(500).fadeIn(500); 10400 $(".js-email-schedule-timezone").addClass("required"); 10401 }); 10402 $(".js-email-schedule_cancel").click(function() { 10403 $(this).parents(".js-email_buttons-schedule_wrap").fadeOut(500).parent().find(".js-email_buttons-one").delay(500).fadeIn(500); 10404 $(".js-email-schedule-time, .js-email-schedule-timezone").removeClass("required"); 10405 }); 10406 $(".js-email-now_trigger").click(function() { 10407 $(".js-email_buttons-one").fadeOut(500).parent().find(".js-email_buttons-now-confirm").delay(500).fadeIn(500); 10408 }); 10409 $(".js-email-now_cancel").click(function() { 10410 $(".js-email_buttons-now-confirm").fadeOut(500).parent().find(".js-email_buttons-one").delay(500).fadeIn(500); 10411 }); 10412 10413 $(".js-email-automate_trigger").click(function() { 10414 $(".js-email_buttons-one").fadeOut(500); 10415 }); 10416 $(".js-email-automate_cancel").click(function() { 10417 $(".js-email_buttons-automate").fadeOut(500); 10418 }); 10419 10420 $('.js-email-confirm-send-immediate').click(function() {
10421 // If showing medialess MMS modal, don't update UI to sending state yet (modal can be closed, returning to pre-send state) 10422 if ($(this).hasClass('js-submit_mms_no_media')) return; 10423 $(this).hide(); 10424 $('.js-email-now_cancel, .js-throttle_wrap, .js-inbox_monster_checkbox_wrap').hide(); 10425 $(this).parent().css('float','none'); 10426 // Preserve child elements (e.g. the Inbox Monster checkbox) instead of clobbering them with .html(), 10427 // which would remove them from the DOM before the form is submitted. 10428 $('.js-send_confirm_message').each(function() { 10429 var $el = $(this); 10430 $el.delay(100).queue(function(next) { 10431 var $preserved = $el.children().detach(); 10432 $el.html('<i class="fas fa-spinner fa-pulse"></i> ' + an_javascript_translation.sending + '...').append($preserved); 10433 next(); 10434 }); 10435 }); 10436 }); 10437 10438 // AN-2238 Edit Random Limit Modal 10439 // @backend > this is just to show how this "should" work, it's not connected to the existing random limit value in any way 10440 edit_random_limit_modal_init = function () { 10441 //console.log('edit modal loaded'); 10442 var initialValue; 10443 10444 initialValue = parseFloat($('.js-random_limit_input').val()) || 0; 10445 10446 10447 // Save button functionality 10448 $('.js-save_random_limit').on('click', function (e) { 10449 e.preventDefault(); 10450 var currentValue = parseFloat($('.js-random_limit_input').val()); 10451 if ( (currentValue > initialValue && initialValue != 0) || isNaN(currentValue)) { 10452 $('.js-random_limit, .js-save_random_limit').hide(); 10453 $('.js-modal_limit_warning, .js-modal_limit_warning_confirm').fadeIn(); 10454 } else { 10455 submitClicked = $(".js-save_random_limit_form").attr('id'); 10456 $(".js-save_random_limit_form").submit(); 10457 } 10458 }); 10459 10460 // note this isn't doing anything, just closing the modal! 10461 $('.js-modal_limit_warning_confirm .js-modal_limit_warning_confirm_save').on('click', function (e) { 10462 e.preventDefault(); 10463 submitClicked = $(".js-save_random_limit_form").attr('id'); 10464 $(".js-save_random_limit_form").submit(); 10465 }); 10466 10467 $('.js-modal_limit_warning_confirm .js-modal_limit_warning_cancel').on('click', function (e) { 10468 e.preventDefault(); 10469 $('.js-random_limit, .js-save_random_limit').fadeIn(); 10470 $('.js-modal_limit_warning, .js-modal_limit_warning_confirm').hide(); 10471 }); 10472 10473 } 10474 // note this should not load on every page 10475 edit_random_limit_modal_init(); 10476 10477 $('.js-email_wrapper_id').val($('select.js-email_wrapper_id_select').val()); 10478 10479 $('select.js-email_wrapper_id_select').on('change', function() { 10480 $('.js-email_wrapper_id').val($(this).val()); 10481 }); 10482 10483 $(".js-autowin-toggle").click(function(e) { 10484 //console.log($(this)); 10485 10486 10487 if ( $( this ).hasClass( "js-autowin-toggle-on" ) ) { 10488 $(this).removeClass("js-autowin-toggle-on autowin-toggle-on").addClass("js-autowin-toggle-off autowin-toggle-off").find("input").prop( "checked", false ); 10489 $(this).parents('.js-automate_fields').find(".js-automate_options-on").removeClass("js-automate_options-on automate_options-on").addClass("js-automate_options-off automate_options-off").find(":input").prop( "disabled", true ).removeClass('required error_input'); 10490 } else { 10491 $(this).removeClass("js-autowin-toggle-off autowin-toggle-off").addClass("js-autowin-toggle-on autowin-toggle-on").find("input").prop( "checked", true ); 10492 $(this).parents('.js-automate_fields').find(".js-automate_options-off").removeClass("js-automate_options-off automate_options-off").addClass("js-automate_options-on automate_options-on").find(":input").prop( "disabled", false ).addClass('required'); 10493 } 10494 10495 //e.preventDefault(); 10496 10497 }); 10498 10499 if ($(".js-autowin-toggle-on").length) { 10500 $(".js-autowin-toggle-on").parents('.js-automate_fields').find(".js-automate_options-on").removeClass("js-automate_options-off automate_options-off").addClass("js-automate_options-on automate_options-on").find(":input").prop( "disabled", false ).addClass('required'); 10501 } else if ($(".js-autowin-toggle-off").length) { 10502 $(".js-autowin-toggle-off").parents('.js-automate_fields').find(".js-automate_options-off").removeClass("js-automate_options-on automate_options-on").addClass("js-automate_options-off automate_options-off").find(":input").prop( "disabled", true ).removeClass('required'); 10503 } 10504 10505 $(".js-email-confirm-automate").click(function() { 10506 $(".js-email-confirm-automate").fadeOut(500).parent().find(".js-email-confirm-automate-send").delay(500).fadeIn(500); 10507 }); 10508 10509 10510 10511 /* automated testing down the list JS */ 10512 10513 var cohorts_url_function = function() { 10514 var cohorts = ''; 10515 $('.js-cohort_checkbox:checked').each(function() { 10516 cohorts = cohorts + 'cohort_ids[]=' + $(this).val() + '&'; 10517 }); 10518 $('.js-replicate_automated').attr('href',$('.js-replicate_automated').data('url') + '?' + cohorts); 10519 if ($('.js-cohort_checkbox:checked').length) { 10520 $('.js-replicate_automated').attr('disabled',false).removeClass('disabled'); 10521 } else { 10522 $('.js-replicate_automated').attr('disabled','disabled').addClass('disabled').attr('href','javascript:void(0);'); 10523 } 10524 } 10525 10526 cohorts_url_function(); 10527 10528 $('.js-cohort_checkbox').on('change', function() { 10529 cohorts_url_function(); 10530 }); 10531 10532 $('.js-replicate_automated').click(function(e) { 10533 if ($(this).hasClass('disabled')) { 10534 e.preventDefault(); 10535 } 10536 if (!$(this).hasClass('disabled') && $('.js-autowin-toggle-on').length) { 10537 var confirmation = confirm(an_javascript_translation.manual_winner); 10538 if (confirmation != true) { 10539 e.preventDefault(); 10540 } 10541 } 10542 }); 10543 10544 10545 10546 /* throttle sending estimates js */ 10547 if (parseInt($('.js-total_filter_size').text()) == 0) { 10548 $('.js-throttle_wrap').hide(); 10549 } 10550 10551 var throttle_estimate = function() { 10552 if ($('.js-throttle_number').val() == '') { 10553 $('.js-throttle_estimate_wrap').hide(); 10554 $('.js-throttle_setting_wrap').hide(); 10555 } else if ($('.js-throttle_number').val() < 1) { 10556 $('.js-throttle_estimate_wrap').hide(); 10557 $('.js-throttle_setting_wrap').hide(); 10558 $('.js-throttle_number').val(''); 10559 } else { 10560 $('.js-throttle_estimate_wrap').show(); 10561 $('.js-throttle_setting_wrap').show(); 10562 $('.js-throttle_number').val(parseInt($('.js-throttle_number').val())); 10563 10564 var hours = Math.ceil(parseInt($('.js-total_filter_size').text().replace(/,/g,"")) / $('.js-throttle_number').val()) - 1; 10565 //console.log(hours); 10566 var date = new Date; 10567 var p = 60 * 1000; 10568 date.setHours(date.getHours() + (hours)); 10569 date = new Date(Math.ceil(date.getTime() / p ) * p); 10570
10571 $('.js-throttle_estimate').text(hours); 10572 $('.js-throttle_time_estimate').text(date.toLocaleString() + ' ' + Intl.DateTimeFormat().resolvedOptions().timeZone); 10573 $('.js-throttle_setting').text(parseInt($('.js-throttle_number').val())); 10574 } 10575 } 10576 10577 $('.js-throttle_number').on('change keyup', function() { 10578 throttle_estimate(); 10579 }); 10580 10581 throttle_estimate(); 10582 10583 /* adding name to query save and count params */ 10584 $('.js-query_name').val($('input.js-query_name_input').val()); 10585 10586 $('input.js-query_name_input').on('change', function() { 10587 $('.js-query_name').val($(this).val()); 10588 }); 10589 10590 10591 /* validating query name on form before save and count */ 10592 $('.js-save_and_count').click(function(e){ 10593 if (!$('form#edit_email_383').valid()){ 10594 $.fn.fancybox.close() 10595 } 10596 }) 10597 10598 /* AN-1804 */ 10599 $('.js-send_by_timezone_link').click(function(e) { 10600 e.preventDefault(); 10601 $(this).hide(); 10602 $('.js-send_by_timezone').removeClass('hidden'); 10603 }); 10604 10605 /* AN-2025 */ 10606 $('.js-always_include_tags_link').click(function (e) { 10607 // $('select.js-always_include_tags_select').select2({ 10608 // placeholder: "Select tags" 10609 // }); 10610 e.preventDefault(); 10611 $(this).slideUp(); 10612 $('.js-always_include_tags').slideDown(); 10613 }); 10614 10615 /** AN-2199 */ 10616 var addToMailstreamInit = function(){ 10617 $('.js-add_targeting_to_mailstream .js-add_to_mailstream').on('click', function(e) { 10618 e.preventDefault(); 10619 if ( $('.js-show_if_mailstream_date').is(':hidden') ) { 10620 alert('Select a mailstream date to add this email to.') 10621 } else { 10622 var $targetingEmail = $('.js-targeting_email'); 10623 console.log($targetingEmail); 10624 var email_text = $targetingEmail.data('title'); 10625 var email_id = $targetingEmail.data('id'); 10626 var emails = [{ admin_title: email_text, is_draft: $targetingEmail.data('is-draft'), targets: null, id: email_id, is_scheduled: $targetingEmail.data('is-scheduled') }]; 10627 render_mailstream_emails(emails, false,false, true, true); 10628 if ($('.js-current_email:visible').length) { 10629 $('.js-add_to_mailstream').addClass('disabled').attr('disabled','disabled'); 10630 } 10631 } 10632 mark_unsaved(); 10633 }) 10634 } 10635 10636 if ($('.js-include_exclude_wrap, .js-mailstream_init').length) { 10637 mailstream_init(); 10638 addToMailstreamInit(); 10639 $('.js-add_to_mailstream_link').click(function (e) { 10640 e.preventDefault(); 10641 $(this).slideUp(); 10642 $('.js-add_targeting_to_mailstream').slideDown(); 10643 10644 }); 10645 //if the email is already in a mailstream, open the mailstream section 10646 if ($('.js-email_in_mailstream').length) { 10647 $('.js-add_to_mailstream_link').trigger('click'); 10648 } 10649 } 10650 10651 if ($) 10652 10653 10654 /* email/report AJAX calculating/targeting count refresh */ 10655 10656 if ($('.js-filter_status').length) { 10657 if ($('.js-filter_permalink').length) { 10658 var filter_url = '/emails/' + $('.js-filter_permalink').val() + '/status'; 10659 } else if ($('.js-filter_permalink_message').length) { 10660 var filter_url = '/mobile_messages/' + $('.js-filter_permalink_message').val() + '/status'; 10661 } else if ($('.js-filter_permalink_query').length) { 10662 var filter_url = '/groups/' + $('.js-filter_permalink_query_group').val() + '/queries/' + $('.js-filter_permalink_query').val() + '/status'; 10663 } else { 10664 var filter_url = '/reports/' + $('.js-filter_permalink_report').val() + '/status'; 10665 } 10666 10667 10668 var filter_json = function(first) { 10669 $.getJSON(filter_url, function(data) { 10670 filter_json_response(data); 10671 }); 10672 }; 10673 10674 var filter_json_response = function(data) { 10675 //console.log($('.js-ab_autosend_modal').is(':visible')); 10676 if (data.finished && !$('.js-ab_autosend_modal').is(':visible')) { 10677 location.reload(); 10678 } else { 10679 setTimeout(function() { 10680 filter_json(); 10681 }, 7000); 10682 } 10683 }; 10684 10685 if ($('.js-filter_status').val() == "false") { 10686 filter_json(); 10687 } 10688 10689 } 10690 10691 10692 /* email discussion board show/hide */ 10693 10694 if ($('.js-start_discussion_button').length) { 10695 if ($('.js-no_comments').length) { 10696 $('.js-email_discussion, .js-mobile_message_discussion').hide(); 10697 } else { 10698 $('.js-start_discussion_button').hide(); 10699 } 10700 10701 $('.js-start_discussion_button').click(function() { 10702 $(this).slideUp(function() { 10703 $('.js-email_discussion, .js-mobile_message_discussion').show(); 10704 }); 10705 }); 10706 } 10707 10708 10709 /* Email Wrapper */ 10710 10711 $('.js-email_wrapper_clips_expand').click(function() { 10712 $('.js-email_wrapper_clips').slideToggle(); 10713 }); 10714 10715 /* Enable Link Appendage in email write */ 10716 10717 $('.js-add_link_appendage-trigger').click(function() { 10718 $(this).hide(); 10719 $('.js-remove_link_appendage-trigger').show(); 10720 $('.js-link_append_wrapper').slideDown(); 10721 }); 10722 10723 /* Mobile Message clips */ 10724 $('body').on('focus', '.js-mobile_message_body, .CodeMirror', function() { 10725 $mobile_textarea_with_focus = $(this); 10726 }); 10727 10728 $('.js-mobile_clips .js-redactor_clip_link, .js-mobile_clips .js-codemirror-clip_link').click(function(e) { 10729 e.preventDefault(); 10730 10731 if (typeof($mobile_textarea_with_focus) != 'undefined' && $mobile_textarea_with_focus.hasClass('CodeMirror')) { 10732 var textInsert = $(this).parent().find('.js-codemirror-clip').text(); 10733 //console.log(textInsert); 10734 $mobile_textarea_with_focus[0].CodeMirror.doc.replaceSelection(textInsert.trim()); 10735 $.fancybox.close(); 10736 10737 } else { 10738 if ($('.js-ladder_action_sms').length) { 10739 var $textarea = $('.js-message_body'); 10740 } else if (typeof($mobile_textarea_with_focus) != 'undefined') { 10741 var $textarea = $mobile_textarea_with_focus; 10742 } else { 10743 var $textarea = $('.js-mobile_message_body').first(); 10744 } 10745 10746 //console.log($textarea);
10747 var cursorPos = $textarea.prop('selectionStart'); 10748 var v = $textarea.val(); 10749 var textBefore = v.substring(0, cursorPos); 10750 var textAfter = v.substring(cursorPos, v.length); 10751 var textInsert = $(this).parent().find('.js-redactor_clip, .js-codemirror-clip').text().trim(); 10752 //console.log(textInsert); 10753 if ($(this).hasClass('page_target_clip')) { 10754 var $clip = $(this).next(); 10755 regex = new RegExp($(this).data('regex')); 10756 if (regex.test($textarea.val())) { 10757 textInsert = $clip.data('match'); 10758 } else { 10759 textInsert = $clip.data('nomatch'); 10760 } 10761 } 10762 10763 $textarea.val(textBefore + textInsert + textAfter); 10764 if ($('.js-ladder_action_sms').length) { 10765 $('.js-mobile_clips').hide(); 10766 $('.js-ladder_modal_action_form').show(); 10767 $.smoothScroll($('.js-ladder_action_sms_write').offset().top - 200); 10768 } else { 10769 $.fancybox.close(); 10770 } 10771 } 10772 10773 10774 10775 }); 10776 10777 10778 /* Page Wrapper */ 10779 if ($.isFunction($.fn.minicolors) ) { 10780 $('.js-minicolors').minicolors({ 10781 position: "top left" 10782 }); 10783 } 10784 10785 10786 $('form.js-edit_page_wrapper_main').submit(function (e) { 10787 var show_warning = false; 10788 $('form.js-edit_page_wrapper_main textarea').each(function() { 10789 if ((/src="http:/i).test($(this).val()) || (/src='http:/i).test($(this).val()) || (/src=http:/i).test($(this).val()) || (/link href="http:/i).test($(this).val()) || (/link href='http:/i).test($(this).val()) || (/link href=http:/i).test($(this).val())) { 10790 show_warning = true; 10791 } 10792 }); 10793 10794 if (show_warning) { 10795 var confirmation = confirm(an_javascript_translation.you_have_added_insecure_content_in_your_html + '\n\n'+ an_javascript_translation.press_ok_to_let_us_rewrite_your_content_with_secure_links + '\n\n' + an_javascript_translation.press_cancel_to_leave_your_content_alone); 10796 if (confirmation == true) { 10797 $('form.js-edit_page_wrapper_main textarea').each(function() { 10798 $(this).val($(this).val().replace(/src="http:/ig,'src="https:').replace(/src=\'http:/ig,'src=\'https:').replace(/src=http:/i,'src=https:').replace(/link href="http:/ig, 'link href="https:').replace(/link href=\'http:/ig, 'link href=\'https:').replace(/link href=http:/ig, 'link href=https:')); 10799 }); 10800 } 10801 } 10802 }); 10803 10804 // Fill in target text as typing 10805 10806 var petitionTargetFill = function(element) { 10807 //console.log('keyup'); 10808 if (element.value > "") { 10809 $(".js-fill-petition-target-name").html(element.value); 10810 } else { 10811 $(".js-fill-petition-target-name").html(an_javascript_translation.petition_target); 10812 } 10813 }; 10814 10815 $(".js-petition-target-name").keyup(function() { petitionTargetFill(this) }); 10816 $(".js-petition-target-name").focusout(function() { petitionTargetFill(this); }); 10817 10818 /* Show and hide email and action stats */ 10819 10820 group_manage_stats_expand_init = function() { 10821 $('.js-manage_action_expand').toggle(function() { 10822 var $el = $(this); 10823 $el.closest('li').find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideDown(100); 10824 }, function() { 10825 $(this).closest('li').find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideUp(100); 10826 }); 10827 } 10828 10829 group_manage_stats_expand_init(); 10830 10831 $("body").on('click', '.js-sponsor_stats_expand', function() { 10832 if ($(this).closest(".js-sponsor_list_line").find(".js-sponsor_list_stats").is(':visible')) { 10833 $(this).closest(".js-sponsor_list_line").find(".js-sponsor_list_stats").slideUp(100); 10834 } else { 10835 $(this).closest(".js-sponsor_list_line").find(".js-sponsor_list_stats").slideDown(100); 10836 } 10837 }); 10838 10839 /* Show and hide file info */ 10840 $(".js-file_info_toggle").toggle(function() { 10841 if ( !$(this).hasClass('list-item__action') && $('.js-content > .js-container').width() > 700) { 10842 $(this).css("transform","rotate(135deg)"); 10843 } 10844 $(this).parent().siblings(".js-file_info").slideDown(150).css('display','block'); 10845 }, function() { 10846 if ( !$(this).hasClass('list-item__action') && $('.js-content > .js-container').width() > 700) { 10847 $(this).css("transform","rotate(0deg)"); 10848 } 10849 $(this).parent().siblings(".js-file_info").slideUp(150); 10850 }); 10851 10852 /* Show and hide subscription info */ 10853 $(".js-view_subscription_toggle").toggle(function() { 10854 $(this).parent().parent().siblings(".js-subscription_info").slideDown(150).css('display','block'); 10855 }, function() { 10856 $(this).parent().parent().siblings(".js-subscription_info").slide
10856Up(150); 10857 }); 10858 $(".js-view_record_toggle").toggle(function() { 10859 $(this).parent().parent().siblings(".js-record_info").slideDown(150).css('display','block'); 10860 }, function() { 10861 $(this).parent().parent().siblings(".js-record_info").slideUp(150); 10862 }); 10863 10864 // show and hide embed stuff 10865 $(".js-embed_toggle-open").click(function() { 10866 $(".js-embed_options").slideDown(200); 10867 $(".js-embed_toggle-close").show(); 10868 $(".js-embed_toggle-open").hide(); 10869 }); 10870 $(".js-embed_toggle-close").click(function() { 10871 $(".js-embed_options").slideUp(200); 10872 $(".js-embed_toggle-open").show(); 10873 $(".js-embed_toggle-close").hide(); 10874 }); 10875 if ($('.js-embed_custom').is(':checked')) { 10876 $('.js-embed_custom_box').show(); 10877 } else { 10878 $('.js-embed_custom_box').hide(); 10879 }; 10880 $(".js-embedSize").click(function(){ 10881 var radio_value = $(this).val(); 10882 if (radio_value == "embed-custom") { 10883 $(".js-embed_custom_box").slideDown(200); 10884 } else if(radio_value != "embed-custom") { 10885 $(".js-embed_custom_box").slideUp(200); 10886 } 10887 }); 10888 10889 /* Show and hide RSVP/Ticket close date options */ 10890 $('.js-event_close_date_checkbox_label input').change(function () { 10891 const formWrap = $(this).closest('.js-event_close_date_wrap').find('.js-event_close_date_form_wrap'); 10892 10893 if ($(this).is(':checked')) { 10894 formWrap.slideDown(); 10895 } 10896 else { 10897 formWrap.slideUp(); 10898 } 10899 }) 10900 10901 /* Show and hide delivery options */ 10902 if ($('.js-petition-delivery-email').is(':checked')) { 10903 $('.js-petition-delivery-email').parent().addClass('selected'); 10904 $('.js-delivery_instructions-email').show(); 10905 } else { 10906 $('.js-petition-delivery-email').parent().removeClass('selected'); 10907 $('.js-delivery_instructions-email').hide(); 10908 }; 10909 if ($('.js-petition-delivery-download').is(':checked')) { 10910 $('.js-petition-delivery-download').parent().addClass('selected'); 10911 $('.js-delivery_instructions-download').show(); 10912 } else { 10913 $('.js-petition-delivery-download').parent().removeClass('selected'); 10914 $('.js-delivery_instructions-download').hide(); 10915 }; 10916 $(".js-petition-delivery-email").click(function() { 10917 $('.js-petition-delivery-email').parent().addClass('selected'); 10918 $('.js-petition-delivery-download').parent().removeClass('selected'); 10919 $(".js-delivery_instructions-email").show(); 10920 $(".js-delivery_instructions-download").hide(); 10921 }); 10922 $(".js-petition-delivery-download").click(function() { 10923 $('.js-petition-delivery-email').parent().removeClass('selected'); 10924 $('.js-petition-delivery-download').parent().addClass('selected'); 10925 $(".js-delivery_instructions-download").show(); 10926 $(".js-delivery_instructions-email").hide(); 10927 }); 10928 10929 /* Show and hide Growth Chart tabs */ 10930 group_manage_growth_chart_init = function() { 10931 var highcharts_initialize_donations = function() { 10932 //console.log('highcharts_initialize_donations'); 10933 if ($('.js-highcharts_initialize_donations').length) { 10934// console.log('true'); 10935 $('#donations_chart').highcharts(JSON.parse($('.js-highcharts_initialize_donations').val())); 10936 } 10937 } 10938 10939 var highcharts_initialize_email = function() { 10940 if ($('.js-highcharts_initialize_email').length) { 10941 $('#email_list_chart').highcharts(JSON.parse($('.js-highcharts_initialize_email').val())); 10942 } 10943 } 10944 10945 var highcharts_initialize_sms = function() { 10946 if ($('.js-highcharts_initialize_sms').length) { 10947 $('#sms_list_chart').highcharts(JSON.parse($('.js-highcharts_initialize_sms').val())); 10948 } 10949 } 10950 10951 $(document).on('tabMove', function(event, element) { 10952 if (element == '#tab_statistics') { 10953 if(typeof highcharts_initialized_email === 'undefined') { 10954 highcharts_initialize_email(); 10955 highcharts_initialized_email = true; 10956 } 10957 10958 if(typeof highcharts_initialized_donations === 'undefined') { 10959 highcharts_initialize_donations(); 10960 highcharts_initialized_donations = true; 10961 } 10962 10963 if(typeof highcharts_initialized_sms === 'undefined') { 10964 highcharts_initialize_sms(); 10965 highcharts_initialized_sms = true; 10966 } 10967 } 10968 }); 10969 10970 $(document).on('groupManageSideBarClick', function(event, element) { 10971 highcharts_initialize_email(); 10972 highcharts_initialize_donations(); 10973 highcharts_initialize_sms(); 10974 }); 10975 10976 highcharts_initialize_email(); 10977 highcharts_initialize_donations(); 10978 highcharts_initialize_sms(); 10979 10980 if ($('.js-growth-chart-hours').is(':checked')) { 10981 $('.js-growth-chart-hours').parent().addClass('selected'); 10982 $('.js-growth_chart_hours').show(); 10983 } else { 10984 $('.js-growth-chart-hours').parent().removeClass('selected'); 10985 $('.js-growth_chart_hours').hide(); 10986 }; 10987 if ($('.js-growth-chart-days').is(':checked')) { 10988 $('.js-growth-chart-days').parent().addClass('selected'); 10989 $('.js-growth_chart_days').show(); 10990 } else { 10991 $('.js-growth-chart-days').parent().removeClass('selected'); 10992 $('.js-growth_chart_days').hide(); 10993 }; 10994 $(".js-growth-chart-hours").click(function() { 10995 $('.js-growth-chart-hours').parent().addClass('selected'); 10996 $('.js-growth-chart-days').parent().removeClass('selected'); 10997 $(".js-growth_chart_hours").show(); 10998 $(".js-growth_chart_days").hide(); 10999 }); 11000 $(".js-growth-chart-days").click(function() { 11001 $('.js-growth-chart-hours').parent().removeClass('selected'); 11002 $('.js-growth-chart-days').parent().addClass('selected'); 11003 $(".js-growth_chart_days").show(); 11004 $(".js-growth_chart_hours").hide(); 11005 }); 11006 11007 /* Show more and less growth chart fields */ 11008 $(".js-show_more_growth").click(function() { 11009 $(this).hide(); 11010 $(this).siblings('.js-show_less_growth').show(); 11011 $(this).parent().siblings('ul').find('.js-extra_growth_fields').slideDown(); 11012 }); 11013 $(".js-show_less_growth").click(function() { 11014 $(this).hide(); 11015 $(this).siblings('.js-show_more_growth').show(); 11016 $(this).parent().siblings('ul').find('.js-extra_growth_fields').slide
11016Up(); 11017 }); 11018 } 11019 11020 group_manage_growth_chart_init(); 11021 11022 /* Show next steps for NGPVAN API */ 11023 $(".js-van_continue1").click(function() { 11024 $(this).hide(); 11025 $('.js-van_step2').show(); 11026 }); 11027 11028 11029 /* upload activists js **************************************************************/ 11030 11031 /* Show and hide Custom Field Matching */ 11032 $(".js-cancel-field_match-select").click(function() { 11033 const width = $(this).closest(".js-field_match-select").outerWidth(); 11034 $(this).closest(".js-field_match-select").siblings(".js-field_match-create").css('width', width); 11035 $(this).closest(".js-field_match-select").hide(); 11036 $(this).closest(".js-field_match-select").siblings(".js-field_match-create").fadeIn(); 11037 $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").attr('disabled',false); 11038 $(this).closest(".js-field_match-select").find(".can_select").attr('disabled',true); 11039 if ($(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'first_name' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'last_name' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'email' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'zip_code' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'address' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'city' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'state' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'can2_phone' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'sms_checkbox' || $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val() == 'country') { 11040 $(this).closest(".js-field_match-select").siblings(".js-field_match-create").find("input").val(''); 11041 } 11042 }); 11043 $(".js-cancel-field_match-create").click(function() { 11044 $(this).closest(".js-field_match-create").hide(); 11045 $(this).closest(".js-field_match-create").siblings(".js-field_match-select").fadeIn(); 11046 $(this).closest(".js-field_match-create").siblings(".js-field_match-select").find(".can_select").attr('disabled',false); 11047 $(this).closest(".js-field_match-create").find("input").attr('disabled',true); 11048 }); 11049 11050 // field matching deduping and erorr checking 11051 if ($('form.edit_list .js-edit_list_dedupe').length) { 11052 var removeFieldMatchSelectedOptions = function() { 11053 upload_selected_fields = []; 11054 $('.js-edit_list_dedupe select.can_select option:selected').each(function() { 11055 if ($(this).val() != '') { 11056 upload_selected_fields.push([$(this).text(), $(this).val()]); 11057 } 11058 }); 11059 11060 $.each(upload_selected_fields, function(i, e) { 11061 $('.js-edit_list_dedupe select.can_select option[value="' + e[1].replace("'","\'") + '"]').not(':selected').each(function() { 11062 $(this).remove(); 11063 }); 11064 }); 11065 } 11066 11067 var recreateFieldMatchOptions = function() { 11068 var field_match_options_html = ''; 11069 11070 $.each(upload_possible_fields, function(i,e) { 11071 field_match_options_html = field_match_options_html + '<option value="' + e[1].replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + '">' + e[0].replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + '</option>'; 11072 }); 11073 11074 $('select.can_select').each(function() { 11075 var selected_value = $(this).val(); 11076 $(this).html(field_match_options_html); 11077 $(this).val(selected_value); 11078 }); 11079 } 11080 11081 removeFieldMatchSelectedOptions(); 11082 11083 $('select.can_select').change(function() { 11084 recreateFieldMatchOptions(); 11085 removeFieldMatchSelectedOptions(); 11086 }); 11087 11088 $('.js-cancel-field_match-select').click(function() { 11089 $(this).closest(".js-field_match-select").find('.can_select span.select2-chosen').html('[Ignore Column]'); 11090 $(this).closest(".js-field_match-select").find('select.can_select').val(''); 11091 recreateFieldMatchOptions(); 11092 removeFieldMatchSelectedOptions(); 11093 }); 11094 } 11095 11096 11097 // disallow core fields as custom fields 11098 11099 $('.js-field_match-create input').on('keyup change', function() { 11100 if ($(this).val() == 'first_name' || $(this).val() == 'last_name' || $(this).val() == 'email' || $(this).val() == 'zip_code' || $(this).val() == 'address' || $(this).val() == 'city' || $(this).val() == 'state' || $(this).val() == 'country' || $(this).val() == 'can2_phone' || $(this).val() == 'phone' || $(this).val() == 'sms_checkbox') { 11101 $(this).val(''); 11102 } 11103 }); 11104 11105 11106 11107 11108 /* User Search/Edit/Merge ************************************************/ 11109 11110 /* Show/Hide User Search by user or report */ 11111 $(".js-user_search-load_report").click(function() { 11112 $(this).fadeOut('fast',function() { 11113 $(".js-search_user_submit-report").fadeIn(); 11114 $(".js-user_search-search_users").fadeIn(); 11115 $(".js-search_user_report").fadeIn(); 11116 $(this).parent().addClass('list_search_select js-list_search_select'); 11117 11118 }); 11119 $(".js-search_user_submit").fadeOut('fast'); 11120 $(".js-search_user_field").fadeOut('fast').parents('.floatlabel-wrapper').fadeOut('fast'); 11121 }); 11122 $(".js-user_search-search_users").click(function() { 11123 $(this).fadeOut('fast', function() { 11124 $(".js-user_search-load_report").fadeIn(); 11125 $(".js-search_user_field").fadeIn(); 11126 //if ($(".js-search_user_field").val() == '') { 11127 $(".js-search_user_field").parents('.floatlabel-wrapper').fadeIn(); 11128 //} 11129 $(".js-search_user_submit").fadeIn(); 11130 $(this).parent().removeClass('list_search_select js-list_search_select'); 11131 }); 11132 $(".js-search_user_report").fadeOut('fast'); 11133 $(".js-search_user_submit-report").fadeOut('fast'); 11134 }); 11135 11136 if ($('select.js-report_id').val() != '') { 11137 $(".js-user_search-load_report").fadeOut('fast',function() { 11138 $(".js-search_user_submit-report").fadeIn(); 11139 $(".js-user_search-search_users").fadeIn(); 11140 $(".js-search_user_report").fadeIn(); 11141 $(".js-user_search-load_report").parent().addClass('list_search_select js-list_search_select'); 11142 11143 }); 11144 $(".js-search_user_submit").fadeOut('fast'); 11145 $(".js-search_user_field").fadeOut('fast').parents('.floatlabel-wrapper').fadeOut('fast'); 11146 } 11147 11148 11149 //remove value in other field if hidden when form is submitted 11150 $('.js-search_user_submit').click(function() { 11151 $('.js-search_user_report select').val(''); 11152 }); 11153 11154 $('.js-search_user_submit-report').click(function() { 11155 $('.js-search_user_field').val(''); 11156 }); 11157 11158 11159/* 11160 //ie9 placeholder fix 11161 $('#merge_user_form .single_user_view label').on('mouseover', function() { 11162 var name = $(this).children('input').attr('name'); 11163 $('input[name="' + name + '"]').parent().addClass('hover-merge'); 11164 }); 11165 11166 $('#merge_user_form .single_user_view label').on('mouseout', function() { 11167 var name = $(this).children('input').attr('name'); 11168 $('input[name="' + name + '"]').parent().removeClass('hover-merge'); 11169 }); 11170*/ 11171 11172 $('.js-merge_user_form .js-single_user_view label').click(function() { 11173 if ($(this).children('input').attr('disabled') != 'disabled') { 11174 if ($(this).hasClass('overwrite-merge')) { 11175 var name = $(this).children('input').attr('name'); 11176 $('input[name="' + name + '"]').attr('checked', false); 11177 $('input[name="' + name + '"]').parent().removeClass('overwrite-merge selected-merge'); 11178 $(this).children('input').attr('checked', true); 11179 $('input[name="' + name + '"]').each(function(i, e) { 11180 if ($(e).attr('checked')) { 11181 $(this).parent().addClass('selected-merge'); 11182 } else { 11183 $(this).parent().addClass('overwrite-merge'); 11184 } 11185 }); 11186 } 11187 } 11188 }); 11189 11190 //add new custom fields, starts with one on the page 11191 var new_custom_field_count = 1; 11192 11193 //blank out hidden field name on load 11194 if ($('.js-custom_field_text_input_show').length) { 11195 $('input#custom_fields_NEW_ITEM_1_key').attr('name',''); 11196 } 11197 11198 $('.js-user_add_new_custom_field').click(function() { 11199 new_custom_field_count++; 11200 var select_options = ''; 11201 var append_html = '' 11202 11203 $('select#custom_fields_NEW_ITEM_1_key option').each(function() { 11204 select_options = select_options + this.outerHTML; 11205 }); 11206 11207 append_html = append_html 11208 + '<div class="single_user_result-custom_field js-single_user_result-custom_field clearfix">' 11209 + '<a href="javascript:void(0);"><i class="far fa-times"></i></a>' 11210 + '<input id="custom_fields_NEW_ITEM_' + new_custom_field_count + '_remove" name="custom_fields[NEW_ITEM_' + new_custom_field_count + '][remove]" type="hidden" value="false">' 11211 + '<div class="relative fifty left edit_user_custom_field">' 11212 + '<select name="custom_fields[NEW_ITEM_' + new_custom_field_count + '][key]" class="can_select create_action-editable-dropdown">' + select_options + '</select>'; 11213 11214 if ($('.js-custom_field_text_input_show').length) { 11215 append_html = append_html 11216 + '<input class="create_action-editable js-create_action-editable mb5 left hundred hide js-user_edit_new_custom_field user_edit_new_custom_field" id="custom_fields_NEW_ITEM_' + new_custom_field_count + '_key" name="" placeholder="'+ an_
11216javascript_translation.custom_field_name +'" size="30" type="text">' 11217 + '<span class="custom_field_text_input_show js-custom_field_text_input_show uppercase tight_letters small"><a href="javascript:void(0);">' + an_javascript_translation.or_create_a_new_custom_field + '</a></span>'; 11218 } 11219 11220 append_html = append_html 11221 + '</div>' 11222 + '<div class="relative fifty left edit_user_custom_field">' 11223 + '<input class="create_action-editable js-create_action-editable mb5 left hundred custom_field" id="custom_fields_NEW_ITEM_' + new_custom_field_count + '_value" name="custom_fields[NEW_ITEM_' + new_custom_field_count + '][value]" placeholder="'+ an_javascript_translation.custom_field_value +'" size="30" type="text">' 11224 + '</div>' 11225 + '</div>'; 11226 11227 $('.js-user_custom_fields').append(append_html); 11228 11229 $('.js-single_user_result-custom_field select.can_select').not('.hasCustomSelect').customSelect({customClass:"can_select"}); 11230 11231 $('.js-add_user_form').trigger('reinitialize.areYouSure'); 11232 11233 }); 11234 11235 11236 // disallow custom fields named as core fields 11237 $('.js-single_user_view-districts').on('keyup change', '.js-user_edit_new_custom_field', function() { 11238 if ($(this).val() == 'first_name' || $(this).val() == 'last_name' || $(this).val() == 'email' || $(this).val() == 'zip_code' || $(this).val() == 'address' || $(this).val() == 'city' || $(this).val() == 'state' || $(this).val() == 'country' || $(this).val() == 'phone' || $(this).val() == 'can2_phone' || $(this).val() == 'sms_checkbox') { 11239 $(this).val(''); 11240 } 11241 }); 11242 11243 $('.js-user_custom_fields').on('click', 'a', function() { 11244 $(this).siblings('input[type=text]').addClass('hide'); 11245 $(this).siblings('input[type=hidden]').val('true'); 11246 $(this).parent().addClass('hide'); 11247 $(this).parent().find('.js-create_action-editable').not('.js-user_edit_new_custom_field').val(''); 11248 }); 11249 11250 are_you_sure_dirty_init = function() { 11251 $('.js-add_user_form, form.js-edit_email_wrapper, form.js-edit_page_wrapper, form.edit_list, form.new_question, form.edit_question, form.js-edit_syndication, .js-network_settings_defaults, form.js-create_ladder_form').areYouSure({'addRemoveFieldsMarksDirty':true} ); 11252 } 11253 are_you_sure_dirty_init(); 11254 11255 11256 $('.js-user_custom_fields input.disabled').attr('disabled','disabled'); 11257 11258 $('.js-add_user_form').submit(function(e) { 11259 //console.log('submit'); 11260 $('.js-user_custom_fields input.disabled').attr('disabled', false); 11261 if ($('.js-add_user_email').val() == '' && $('.js-add_user_mobile').val() == '') { 11262 $('.js-add_user_email, .js-add_user_mobile').addClass('required'); 11263 } else { 11264 $('.js-add_user_email, .js-add_user_mobile').removeClass('required'); 11265 } 11266 }); 11267 11268 /* user view *****************/ 11269 /* turbo frames */ 11270 $(window).on('turbo:frame-load', function(e) { 11271 //console.log("turbo_frame_loaded_callback_" + $(e.target).attr('id')); 11272 window["turbo_frame_loaded_callback_" + $(e.target).attr('id')](); 11273 }); 11274 11275 window["turbo_frame_loaded_callback_emails-lazy"] = function() { 11276 // User Emails 11277 var listjs_options29 = { 11278 valueNames: [ 'listjs_name', 'listjs_date' ], 11279 page: 10, 11280 plugins: [ ListPagination({}) ], 11281 item: '<li class="clearfix pt5 pb5"><div class="li_wrapper"></div></li>' 11282 }; 11283 11284 if ($('.js-user_view_emails ul').length) { 11285 user_view_email_list_array = []; 11286 if ($('.js-emails').val()) { 11287 $.each(JSON.parse($('.js-emails').val()), function(i, e) { 11288 user_view_email_list_array.push({ li_wrapper: e }); 11289 }); 11290 11291 var userList29 = new List('user_view_emails', listjs_options29, user_view_email_list_array); 11292 } 11293 11294 } 11295 } 11296 window["turbo_frame_loaded_callback_emails-lazy"](); 11297 11298 window["turbo_frame_loaded_callback_mobile-messages-lazy"] = function() { 11299 // User Messages 11300 var listjs_options29a = { 11301 valueNames: [ 'listjs_name', 'listjs_date' ], 11302 page: 10, 11303 plugins: [ ListPagination({}) ], 11304 item: '<li class="clearfix pt5 pb5"><div class="li_wrapper"></div></li>' 11305 }; 11306 11307 if ($('.js-user_view_messages ul').length) { 11308 //check variable exists 11309 user_view_message_list_array = []; 11310 if ($('.js-messages').val()) { 11311 $.each(JSON.parse($('.js-messages').val()), function(i, e) { 11312 user_view_message_list_array.push({ li_wrapper: e }); 11313 }); 11314 11315 var userList29a = new List('user_view_sms', listjs_options29a, user_view_message_list_array); 11316 } 11317 11318 11319 } 11320 } 11321 window["turbo_frame_loaded_callback_mobile-messages-lazy"](); 11322 11323 window["turbo_frame_loaded_callback_conversations-lazy"] = function() { 11324 } 11325 window["turbo_frame_loaded_callback_conversations-lazy"](); 11326 11327 window["turbo_frame_loaded_callback_tags-lazy"] = function() { 11328 // User Tags 11329 var listjs_options41 = { 11330 valueNames: [ 'listjs_date', 'listjs_name' ], 11331 page: 10, 11332 plugins: [ ListPagination({}) ] 11333 }; 11334 11335 if ($('.js-user_view_tags ul li').length) { 11336 var userList41 = new List('user_view_tags', listjs_options41); 11337 } 11338 $('a').not('.js-zendesk a, a.js-no_smooth_scroll').smoothScroll(); 11339 } 11340 window["turbo_frame_loaded_callback_tags-lazy"](); 11341 11342 window["turbo_frame_loaded_callback_ladders-lazy"] = function() { 11343 // User Tags 11344 var listjs_options60a = { 11345 valueNames: [ 'listjs_date', 'listjs_name' ], 11346 page: 10, 11347 plugins: [ ListPagination({}) ] 11348 }; 11349 11350 if ($('.js-user_view_ladders ul li').length) { 11351 var userList60a = new List('user_view_ladders', listjs_options60a); 11352 } 11353 $('a').not('.js-zendesk a, a.js-no_smooth_scroll').smoothScroll(); 11354 } 11355 11356 window["turbo_frame_loaded_callback_ladders-lazy"](); 11357 11358 window["turbo_frame_loaded_callback_source-codes-lazy"] = function() { 11359 var listjs_options32 = { 11360 valueNames: [ 'listjs_date', 'listjs_name' ], 11361 page: 10, 11362 plugins: [ ListPagination({}) ] 11363 }; 11364 11365 if ($('.js-user_view_source ul li').length) { 11366 var userList32 = new List('user_view_source', listjs_options32); 11367 } 11368 } 11369 window["turbo_frame_loaded_callback_source-codes-lazy"](); 11370 11371 window["turbo_frame_loaded_callback_custom-fields-lazy"] = function() { 11372 var listjs_options31 = { 11373 valueNames: [ 'listjs_field', 'listjs_name' ], 11374 page: 10, 11375 plugins: [ ListPagination({}) ] 11376 }; 11377 11378 if ($('.js-user_view_customfields ul li').length) { 11379 var userList31 = new List('user_view_customfields', listjs_options31); 11380 } 11381 $('a').not('.js-zendesk a, a.js-no_smooth_scroll').smoothScroll(); 11382 } 11383 window["turbo_frame_loaded_callback_custom-fields-lazy"](); 11384 11385 window["turbo_frame_loaded_callback_donations-list-lazy"] = function() { 11386 // User Donations 11387 var listjs_options27 = { 11388 valueNames: [ 'listjs_name', 'listjs_date', 'listjs_amount' ], 11389 page: 10, 11390 plugins: [ ListPagination({}) ], 11391 item: '<li class="clearfix pt5 pb5"><div class="li_wrapper"></div></li>' 11392 }; 11393 11394 if ($('.js-user_view_donations ul').length) { 11395 user_view_donation_list_array = []; 11396 if ($('.js-donations').val()) { 11397 $.each(JSON.parse($('.js-donations').val()), function(i, e) { 11398 user_view_donation_list_array.push({ li_wrapper: e }); 11399 }); 11400 var userList27 = new List('user_view_donations', listjs_options27, user_view_donation_list_array); 11401 var donations_fancy_function = function() { 11402 $(".js-user_view_donations ul .js-fancylink").each(function() { 11403 if (!$(this).data('fancybox')) { 11404 $(this).fancybox({ 11405 onComplete: function() { 11406 $('body').addClass('body_has_modal'); 11407 }, 11408 onClosed: function() { 11409 $('.js-file_delete_link').css('display','inline'); 11410 $('.js-edit_confirm_delete').css('display','none'); 11411 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
11412 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 11413 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 11414 $('body').removeClass('form_builder_edit'); 11415 }, 11416 margin: 15, 11417 hideOnOverlayClick: false 11418 }); 11419 } 11420 }); 11421 11422 $(".js-user_view_donations ul select.js-form_select2").each(function() { 11423 if ($.isFunction($.fn.select2) && !$(this).data('select2')) { 11424 $(this).select2({ 11425 allowClear: true, 11426 closeOnSelect: false, 11427 matcher: function (term, text, option) { 11428 if (term.length == 0) return true; 11429 11430 if(term.split(" ").length == 1){ 11431 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 11432 } 11433 11434 keywords=(term).split(/ |,|\[|\]|\(|\)/); 11435 // `data.text` is the text that is displayed for the data object 11436 // check if data.text contains all of keywords, if some is missing, return null 11437 for (var i = 0; i < keywords.length; i++) { 11438 11439 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 11440 // Return `null` if the term should not be displayed 11441 return null; 11442 11443 } 11444 // If here, data.text contains all keywords, so return it. 11445 return text; 11446 } 11447 }); 11448 $(this).select2({ allowClear: true, minimumResultsForSearch: Infinity }); 11449 } 11450 }); 11451 11452 $(".js-datepick-days").datetimepicker({ 11453 format: "MM dd, yyyy", 11454 showMeridian: true, 11455 autoclose: true, 11456 pickerPosition: "bottom-left", 11457 startDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), 11458 minView: 2 11459 }).on('hide', function(ev) { 11460 if (typeof(form_id) !== 'undefined') { 11461 $('#' + form_id).valid(); 11462 } 11463 }); 11464 11465 $(".js-datepick-past").datetimepicker({ 11466 format: "MM dd, yyyy", 11467 showMeridian: true, 11468 autoclose: true, 11469 pickerPosition: "bottom-left", 11470 endDate: new Date(new Date().getTime()), 11471 minView: 2 11472 }).on('hide', function(ev) { 11473 if (typeof(form_id) !== 'undefined') { 11474 $('#' + form_id).valid(); 11475 } 11476 }); 11477 11478 canValidate(); 11479 } 11480 11481 userList27.on('paged', donations_fancy_function); 11482 userList27.on('searchComplete', donations_fancy_function); 11483 donations_fancy_function(); 11484 } 11485 } 11486 11487 // User Search - Recurring Donations 11488 var listjs_options48 = { 11489 valueNames: [ 'listjs_name', 'listjs_amount', 'listjs_period', 'listjs_created', 'listjs_last', 'listjs_status' ], 11490 page: 10, 11491 plugins: [ ListPagination({}) ] 11492 }; 11493 11494 if ($('.js-user_view_recurring ul li').length) { 11495 var userList48 = new List('user_view_recurring', listjs_options48); 11496 } 11497 11498 $(".js-fancylink_add_transaction").fancybox({ 11499 onComplete: function() { 11500 $('body').addClass('body_has_modal'); 11501 }, 11502 onClosed: function() { 11503 $('.js-file_delete_link').css('display','inline'); 11504 $('.js-edit_confirm_delete').css('display','none'); 11505 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 11506 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 11507 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 11508 $('body').removeClass('form_builder_edit'); 11509 }, 11510 margin: 15, 11511 hideOnOverlayClick: false 11512 }); 11513 form_select2_init(); 11514 $('a').not('.js-zendesk a, a.js-no_smooth_scroll').smoothScroll(); 11515 11516 } 11517 window["turbo_frame_loaded_callback_donations-list-lazy"](); 11518 11519 window["turbo_frame_loaded_callback_actions-list-lazy"] = function() { 11520 // User Actions 11521 var listjs_options28 = { 11522 valueNames: [ 'listjs_name', 'listjs_date', 'action_type_badge' ], 11523 page: 10, 11524 plugins: [ ListPagination({}) ], 11525 item: '<li class="clearfix pt5 pb5"><div class="li_wrapper"></div></li>' 11526 }; 11527 11528 if ($('.js-user_view_actions ul').length) { 11529 user_view_action_list_array = []; 11530 if ($('.js-actions').val()) { 11531 $.each(JSON.parse($('.js-actions').val()), function(i, e) { 11532 user_view_action_list_array.push({ li_wrapper: e }); 11533 }); 11534 11535 var userList28 = new List('user_view_actions', listjs_options28, user_view_action_list_array); 11536 var actions_fancy_function = function() { 11537 $(".js-user_view_actions ul .js-fancylink").each(function() { 11538 if (!$(this).data('fancybox')) { 11539 $(this).fancybox({ 11540 onComplete: function() { 11541 $('body').addClass('body_has_modal'); 11542 }, 11543 onClosed: function() { 11544 $('.js-file_delete_link').css('display','inline'); 11545 $('.js-edit_confirm_delete').css('display','none'); 11546 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
11547 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 11548 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 11549 $('body').removeClass('form_builder_edit'); 11550 }, 11551 margin: 15, 11552 hideOnOverlayClick: false 11553 }); 11554 } 11555 }); 11556 } 11557 11558 userList28.on('paged', actions_fancy_function); 11559 userList28.on('searchComplete', actions_fancy_function); 11560 actions_fancy_function(); 11561 } 11562 } 11563 } 11564 window["turbo_frame_loaded_callback_actions-list-lazy"](); 11565 11566 11567 11568 $(window).on('turbo:fetch-request-error turbo:frame-missing', function(e) { 11569 e.preventDefault(); 11570 $(e.target).html('<p class="nomb">' + an_javascript_translation.an_error_occurred_refresh_and_try_again + '</p>'); 11571 }); 11572 11573 11574 11575 /* resubscribe bouncing/spam alert */ 11576 $('.js-bouncing_resubscribe').click(function(e) { 11577 11578 $.ajax({ 11579 url: $(this).data('bounce-check-path'), 11580 dataType: 'json', 11581 async: false, 11582 success: function (data) { 11583 if (data.flagged == true) { 11584 e.preventDefault(); 11585 alert(an_javascript_translation.bounce_resub_message); 11586 } 11587 }, 11588 error: function () { 11589 e.preventDefault(); 11590 alert(an_javascript_translation.bounce_resub_message); 11591 } 11592 }); 11593 }); 11594 11595 11596 11597 /* disable/enable goal counter */ 11598 if ($(".js-disable_goal_counter input").is(":checked")) { 11599 $(".js-disable_goal_counter").hide(); 11600 $(".js-enable_goal_counter").show(); 11601 $(".js-goal_tracker").hide(); 11602 $(".js-goal_tracker > *").css("opacity","0.01"); 11603 $(".action_status_tracker").addClass("removed_goal_slider"); 11604 } else { 11605 $(".js-enable_goal_counter").hide(); 11606 $(".js-disable_goal_counter").show(); 11607 }; 11608 $(".js-enable_goal_counter input").click(function(e) { 11609 if ($('.js-random_limit_input').length && $('.js-random_limit_input').val() != '') { 11610 var random_limit_confirm = confirm(an_javascript_translation.enabling_order_by_timezone_will_remove_your_random_limit); 11611 if (random_limit_confirm != true) { 11612 e.preventDefault(); 11613 return false; 11614 } else { 11615 $('.js-random_limit_input').val('').addClass('disabled').attr('disabled','disabled').parents('.js-random_limit').addClass('disabled'); 11616 } 11617 } else if ($('.js-random_limit_input').length) { 11618 $('.js-random_limit_input').val('').addClass('disabled').attr('disabled','disabled').parents('.js-random_limit').addClass('disabled'); 11619 } 11620 $(".js-disable_goal_counter").show(); 11621 $(".js-enable_goal_counter").hide(); 11622 $(".js-goal_tracker").slideDown(300, function() { 11623 $(".js-goal_tracker > *").fadeTo(800, 1); 11624 fundraising_goal_donors_dollars_switch($('.js-donate_slider_type')); 11625 ticketed_goal_donors_dollars_switch($('.js-ticketed_slider_type')); 11626 }); 11627 $(".action_status_tracker").removeClass("click_removed_goal_slider"); 11628 $(".action_status_tracker").removeClass("removed_goal_slider"); 11629 }); 11630 if ($('.js-random_limit_input').length && $('.js-disable_goal_counter:visible').length) { 11631 $('.js-random_limit_input').val('').addClass('disabled').attr('disabled','disabled').parents('.js-random_limit').addClass('disabled'); 11632 } 11633 $(".js-disable_goal_counter input").click(function() { 11634 if ($('.js-random_limit_input').length) { 11635 $('.js-random_limit_input').removeClass('disabled').attr('disabled',false).parents('.js-random_limit').removeClass('disabled'); 11636 } 11637 $(".js-enable_goal_counter").show(); 11638 $(".js-disable_goal_counter").hide(); 11639 $(".js-goal_tracker > *").fadeTo(300, 0.01, function() { 11640 $(".js-goal_tracker").slideUp(500); 11641 }); 11642 $(".action_status_tracker").addClass("click_removed_goal_slider"); 11643 }); 11644 11645 /* Toggle "edit goal" drawer */ 11646 $(".js-edit_goal").click( function(e) { 11647 e.preventDefault(); 11648 $(".js-edit_goal_wrap").removeClass("hide"); 11649 $(".js-edit_goal_cancel").removeClass("hide"); 11650 $(this).addClass("hide"); 11651 }); 11652 11653 /* Toggle "edit goal" drawer */ 11654 $(".js-edit_goal_cancel").click( function(e) { 11655 e.preventDefault(); 11656 $(".js-edit_goal_wrap").addClass('hide'); 11657 $(".js-edit_goal").removeClass("hide"); 11658 $(this).addClass("hide"); 11659 }); 11660 11661 //Call Campaign's click to call 11662 $('.js-click-to-call-toggle .js-switch-toggle').click(function() { 11663 var $click_to_call_hidden = $(".js-call-campaign-click-to-call"); 11664 if($click_to_call_hidden.val() == "0"){ 11665 $click_to_call_hidden.val("1"); 11666 $(this).addClass('switch-enabled js-switch-enabled').removeClass('switch-disabled js-switch-disabled').parents('.js-click-to-call-toggle').addClass('click_to_call_toggle-on').removeClass('click_to_call_toggle-off'); 11667 } 11668 else{
11669 $click_to_call_hidden.val("0"); 11670 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled').parents('.js-click-to-call-toggle').removeClass('click_to_call_toggle-on').addClass('click_to_call_toggle-off'); 11671 } 11672 submitClicked = false; 11673 if($(".js-edit-call-campaign").data('validator')){ 11674 $(".js-edit-call-campaign").data('validator').cancelSubmit = true; 11675 } 11676 $(".js-edit-call-campaign").submit(); 11677 }); 11678 11679 if ($('.js-start_record_upload').length) { 11680 // Call Campaigns Record MP3 11681 const button = document.querySelector('.js-start_record_upload'); 11682 //const modal_button = document.querySelector('.js-start_recording_modal'); 11683 const playerWrap = document.querySelector('.js-upload_audio_player_wrap'); 11684 const recorder = new MicRecorder({ 11685 bitRate: 128 11686 }); 11687 11688 button.addEventListener('click', startRecording); 11689 $(button).unbind('click.fb'); 11690 11691 function startRecording(e) { 11692 recorder.start().then(() => { 11693 button.innerHTML = '<i class="fas fa-stop mr5"></i> ' + an_javascript_translation.stop_recording; 11694 button.classList.toggle('btn-danger'); 11695 11696 button.removeEventListener('click', startRecording); 11697 button.addEventListener('click', stopRecording); 11698 11699 11700 if ( playerWrap.innerHTML != "" ) { 11701 playerWrap.removeChild(playerWrap.lastChild); 11702 } 11703 11704 }).catch((e) => { 11705 console.error(e); 11706 $('.js-mic_error_modal').trigger('click'); 11707 }); 11708 11709 e.preventDefault(); 11710 } 11711 11712 11713 function stopRecording(e) { 11714 recorder.stop().getMp3().then(([buffer, blob]) => { 11715 //console.log(buffer, blob); 11716 const file = new File(buffer, 'music.mp3', { 11717 type: blob.type, 11718 lastModified: Date.now() 11719 }); 11720 11721 const player = new Audio(URL.createObjectURL(file)); 11722 11723 const reader = new FileReader(); 11724 reader.onloadend = () => { 11725 document.querySelector('.js-recording_upload').value = reader.result; 11726 }; 11727 11728 reader.readAsDataURL(file); 11729 11730 11731 player.controls = true; 11732 playerWrap.appendChild(player); 11733 11734 11735 button.innerHTML = '<i class="fas fa-play mr5"></i> ' + an_javascript_translation.start_new_recording; 11736 11737 button.removeEventListener('click', stopRecording); 11738 button.addEventListener('click', startRecording); 11739 }).catch((e) => { 11740 console.error(e); 11741 }); 11742 11743 e.preventDefault(); 11744 } 11745 } 11746 11747 11748 /* disable/enable recurring donations */ 11749 if ($(".js-disable_recurring_donation").length) { 11750 if ($(".js-disable_recurring_donation").hasClass("js-recurring_checked")) { 11751 $(".js-disable_recurring_donation input").attr('checked','checked'); 11752 $(".js-disable_recurring_donation").show(); 11753 $(".js-enable_recurring_donation").hide(); 11754 $('input[name="recurring_donation_toggle"]').val('enable_recurring_donation'); 11755 } else { 11756 $(".js-disable_recurring_donation").hide(); 11757 $(".js-enable_recurring_donation input").attr('checked','checked'); 11758 $(".js-enable_recurring_donation").show(); 11759 $(".js-donate_recurring").hide(); 11760 $(".js-donate_recurring > *").css("opacity","0.01"); 11761 $('input[name="recurring_donation_toggle"]').val('disable_recurring_donation'); 11762 }; 11763 11764 $(".js-enable_recurring_donation input").click(function() { 11765 $(".js-disable_recurring_donation").show(); 11766 $(".js-enable_recurring_donation").hide(); 11767 $(".js-donate_recurring").slideDown(300, function() { 11768 $(".js-donate_recurring > *").fadeTo(800, 1); 11769 //fundraising_goal_donors_dollars_switch($('.donate_slider_type')); 11770 }); 11771 11772 $('input[name="recurring_donation_toggle"]').val('enable_recurring_donation'); 11773 }); 11774 11775 $(".js-disable_recurring_donation input").click(function() { 11776 $(".js-enable_recurring_donation").show(); 11777 $(".js-disable_recurring_donation").hide(); 11778 $(".js-donate_recurring > *").fadeTo(300, 0.01, function() { 11779 $(".js-donate_recurring").slideUp(500); 11780 }); 11781 11782 $('input[name="recurring_donation_toggle"]').val('disable_recurring_donation'); 11783 }); 11784 } 11785 11786 11787 11788 // fundraising without email permissions checks 11789 function fundraisingNoEmailAjax(permalink, change) { 11790 $.getJSON('/groups/' + permalink + '/check_permissions', function(data) { 11791 if (data.settings) { 11792 $('.js-bypass_email_wrap').slideDown('fast'); 11793 } else {
11794 $('.js-bypass_email_wrap').slideUp('fast'); 11795 if (change) { 11796 //console.log('fire'); 11797 $('#fundraising_donations_without_email').attr('checked',false); 11798 $('.js-fundraising_default_email').removeClass('required'); 11799 } 11800 } 11801 }) 11802 .error(function() { 11803 //console.log('error'); 11804 $('.js-bypass_email_wrap').slideUp('fast'); 11805 if (change) { 11806 $('#fundraising_donations_without_email').attr('checked',false); 11807 $('.js-fundraising_default_email').removeClass('required'); 11808 } 11809 }); 11810 } 11811 11812 if ($('.js-bypass_email_wrap').length) { 11813 11814 // pass change variable if the user manipulates the select... 11815 $('.js-create_donate_form select.js-sponsor-group-select').on('change', function() { 11816 //console.log('change'); 11817 if ($(this).val() != '') { 11818 fundraisingNoEmailAjax($(this).val(), true); 11819 } else { 11820 $('.js-bypass_email_wrap').slideUp('fast'); 11821 $('#fundraising_donations_without_email').attr('checked',false); 11822 $('.js-fundraising_default_email').removeClass('required'); 11823 } 11824 11825 }); 11826 11827 // ...otherwise, preserve checkbox state on load, even if hidden 11828 if ($('.js-create_donate_form select.js-sponsor-group-select').val() != '') { 11829 fundraisingNoEmailAjax($('.js-create_donate_form select.js-sponsor-group-select').val(), false); 11830 } else { 11831 $('.js-bypass_email_wrap').addClass('hide'); 11832 $('#fundraising_donations_without_email').attr('checked',false); 11833 } 11834 11835 if ($('#fundraising_donations_without_email').attr('checked')) { 11836 $('.js-optional_email_wrap').removeClass('hide'); 11837 $('.js-fundraising_default_email').addClass('required'); 11838 } else { 11839 $('.js-optional_email_wrap').addClass('hide'); 11840 $('.js-fundraising_default_email').removeClass('required'); 11841 } 11842 11843 $('#fundraising_donations_without_email').on('change', function() { 11844 if ($('#fundraising_donations_without_email').attr('checked')) { 11845 $('.js-optional_email_wrap').slideDown('fast'); 11846 $('.js-fundraising_default_email').addClass('required'); 11847 } else { 11848 $('.js-optional_email_wrap').slideUp('fast'); 11849 $('.js-fundraising_default_email').removeClass('required'); 11850 } 11851 }); 11852 } 11853 11854 11855 /* Ladder triple toggle */ 11856 11857 $('.js-triple_toggle .js-switch-toggle').click(function(e) { 11858 11859 if ($(this).hasClass('js-switch-disabled')) { 11860 11861 if ($(this).is('.js-active-switch')) { 11862 var active_confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_activate_this_ladder_activists_will_enter_active_ladders_when_they_trigger_rungs); 11863 if (active_confirmation != true) { 11864 e.preventDefault(); 11865 return false; 11866 } 11867 $(this).closest(".js-triple_toggle").addClass('js-triple-active triple-active').removeClass('js-triple-closed js-triple-stopped js-triple-paused triple-closed triple-stopped triple-paused'); 11868 } else if ($(this).is('.js-closed-switch')) { 11869 var closed_confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_close_this_ladder_activists_will_no_longer_enter_closed_ladders_when_they_trigger_rungs); 11870 if (closed_confirmation != true) { 11871 e.preventDefault(); 11872 return false; 11873 } 11874 $(this).closest(".js-triple_toggle").addClass('js-triple-closed triple-closed').removeClass('js-triple-active js-triple-stopped js-triple-paused triple-active triple-stopped triple-paused'); 11875 } else if ($(this).is('.js-stopped-switch')) { 11876 var stopped_confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_stop_this_ladder); 11877 if (stopped_confirmation != true) { 11878 e.preventDefault(); 11879 return false; 11880 } 11881 $(this).closest(".js-triple_toggle").addClass('js-triple-stopped triple-stopped').removeClass('js-triple-active js-triple-closed js-triple-paused triple-active triple-closed triple-paused'); 11882 } else if ($(this).is('.js-paused-switch')) { 11883 var stopped_confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_pause_this_ladder); 11884 if (stopped_confirmation != true) { 11885 e.preventDefault(); 11886 return false; 11887 } 11888 $(this).closest(".js-triple_toggle").addClass('js-triple-paused triple-paused').removeClass('js-triple-active js-triple-closed js-triple-stopped triple-active triple-closed triple-stopped'); 11889 } 11890 11891 $(this).addClass('switch-enabled js-switch-enabled').removeClass('switch-disabled js-switch-disabled'); 11892 $(this).parent().parent().siblings().find('.js-switch-toggle').addClass('switch-disabled js-switch-disabled').removeClass('switch-enabled js-switch-enabled'); 11893 11894 } 11895 11896 }); 11897 11898 11899 /* Show/Hide File Deletion Confirmation */ 11900 $(".js-file_delete_link").click(function() {
11901 $(this).closest(".js-edit_folder_modal, .js-edit_file_modal").find(".js-edit_confirm_delete").slideDown(300); 11902 $(this).fadeOut("300"); 11903 }); 11904 $(".js-cancel_file_delete_link").click(function() { 11905 $(this).closest(".js-edit_confirm_delete").slideUp(300); 11906 $(this).closest(".js-edit_folder_modal, .js-edit_file_modal").find(".js-file_delete_link").fadeIn(300); 11907 }); 11908 11909 /* Show/Hide Target File Deletion Confirmation */ 11910 $(".js-target_file_delete_link").click(function() { 11911 $(this).parent().parent().siblings(".js-edit_confirm_delete").slideDown(300); 11912 }); 11913 11914 /* Show/Hide Leave Group Confirmation */ 11915 $(".js-leave_group_button").click(function() { 11916 $(this).siblings(".js-leave_group_confirm").slideDown(150); 11917 }); 11918 $(".js-cancel_leave_group").click(function() { 11919 $(this).closest(".js-leave_group_confirm").slideUp(150); 11920 }); 11921 11922 /* Show/Hide Remove User From Group */ 11923 $('body').on('click', ".js-group_member_option", function() { 11924 if (!$(this).hasClass('disabled')) { 11925 //$(this).fadeOut(250); 11926 $(this).siblings(".js-group_member_option_confirm").delay(250).fadeIn(250).css('display','flex'); 11927 } 11928 }); 11929 $('body').on('click', ".js-group_member_option_cancel", function() { 11930 $(this).parent(".js-group_member_option_confirm").fadeOut(250); 11931 $(this).parent().siblings(".js-group_member_option").delay(250).fadeIn(250); 11932 }); 11933 11934 /* Show and hide pending member descriptions */ 11935 $('body').on('click', ".js-group_member_pending_desc_link", function() { 11936 //$(this).fadeOut(250); 11937 if ($(this).parent().siblings(".js-group_member_pending_desc").css('display') == 'none') { 11938 $(this).parent().siblings(".js-group_member_pending_desc").delay(250).fadeIn(250).css('display','block'); 11939 } else { 11940 $(this).parent().siblings(".js-group_member_pending_desc").delay(250).fadeOut(250); 11941 } 11942 }); 11943 $('body').on('click', ".js-group_member_option_cancel", function() { 11944 $(this).parent(".js-group_member_option_confirm").fadeOut(250); 11945 $(this).parent().siblings(".js-group_member_option").delay(250).fadeIn(250); 11946 }); 11947 11948 /* Show/Hide event campaign location */ 11949 // if ($('.js-event_location_custom_link').length && $('input.js-event-location').val() == '' && $('input.js-event-address').val() == '' && $('input.js-event-city').val() == '' && $('input.js-event-zip').val() == '' && $('select.js-event-state').val() == '' && $('select.js-event-province').val() == '' ) { 11950 // $('.js-event-state, .js-event-province').not('.hasCustomSelect').customSelect({customClass:"can_select"}); 11951 // $('.js-event_location').addClass('hide'); 11952 // } 11953 11954 // $(".js-event_location_custom_link").click(function() { 11955 // $(this).parent().parent().siblings(".js-event_location").slideDown(250); 11956 // $(this).parent().siblings(".js-suggested_modal_link_wrap").delay(350).slideUp(500); 11957 // $(this).fadeOut(250); 11958 // $(this).siblings(".js-event_location_suggested_link").delay(250).fadeIn(250); 11959 // }); 11960 11961 // $(".js-event_location_suggested_link").click(function() { 11962 // $(this).parent().parent().siblings(".js-event_location").slideUp(250); 11963 // $(this).parent().siblings(".js-suggested_modal_link_wrap").delay(350).slideDown(500); 11964 // $(this).fadeOut(250); 11965 // $(this).siblings(".js-event_location_custom_link").delay(250).fadeIn(250); 11966 // }); 11967 11968 /* Show/Hide Remove Events from Campaign */ 11969 // now in remove_event_confirm_controller.js 11970 // $(".js-remove_event_option").click(function() { 11971 // $(this).siblings(".js-remove_event_option_confirm").delay(250).fadeIn(250); 11972 // }); 11973 // $(".js-remove_event_option_cancel").click(function() { 11974 // $(this).parent(".js-remove_event_option_confirm").fadeOut(250); 11975 // }); 11976 11977 //event campaign one click rsvp 11978 if ($('.js-one_click_label').find('input').is(':checked')) { 11979 $('.js-one_click_warning').show(); 11980 } 11981 11982 $('.js-one_click_label').change(function() { 11983 //console.log($(this).find('input').is(':checked')); 11984 if ($(this).find('input').is(':checked')) { 11985 $('.js-one_click_warning').slideDown(); 11986 } else { 11987 $('.js-one_click_warning').hide(); 11988 11989 } 11990 11991 }); 11992 11993 //event campaign show map placeholder on step 1 AN-2105 11994 if ($('.js-show_map_placeholder').find('input').is(':checked')) { 11995 $('.js-event_map_wrap_placeholder').show(); 11996 } 11997 11998 $('.js-show_map_placeholder').change(function() { 11999 if ($(this).find('input').is(':checked')) { 12000 $('.js-event_map_wrap_placeholder').slideDown(); 12001 } else { 12002 $('.js-event_map_wrap_placeholder').hide(); 12003 12004 } 12005 12006 }); 12007 12008 function onRSVPAjax(form, buttonEl, onCompleteRsvp) { 12009 $.ajax({ 12010 type: "POST", 12011 url: form.attr('action'), 12012 data: form.serialize(), 12013 dataType: 'json', 12014 success: function(data) { 12015 if (data.error == "full") { 12016 buttonEl.removeClass('disabled'); 12017 } else { 12018 onCompleteRsvp(); 12019 } 12020 }, 12021 error: function(jqXHR, textStatus, errorThrown) { 12022 // console.log(jqXHR); 12023 // console.log(textStatus); 12024 // console.log(errorThrown); 12025 buttonEl.removeClass('disabled'); 12026 } 12027 }); 12028 } 12029 12030 function onRSVP(e) { 12031 const buttonEl = $(e.currentTarget);
12032 const form = buttonEl.parents('.js-rsvp_form'); 12033 //buttonEl.off('click', onRSVP); 12034 // Fade out button background 12035 buttonEl.addClass('disabled'); 12036 12037 function onCompleteRsvp() { 12038 buttonEl.addClass('success'); 12039 buttonEl.parent('.js-rsvp_container') 12040 .find('.js-rsvp_success') 12041 .removeClass('hide'); 12042 } 12043 12044 onRSVPAjax(form, buttonEl, onCompleteRsvp); 12045 12046 return false; 12047 }; 12048 $('.js-single_event_campaign_result .js-rsvp_button').on('click', onRSVP); 12049 12050 // map RSVP button 12051 function onMapRSVP(e) { 12052 const buttonEl = $(e.currentTarget); 12053 const form = buttonEl.parents('.js-rsvp_form'); 12054 //buttonEl.off('click', onMapRSVP); 12055 // Fade out button background 12056 buttonEl.addClass('disabled'); 12057 12058 function onCompleteRsvp() { 12059 buttonEl.addClass('success'); 12060 $('#map-notice-content').find('.js-rsvp_success').removeClass('hide'); 12061 } 12062 12063 onRSVPAjax(form, buttonEl, onCompleteRsvp); 12064 12065 return false; 12066 }; 12067 $('body').on('click', '#map-notice-content .js-rsvp_button', onMapRSVP); 12068 12069 $('body').on('click', '#map-notice-content .js-expand-on-click', function (e) { 12070 e.preventDefault(); 12071 $(e.currentTarget).addClass('expanded'); 12072 }); 12073 $('body').on('click', '#map-notice-content .js-disclaimer-trigger', function () { 12074 $('#map-notice-content .js-disclaimer-full').slideToggle(); 12075 }); 12076 12077 12078 // Advanced Event Campaign Search 12079 if ($('.js-start_date_threshold').val() != '' || $('.js-end_date_threshold').val() != '' || $('.js-virtual_only').is(':checked')) { 12080 $(".js-event_campaign_list_filters-show").hide(); 12081 $(".js-event_campaign_list_filters-show").siblings(".js-event_campaign_list_filters-hide").show(); 12082 $(".js-event_campaign_list_filters-show").parent().parent().siblings(".js-event_campaign_list_filters").show(); 12083 } 12084 12085 $(".js-event_campaign_list_filters-show").click(function() { 12086 $(this).hide(); 12087 $(this).siblings(".js-event_campaign_list_filters-hide").show(); 12088 $(this).parent().parent().siblings(".js-event_campaign_list_filters").slideDown(500); 12089 }); 12090 12091 $(".js-event_campaign_list_filters-hide").click(function() { 12092 $(this).hide(); 12093 $(this).siblings(".js-event_campaign_list_filters-show").show(); 12094 $(this).parent().parent().siblings(".js-event_campaign_list_filters").slideUp(250); 12095 }); 12096 12097 if ($('.js-start_date_threshold').val() == '' && $('.js-end_date_threshold').val() == '') { 12098 $('.js-start_date_threshold, .js-end_date_threshold').removeClass('required error_input'); 12099 } else { 12100 $('.js-start_date_threshold, .js-end_date_threshold').addClass('required'); 12101 } 12102 12103 $('.js-start_date_threshold, .js-end_date_threshold').on('change', function() { 12104 if ($('.js-start_date_threshold').val() == '' && $('.js-end_date_threshold').val() == '') { 12105 $('.js-start_date_threshold, .js-end_date_threshold').removeClass('required error_input'); 12106 } else { 12107 $('.js-start_date_threshold, .js-end_date_threshold').addClass('required'); 12108 } 12109 }); 12110 12111 $('.js-quick_date--today').click(function() { 12112 var today = new Date(); 12113 $('.js-start_date_threshold, .js-end_date_threshold').val(today.toLocaleDateString()); 12114 }); 12115 12116 $('.js-quick_date--tomorrow').click(function() { 12117 var today = new Date(); 12118 var tomorrow = new Date(today); 12119 tomorrow.setDate(tomorrow.getDate() + 1); 12120 var tomorrow_formatted = new Date(tomorrow).toLocaleDateString(); 12121 $('.js-start_date_threshold, .js-end_date_threshold').val(tomorrow_formatted); 12122 }); 12123 12124 $('.js-quick_date--weekend').click(function() { 12125 function nextDay(d, dow){ 12126 d.setDate(d.getDate() + (dow+(7-d.getDay())) % 7); 12127 return d; 12128 } 12129 var today = new Date(); 12130 var weekend_start = new Date(today); 12131 nextDay(weekend_start, 6); 12132 var weekend_start_formatted = new Date(weekend_start).toLocaleDateString(); 12133 $('.js-start_date_threshold').val(weekend_start_formatted); 12134 12135 var weekend_end = new Date(today); 12136 nextDay(weekend_end, 0); 12137 var weekend_end_formatted = new Date(weekend_end).toLocaleDateString(); 12138 $('.js-end_date_threshold').val(weekend_end_formatted); 12139 }); 12140 12141 12142 12143 /* Show/Hide Remove Sponsor */ 12144 $(".js-remove_sponsor_option").click(function() { 12145 //$(this).fadeOut(250); 12146 $(this).siblings(".js-remove_sponsor_option_confirm").delay(250).fadeIn(250); 12147 }); 12148 $(".js-remove_sponsor_option_cancel").click(function() { 12149 $(this).parent(".js-remove_sponsor_option_confirm").fadeOut(250); 12150 //$(this).parent().siblings(".js-remove_sponsor_option").delay(250).fadeIn(250); 12151 }); 12152 12153 /* Show/Hide Remove Events from Campaign */ 12154 $(".js-delete_locations_wrap a").click(function() {
12155 $(this).parent(".js-delete_locations_wrap").slideUp(350); 12156 $(this).parent(".js-delete_locations_wrap").siblings(".js-delete_locations_confirm_wrap").delay(350).slideDown(350); 12157 }); 12158 $(".js-delete_locations_cancel").click(function() { 12159 $(this).parent(".js-delete_locations_confirm_wrap").slideUp(350); 12160 $(this).parent(".js-delete_locations_confirm_wrap").siblings(".js-delete_locations_wrap").delay(350).slideDown(350); 12161 }); 12162 12163 /* event campaign code. i don't know if this is used anymore... */ 12164 suggested_location_list = '<ul class="lined js-lined">' 12165 + '<li>' 12166 + '<strong class="block location js-location">' + an_javascript_translation.my_house + '</strong>' 12167 + '<span class="block address js-address">1806 Belmont Rd. NW</span>' 12168 + '<span class="block city_state_zip js-city_state_zip"><span class="city js-city">Washington</span>, <span class="state js-state" data-state-long="District of Columbia">DC</span> <span class="zip js-zip">20009</span></span>' 12169 + '<a href="javascript:;" onclick="$.fancybox.close();" class="button choose_location_button js-choose_location_button">' + an_javascript_translation.select + '</a>' 12170 + '</li>' 12171 + '<li>' 12172 + '<strong class="block location js-location">The White House</strong>' 12173 + '<span class="block address js-address">1600 Pennsylvania Ave. NW</span>' 12174 + '<span class="block city_state_zip js-city_state_zip"><span class="city js-city">Washington</span>, <span class="state js-state" data-state-long="District of Columbia">DC</span> <span class="zip js-zip">20001</span></span>' 12175 + '<a href="javascript:;" onclick="$.fancybox.close();" class="button choose_location_button js-choose_location_button">' + an_javascript_translation.select + '</a>' 12176 + '</li>' 12177 + '</ul>'; 12178 12179 location_search_validate = false; 12180 12181 $('.js-location_search').click(function() { 12182 location_search_validate = true; 12183 console.log('hello'); 12184 if ($('.js-host_campaign_zip_search').val() != '' && $(this).parent().find('select.js-form-country').val() != '') { 12185 $('.js-host_campaign_zip_search').removeClass('error_input'); 12186 $(this).parent().find('span.js-form-country').removeClass('error_input'); 12187 $('.js-suggested_location_list').html('<div class="height-hundred flex_horz flex_vert">' + an_javascript_translation.loading + '</div>'); 12188 $.get($('.js-host_campaign_url').val() + '?zipcode=' + $('.js-host_campaign_zip_search').val() + '&country=' + $('.js-suggested_modal .js-country_drop_wrap select').val(), function(data) { 12189 12190 if (data != '<ul class="lined js-lined">\n</ul>') { 12191 $('.js-suggested_location_list').html(data); 12192 choose_location_click(); 12193 } else { 12194 $('.js-suggested_location_list').html('<div class="height-hundred flex_horz flex_vert">' + an_javascript_translation.no_locations_were_found_near_you + '</div>'); 12195 } 12196 12197 }) 12198 .fail(function() { 12199 $('.js-suggested_location_list').html('<div class="height-hundred flex_horz flex_vert">' + an_javascript_translation.an_error_occurred_please_try_again + '</div>'); 12200 }); 12201 } else { 12202 $('.js-host_campaign_zip_search').removeClass('error_input'); 12203 $(this).parent().find('span.js-form-country').removeClass('error_input'); 12204 12205 if ($('.js-host_campaign_zip_search').val() == '') { 12206 $('.js-host_campaign_zip_search').addClass('error_input'); 12207 } 12208 12209 if ($(this).parent().find('select.js-form-country').val() == '') { 12210 $(this).parent().find('span.js-form-country').addClass('error_input'); 12211 } 12212 12213 } 12214 12215 }); 12216 12217 $('.js-host_campaign_zip_search').on('keyup', function() { 12218 if (location_search_validate) { 12219 if ($('.js-host_campaign_zip_search').val() != '') { 12220 $('.js-host_campaign_zip_search').removeClass('error_input'); 12221 } else { 12222 $('.js-host_campaign_zip_search').addClass('error_input'); 12223 } 12224 } 12225 }); 12226 12227 var choose_location_click = function() { 12228 console.warn('this code has been deprecated..'); 12229 return; 12230 $('.js-choose_location_button').click(function() { 12231 $('.js-event-location').val($(this).siblings('.js-location').html()); 12232 $('.js-event-address').val($(this).siblings('.js-address').html()); 12233 $('.js-event-city').val($(this).siblings('.js-city_state_zip').children('.js-city').html()); 12234 $('select.js-event-state').val($(this).siblings('.js-city_state_zip').children('.js-state').html()); 12235 $('select.js-event-province').val($(this).siblings('.js-city_state_zip').children('.js-state').html()); 12236 $('.js-create-event-state-drop_down .can_selectInner').html( 12237 $(this).siblings('.js-city_state_zip').children('.js-state').data('state-long') 12238 ); 12239 12240 $('.js-form-country').val( 12241 $(this).siblings('.js-city_state_zip').children('.js-country').data('country-short') 12242 ); 12243 12244 if ($(this).siblings('.js-city_state_zip').children('.js-country').data('country-short') == 'US') { 12245 $('.js-create-event-state-drop_down, .js-event-state-select-wrap').show(); 12246 $('.js-event-state').show().attr('disabled', false).addClass('required'); 12247 $('.js-event-province').hide().attr('disabled', 'disabled').removeClass('required'); 12248 } else if ($(this).siblings('.js-city_state_zip').children('.js-country').data('country-short') == 'CA') { 12249 $('.js-event-state').hide().attr('disabled', 'disabled').removeClass('required'); 12250 $('.js-event-province').show().attr('disabled', false).addClass('required'); 12251 $('.js-create-event-state-drop_down, .js-event-state-select-wrap').show(); 12252 } else { 12253 $('.js-event-state-select-wrap, .js-create-event-state-drop_down').hide(); 12254 $('.js-event-state, .js-event-province').hide().attr('disabled', 'disabled').removeClass('required'); 12255 } 12256 12257 $('.js-country_drop_wrap .can_selectInner').html( 12258 $(this).siblings('.js-city_state_zip').children('.js-country').html() 12259 ); 12260 12261 $('.js-event-zip').val( 12262 $(this).siblings('.js-city_state_zip').children('.js-zip').html() 12263 )[0].dispatchEvent(new Event('input')); 12264 12265 // $(".js-event_location").slideDown(250); 12266 // $(".js-suggested_modal_link_wrap").delay(350).slideUp(500); 12267 // $('.js-event_location_custom_link').delay(700).fadeOut(250); 12268 // $(".js-event_location_suggested_link").delay(950).fadeIn(250); 12269 12270 var that = this; 12271 $.post( 12272 $('.js-location_select_url').val() + '?location_id=' + $(that).parent().attr('id'), 12273 function(data) {} 12274 ); 12275 }); 12276 } 12277 12278 12279 /* File drag/drop */ 12280 if ($('.js-admin_can_reorder').length) { 12281 if ($.isFunction($.fn.sortable) ) { 12282 //mouseX = false;
12283 12284 $(document).on('mousemove', function(e) { 12285 //console.log(e.pageY); 12286 mouseY = e.pageY; 12287 mouseX = e.pageX; 12288 12289 //mouseX = e.pageX - mouseXclick; 12290 }); 12291 12292 12293 var oldContainer; 12294 var group = $(".js-admin_can_reorder ul.js-nested").sortable({ 12295 //group: 'file_browser_reorder', 12296 handle: '.js-file_reorder', 12297 12298 onDrag: function ($item, position, _super) { 12299 //console.log($item); 12300 position.top = mouseY - 153; 12301 position.left = mouseX - mouseXorig; 12302 //position.left = mouseX; 12303 //console.log(position); 12304 $item.css(position); 12305 12306 if ($('.js-admin_can_reorder ul').children().first().attr('class') == 'placeholder' && $('.js-level_up').length) { 12307 $('.js-admin_can_reorder ul li.placeholder').css('display','none'); 12308 } else { 12309 $('.js-admin_can_reorder ul li.placeholder').css('display','block'); 12310 } 12311 }, 12312 12313 // Called after the drag has been started, 12314 // that is the mouse button is beeing held down and 12315 // the mouse is moving. 12316 // The container is the closest initialized container. 12317 // Therefore it might not be the container, that actually contains the item. 12318 onDragStart: function ($item, container, _super) { 12319 $item.css({ 12320 height: $item.height(), 12321 width: $item.width() 12322 }) 12323 12324 $item.addClass("dragged") 12325 $("body").addClass("dragging") 12326 }, 12327 12328 onDrop: function ($item, container, _super) { 12329 //console.log($(container).attr('id')); 12330 $item.removeClass("dragged").removeAttr("style"); 12331 $("body").removeClass("dragging"); 12332 12333 //if ($('.admin_can_reorder ul.nested li').first().attr('class') == 'level_up') { 12334 12335 12336 file_reorder_list = []; 12337 $('.js-admin_can_reorder ul.js-nested li:not(.js-admin_can_reorder ul.js-nested li ul li)').each(function(){ 12338 var list_id = {}; 12339 list_id.id = $(this).attr('id'); 12340 12341 list_id.sublist = []; 12342 $(this).find('ul li').each(function(){ 12343 var sublist = {}; 12344 sublist.id = $(this).attr('id'); 12345 list_id.sublist.push(sublist); 12346 $(this).remove(); 12347 }); 12348 12349 file_reorder_list.push(list_id); 12350 }); 12351 //} 12352 12353 //post via ajax to set the drag/drop ordering... 12354 var url = "/groups/"; 12355 url += $(".js-user_path").val()+"/files/"; 12356 url += $(".js-folder_id").val()+"/arrange"; 12357 $.post(url, { new_order: file_reorder_list } ); 12358 12359 }, 12360 12361 afterMove: function (placeholder, container) { 12362 //if ($('.admin_can_reorder ul.nested li').first().attr('class') == 'level_up') { 12363 if(oldContainer != container){ 12364 if(oldContainer) 12365 oldContainer.el.removeClass("active") 12366 container.el.addClass("active") 12367 12368 oldContainer = container 12369 } 12370 //} 12371 }, 12372 12373 onMousedown: function($item, event, _super) { 12374 //console.log('mousedown'); 12375 //if (mouseX == false) { 12376 mouseXorig = event.pageX; 12377 //console.log(mouseX); 12378 //} 12379 event.preventDefault() 12380 }, 12381 12382 }); 12383 12384 12385 12386 /* 12387 $(".admin_can_reorder ul.nested .level_up").sortable({ 12388 group: 'no-drop', 12389 drop: false 12390 }) 12391 */ 12392 } 12393 12394 } 12395 12396 12397 $('.js-group_quick_switch_loading').not('.disabled').on("select2-open", function() { 12398 //console.log(this); 12399 var $that = $(this); 12400 var $that_parent = $that.parent(); 12401 $('.select2-drop-active').hide(); 12402 $that.select2('enable',false); 12403 $that_parent.find('.select2-chosen').html("[" + an_javascript_translation.loading + "...]"); 12404 $.get('/groups/select?mode=manage', function(data) { 12405 selectmenu = data; 12406 $that_parent.html(data); 12407 //console.log($that_parent); 12408 $that_parent.find('select.js-group_quick_switch').select2({ 12409 dropdownCssClass: "select2-dropdown-group_quick_switch", 12410 matcher: function (term, text, option) { 12411 if (term.length == 0) return true; 12412 12413 if(term.split(" ").length == 1){ 12414 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 12415 } 12416 12417 keywords=(term).split(/ |,|\[|\]|\(|\)/); 12418 // `data.text` is the text that is displayed for the data object 12419 // check if data.text contains all of keywords, if some is missing, return null 12420 for (var i = 0; i < keywords.length; i++) { 12421 12422 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 12423 // Return `null` if the term should not be displayed 12424 return null; 12425 12426 } 12427 // If here, data.text contains all keywords, so return it. 12428 return text; 12429 } 12430 }).select2('open'); 12431 }) 12432 .fail(function() { 12433 //change 12434 $that.find('.select2-chosen').html(an_javascript_translation.an_error_occurred); 12435 }); 12436 }); 12437 12438 12439 /* file and action and user menu dropdown switcher */ 12440 $('body').on('change', 'select.js-file-file_repository_switcher, select.js-targets-target_repository_switcher', function() { 12441 var url = $(this).val(); // get selected value 12442 if (url != '') { // require a URL 12443 window.location = url; // redirect 12444 } 12445 return false;
12446 }); 12447 12448 $('.js-menu_create_action-mobile select').on('change', function() { 12449 var url = $(this).val(); // get selected value 12450 if (url != '') { // require a URL 12451 window.location = url; // redirect 12452 } 12453 return false; 12454 }); 12455 12456 $('.js-user_menu-user-mobile select').on('change', function() { 12457 var url = $(this).val(); // get selected value 12458 if (url != '') { // require a URL 12459 window.location = url; // redirect 12460 } 12461 return false; 12462 }); 12463 12464 12465 12466 /* Custom Form HTML */ 12467 $(".js-add_custom_form_html").click(function(e) { 12468 e.preventDefault(); 12469 $(".js-custom_form_html").slideDown(200); 12470 $(".js-add_custom_form_html-close").show().css("display", "inline-block"); 12471 $(".js-add_custom_form_html").hide(); 12472 }); 12473 12474 // $(".js-add_custom_form_html-close").click(function() { 12475 // $(".js-custom_form_html").slideUp(200); 12476 // $(".js-add_custom_form_html").show(); 12477 // $(".js-add_custom_form_html-close").hide(); 12478 // }); 12479 12480 12481 12482 function init_codemirror(textarea) { 12483 //console.log(textarea); 12484 if ($(textarea).hasClass('js-html-textarea')) { 12485 const cm = CodeMirror.fromTextArea(textarea, { 12486 lineNumbers: true, 12487 mode: 'htmlmixedliquid', 12488 indentUnit: 4, 12489 lineWrapping: true, 12490 viewportMargin: Infinity 12491 }); 12492 const $parent = $(textarea).closest('.js-html_textarea_wrap') 12493 const $insertBtn = $parent.find('.js-insert_clip_modal'); 12494 12495 $insertBtn.fancybox({ 12496 onComplete: function() { 12497 $('body').addClass('body_has_modal'); 12498 }, 12499 onClosed: function() { 12500 $('body').removeClass('body_has_modal'); 12501 }, 12502 margin: 15, 12503 hideOnOverlayClick: false 12504 }); 12505 $parent.find('.js-codemirror-clip_link').click(function (e) { 12506 e.preventDefault(); 12507 var textInsert = $(this).parent().find('.js-codemirror-clip').text(); 12508 cm.doc.replaceSelection(textInsert.trim()); 12509 $.fancybox.close(); 12510 }); 12511 12512 setInterval(function () { 12513 cm.save(); 12514 }, 100) 12515 } 12516 12517 if ($(textarea).hasClass('js-sql-textarea')) { 12518 const cm = CodeMirror.fromTextArea(textarea, { 12519 lineNumbers: false, 12520 mode: 'text/x-sql', 12521 // indentUnit: 4, 12522 lineWrapping: true, 12523 // viewportMargin: Infinity, 12524 readOnly: true, 12525 }); 12526 const checkForVisibleInterval = setInterval(()=> { 12527 if ($(textarea).parent().is(":visible")) { 12528 cm.refresh(); 12529 clearInterval(checkForVisibleInterval); 12530 } 12531 }, 500); 12532 }; 12533 12534 if ($(textarea).hasClass('js-mobile-codemirror-textarea')) { 12535 const cm = CodeMirror.fromTextArea(textarea, { 12536 lineNumbers: false, 12537 mode: 'htmlmixedliquid', 12538 indentUnit: 4, 12539 lineWrapping: true, 12540 viewportMargin: Infinity 12541 }); 12542 12543 var context = {}; 12544 var scope = {}; 12545 $('.js-codemirror-clip').each(function() { 12546 //console.log($(this).data('dropkiq-context')); 12547 //console.log($(this).data('dropkiq-scope')); 12548 $.extend(context, $(this).data('dropkiq-context')); 12549 $.extend(scope, $(this).data('dropkiq-scope')); 12550 }); 12551 //console.log(context); 12552 //console.log(scope); 12553 12554 //console.log($(that).find('.js-mobile_message_body').last()); 12555 var options = {}; 12556 if (typeof(window.DropkiqUI) != "undefined") { 12557 var dropkiqUI = new window.DropkiqUI(cm, {}, context, scope, "4fee6b50-29d5-0138-0a6d-4a36325215e0", options); 12558 dropkiqUI.registerFilter('no_profanity', function(){ 12559 return $('.js-dropkiq-no_profanity').data('dropkiq-no_profanity') 12560 }, "no_profanity", [], an_javascript_translation.output_blank_if_text_matches_profanity_list); 12561 dropkiqUI.registerFilter('title_case', function(){ 12562 return $('.js-dropkiq-titlecase').data('dropkiq-titlecase') 12563 }, "title_case", [], an_javascript_translation.output_string_with_first_letters_capitalized); 12564 dropkiqUI.registerFilter('us_state_full', function(){ 12565 return $('.js-dropkiq-us_state_full').data('dropkiq-us_state_full') 12566 }, "us_state_full", [], an_javascript_translation.only_output_a_state_full_name_if_the_value); 12567 } 12568 12569 setInterval(function () { 12570 cm.save(); 12571 $(textarea).trigger('change'); 12572 }, 100); 12573 }; 12574 } 12575 12576 if ($('.js-mobile_message_body').length) { 12577 $(".js-mobile_message_body").each(function() { 12578 $(this).charCount({ 12579 allowed: 160, 12580 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 12581 wrapperSelector: '.js-sms_body_textarea', 12582 hostname: $('.js-mobile_custom_shortlink').val(), 12583 regex: "url_strict" 12584 }); 12585 12586 var context = {}; 12587 var scope = {}; 12588
12589 $('.js-redactor_clip').each(function() { 12590 //console.log($(this).data('dropkiq-context')); 12591 //console.log($(this).data('dropkiq-scope')); 12592 $.extend(context, $(this).data('dropkiq-context')); 12593 $.extend(scope, $(this).data('dropkiq-scope')); 12594 }); 12595 //console.log(context); 12596 //console.log(scope); 12597 12598 12599 var textArea = this; 12600 //console.log(this); 12601 var options = {}; 12602 if (typeof(window.DropkiqUI) != "undefined") { 12603 var dropkiqUI = new window.DropkiqUI(textArea, {}, context, scope, "4fee6b50-29d5-0138-0a6d-4a36325215e0", options); 12604 dropkiqUI.registerFilter('no_profanity', function(){ 12605 return $('.js-dropkiq-no_profanity').data('dropkiq-no_profanity') 12606 }, "no_profanity", [], an_javascript_translation.output_blank_if_text_matches_profanity_list); 12607 dropkiqUI.registerFilter('title_case', function(){ 12608 return $('.js-dropkiq-titlecase').data('dropkiq-titlecase') 12609 }, "title_case", [], an_javascript_translation.output_string_with_first_letters_capitalized); 12610 dropkiqUI.registerFilter('us_state_full', function(){ 12611 return $('.js-dropkiq-us_state_full').data('dropkiq-us_state_full') 12612 }, "us_state_full", [], an_javascript_translation.only_output_a_state_full_name_if_the_value); 12613 } 12614 }); 12615 } 12616 12617 /* Disclaimer HTML */ 12618 $(".js-add_disclaimer_text").click(function() { 12619 $(".js-disclaimer_create").slideDown(200); 12620 $(".js-add_disclaimer_text-close").show(); 12621 $(".js-add_disclaimer_text").hide(); 12622 }); 12623 $(".js-add_disclaimer_text-close").click(function() { 12624 $(".js-disclaimer_create").slideUp(200); 12625 $(".js-add_disclaimer_text").show(); 12626 $(".js-add_disclaimer_text-close").hide(); 12627 }); 12628 12629 $('textarea.js-html-textarea, textarea.js-sql-textarea, textarea.js-mobile-codemirror-textarea').each(function () { 12630 init_codemirror(this); 12631 }); 12632 12633 /* pop the save box up */ 12634 //$(".js-create_action_toolbox-old").animate({bottom:0},1500); 12635 $('.js-create_action_toolbox').scrollToFixed( { 12636 bottom: 0, 12637 limit: function() { 12638 form = $('.js-create_action_toolbox').parents('form') 12639 if(form.length == 0){form = $("#create_email2_form, .js-edit_email_wrapper")} 12640 if (form.height() > 200) { 12641 return $('.js-create_action_toolbox').prev().offset().top + $('.js-create_action_toolbox').prev().height() 12642 } else { 12643 if ($('.js-create_action_toolbox').parents('form').prev().length == 0) { 12644 return 0; 12645 } 12646 return form.prev().offset().top + $('.js-create_action_toolbox').parents('form').prev().height() 12647 } 12648 }, 12649 minWidth: 1024 12650 }); 12651 12652 $('.js-targeting_header').scrollToFixed( { 12653 limit: function() { 12654 return $('.js-targeting_body').offset().top + $('.js-targeting_body').height(); 12655 }, 12656 minWidth: 768, 12657 preAbsolute: function() { $(this).addClass('notop-important'); }, 12658 postAbsolute: function() { $(this).removeClass('notop-important'); }, 12659 zIndex: 5 12660 }); 12661 //$(".js-create_action_toolbox").sticky({bottomSpacing: $('.js-site_footer').height()}); 12662 12663 /* remove the customSelectChanged class if a state isn't selected */ 12664 $('.js-event-state-select-wrap select.js-event-state, .js-event-state-select-wrap select.js-event-province').change(function() { 12665 var selectedState = $('.js-create-event-state-drop_down .can_selectInner').text(); 12666 if (selectedState == "State *") { 12667 $(".js-create-event-state-drop_down > span").removeClass("customSelectChanged"); 12668 } 12669 }); 12670 12671 /* show country drop down */ 12672 $('.js-country_drop_wrap select').each(function() { 12673 12674 if (!$(this).parents().hasClass('can_embed')) { 12675 //$(this).val('GB'); 12676 detected_country = $(this).val(); 12677 if (typeof(detected_country) == 'undefined' || detected_country == '') { 12678 detected_country = 'US'; 12679 } 12680 12681 if ($('.js-event-province').length) { 12682 12683 if (!$(this).hasClass('js-country_suggested_locations') ) { 12684 12685 detected_country = $(this).val(); 12686 12687 12688 if (!$('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').hasClass('hasCustomSelect')) { 12689 $('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').customSelect({customClass:"can_select"}); 12690 } 12691 if (detected_country == 'CA') { 12692 $(this).parents('.js-city_state_zip').find('.js-event-province, .js-event-state-select-wrap').show(); 12693 $(this).parents('.js-city_state_zip').find('select.js-event-province').attr('disabled', false); 12694 if (!$('.js-event_physical_location_toggle-enabled').length) { 12695 $(this).parents('.js-city_state_zip').find('select.js-event-province').addClass('required'); 12696 } 12697 12698 $(this).parents('.js-city_state_zip').find('.js-event-state').hide(); 12699 $(this).parents('.js-city_state_zip').find('select.js-event-state').attr('disabled', 'disabled'); 12700 if (!$('.js-event_physical_location_toggle-enabled').length) { 12701 $(this).parents('.js-city_state_zip').find('select.js-event-state').removeClass('required'); 12702 } 12703 } else if (detected_country == 'US') { 12704 $(this).parents('.js-city_state_zip').find('.js-event-province').hide(); 12705 $(this).parents('.js-city_state_zip').find('select.js-event-province').attr('disabled', 'disabled'); 12706 if (!$('.js-event_physical_location_toggle-enabled').length) { 12707 $(this).parents('.js-city_state_zip').find('select.js-event-province').removeClass('required'); 12708 } 12709 12710 $(this).parents('.js-city_state_zip').find('.js-event-state, .js-event-state-select-wrap').show(); 12711 $(this).parents('.js-city_state_zip').find('select.js-event-state').attr('disabled', false); 12712 if (!$('.js-event_physical_location_toggle-enabled').length) { 12713 $(this).parents('.js-city_state_zip').find('select.js-event-state').addClass('required'); 12714 } 12715 } else { 12716 $(this).parents('.js-city_state_zip').find('.js-event-province, .js-event-state, .js-event-state-select-wrap').hide(); 12717 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 12718 $(this).parents('.js-city_state_zip').find('select.js-event-province, select.js-event-state').attr('disabled', 'disabled').removeClass('required'); 12719 } 12720 } 12721 } 12722 12723 12724 } else if (detected_country != 'US' && $('.js-donate_form, .js-event_end_date, .js-single_include_exclude_section, .js-user-state-drop_down, .js-profile-form-country, .js-buy_tickets_form').length) { 12725 if (!$('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').hasClass('hasCustomSelect')) { 12726 $('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').customSelect({customClass:"can_select"}); 12727 } 12728 12729 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').removeClass('required'); 12730 $('.js-cc_state_drop_wrap').hide(); 12731 if ($('.js-international_link').parent().parent().hasClass('js-col3of12')) { 12732 $('.js-international_link').parent(".js-international_link-wrap").toggle(); 12733 } else { 12734 $(this).parent().parent().parent().find(".js-international_link-wrap").toggle(); 12735 } 12736 $(this).parent().parent().parent().find(".js-create-event-state-drop_down, .js-user-state-drop_down").toggle(); 12737 $(this).parent().parent().parent().find('.js-country_drop_wrap').toggle().css('display','block'); 12738 $(this).parent().parent().parent().find('.js-country_drop_wrap select').addClass('required'); 12739 } else { 12740 $('.js-international_link_country').text(detected_country); 12741 } 12742 12743 /* hide zip code */ 12744 if ($(this).val() == 'IE' || $(this).val() == 'Ireland') { 12745 $('#form-zip_code').removeClass('required'); 12746 $('#form-zip_code').val(''); 12747 $('#form-zip_code').closest('li.core_field').hide(); 12748 } 12749 } 12750 }); 12751 12752 12753 $('.js-international_link:not(.disabled)').click(function() { 12754 if (!$(this).parents().hasClass('can_embed')) { 12755 $('.js-cc_state_drop_wrap').hide(); 12756 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').removeClass('required'); 12757 if ($(this).parent().parent().hasClass('js-col3of12')) { 12758 $(this).parent(".js-international_link-wrap").slideToggle(); 12759 } else { 12760 $(this).parent(".js-international_link-wrap").delay('500').slideToggle(); 12761 } 12762 $(this).parent().parent().find(".js-create-event-state-drop_down, .js-user-state-drop_down").slideToggle(); 12763 $(this).parent().parent().find('.js-country_drop_wrap').slideToggle().css('display','block'); 12764 $(this).parent().parent().find('.js-country_drop_wrap select').addClass('required'); 12765 } 12766 12767 }); 12768 12769 $('.js-country_drop_wrap select').on('change', function() { 12770 if (!$(this).parents().hasClass('can_embed')) { 12771 //if ($(this).val() == 'US' || $(this).val() == 'United States') { 12772 if (typeof(detected_country) == 'undefined' || detected_country == '') { 12773 detected_country = 'US'; 12774 } 12775 12776 // TODO: This is event form related validation that I need to remove 12777 // but it also operates on many other forms. 12778 if ($('.js-event-province').length) { 12779 console.log($(this)); 12780 if (!$(this).hasClass('js-country_suggested_locations')) { 12781 detected_country = $(this).val(); 12782 //console.log(detected_country); 12783 if ($(this).val() == 'CA') { 12784 $(this).parents('.js-city_state_zip').find('.js-event-province, .js-event-state-select-wrap').show(); 12785 $(this).parents('.js-city_state_zip').find('select.js-event-province').attr('disabled', false); 12786 if (!$('.js-event_physical_location_toggle-enabled').length) { 12787 $(this).parents('.js-city_state_zip').find('select.js-event-province').addClass('required'); 12788 } 12789 12790 $(this).parents('.js-city_state_zip').find('.js-event-state').hide(); 12791 $(this).parents('.js-city_state_zip').find('select.js-event-state').attr('disabled', 'disabled').removeClass('required'); 12792 } else if ($(this).val() == 'US') { 12793 $(this).parents('.js-city_state_zip').find('.js-event-province').hide(); 12794 $(this).parents('.js-city_state_zip').find('select.js-event-province').attr('disabled', 'disabled').removeClass('required'); 12795 12796 $(this).parents('.js-city_state_zip').find('.js-event-state, .js-event-state-select-wrap').show(); 12797 $(this).parents('.js-city_state_zip').find('select.js-event-state').attr('disabled', false); 12798 if (!$('.js-event_physical_location_toggle-enabled').length) { 12799 $(this).parents('.js-city_state_zip').find('select.js-event-state').addClass('required'); 12800 } 12801 12802 } else { 12803 $(this).parents('.js-city_state_zip').find('.js-event-province, .js-event-state, .js-event-state-select-wrap').hide(); 12804 $(this).parents('.js-city_state_zip').find('select.js-event-province, select.js-event-state').attr('disabled', 'disabled').removeClass('required'); 12805 } 12806 } 12807 12808 12809 } else if ($('.js-donate_form, .js-event_end_date, .js-single_include_exclude_section, .js-user-state-drop_down, .js-profile-form-country, .js-buy_tickets_form').length) { 12810 if ($(this).val() == 'US') { 12811 $(this).removeClass('required'); 12812 $(this).parent().parent().parent().find('.js-country_drop_wrap').hide(); 12813 12814 if (!$('.js-tab_comp').length) { 12815 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').addClass('required'); 12816 } 12817 12818 $('.js-cc_state_drop_wrap, .js-user-state-drop_down').slideToggle(); 12819 $(this).parent().parent().parent().find('.js-international_link-wrap').slideToggle(); 12820 $(".js-create-event-state-drop_down").slideToggle(); 12821 } 12822 } else { 12823 if ($(this).val() == detected_country) { 12824 $(this).removeClass('required'); 12825 $(this).parent().parent().parent().find('.js-country_drop_wrap').hide(); 12826 12827 if (!$('.js-tab_comp').length) { 12828 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').addClass('required'); 12829 } 12830 12831 $('.js-cc_state_drop_wrap, .js-user-state-drop_down').slideToggle(); 12832 $(this).parent().parent().parent().find('.js-international_link-wrap').slideToggle(); 12833 $(".js-create-event-state-drop_down").slideToggle(); 12834 } 12835 } 12836 12837 12838 /* toggle zip code */ 12839 if ($(this).val() == 'IE' || $(this).val() == 'Ireland') { 12840 $('#form-zip_code').removeClass('required'); 12841 $('#form-zip_code').val(''); 12842 $('#form-zip_code').closest('li.core_field').hide(); 12843 } else { 12844 $('#form-zip_code').addClass('required'); 12845 $('#form-zip_code').closest('li.core_field').show(); 12846 } 12847 } 12848 }); 12849 12850 12851 12852 /* Remove the label if it's empty */ 12853 $('.js-visual_form_target label.check_radio_label').each(function() { 12854 if ($(this).html() == '') { 12855 $(this).hide(); 12856 $(this).next().css('width','100%'); 12857 } 12858 }); 12859 12860 /* Fade in the includes/excludes */ 12861 if ($('select.js-email-email_list, input.js-email-email_list').val() != '') { 12862 $('.js-include_exclude_wrap').animate({opacity: 1}, 1000); 12863 } else { 12864 $('.js-include_exclude_wrap').animate({opacity: 0.3}, 1000); 12865 } 12866 12867 $('select.js-email-email_list').change(function() { 12868 if ($(this).val() != '') { 12869 $('.js-include_exclude_wrap').animate({opacity: 1}, 1000); 12870 } else { 12871 $('.js-include_exclude_wrap').animate({opacity: 0.3}, 1000); 12872 } 12873 }); 12874 12875 /* handle uuid csv parsing */ 12876 12877 $('body').on('change','.js-uuid_csv_file', function() { 12878 $(this).parent().find('.js-uuid_delete_link').show(); 12879 $(this).parent().find('.js-uuid_delete_link').siblings('.js-file_upload_icon').hide(); 12880 }); 12881 12882 uuid_delete_link_function = function($that) { 12883 $that.click(function() { 12884 $(this).hide(); 12885 $(this).siblings('.js-file_upload_icon').show(); 12886 $(this).parent().find('.js-uuid_csv_file').val(''); 12887 $(this).parent().find('.js-uuid_csv_file').siblings('.js-uploaded_file_name').html(an_javascript_translation.browse_file_or_drag_and_drop); 12888 }); 12889 } 12890 12891 $('.js-uuid_delete_link').each(function() { 12892 uuid_delete_link_function($(this)); 12893 }); 12894 12895 $('.js-uuid_input').each(function() { 12896 if ($(this).val() != '') { 12897 $(this).parents('.js-uuid_wrapper').find('.js-uuid_upload_wrapper').hide(); 12898 $(this).parents('.js-uuid_wrapper').find('.js-uuid_uploaded_wrapper').show(); 12899 $(this).parents('.js-uuid_wrapper').find('.js-uuids_count').text($(this).val().split(',')[1]); 12900 } 12901 }); 12902 12903 12904 12905 $('body').on('click', '.js-uuid_csv_parse', function() { 12906 var $that = $(this); 12907 if (!$that.hasClass('disabled')) { 12908 var fileInput = $that.parent().find('.js-uuid_csv_file')[0]; 12909 var url = $that.data('url'); 12910 var file = fileInput.files[0]; 12911 var formData = new FormData(); 12912 formData.append('file', file); 12913 12914 $that.addClass('disabled').attr('disabled','disabled').text(an_javascript_translation.loading); 12915 $that.parent().find('.js-upload_label_box').addClass('disabled'); 12916 $that.parent().find('.js-uuid_csv_file').addClass('disabled').attr('disabled','disabled'); 12917 $that.parent().find('.js-uuid_csv_file').addClass('disabled').attr('disabled','disabled'); 12918 $that.parent().find('.js-uuid_delete_link').addClass('disabled').attr('disabled','disabled').off('click'); 12919 12920 12921 $.ajax({ 12922 type: "POST", 12923 processData: false, 12924 contentType: false, 12925 url: url, 12926 data: formData, 12927 success: function(data) { 12928 if(data == null){ 12929 alert(an_javascript_translation.we_were_unable_to_read); 12930 }else{ 12931 $that.parents('.js-uuid_wrapper').find('.js-uuid_input').val(data.id + ',' + data.rows); 12932 $that.parent().find('.js-uuid_csv_file').val(""); 12933 $that.parent().slideUp(function() { 12934 $that.parent().siblings('.js-uuid_uploaded_wrapper').show(); 12935 targeting_set_filters(false); 12936 }); 12937 $that.parent().siblings('.js-uuid_uploaded_wrapper').find('.js-uuids_count').text(data.rows); 12938 } 12939 12940 12941 // console.log(result_array); 12942 //result_array.shift(); 12943 //var result = result_array.join(); 12944 // console.log(result); 12945 //$that.parent().find('.js-uuid_input').val(result); 12946 }, 12947 error: function() { 12948 12949 alert(an_javascript_translation.we_were_unable_to_read); 12950 }, 12951 complete: function() { 12952 $that.removeClass('disabled').attr('disabled',false).text(an_javascript_translation.load_file); 12953 $that.parent().find('.js-upload_label_box').removeClass('disabled'); 12954 $that.parent().find('.js-uuid_csv_file').removeClass('disabled').attr('disabled',false); 12955 $that.parent().find('.js-uuid_csv_file').removeClass('disabled').attr('disabled',false); 12956 $that.parent().find('.js-uuid_delete_link').removeClass('disabled').attr('disabled',false); 12957 uuid_delete_link_function($that.parent().find('.js-uuid_delete_link')); 12958 } 12959 }); 12960 } 12961 12962 }); 12963 12964 $('body').on('click', '.js-uuids_clear', function() { 12965 $(this).parents('.js-uuid_
12965uploaded_wrapper').slideUp(function() { 12966 $(this).parents('.js-uuid_wrapper').find('.js-uuid_upload_wrapper, .js-uuid_multi_select_wrapper').show(); 12967 targeting_set_filters(false); 12968 }); 12969 12970 $(this).parents('.js-uuid_wrapper').find('.js-uuid_input').val(''); 12971 $(this).parents('.js-uuid_wrapper').find('.js-uploaded_file_name').html(an_javascript_translation.browse_file_or_drag_and_drop); 12972 $(this).parents('.js-uuid_wrapper').find('.js-uuid_delete_link').hide(); 12973 $(this).parents('.js-uuid_wrapper').find('.js-uuid_delete_link').siblings('.js-file_upload_icon').show(); 12974 }); 12975 12976 /* Fade in the email wrapper -- this code no longer does anything */ 12977 if ($('#wrapper_select_id').length) { 12978 if ($('#wrapper_select_id').val() != 'default') { 12979 $('#email_wrapper').animate({opacity: 1}, 1000); 12980 $('.create_action-editable').attr('disabled', false ); 12981 } else { 12982 $('#email_wrapper').animate({opacity: 0.3}, 1000); 12983 $('.create_action-editable').attr('disabled', true ); 12984 } 12985 12986 $('#wrapper_select_id').change(function() { 12987 if ($(this).val() != 'default') { 12988 $('#email_wrapper').animate({opacity: 1}, 1000); 12989 $('.create_action-editable').attr('disabled', false ); 12990 } else { 12991 $('#email_wrapper').animate({opacity: 0.3}, 1000); 12992 $('.create_action-editable').attr('disabled', true ); 12993 } 12994 }); 12995 } 12996 12997 /* Change find a group keyword/zip code input placeholder */ 12998 if ($('.js-group_search_form_wrap').length) { 12999 if ($('select.js-group_search-type').val() == 'keyword') { 13000 $('js-.group_search-textinput').attr('placeholder', `${an_javascript_translation.enter_keywords} *`); 13001 } else if ($('select.js-group_search-type').val() == 'zip_code') { 13002 $('.js-group_search-textinput').attr('placeholder',`${an_javascript_translation.enter_a_zip_code} *`); 13003 } 13004 13005 $('select.js-group_search-type').change(function() { 13006 if ($('select.js-group_search-type').val() == 'keyword') { 13007 $('.js-group_search-textinput').attr('placeholder', `${an_javascript_translation.enter_keywords} *`); 13008 } else if ($('select.js-group_search-type').val() == 'zip_code') { 13009 $('.js-group_search-textinput').attr('placeholder', `${an_javascript_translation.enter_a_zip_code} *`); 13010 } 13011 }); 13012 } 13013 13014 /* targeting application */ 13015 13016 var targeting_is_enabled = function() { 13017 return $('.js-sies_head.disabled').length; 13018 } 13019 13020 var targeting_collapse_all = function() { 13021 if (!targeting_is_enabled()) { 13022 $('.js-sies_head').removeClass('sies_head-selected sies_head-active'); 13023 $('.js-single_include_exclude_cols_wrap').addClass('hide'); 13024 } 13025 } 13026 13027 var targeting_expand_all = function() { 13028 if (!targeting_is_enabled()) { 13029 $('.js-sies_head').addClass('sies_head-selected sies_head-active'); 13030 $('.js-single_include_exclude_cols_wrap').removeClass('hide'); 13031 } 13032 } 13033 13034 var targeting_collapse_section = function(section) { 13035 if (!targeting_is_enabled()) { 13036 $(section).removeClass('sies_head-selected sies_head-active'); 13037 $(section).parents('.js-single_include_exclude_section').find('.js-single_include_exclude_cols_wrap').addClass('hide'); 13038 } 13039 } 13040 13041 var targeting_expand_section = function(section, expand_sections) { 13042 if (!targeting_is_enabled() && expand_sections) { 13043 $(section).addClass('sies_head-selected sies_head-active'); 13044 $(section).parents('.js-single_include_exclude_section').find('.js-single_include_exclude_cols_wrap').removeClass('hide'); 13045 } 13046 } 13047 13048 var targeting_set_up = function() { 13049 $('.js-single_include_exclude_cols_wrap').addClass('hide'); 13050 targeting_collapse_all(); 13051 $.get('/reports/preview', function( data ) { 13052 $('.js-targeting_kitchen_sink').append(data); 13053 }); 13054 } 13055 13056 if ($('.js-single_include_exclude_section').length) { 13057 targeting_set_up(); 13058 } 13059 13060 13061 targeting_set_filters = function(expand_sections) { 13062 $('.js-include_exclude_sidebar_include_target, .js-include_exclude_sidebar_exclude_target').text(''); 13063 $('.js-sies_count').not('.js-targeting_kitchen_sink .js-sies_count').remove(); 13064 13065 var section_engagement_count = 0, 13066 section_tags_count = 0, 13067 section_fundraising_count = 0, 13068 section_email_count = 0, 13069 section_mobile_count = 0, 13070 section_geography_count = 0, 13071 section_queries_count = 0, 13072 section_any_selections = false;
13073 13074 $('.js-filter_item').each(function() { 13075 var $this = $(this); 13076 var classList = this.classList; 13077 var included = classList.contains("js-filter_item_include"); 13078 13079 if (classList.contains("js-filter_item_action_activity")) { 13080 var count_value = $(this).find('.js-action_count').val(); 13081 var days_value = $(this).find('.js-action_days').val(); 13082 var days_future_value = $(this).find('.js-action_days-future').val(); 13083 var action_action_type = $(this).find('select.js-action_type_options_select').find('option:selected').text(); 13084 13085 if (count_value != '' && days_value != '') { 13086 if (days_future_value != '') { 13087 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_action_activity_exclude').clone(); 13088 } else { 13089 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_action_activity_include').clone(); 13090 } 13091 13092 var $preview_item = $(preview_item); 13093 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13094 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13095 var selection_item_action_type = $preview_item.find('.js-preview_item_activity_action_type'); 13096 13097 $(selection_item_count).text(count_value); 13098 $(selection_item_days).text(days_value); 13099 $(selection_item_action_type).text(action_action_type); 13100 13101 if (!$.isNumeric( days_value )) { 13102 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13103 $preview_item.find('.js-preview_item_activity_since').show(); 13104 } 13105 13106 if (days_future_value != '') { 13107 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13108 $(selection_item_days_future).text(days_future_value); 13109 } 13110 13111 if (included) { 13112 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13113 } else { 13114 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13115 } 13116 13117 section_engagement_count ++; 13118 section_any_selections = true; 13119 13120 } 13121 } else if (classList.contains("js-filter_item_email_engagement")) { 13122 //console.log("class list contains js-filter_item_email_engagement") 13123 var days_value = $(this).find('.js-email_engagement_days').val(); 13124 var days_future_value = $(this).find('.js-email_engagement_days-future').val(); 13125 var opener_verification_type = $(this).find('.js-target_opener_verification_type_select').val(); 13126 //console.log(opener_verification_type); 13127 if (count_value != '' && days_value != '') { 13128 if (days_future_value != '') { 13129 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_engagement_exclude').clone(); 13130 } else { 13131 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_engagement_include').clone(); 13132 } 13133 13134 var $preview_item = $(preview_item); 13135 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13136 13137 $(selection_item_days).text(days_value); 13138 13139 if (!$.isNumeric( days_value )) { 13140 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13141 $preview_item.find('.js-preview_item_activity_since').show(); 13142 } 13143 13144 if (days_future_value != '') { 13145 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13146 $(selection_item_days_future).text(days_future_value); 13147 } 13148 13149 if (opener_verification_type == "verified_opens_only") { 13150 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_include .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13151 } else if (opener_verification_type == "unverified_opens_only") { 13152 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_exclude .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13153 } else { 13154 $preview_item.find('.js-preview_item_openers_type').text(''); 13155 } 13156 13157 if (included) { 13158 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13159 } else { 13160 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13161 } 13162
13163 section_engagement_count ++; 13164 section_any_selections = true; 13165 13166 } 13167 } else if (classList.contains("js-filter_item_predictive_email_open_activity")) { 13168 const filter_value = $(this).find('.js-predictive_email_open_score').val(); 13169 // Return if we don't have a value. 13170 if (filter_value == '') return; 13171 const getTemplate = (side) => { 13172 if (side === 'include') { 13173 return $('.js-targeting_kitchen_sink .js-preview_item_predictive_engagement_include').clone(); 13174 } else { 13175 return $('.js-targeting_kitchen_sink .js-preview_item_predictive_engagement_exclude').clone(); 13176 } 13177 }; 13178 13179 const appendToPreview = (side, item) => { 13180 if (side === 'include') { 13181 $('.js-include_exclude_sidebar_include_target').append(item); 13182 } else { 13183 $('.js-include_exclude_sidebar_exclude_target').append(item); 13184 } 13185 } 13186 13187 const updateTemplateValues = (template, replacement) => { 13188 const $template = $(template); 13189 const selection_item_score = $template.find('.js-preview_item_predictive_email_open_score'); 13190 $(selection_item_score).text(replacement); 13191 return $template; 13192 } 13193 13194 const side = included ? 'include' : 'exclude'; 13195 13196 const template = getTemplate(side); 13197 const $preview_item = updateTemplateValues(template, filter_value); 13198 13199 appendToPreview(side, $preview_item); 13200 13201 section_engagement_count ++; 13202 section_any_selections = true; 13203 } else if (classList.contains("js-filter_item_email_received_activity")) { 13204 //console.log("class list contains js-filter_item_email_received_activity") 13205 var count_value = $(this).find('.js-email_received_count').val(); 13206 var days_value = $(this).find('.js-email_received_days').val(); 13207 var days_future_value = $(this).find('.js-email_received_days-future').val(); 13208 var network_select = $(this).find('input.js-email_received_children'); 13209 var network_select_value = $(network_select).select2('data'); 13210 //console.log(network_select) 13211 if (count_value != '' && days_value != '') { 13212 if (days_future_value != '') { 13213 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email-received-activity_exclude').clone(); 13214 } else { 13215 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email-received-activity_include').clone(); 13216 } 13217 13218 var $preview_item = $(preview_item); 13219 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13220 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13221 var selection_item_network = $preview_item.find('.js-preview_item_selection'); 13222 13223 selection_item_network.remove(); 13224 13225 //console.log(selection_item_days); 13226 //console.log(days_value); 13227 13228 $(selection_item_count).text(count_value); 13229 $(selection_item_days).text(days_value); 13230 13231 if (network_select_value.length) { 13232 $.each(network_select_value, function(i, e) { 13233 var selection_item_element = selection_item_network.clone().text(e.text); 13234 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13235 }); 13236 } else { 13237 $preview_item.find('.js-preview_item_activity_network').hide(); 13238 } 13239 13240 if (!$.isNumeric(days_value)) { 13241 $preview_item.find('.js-preview_item_email-received_last, .js-preview_item_activity_days_label').hide(); 13242 $preview_item.find('.js-preview_item_email-received_since').show(); 13243 } 13244 13245 if (days_future_value != '') { 13246 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13247 $(selection_item_days_future).text(days_future_value); 13248 } 13249 13250 if (included) { 13251 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13252 } else { 13253 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13254 } 13255 13256 section_engagement_count++; 13257 section_any_selections = true; 13258 13259 } 13260 13261 } else if (classList.contains("js-filter_item_email_open_activity")) {
13262 // console.log("class list contains js-filter_item_email_open_activity") 13263 var count_value = $(this).find('.js-email_open_count').val(); 13264 var days_value = $(this).find('.js-email_open_days').val(); 13265 var days_future_value = $(this).find('.js-email_open_days-future').val(); 13266 var network_select = $(this).find('input.js-email_open_children'); 13267 var network_select_value = $(network_select).select2('data'); 13268 var opener_verification_type = $(this).find('.js-target_opener_verification_type_select').val(); 13269 var cross_group = $(this).find('.js-adc_opt_in_checkbox:checked').val(); 13270 13271 if (count_value != '' && days_value != '') { 13272 if (days_future_value != '') { 13273 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_open_activity_exclude').clone(); 13274 } else { 13275 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_open_activity_include').clone(); 13276 } 13277 13278 var $preview_item = $(preview_item); 13279 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13280 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13281 var selection_item_network = $preview_item.find('.js-preview_item_selection'); 13282 13283 selection_item_network.remove(); 13284 13285 $(selection_item_count).text(count_value); 13286 $(selection_item_days).text(days_value); 13287 13288 if (network_select_value.length) { 13289 $.each(network_select_value, function(i, e) { 13290 var selection_item_element = selection_item_network.clone().text(e.text); 13291 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13292 }); 13293 } else { 13294 $preview_item.find('.js-preview_item_activity_network').hide(); 13295 } 13296 13297 if (!$.isNumeric( days_value )) { 13298 //console.log("not days value numeric)") 13299 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13300 $preview_item.find('.js-preview_item_activity_since').show(); 13301 } 13302 13303 if (days_future_value != '') { 13304 //console.log("yes days are in the future value") 13305 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13306 $(selection_item_days_future).text(days_future_value); 13307 } 13308 13309 if (opener_verification_type == "verified_opens_only") { 13310 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_include .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13311 } else if (opener_verification_type == "unverified_opens_only") { 13312 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_exclude .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13313 } else { 13314 $preview_item.find('.js-preview_item_openers_type').text(''); 13315 } 13316 13317 if (cross_group == 'true') { 13318 $preview_item.find('.js-preview_item_activity_cross_group').show(); 13319 } else { 13320 $preview_item.find('.js-preview_item_activity_cross_group').hide(); 13321 } 13322 13323 if (included) { 13324 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13325 } else { 13326 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13327 } 13328 13329 section_engagement_count ++; 13330 section_any_selections = true; 13331 13332 } 13333 } else if (classList.contains("js-filter_item_email_click_activity")) { 13334 var count_value = $(this).find('.js-email_click_count').val(); 13335 var days_value = $(this).find('.js-email_click_days').val(); 13336 var days_future_value = $(this).find('.js-email_click_days-future').val(); 13337 var network_select = $(this).find('input.js-email_click_children'); 13338 var network_select_value = $(network_select).select2('data'); 13339 var cross_group = $(this).find('.js-adc_opt_in_checkbox:checked').val(); 13340 13341 if (count_value != '' && days_value != '') { 13342 if (days_future_value != '') { 13343 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_click_activity_exclude').clone(); 13344 } else { 13345 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_click_activity_include').clone(); 13346 } 13347 13348 var $preview_item = $(preview_item); 13349 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13350 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13351 var selection_item_network = $preview_item.find('.js-preview_item_selection'); 13352 13353 selection_item_network.remove(); 13354 13355 $(selection_item_count).text(count_value); 13356 $(selection_item_days).text(days_value); 13357 13358 if (network_select_value.length) { 13359 $.each(network_select_value, function(i, e) { 13360 var selection_item_element = selection_item_network.clone().text(e.text); 13361 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13362 }); 13363 } else { 13364 $preview_item.find('.js-preview_item_activity_network').hide(); 13365 } 13366 13367 if (!$.isNumeric( days_value )) { 13368 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13369 $preview_item.find('.js-preview_item_activity_since').show(); 13370 } 13371 13372 if (days_future_value != '') { 13373 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13374 $(selection_item_days_future).text(days_future_value); 13375 } 13376 13377 if (cross_group == 'true') { 13378 $preview_item.find('.js-preview_item_activity_cross_group').show(); 13379 } else { 13380 $preview_item.find('.js-preview_item_activity_cross_group').hide(); 13381 } 13382 13383 if (included) { 13384 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13385 } else { 13386 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13387 } 13388
13389 section_engagement_count ++; 13390 section_any_selections = true; 13391 13392 } 13393 } else if (classList.contains("js-filter_item_email_subscription")) { 13394 var days_value = $(this).find('.js-email_subscription_days').val(); 13395 var days_future_value = $(this).find('.js-email_subscription_days-future').val(); 13396 var first_time_only_value = $(this).find('.js-joined_first-time-only:checked').length; 13397 13398 if (days_value != '') { 13399 if (days_future_value != '') { 13400 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_subscription_exclude').clone(); 13401 } else { 13402 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_subscription_include').clone(); 13403 } 13404 13405 var $preview_item = $(preview_item); 13406 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13407 13408 $(selection_item_days).text(days_value); 13409 13410 if (!$.isNumeric( days_value )) { 13411 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13412 $preview_item.find('.js-preview_item_activity_since').show(); 13413 } 13414 13415 if (days_future_value != '') { 13416 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13417 $(selection_item_days_future).text(days_future_value); 13418 } 13419 13420 if (first_time_only_value == 1) { 13421 $preview_item.find('.js-preview_item_first_time').show(); 13422 $preview_item.find('.js-preview_item_not_first_time').hide(); 13423 } else { 13424 $preview_item.find('.js-preview_item_first_time').hide(); 13425 $preview_item.find('.js-preview_item_not_first_time').show(); 13426 } 13427 13428 if (included) { 13429 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13430 } else { 13431 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13432 } 13433 13434 section_engagement_count ++; 13435 section_any_selections = true; 13436 13437 } 13438 } else if (classList.contains("js-filter_item_mobile_click_activity")) { 13439 var count_value = $(this).find('.js-mobile_click_count').val(); 13440 var days_value = $(this).find('.js-mobile_click_days').val(); 13441 var days_future_value = $(this).find('.js-mobile_click_days-future').val(); 13442 var network_select = $(this).find('input.js-mobile_click_children'); 13443 var network_select_value = $(network_select).select2('data'); 13444 var cross_group = $(this).find('.js-adc_opt_in_checkbox:checked').val(); 13445 13446 if (count_value != '' && days_value != '') { 13447 if (days_future_value != '') { 13448 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_click_activity_exclude').clone(); 13449 } else { 13450 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_click_activity_include').clone(); 13451 } 13452 13453 var $preview_item = $(preview_item); 13454 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13455 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13456 var selection_item_network = $preview_item.find('.js-preview_item_selection'); 13457 13458 selection_item_network.remove(); 13459 13460 $(selection_item_count).text(count_value); 13461 $(selection_item_days).text(days_value); 13462 13463 if (network_select_value.length) { 13464 $.each(network_select_value, function(i, e) { 13465 var selection_item_element = selection_item_network.clone().text(e.text); 13466 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13467 }); 13468 } else { 13469 $preview_item.find('.js-preview_item_activity_network').hide(); 13470 } 13471 13472 if (!$.isNumeric( days_value )) { 13473 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13474 $preview_item.find('.js-preview_item_activity_since').show(); 13475 } 13476 13477 if (days_future_value != '') { 13478 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13479 $(selection_item_days_future).text(days_future_value); 13480 } 13481 13482 // Span is always present in kitchen-sink templates (may start with .hide). 13483 // Toggle class so booster copy appears when the ADC checkbox is checked. 13484 if (cross_group == 'true') { 13485 $preview_item.find('.js-preview_item_activity_cross_group').removeClass('hide').show(); 13486 } else { 13487 $preview_item.find('.js-preview_item_activity_cross_group').addClass('hide').hide(); 13488 } 13489 13490 if (included) { 13491 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13492 } else { 13493 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13494 } 13495
13496 section_engagement_count ++; 13497 section_any_selections = true; 13498 13499 } 13500 } else if (classList.contains("js-filter_item_mobile_subscription")) { 13501 var days_value = $(this).find('.js-mobile_subscription_days').val(); 13502 var days_future_value = $(this).find('.js-mobile_subscription_days-future').val(); 13503 var first_time_only_value = $(this).find('.js-joined_first-time-only:checked').length; 13504 13505 if (days_value != '') { 13506 if (days_future_value != '') { 13507 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_subscription_exclude').clone(); 13508 } else { 13509 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_subscription_include').clone(); 13510 } 13511 13512 var $preview_item = $(preview_item); 13513 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13514 13515 $(selection_item_days).text(days_value); 13516 13517 if (!$.isNumeric( days_value )) { 13518 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13519 $preview_item.find('.js-preview_item_activity_since').show(); 13520 } 13521 13522 if (days_future_value != '') { 13523 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13524 $(selection_item_days_future).text(days_future_value); 13525 } 13526 13527 if (first_time_only_value == 1) { 13528 $preview_item.find('.js-preview_item_first_time').show(); 13529 $preview_item.find('.js-preview_item_not_first_time').hide(); 13530 } else { 13531 $preview_item.find('.js-preview_item_first_time').hide(); 13532 $preview_item.find('.js-preview_item_not_first_time').show(); 13533 } 13534 13535 if (included) { 13536 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13537 } else { 13538 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13539 } 13540 13541 section_engagement_count ++; 13542 section_any_selections = true; 13543 13544 } 13545 } else if (classList.contains("js-filter_item_ladders")) { 13546 var select = $(this).find('input.js-dynamic_targeting_select'); 13547 var value = $(select).select2('data'); 13548 13549 if (value && value.length) { 13550 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_ladders').clone(); 13551 var $preview_item = $(preview_item); 13552 var selection_item = $preview_item.find('.js-preview_item_selection'); 13553 13554 selection_item.remove(); 13555 13556 $.each(value, function(i, e) { 13557 var selection_item_element = selection_item.clone().text(e.text); 13558 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13559 }); 13560 13561 if (included) { 13562 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13563 } else { 13564 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13565 } 13566 13567 section_engagement_count ++; 13568 section_any_selections = true; 13569 13570 } 13571 } else if (classList.contains("js-filter_item_tags")) { 13572 var select = $(this).find('input.js-dynamic_targeting_select'); 13573 var value = $(select).select2('data'); 13574 13575 if (value && value.length) { 13576 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_tags').clone(); 13577 var $preview_item = $(preview_item); 13578 var selection_item = $preview_item.find('.js-preview_item_selection'); 13579 13580 selection_item.remove(); 13581 13582 $.each(value, function(i, e) { 13583 var selection_item_element = selection_item.clone().text(e.text); 13584 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13585 }); 13586 13587 if (included) { 13588 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13589 } else { 13590 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13591 } 13592 13593 section_tags_count ++; 13594 section_any_selections = true; 13595 13596 } 13597 } else if (classList.contains("js-filter_item_sources")) { 13598 var select = $(this).find('input.js-dynamic_targeting_select'); 13599 var value = $(select).select2('data'); 13600 var checkbox = $(this).find('.js-filter_item_sources_new'); 13601 13602 if (value && value.length) { 13603 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_sources').clone(); 13604 var $preview_item = $(preview_item); 13605 var selection_item = $preview_item.find('.js-preview_item_selection'); 13606 13607 selection_item.remove(); 13608 13609 $.each(value, function(i, e) { 13610 var selection_item_element = selection_item.clone().text(e.text); 13611 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13612 }); 13613 13614 if ($(checkbox).is(':checked')) { 13615 $preview_item.find('.js-preview_item_sources_new').show(); 13616 } else { 13617 $preview_item.find('.js-preview_item_sources_new').hide(); 13618 } 13619 13620 if (included) { 13621 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13622 } else { 13623 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13624 } 13625 13626 section_tags_count ++; 13627 section_any_selections = true; 13628 13629 } 13630 } else if (classList.contains("js-filter_item_field_values")) { 13631 var value = $(this).find('.js-form_value_targeting_entry'); 13632 13633 if (value && value.length) { 13634 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_field_values').clone(); 13635 var $preview_item = $(preview_item); 13636 var selection_item = $preview_item.find('.js-preview_item_selection'); 13637 13638 selection_item.remove(); 13639 13640 $.each(value, function(i, e) { 13641 var selection_item_element = selection_item.clone(); 13642 var $selection_item_element = $(selection_item_element); 13643 var $e = $(e); 13644 $selection_item_element.find('.js-preview_item_selection_field_name').text($e.find('.js-form_value_targeting_entry_name').text()); 13645 $selection_item_element.find('.js-preview_item_selection_field_value').text($e.find('.js-form_value_targeting_entry_value').text()); 13646 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13647 }); 13648 13649 if (included) { 13650 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13651 } else { 13652 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13653 } 13654 13655 section_tags_count ++; 13656 section_any_selections = true; 13657 13658 } 13659 } else if (classList.contains("js-filter_item_action")) { 13660 var select = $(this).find('input.js-dynamic_targeting_select'); 13661 var value = $(select).select2('data'); 13662 13663 if (value && value.length) { 13664 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_action').clone(); 13665 var $preview_item = $(preview_item); 13666 var selection_item = $preview_item.find('.js-preview_item_selection'); 13667 13668 selection_item.remove(); 13669 13670 $.each(value, function(i, e) { 13671 var selection_item_element = selection_item.clone().text(e.text); 13672 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13673 }); 13674 13675 if (included) { 13676 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13677 } else { 13678 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13679 } 13680 13681 section_fundraising_count ++; 13682 section_any_selections = true; 13683 13684 } 13685 } else if (classList.contains("js-filter_item_fundraising_donors")) { 13686 var checkbox = $(this).find('input'); 13687 13688 if ($(checkbox).is(':checked')) { 13689 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_donors').clone(); 13690 13691 if (included) { 13692 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13693 } else { 13694 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13695 } 13696 13697 section_fundraising_count ++; 13698 section_any_selections = true; 13699 13700 } 13701 } else if (classList.contains("js-filter_item_fundraising_active_recurring")) { 13702 var checkbox = $(this).find('input'); 13703 13704 if ($(checkbox).is(':checked')) { 13705 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_active_recurring').clone(); 13706 13707 if (included) { 13708 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13709 } else { 13710 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13711 } 13712 13713 section_fundraising_count ++; 13714 section_any_selections = true; 13715 13716 } 13717 } else if (classList.contains("js-filter_item_fundraising_failing_recurring")) { 13718 var checkbox = $(this).find('input'); 13719 13720 if ($(checkbox).is(':checked')) { 13721 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_failing_recurring').clone(); 13722 13723 if (included) { 13724 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13725 } else { 13726 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13727 } 13728 13729 section_fundraising_count ++; 13730 section_any_selections = true; 13731 13732 } 13733 }
13733 else if (classList.contains("js-filter_item_fundraising_canceled_recurring")) { 13734 var checkbox = $(this).find('input'); 13735 13736 if ($(checkbox).is(':checked')) { 13737 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_canceled_recurring').clone(); 13738 13739 if (included) { 13740 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13741 } else { 13742 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13743 } 13744 13745 section_fundraising_count ++; 13746 section_any_selections = true; 13747 13748 } 13749 } else if (classList.contains("js-filter_item_fundraising_saved")) { 13750 var checkbox = $(this).find('input'); 13751 13752 if ($(checkbox).is(':checked')) { 13753 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_saved').clone(); 13754 13755 if (included) { 13756 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13757 } else { 13758 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13759 } 13760 13761 section_fundraising_count ++; 13762 section_any_selections = true; 13763 13764 } 13765 } else if (classList.contains("js-filter_item_fundraising_amount")) { 13766 var count_value = $(this).find('.js-fundraising_amount').val(); 13767 var days_value = $(this).find('.js-fundraising_days').val(); 13768 var days_future_value = $(this).find('.js-fundraising_days-future').val(); 13769 var currency_symbol = $(this).find('.js-currency-symbol').text(); 13770 var exclude_recurrences = $(this).find('.js-fundraising_exclude_recurrences').is(":checked"); 13771 13772 if (count_value != '' && days_value != '') { 13773 if (days_future_value != '') { 13774 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_amount_exclude').clone(); 13775 } else { 13776 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_amount_include').clone(); 13777 } 13778 13779 var $preview_item = $(preview_item); 13780 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13781 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13782 var selection_item_currency = $preview_item.find('.js-preview_item_activity_currency'); 13783 13784 $(selection_item_count).text(count_value); 13785 $(selection_item_days).text(days_value); 13786 $(selection_item_currency).text(currency_symbol); 13787 13788 if (!$.isNumeric( days_value )) { 13789 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13790 $preview_item.find('.js-preview_item_activity_since').show(); 13791 } 13792 13793 if (days_future_value != '') { 13794 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13795 $(selection_item_days_future).text(days_future_value); 13796 } 13797 13798 if (exclude_recurrences) { 13799 $preview_item.find('.js-preview_item_recurrences').show(); 13800 } else { 13801 $preview_item.find('.js-preview_item_recurrences').hide(); 13802 } 13803 13804 if (included) { 13805 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13806 } else { 13807 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13808 } 13809 13810 section_fundraising_count ++; 13811 section_any_selections = true; 13812 13813 } 13814 } else if (classList.contains("js-filter_item_fundraising_times")) { 13815 var count_value = $(this).find('.js-fundraising_count').val(); 13816 var days_value = $(this).find('.js-fundraising_days').val(); 13817 var days_future_value = $(this).find('.js-fundraising_days-future').val(); 13818 var exclude_recurrences = $(this).find('.js-fundraising_exclude_recurrences').is(":checked"); 13819 13820 if (count_value != '' && days_value != '') { 13821 if (days_future_value != '') { 13822 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_times_exclude').clone(); 13823 } else { 13824 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_times_include').clone(); 13825 } 13826 13827 var $preview_item = $(preview_item); 13828 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13829 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13830 13831 $(selection_item_count).text(count_value); 13832 $(selection_item_days).text(days_value); 13833 13834 if (!$.isNumeric( days_value )) { 13835 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13836 $preview_item.find('.js-preview_item_activity_since').show(); 13837 } 13838 13839 if (days_future_value != '') { 13840 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13841 $(selection_item_days_future).text(days_future_value); 13842 } 13843 13844 if (exclude_recurrences) { 13845 $preview_item.find('.js-preview_item_recurrences').show(); 13846 } else { 13847 $preview_item.find('.js-preview_item_recurrences').hide(); 13848 } 13849 13850 if (included) { 13851 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13852 } else { 13853 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13854 } 13855 13856 section_fundraising_count ++; 13857 section_any_selections = true; 13858 13859 } 13860 } else if (classList.contains("js-filter_item_fundraising_contribution_value")) { 13861 var count_value = $(this).find('.js-fundraising_amount').val(); 13862 var days_value = $(this).find('.js-fundraising_days').val(); 13863 var days_future_value = $(this).find('.js-fundraising_days-future').val(); 13864 var currency_symbol = $(this).find('.js-currency-symbol').text(); 13865 13866 if (count_value != '' && days_value != '') { 13867 if (days_future_value != '') { 13868 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_contribution_value_exclude').clone(); 13869 } else { 13870 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_fundraising_contribution_value_include').clone(); 13871 } 13872 13873 var $preview_item = $(preview_item); 13874 var selection_item_count = $preview_item.find('.js-preview_item_activity_count'); 13875 var selection_item_days = $preview_item.find('.js-preview_item_activity_days'); 13876 var selection_item_currency = $preview_item.find('.js-preview_item_activity_currency'); 13877 13878 $(selection_item_count).text(count_value); 13879 $(selection_item_days).text(days_value); 13880 $(selection_item_currency).text(currency_symbol); 13881 13882 if (!$.isNumeric( days_value )) { 13883 $preview_item.find('.js-preview_item_activity_last, .js-preview_item_activity_days_label').hide(); 13884 $preview_item.find('.js-preview_item_activity_since').show(); 13885 } 13886 13887 if (days_future_value != '') { 13888 var selection_item_days_future = $preview_item.find('.js-preview_item_activity_days-future'); 13889 $(selection_item_days_future).text(days_future_value); 13890 } 13891 13892 if (included) { 13893 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13894 } else { 13895 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13896 } 13897 13898 section_fundraising_count ++; 13899 section_any_selections = true; 13900 13901 } 13902 } else if (classList.contains("js-filter_item_emails")) { 13903 var select = $(this).find('input.js-dynamic_targeting_select'); 13904 var value = $(select).select2('data'); 13905 13906 if (value && value.length) { 13907 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_emails').clone(); 13908 var $preview_item = $(preview_item); 13909 var selection_item = $preview_item.find('.js-preview_item_selection'); 13910 13911 selection_item.remove(); 13912 13913 $.each(value, function(i, e) { 13914 var selection_item_element = selection_item.clone().html(e.text); 13915 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13916 }); 13917 13918 if (included) { 13919 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13920 } else { 13921 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13922 } 13923 13924 section_email_count ++; 13925 section_any_selections = true; 13926 13927 } 13928 } else if (classList.contains("js-filter_item_email_campaigns")) { 13929 var select = $(this).find('input.js-dynamic_targeting_select'); 13930 var value = $(select).select2('data'); 13931 13932 if (value && value.length) { 13933 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_campaigns').clone(); 13934 var $preview_item = $(preview_item); 13935 var selection_item = $preview_item.find('.js-preview_item_selection'); 13936 13937 selection_item.remove(); 13938 13939 $.each(value, function(i, e) { 13940 var selection_item_element = selection_item.clone().text(e.text); 13941 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13942 }); 13943 13944 if (included) { 13945 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13946 } else { 13947 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13948 } 13949 13950 section_email_count ++; 13951 section_any_selections = true; 13952 13953 } 13954 } else if (classList.contains("js-filter_item_email_opens")) {
13955 //console.log("class list contains js-filter_item_email_opens") 13956 var select = $(this).find('input.js-dynamic_targeting_select'); 13957 var value = $(select).select2('data'); 13958 13959 if (value && value.length) { 13960 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_opens').clone(); 13961 var $preview_item = $(preview_item); 13962 var selection_item = $preview_item.find('.js-preview_item_selection'); 13963 var opener_verification_type = $(this).find('.js-target_opener_verification_type_select').val(); 13964 //console.log(opener_verification_type); 13965 //console.log($preview_item); 13966 13967 selection_item.remove(); 13968 13969 $.each(value, function(i, e) { 13970 var selection_item_element = selection_item.clone().html(e.text); 13971 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 13972 }); 13973 13974 if (opener_verification_type == "verified_opens_only") { 13975 13976 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_include .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13977 } else if (opener_verification_type == "unverified_opens_only") { 13978 $preview_item.find('.js-preview_item_openers_type').text($('.js-targeting_kitchen_sink .js-preview_item_engagement_exclude .js-preview_item_openers_type').text()); // include is verified, exclude is unverified, in the dummy report 13979 } else { 13980 $preview_item.find('.js-preview_item_openers_type').text(''); 13981 } 13982 13983 if (included) { 13984 $('.js-include_exclude_sidebar_include_target').append(preview_item); 13985 } else { 13986 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 13987 } 13988 13989 section_email_count ++; 13990 section_any_selections = true; 13991 13992 } 13993 } else if (classList.contains("js-filter_item_email_clicks")) { 13994 var select = $(this).find('input.js-dynamic_targeting_select'); 13995 var value = $(select).select2('data'); 13996 13997 if (value && value.length) { 13998 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_email_clicks').clone(); 13999 var $preview_item = $(preview_item); 14000 var selection_item = $preview_item.find('.js-preview_item_selection'); 14001 14002 selection_item.remove(); 14003 14004 $.each(value, function(i, e) { 14005 var selection_item_element = selection_item.clone().html(e.text); 14006 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14007 }); 14008 14009 if (included) { 14010 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14011 } else { 14012 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14013 } 14014 14015 section_email_count ++; 14016 section_any_selections = true; 14017 14018 } 14019 } else if (classList.contains("js-filter_item_mobile")) { 14020 var select = $(this).find('input.js-dynamic_targeting_select'); 14021 var value = $(select).select2('data'); 14022 14023 if (value && value.length) { 14024 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile').clone(); 14025 var $preview_item = $(preview_item); 14026 var selection_item = $preview_item.find('.js-preview_item_selection'); 14027 14028 selection_item.remove(); 14029 14030 $.each(value, function(i, e) { 14031 var selection_item_element = selection_item.clone().text(e.text); 14032 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14033 }); 14034 14035 if (included) { 14036 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14037 } else { 14038 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14039 } 14040 14041 section_mobile_count ++; 14042 section_any_selections = true; 14043 14044 } 14045 } else if (classList.contains("js-filter_item_mobile_click")) { 14046 var select = $(this).find('input.js-dynamic_targeting_select'); 14047 var value = $(select).select2('data'); 14048 14049 if (value && value.length) { 14050 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_click').clone(); 14051 var $preview_item = $(preview_item); 14052 var selection_item = $preview_item.find('.js-preview_item_selection'); 14053 14054 selection_item.remove(); 14055 14056 $.each(value, function(i, e) { 14057 var selection_item_element = selection_item.clone().text(e.text); 14058 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14059 }); 14060 14061 if (included) { 14062 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14063 } else { 14064 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14065 } 14066 14067 section_mobile_count ++; 14068 section_any_selections = true; 14069 14070 } 14071 } else if (classList.contains("js-filter_item_mobile_carrier")) { 14072 var select = $(this).find('input.js-dynamic_targeting_select'); 14073 var value = $(select).select2('data'); 14074 //console.log(value); 14075 14076 if (value && value.length) { 14077 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_mobile_carrier').clone(); 14078 var $preview_item = $(preview_item); 14079 var selection_item = $preview_item.find('.js-preview_item_selection'); 14080 14081 selection_item.remove(); 14082 14083 $.each(value, function(i, e) { 14084 var selection_item_element = selection_item.clone().text(e.text); 14085 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14086 }); 14087 14088 if (included) { 14089 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14090 } else { 14091 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14092 } 14093 14094 section_mobile_count ++; 14095 section_any_selections = true; 14096 14097 } 14098 } else if (classList.contains("js-filter_item_state")) { 14099 var select = $(this).find('select'); 14100 var value = $(select).select2('data'); 14101 14102 if (value && value.length) { 14103 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_state').clone(); 14104 var $preview_item = $(preview_item); 14105 var selection_item = $preview_item.find('.js-preview_item_selection'); 14106 14107 selection_item.remove(); 14108 14109 $.each(value, function(i, e) { 14110 var selection_item_element = selection_item.clone().text(e.text); 14111 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14112 }); 14113 14114 if (included) { 14115 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14116 } else { 14117 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14118 } 14119 14120 section_geography_count ++; 14121 section_any_selections = true; 14122 14123 } 14124 } else if (classList.contains("js-filter_item_county")) { 14125 var select = $(this).find('input.js-dynamic_targeting_select'); 14126 var value = $(select).select2('data'); 14127 14128 if (value && value.length) { 14129 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_county').clone(); 14130 var $preview_item = $(preview_item); 14131 var selection_item = $preview_item.find('.js-preview_item_selection'); 14132 14133 selection_item.remove(); 14134 14135 $.each(value, function(i, e) { 14136 var selection_item_element = selection_item.clone().text(e.text); 14137 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14138 }); 14139 14140 if (included) { 14141 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14142 } else { 14143 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14144 } 14145 14146 section_geography_count ++; 14147 section_any_selections = true; 14148 14149 } 14150 } else if (classList.contains("js-filter_item_district")) { 14151 var select = $(this).find('input.js-dynamic_targeting_select'); 14152 var value = $(select).select2('data'); 14153 14154 if (value && value.length) { 14155 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_district').clone(); 14156 var $preview_item = $(preview_item); 14157 var selection_item = $preview_item.find('.js-preview_item_selection'); 14158 14159 selection_item.remove(); 14160 14161 $.each(value, function(i, e) { 14162 var selection_item_element = selection_item.clone().text(e.text); 14163 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14164 }); 14165 14166 if (included) { 14167 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14168 } else { 14169 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14170 } 14171 14172 section_geography_count ++; 14173 section_any_selections = true; 14174 14175 } 14176 } else if (classList.contains("js-filter_item_country")) { 14177 var select = $(this).find('select'); 14178 var value = $(select).select2('data'); 14179 14180 if (value && value.length) { 14181 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_country').clone(); 14182 var $preview_item = $(preview_item); 14183 var selection_item = $preview_item.find('.js-preview_item_selection'); 14184 14185 selection_item.remove(); 14186 14187 $.each(value, function(i, e) { 14188 var selection_item_element = selection_item.clone().text(e.text); 14189 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14190 }); 14191 14192 if (included) { 14193 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14194 } else { 14195 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14196 } 14197 14198 section_geography_count ++; 14199 section_any_selections = true; 14200 14201 } 14202 } else if (classList.contains("js-filter_item_zip")) { 14203 var radius_value = $(this).find('input.js-zip_radius_distance').val(); 14204 var zip_value = $(this).find('input.js-zip_radius_zipcode').val(); 14205 var country_select = $(this).find('select.js-form-country'); 14206 var country_value = $(country_select).val(); 14207 var units_value = $(this).find('select.js-zip_radius_unit option:selected').text(); 14208 if (radius_value != '' && zip_value != '' && country_value != '') { 14209 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_zip').clone(); 14210 var $preview_item = $(preview_item); 14211 var selection_item_radius = $preview_item.find('.js-preview_item_selection_radius'); 14212 var selection_item_zip = $preview_item.find('.js-preview_item_selection_zip'); 14213 var selection_item_country = $preview_item.find('.js-preview_item_selection_country'); 14214 var selection_item_units = $preview_item.find('.js-preview_item_selection_units'); 14215 14216 $(selection_item_radius).text(radius_value); 14217 $(selection_item_zip).text(zip_value); 14218 $(selection_item_country).text($(country_select).find('option[value=' + country_value + ']').text()); 14219 $(selection_item_units).text(units_value); 14220 14221 if (included) { 14222 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14223 } else { 14224 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14225 } 14226 14227 section_geography_count ++; 14228 section_any_selections = true; 14229 14230 } 14231 } else if (classList.contains("js-filter_item_city")) { 14232 var radius_value = $(this).find('input.js-zip_radius_distance').val(); 14233 var city_select = $(this).find('input.js-dynamic_targeting_select'); 14234 var city_value = $(city_select).select2('data'); 14235 var units_value = $(this).find('select.js-cityradius_unit option:selected').text(); 14236 14237 if (radius_value != '' && city_value && city_value.length) { 14238 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_city').clone(); 14239 var $preview_item = $(preview_item); 14240 var selection_item_radius = $preview_item.find('.js-preview_item_selection_radius'); 14241 var selection_item_city = $preview_item.find('.js-preview_item_selection'); 14242 var selection_item_units = $preview_item.find('.js-preview_item_selection_units'); 14243 14244 selection_item_city.remove(); 14245 14246 $(selection_item_radius).text(radius_value); 14247 $(selection_item_units).text(units_value); 14248 14249 $.each(city_value, function(i, e) { 14250 var selection_item_element = selection_item_city.clone().text(e.text); 14251 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14252 }); 14253 14254 if (included) { 14255 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14256 } else { 14257 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14258 } 14259 14260 section_geography_count ++; 14261 section_any_selections = true; 14262 14263 } 14264 } else if (classList.contains("js-filter_item_event_campaign")) { 14265 var radius_value = $(this).find('input.js-zip_radius_distance').val(); 14266 var event_campaign_select = $(this).find('input.js-dynamic_targeting_select'); 14267 var event_campaign_value = $(event_campaign_select).select2('data'); 14268 var units_value = $(this).find('select.js-eventradius_unit option:selected').text(); 14269 14270 if (radius_value != '' && event_campaign_value && event_campaign_value.length) { 14271 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_event_campaign').clone(); 14272 var $preview_item = $(preview_item); 14273 var selection_item_radius = $preview_item.find('.js-preview_item_selection_radius'); 14274 var selection_item_event_campaign = $preview_item.find('.js-preview_item_selection'); 14275 var selection_item_units = $preview_item.find('.js-preview_item_selection_units'); 14276 14277 selection_item_event_campaign.remove(); 14278 14279 $(selection_item_radius).text(radius_value); 14280 $(selection_item_units).text(units_value); 14281 14282 $.each(event_campaign_value, function(i, e) { 14283 var selection_item_element = selection_item_event_campaign.clone().text(e.text); 14284 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14285 }); 14286 14287 if (included) { 14288 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14289 } else { 14290 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14291 } 14292 14293 section_geography_count ++; 14294 section_any_selections = true; 14295 14296 } 14297 } else if (classList.contains("js-filter_item_letter")) { 14298 var select = $(this).find('select'); 14299 var value = $(select).val(); 14300 14301 if (value != '') { 14302 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_letter').clone(); 14303 var $preview_item = $(preview_item); 14304 var selection_item = $preview_item.find('.js-preview_item_selection'); 14305 14306 $(selection_item).text($(select).find('option[value=' + value + ']').text()); 14307 14308 if (included) { 14309 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14310 } else { 14311 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14312 } 14313 14314 section_geography_count ++; 14315 section_any_selections = true; 14316 14317 } 14318 } else if (classList.contains("js-filter_item_language")) { 14319 var select = $(this).find('select'); 14320 var value = $(select).select2('data'); 14321 14322 if (value && value.length) { 14323 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_language').clone(); 14324 var $preview_item = $(preview_item); 14325 var selection_item = $preview_item.find('.js-preview_item_selection'); 14326 14327 selection_item.remove(); 14328 14329 $.each(value, function(i, e) { 14330 var selection_item_element = selection_item.clone().text(e.text); 14331 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14332 }); 14333 14334 if (included) { 14335 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14336 } else { 14337 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14338 } 14339 14340 section_geography_count ++; 14341 section_any_selections = true; 14342 14343 } 14344 } else if (classList.contains("js-filter_item_queries")) { 14345 var select = $(this).find('input.js-dynamic_targeting_select'); 14346 var value = $(select).select2('data'); 14347 14348 if (value && value.length) { 14349 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_queries').clone(); 14350 var $preview_item = $(preview_item); 14351 var selection_item = $preview_item.find('.js-preview_item_selection'); 14352 14353 selection_item.remove(); 14354 14355 $.each(value, function(i, e) { 14356 var selection_item_element = selection_item.clone().text(e.text); 14357 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14358 }); 14359 14360 if (included) { 14361 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14362 } else { 14363 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14364 } 14365 14366 section_queries_count ++; 14367 section_any_selections = true; 14368 14369 } 14370 } else if (classList.contains("js-filter_item_reports")) { 14371 var select = $(this).find('input.js-dynamic_targeting_select'); 14372 var value = $(select)
14372.select2('data'); 14373 14374 if (value && value.length) { 14375 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_reports').clone(); 14376 var $preview_item = $(preview_item); 14377 var selection_item = $preview_item.find('.js-preview_item_selection'); 14378 14379 selection_item.remove(); 14380 14381 $.each(value, function(i, e) { 14382 var selection_item_element = selection_item.clone().text(e.text); 14383 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14384 }); 14385 14386 if (included) { 14387 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14388 } else { 14389 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14390 } 14391 14392 section_queries_count ++; 14393 section_any_selections = true; 14394 14395 } 14396 } else if (classList.contains("js-filter_item_new_uuids")) { 14397 var select = $(this).find('input.js-dynamic_targeting_select'); 14398 var value = $(select).select2('data'); 14399 14400 if (value && value.length) { 14401 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_uuids').clone(); 14402 var $preview_item = $(preview_item); 14403 var selection_item = $preview_item.find('.js-preview_item_selection'); 14404 14405 selection_item.remove(); 14406 14407 $.each(value, function(i, e) { 14408 var selection_item_element = selection_item.clone().text(e.text); 14409 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14410 }); 14411 14412 if (included) { 14413 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14414 } else { 14415 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14416 } 14417 14418 section_queries_count ++; 14419 section_any_selections = true; 14420 14421 } 14422 } else if (classList.contains("js-filter_item_uuids")) { 14423 var uuids = $(this).find('.js-uuid_uploaded_wrapper'); 14424 var uuids_count = $(uuids).find('.js-uuids_count').text(); 14425 14426 if (uuids && uuids.length && $(this).find('.js-uuid_input').val() != '') { 14427 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_uuids').clone(); 14428 var $preview_item = $(preview_item); 14429 var selection_item = $preview_item.find('.js-preview_item_selection'); 14430 14431 selection_item.remove(); 14432 14433 var selection_item_element = selection_item.clone(); 14434 var $selection_item_element = $(selection_item_element); 14435 $selection_item_element.find('.js-preview_item_uuids_count').text(uuids_count); 14436 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14437 14438 if (included) { 14439 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14440 } else { 14441 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14442 } 14443 14444 section_queries_count ++; 14445 section_any_selections = true; 14446 14447 } 14448 } else if (classList.contains("js-filter_item_network_email")) { 14449 var select = $(this).find('input.js-dynamic_targeting_select'); 14450 var value = $(select).select2('data'); 14451 14452 if (value && value.length) { 14453 var preview_item = $('.js-targeting_kitchen_sink .js-preview_item_network_email').clone(); 14454 var $preview_item = $(preview_item); 14455 var selection_item = $preview_item.find('.js-preview_item_selection'); 14456 14457 selection_item.remove(); 14458 14459 $.each(value, function(i, e) { 14460 var selection_item_element = selection_item.clone().text(e.text); 14461 $preview_item.find('.js-preview_item_selection_wrap').append(selection_item_element); 14462 }); 14463 14464 if (included) { 14465 $('.js-include_exclude_sidebar_include_target').append(preview_item); 14466 } else { 14467 $('.js-include_exclude_sidebar_exclude_target').append(preview_item); 14468 } 14469 14470 section_queries_count ++; 14471 section_any_selections = true; 14472 14473 } 14474 } 14475 }); 14476 //console.log('fire'); 14477 if (section_any_selections) { 14478 $('.js-include_exclude_sidebar_active').show(); 14479 $('.js-include_exclude_sidebar_empty').hide(); 14480 $('.js-no_target_warning').hide(); 14481 $('.js-no_target_warning').removeClass('error_input'); 14482 $('.js-no_target_warning_checkbox').attr('checked', false); 14483 } else { 14484 //console.log('else'); 14485 $('.js-include_exclude_sidebar_active').hide(); 14486 $('.js-include_exclude_sidebar_empty').show(); 14487 //console.log($('.js-random_limit_input').val()); 14488 if ($('.js-random_limit_input').val() == '' && !$('.js-builder').length) { 14489 $('.js-no_target_warning').show(); 14490 } else { 14491 $('.js-no_target_warning').hide(); 14492 $('.js-no_target_warning').removeClass('error_input'); 14493 $('.js-no_target_warning_checkbox').attr('checked', false); 14494 } 14495 } 14496
14497 if (section_engagement_count > 0 || !section_any_selections) { 14498 if (section_engagement_count > 0) { // because this is opened by default on page load, no counts in that situation, so they shouldn't be set 14499 $('.js-single_include_exclude_section_engagement .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_engagement_count)); 14500 } 14501 14502 var section = $('.js-single_include_exclude_section_engagement .js-sies_head'); 14503 if (!$(section).hasClass('sies_head-active')) { 14504 targeting_expand_section(section, expand_sections); 14505 } 14506 } 14507 14508 if (section_geography_count > 0 ) { 14509 $('.js-single_include_exclude_section_geography .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_geography_count)); 14510 var section = $('.js-single_include_exclude_section_geography .js-sies_head'); 14511 if (!$(section).hasClass('sies_head-active')) { 14512 targeting_expand_section(section, expand_sections); 14513 } 14514 } 14515 14516 if (section_email_count > 0) { 14517 $('.js-single_include_exclude_section_emails .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_email_count)); 14518 var section = $('.js-single_include_exclude_section_emails .js-sies_head'); 14519 if (!$(section).hasClass('sies_head-active')) { 14520 targeting_expand_section(section, expand_sections); 14521 } 14522 } 14523 14524 if (section_mobile_count > 0) { 14525 $('.js-single_include_exclude_section_mobile .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_mobile_count)); 14526 var section = $('.js-single_include_exclude_section_mobile .js-sies_head'); 14527 if (!$(section).hasClass('sies_head-active')) { 14528 targeting_expand_section(section, expand_sections); 14529 } 14530 } 14531 14532 if (section_queries_count > 0) { 14533 $('.js-single_include_exclude_section_queries .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_queries_count)); 14534 var section = $('.js-single_include_exclude_section_queries .js-sies_head'); 14535 if (!$(section).hasClass('sies_head-active')) { 14536 targeting_expand_section(section, expand_sections); 14537 } 14538 } 14539 14540 if (section_fundraising_count > 0) { 14541 $('.js-single_include_exclude_section_fundraising .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_fundraising_count)); 14542 var section = $('.js-single_include_exclude_section_fundraising .js-sies_head'); 14543 if (!$(section).hasClass('sies_head-active')) { 14544 targeting_expand_section(section, expand_sections); 14545 } 14546 } 14547 14548 if (section_tags_count > 0) { 14549 $('.js-single_include_exclude_section_tags .js-sies_count_wrap').append($('.js-targeting_kitchen_sink .js-sies_count').clone().text(section_tags_count)); 14550 var section = $('.js-single_include_exclude_section_tags .js-sies_head'); 14551 if (!$(section).hasClass('sies_head-active')) { 14552 targeting_expand_section(section, expand_sections); 14553 } 14554 } 14555 } 14556 14557 $('.js-filter_item, .js-random_limit_input').change(function() { 14558 targeting_set_filters(false); 14559 }); 14560 14561 $('.js-sies_head').click(function() { 14562 if ($(this).hasClass('sies_head-active')) { 14563 targeting_collapse_section(this); 14564 } else { 14565 targeting_expand_section(this, true); 14566 } 14567 }); 14568 14569 $('.js-sies_collapse_all').click(function() { 14570 targeting_collapse_all(); 14571 }); 14572 14573 $('.js-sies_expand_all').click(function() { 14574 targeting_expand_all(); 14575 }); 14576 14577 var list_select_ajax = false; 14578 14579 if ($.isFunction($.fn.fancybox) ) { 14580 /* For create email step 2 */ 14581 $(".js-form_value_link").fancybox({ 14582 margin: 15, 14583 hideOnOverlayClick: false 14584 }); 14585 } 14586 14587 if ($.isFunction($.fn.select2)) { 14588 $('select.js-query_import_select').select2({ 14589 matcher: function (term, text, option) { 14590 if (term.length == 0) return true; 14591 14592 if(term.split(" ").length == 1){ 14593 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 14594 } 14595 14596 keywords=(term).split(/ |,|\[|\]|\(|\)/); 14597 // `data.text` is the text that is displayed for the data object 14598 // check if data.text contains all of keywords, if some is missing, return null 14599 for (var i = 0; i < keywords.length; i++) { 14600 14601 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 14602 // Return `null` if the term should not be displayed 14603 return null; 14604 14605 } 14606 // If here, data.text contains all keywords, so return it. 14607 return text; 14608 } 14609 }); 14610 } 14611 14612 14613 function getListNameFromSelect() { 14614 if ($('select.js-email-email_list').length) { 14615 return $('select.js-email-email_list').val(); 14616 } 14617 return $('.js-email-email_list').val(); 14618 } 14619 14620 14621 // ajax function 14622 var targetingAjaxLoad = function (load_all) { 14623 // NOTE: this same code gets duplicated in the inner function? 14624 var url_array = window.location.pathname.split('/'); 14625 url_array.pop(); 14626 url_array.push('list_select'); 14627 var url = url_array.join('/'); 14628 // Initial value is the currently selected list name 14629 // store as a constant here so we don't nuke it later. 14630 const LIST_NAME = getListNameFromSelect(); 14631 var value = LIST_NAME; 14632 14633 if (load_all || getURLParameter('show_all') == "true") { 14634 value = value + "&show_all=true"; 14635 } 14636 14637 list_select_ajax = $.get(url + '?list=' + value, function (data) { 14638 const IS_QUERY_BUILDER_MODE = $('.js-builder').length > 0; 14639 14640 // Emits metadata used to hide and show things based upon permissions, features, etc 14641 if (data["__meta_data"] && data["__meta_data"]["data"]) { 14642 CAN_JS_EVENT_BRIDGE.EmitListMetaDataChanged(data["__meta_data"]["data"]); 14643 } else { 14644 console.error("No meta data found in targeting AJAX response."); 14645 } 14646 14647 // Query builder mode 14648 if (IS_QUERY_BUILDER_MODE) { 14649 var url_array = window.location.pathname.split('/'); 14650 url_array.pop(); 14651 url_array.push('queries'); 14652 var url = url_array.join('/'); 14653 var value; 14654 14655 if ($('select.js-email-email_list').length) { 14656 value = $('select.js-email-email_list').val(); 14657 } else { 14658 value = $('.js-email-email_list').val(); 14659 } 14660 14661 $.get(url + '?list=' + value, function (data) { 14662 $('select.js-query_import_select').select2('destroy'); 14663 $('select.js-query_import_select').html('<option value="">[' + an_javascript_translation.choose_a_query + ']</option>' + data); 14664 14665 $('select.js-query_import_select').select2({ 14666 matcher: function (term, text, option) { 14667 if (term.length == 0) return true; 14668 14669 if (term.split(" ").length == 1) { 14670 return text.toUpperCase().indexOf(term.toUpperCase()) != -1; 14671 } 14672 14673 keywords = (term).split(/ |,|\[|\]|\(|\)/); 14674 // `data.text` is the text that is displayed for the data object 14675 // check if data.text contains all of keywords, if some is missing, return null 14676 for (var i = 0; i < keywords.length; i++) { 14677 14678 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 14679 // Return `null` if the term should not be displayed 14680 return null; 14681 14682 } 14683 // If here, data.text contains all keywords, so return it. 14684 return text; 14685 } 14686 }); 14687 14688 $('select.js-query_import_select').attr('disabled', false).removeClass('disabled'); 14689 14690 if ($('select.js-email-email_list option:selected').hasClass('network')) { 14691 var url_array = window.location.pathname.split('/'); 14692 url_array.pop(); 14693 url_array.push('collections'); 14694 var url = url_array.join('/'); 14695 var value; 14696 14697 if ($('select.js-email-email_list').length) { 14698 value = $('select.js-email-email_list').val(); 14699 } else { 14700 value = $('.js-email-email_list').val(); 14701 } 14702 14703 $.get(url + '?list=' + value, function (data) { 14704 //console.log(data.collections_apply.data); 14705 $('.js-queries_collection_apply').select2({ 14706 data: data.collections_apply.data, 14707 placeholder: an_javascript_translation.select_collection, 14708 allowClear: true 14709 }); 14710 }); 14711 } 14712 }) 14713 .error(function () { 14714 $('select.js-query_import_select').select2('destroy'); 14715 $('select.js-query_import_select').html('<option value="">[' + an_javascript_translation.an_error_occurred + ']</option>'); 14716 $('select.js-query_import_select').select2({ 14717 matcher: function (term, text, option) { 14718 if (term.length == 0) return true; 14719 14720 if (term.split(" ").length == 1) { 14721 return text.toUpperCase().indexOf(term.toUpperCase()) != -1; 14722 } 14723 14724 keywords = (term).split(/ |,|\[|\]|\(|\)/); 14725 // `data.text` is the text that is displayed for the data object 14726 // check if data.text contains all of keywords, if some is missing, return null 14727 for (var i = 0; i < keywords.length; i++) { 14728 14729 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 14730 // Return `null` if the term should not be displayed 14731 return null; 14732 14733 } 14734 // If here, data.text contains all keywords, so return it. 14735 return text; 14736 } 14737 }); 14738 14739 $('select.js-query_import_select').attr('disabled', false).removeClass('disabled'); 14740 }); 14741 14742 14743 $('.js-query_message').hide(); 14744 14745 if ($('select.js-email-email_list').length) { 14746 list_name = $('select.js-email-email_list').val(); 14747 $('.js-adc_opt_in_button').attr('href', '/groups/' + list_name + '/cross_data_opt_in'); 14748 } 14749 14750 // set up query builder, see partial returned from AJAX 14751 Function(data)(); 14752 14753 14754 14755 if ($('.js-query_params').val() != '' && $('.js-query_params').val() != '{}') { 14756 $('.js-builder').queryBuilder('setRules', JSON.parse($('.js-query_params').val())); 14757 $('form.js-edit_query').trigger('reinitialize.areYouSure'); 14758 $('form.js-edit_query').areYouSure({ 'addRemoveFieldsMarksDirty': true }); 14759 } 14760 14761 $('#builder .btn-group .active input').each(function () { 14762 if ($(this).val() == 'AND') { 14763 $(this).parent().parent().parent().parent().removeClass('query-builder-or-group'); 14764 $(this).parent().removeClass('query-builder-or-button'); 14765 } else { 14766 $(this).parent().parent().parent().parent().addClass('query-builder-or-group'); 14767 $(this).parent().addClass('query-builder-or-button'); 14768 } 14769 }); 14770 14771 $('.js-create_action_toolbox input, .js-form_value_link, .js-preview_no_save, .js-sies_head').removeClass('disabled').attr('disabled', false); 14772 14773 // Why are we destroying the function here? 14774 list_select_ajax = false;
14775 14776 14777 if ($('.js-email-email_list option:selected').hasClass('js-allow_phone_false')) { 14778 $('.js-phone_mobile_fields').hide(); 14779 } else { 14780 $('.js-phone_mobile_fields').show(); 14781 } 14782 14783 if ($.isEmptyObject($('.js-builder').queryBuilder('getRules'))) { 14784 if ($('.js-random_limit_input').val() == '') { 14785 $('.js-no_target_warning').show(); 14786 } else { 14787 $('.js-no_target_warning').hide(); 14788 $('.js-no_target_warning').removeClass('error_input'); 14789 $('.js-no_target_warning_checkbox').attr('checked', false); 14790 } 14791 } else { 14792 $('.js-no_target_warning').hide().removeClass('error_input'); 14793 $('.js-no_target_warning_checkbox').attr('checked', false); 14794 } 14795 14796 $('.js-builder').on('change click', function () { 14797 //console.log('change'); 14798 if ($.isEmptyObject($('.js-builder').queryBuilder('getRules'))) { 14799 if ($('.js-random_limit_input').val() == '') { 14800 $('.js-no_target_warning').show(); 14801 } else { 14802 $('.js-no_target_warning').hide(); 14803 $('.js-no_target_warning').removeClass('error_input'); 14804 $('.js-no_target_warning_checkbox').attr('checked', false); 14805 } 14806 } else { 14807 $('.js-no_target_warning').hide().removeClass('error_input'); 14808 $('.js-no_target_warning_checkbox').attr('checked', false); 14809 } 14810 }); 14811 if (typeof (always_include_tags_json_data) != 'undefined') { 14812 if ($('select.js-email-email_list').val() == 'subscribers') { 14813 $('.js-always_include_tags_wrap').hide(); 14814 } else { 14815 $('.js-always_include_tags_wrap').show(); 14816 } 14817 14818 $('.js-always-include-tags_power_query_select').val(''); 14819 $('.js-always-include-tags_power_query_select').select2({ 14820 data: always_include_tags_json_data, 14821 multiple: true, 14822 separator: '@!@', 14823 closeOnSelect: false, 14824 // text for loading more results 14825 //formatLoadMore : 'Loading more...', 14826 query: function (q) { 14827 // pageSize is number of results to show in dropdown 14828 var pageSize, 14829 results; 14830 pageSize = 500; 14831 results = $.grep(this.data, function (e) { 14832 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 14833 if (q.term.length == 0) return true; 14834 14835 if (q.term.split(" ").length == 1) { 14836 return e.text.toUpperCase().indexOf(q.term.toUpperCase()) != -1; 14837 } 14838 14839 keywords = (q.term).split(/ |,|\[|\]|\(|\)/); 14840 // `data.text` is the text that is displayed for the data object 14841 // check if data.text contains all of keywords, if some is missing, return null 14842 for (var i = 0; i < keywords.length; i++) { 14843 14844 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 14845 // Return `null` if the term should not be displayed 14846 return null; 14847 14848 } 14849 // If here, data.text contains all keywords, so return it. 14850 return e; 14851 }); 14852 q.callback({ 14853 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 14854 // retrieve more when user hits bottom 14855 more: results.length >= q.page * pageSize 14856 }); 14857 14858 //console.log(q.term); 14859 //console.log(this.data); 14860 14861 14862 }, 14863 placeholder: an_javascript_translation.click_to_make_your_selections 14864 }); 14865 14866 var selected_array = []; 14867 14868 $(always_include_tags_json_data).each(function () { 14869 //console.log(this); 14870 if (this.selected == "true") { 14871 //console.log('true'); 14872 selected_array.push({ "id": this.id, "text": this.text }); 14873 } else if (this.children) { 14874 $(this.children).each(function () { 14875 if (this.selected == "true") { 14876 selected_array.push({ "id": this.id, "text": this.text }); 14877 } 14878 }); 14879 } 14880 }); 14881 14882 //console.log(selected_array); 14883 14884 //if (selected_array.length) { 14885 $('.js-always-include-tags_power_query_select').select2("data", selected_array); 14886 14887 if (selected_array.length) { 14888 $('.js-always_include_tags_link').hide(); 14889 $('.js-always_include_tags').show(); 14890 } else { 14891 $('.js-always_include_tags_link').show(); 14892 $('.js-always_include_tags').hide(); 14893 } 14894 //} 14895 } 14896 14897 14898 $('.js-targeting-dummy').hide(); 14899 $('.js-targeting-dummy').siblings('.select2-container').not('.js-targeting-dummy').show(); 14900 } 14901 14902 // Targeting / Other Modes 14903 if (!IS_QUERY_BUILDER_MODE) { 14904 // TARGETING MODE 14905 // This is now handled via cross_data_opt_in_modal_controller.js 14906 // if ($('select.js-email-email_list').length) { 14907 // list_name = $('select.js-email-email_list').val();
14908 // $('.js-adc_opt_in_button').attr('href', '/groups/' + list_name + '/cross_data_opt_in'); 14909 // } 14910 14911 $.each(data, function (i, object) { 14912 //console.log(object.name); 14913 if (object.name == 'hidden') { 14914 $('.js-network_group_permission_show_hide').css('display', 'block'); 14915 // Handled via CanJsEventBridge events now 14916 // $('.js-cross_data_enabled, .js-cross_data_disabled, .js-partnerships_advertisement').hide(); 14917 // $('.js-predictive_email_open_score').removeClass('disabled').attr('disabled', false); 14918 var hidden_array = object.data; 14919 //console.log(hidden_array); 14920 $.each(hidden_array, function (i, e) { 14921 if (e == 'letters') { 14922 $('.js-letter_campaign_select').hide(); 14923 } else if (e == 'reports') { 14924 $('.js-reports_select').hide(); 14925 } else if (e == 'emails') { 14926 $('.js-emails_select').hide(); 14927 } else if (e == 'mobile_messages') { 14928 $('.js-mobile_messages_select').hide(); 14929 } else if (e == 'ladders') { 14930 $('.js-ladders_select').hide(); 14931 } else if (e == 'queries') { 14932 $('.js-queries_select').hide(); 14933 } else if (e == 'event_campaigns') { 14934 $('.js-event_campaigns_select').hide(); 14935 } else if (e == 'tags') { 14936 $('.js-tags_select, .js-always_include_tags_wrap').hide(); 14937 } else if (e == 'fundraisings') { 14938 $('.js-fundraising_select').hide(); 14939 } else if (e == 'groups') { 14940 $('.js-network_groups_select').hide(); 14941 } else if (e == 'collections') { 14942 $('.js-collections_select').hide(); 14943 } else if (e == 'phone_mobile_fields') { 14944 $('.js-phone_mobile_fields').hide(); 14945 } 14946 }); 14947 14948 if ($('select.js-email-email_list').val() == 'subscribers') { 14949 $('.js-filter_item_predictive_email_open_activity').hide(); 14950 $('.js-include-event-campaign-li').hide(); 14951 $('.js-exclude-event-campaign-li').hide(); 14952 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_received_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-ladder-li, .js-include-carriers-li').hide(); 14953 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_received_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-ladder-li, .js-exclude-carriers-li').hide(); 14954 $('.js-include-tags-li').hide(); 14955 $('.js-exclude-tags-li').hide(); 14956 $('.js-always_include_tags_wrap').hide(); 14957 $('.js-mobile_messages_select, .js-mobile_click_activity').hide(); 14958 } else { 14959 $('.js-filter_item_predictive_email_open_activity').show(); 14960 $('.js-include-event-campaign-li').show(); 14961 $('.js-exclude-event-campaign-li').show(); 14962 $('.js-include-tags-li').show(); 14963 $('.js-exclude-tags-li').show(); 14964 $('.js-always_include_tags_wrap').show(); 14965 $('.js-include-ladder-li').show(); 14966 $('.js-exclude-ladder-li').show(); 14967 $('.js-mobile_messages_select, .js-mobile_click_activity').show(); 14968 14969 if ($('.js-email-email_list option:selected').hasClass('js-carrier_enabled')) { 14970 $('.js-include-carriers-li, .js-exclude-carriers-li').show(); 14971 } else { 14972 $('.js-include-carriers-li, .js-exclude-carriers-li').hide(); 14973 } 14974 14975 if ($('.js-email-email_list option:selected').hasClass('network')) { 14976 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-email_received_children-li').show(); 14977 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-email_received_children-li').show(); 14978 } else { 14979 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-email_received_children-li').hide(); 14980 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-email_received_children-li').hide(); 14981 } 14982 } 14983 } else if (object.name == 'include[letter]' || object.name == 'exclude[letter]' || object.name == 'include[custom_fields]' || object.name == 'exclude[custom_fields]') { 14984 $('[name="' + object.name + '"]').html(object.html); 14985 } else if (object.name == 'collections_apply' && object.data) { 14986 $('[name="' + object.name + '"]').select2({ 14987 data: object.data, 14988 placeholder: an_javascript_translation.select_collection, 14989 allowClear: true 14990 }); 14991 } else { 14992 $('[name="' + object.name + '"]').val(''); 14993 $('[name="' + object.name + '"]').select2({ 14994 data: object.data, 14995 multiple: true, 14996 separator: '@!@', 14997 closeOnSelect: false, 14998 // text for loading more results 14999 //formatLoadMore : 'Loading more...', 15000 query: function (q) { 15001 // pageSize is number of results to show in dropdown 15002 var pageSize, 15003 results; 15004 pageSize = 500; 15005 results = $.grep(this.data, function (e) { 15006 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 15007 if (q.term.length == 0) return true; 15008 15009 if (q.term.split(" ").length == 1) { 15010 return e.text.toUpperCase().indexOf(q.term.toUpperCase()) != -1; 15011 } 15012 15013 keywords = (q.term).split(/ |,|\[|\]|\(|\)/); 15014 // `data.text` is the text that is displayed for the data object 15015 // check if data.text contains all of keywords, if some is missing, return null 15016 for (var i = 0; i < keywords.length; i++) { 15017 15018 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 15019 // Return `null` if the term should not be displayed 15020 return null; 15021 15022 } 15023 // If here, data.text contains all keywords, so return it. 15024 return e; 15025 }); 15026 q.callback({ 15027 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 15028 // retrieve more when user hits bottom 15029 more: results.length >= q.page * pageSize 15030 }); 15031 15032 //console.log(q.term); 15033 //console.log(this.data); 15034 15035 15036 }, 15037 placeholder: an_javascript_translation.click_to_make_your_selections, 15038 escapeMarkup: ($.grep(["[email]", "[email_open]", "[email_click]"], function (substring) { return object.name.indexOf(substring) > -1; }).length > 0) ? function (m) { return m; } : Select2.util.escapeMarkup 15039 }); 15040 15041 var selected_array = []; 15042 15043 $(object.data).each(function () { 15044 //console.log(this); 15045 if (this.selected == "true") { 15046 //console.log('true'); 15047 selected_array.push({ "id": this.id, "text": this.text }); 15048 } else if (this.children) { 15049 $(this.children).each(function () { 15050 if (this.selected == "true") { 15051 selected_array.push({ "id": this.id, "text": this.text }); 15052 } 15053 }); 15054 } 15055 }); 15056 15057 $('[name="' + object.name + '"]').select2("data", selected_array); 15058 15059 if (object.name == "always_include_tags[]" && selected_array.length) { 15060 $('.js-always_include_tags_link').hide(); 15061 $('.js-always_include_tags').show(); 15062 } else if (object.name == "always_include_tags[]") { 15063 $('.js-always_include_tags_link').show(); 15064 $('.js-always_include_tags').hide(); 15065 } 15066 //} 15067 15068 $('.js-targeting-dummy').hide(); 15069 $('.js-targeting-dummy').siblings('.select2-container').not('.js-targeting-dummy').show(); 15070 } 15071 15072 }); 15073 15074 $('.js-multi_select').select2({ 15075 placeholder: an_javascript_translation.click_to_make_your_selections, 15076 closeOnSelect: false, 15077 matcher: function (term, text, option) { 15078 if (term.length == 0) return true; 15079 15080 if (term.split(" ").length == 1) { 15081 return text.toUpperCase().indexOf(term.toUpperCase()) != -1; 15082 } 15083 15084 keywords = (term).split(/ |,|\[|\]|\(|\)/); 15085 // `data.text` is the text that is displayed for the data object 15086 // check if data.text contains all of keywords, if some is missing, return null 15087 for (var i = 0; i < keywords.length; i++) { 15088 15089 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 15090 // Return `null` if the term should not be displayed 15091 return null; 15092 15093 } 15094 // If here, data.text contains all keywords, so return it. 15095 return text; 15096 } 15097 }); 15098 15099 $('.js-email-include-letter option').each(function (i, e) { 15100 if (prev_include_val != null) { 15101 if ($(e).attr('value') == prev_include_val) { 15102 $(e).attr('selected', true); 15103 } else { 15104 $(e).attr('selected', false); 15105 } 15106 } 15107 }); 15108 15109 $('.js-email-exclude-letter option').each(function (i, e) { 15110 if (prev_exclude_val != null) { 15111 if ($(e).attr('value') == prev_exclude_val) { 15112 $(e).attr('selected', true); 15113 } else { 15114 $(e).attr('selected', false); 15115 } 15116 } 15117 }); 15118 15119 $('.js-email-include-letter').siblings('.can_select').children('.can_selectInner').html($('.js-email-include-letter option:selected').html()); 15120 $('.js-email-exclude-letter').siblings('.can_select').children('.can_selectInner').html($('.js-email-exclude-letter option:selected').html()); 15121 15122 $('.letter_campaign_select select').trigger('render'); 15123 15124 $('select.js-form_value_targeting_name').prepend('<option value=""></option>').trigger('render'); 15125 15126 $('.js-create_action_toolbox input, .js-form_value_link, .js-preview_no_save, .js-sies_head').removeClass('disabled').attr('disabled', false); 15127 $('span.js-zip_radius').removeClass('can_selectDisabled'); 15128 $(".js-form_value_link").fancybox({ 15129 margin: 15, 15130 hideOnOverlayClick: false 15131 }); 15132 15133 15134 15135 15136 // targeting_set_filters needs to be deffered a tick here 15137 // because stimulus controller value change callbacks get set in a microqueue 15138 // which means that controllers that are changing values on the list change 15139 // don't have time to update the values before the preview gets rendered. 15140 // so we end up with previews that don't match filter views. 15141 // One alterative to setting a timeout is to rerun this function in stimulus 15142 // but that is a big performance hit. 15143 // This is a workaround for that until we refactor this preview code. 15144 setTimeout(function () { 15145 targeting_set_filters(true); 15146 // This event should happen after everything has been handled. 15147 CAN_JS_EVENT_BRIDGE.EmitTargetingAjaxLoaded(data); 15148 }, 0) 15149 15150 list_select_ajax = false;
15151 } 15152 15153 // shows open verification dropdown if verified or unverified options are selected && $(this).val() != "all_opens" 15154 // $('select.js-target_opener_verification_type_select').each(function(i, e) { 15155 // console.log("this value:") 15156 // console.log($(this).val()) 15157 // if ($(this).hasClass('js-target_openers_option_selected') ) { 15158 // $(this).closest('.js-target_openers_select').show(); 15159 // } else { 15160 // $(this).closest('.js-target_openers_select').hide(); 15161 // } 15162 // }); 15163 15164 15165 }) 15166 .error(function (e) { 15167 console.error(e); 15168 if ($('.js-builder').length) { 15169 $('.js-query_message').text(an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again).show(); 15170 } 15171 var data = 15172 { 15173 "email-include-action-dummy": { 15174 "name": "email-include-action-dummy", 15175 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15176 }, 15177 "email-exclude-action-dummy": { 15178 "name": "email-exclude-action-dummy", 15179 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15180 }, 15181 "email-exclude-email-dummy": { 15182 "name": "email-exclude-email-dummy", 15183 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15184 }, 15185 "email-exclude-report-dummy": { 15186 "name": "email-exclude-report-dummy", 15187 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15188 }, 15189 "email-exclude-eventcampaign-dummy": { 15190 "name": "email-exclude-eventcampaign-dummy", 15191 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15192 }, 15193 "email-include-report-dummy": { 15194 "name": "email-include-report-dummy", 15195 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15196 }, 15197 "email-include-network-dummy": { 15198 "name": "email-include-network-dummy", 15199 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15200 }, 15201 "email-exclude-network-dummy": { 15202 "name": "email-exclude-network-dummy", 15203 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15204 }, 15205 "email-include-district-dummy": { 15206 "name": "email-include-district-dummy", 15207 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15208 }, 15209 "email-exclude-district-dummy": { 15210 "name": "email-exclude-district-dummy", 15211 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15212 }, 15213 "email-include-city-dummy": { 15214 "name": "email-include-city-dummy", 15215 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15216 }, 15217 "email-exclue-city-dummy": { 15218 "name": "email-exclude-city-dummy", 15219 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15220 }, 15221 "email-include-email-dummy": { 15222 "name": "email-include-email-dummy", 15223 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15224 }, 15225 "email-include-email_open-dummy": { 15226 "name": "email-include-email_open-dummy", 15227 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15228 }, 15229 "email-include-email_click-dummy": { 15230 "name": "email-include-email_click-dummy", 15231 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15232 }, 15233 "email-exclude-email_click-dummy": { 15234 "name": "email-exclude-email_click-dummy", 15235 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15236 }, 15237 "email-include-email_campaign-dummy": { 15238 "name": "email-include-email_campaign-dummy", 15239 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15240 }, 15241 "email-exclude-email_campaign-dummy": { 15242 "name": "email-exclude-email_campaign-dummy", 15243 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15244 }, 15245 "email-include-tags-dummy": { 15246 "name": "email-include-tags-dummy", 15247 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15248 }, 15249 "email-exclude-tags-dummy": { 15250 "name": "email-exclude-tags-dummy", 15251 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15252 }, 15253 "email-include-sources-dummy": { 15254 "name": "email-include-sources-dummy", 15255 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15256 }, 15257 "email-exclude-sources-dummy": { 15258 "name": "email-exclude-sources-dummy", 15259 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15260 }, 15261 "email-include-queries-dummy": { 15262 "name": "email-include-queries-dummy", 15263 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15264 }, 15265 "email-exclude-queries-dummy": { 15266 "name": "email-exclude-queries-dummy", 15267 "html": "<option disabled value=\"\">" + an_javascript_translation.there_was_an_error_save_or_reload_the_page_to_try_again + "</option>" 15268 } 15269 }; 15270 15271 $.each(data, function (i, object) { 15272 $('[name="' + object.name + '"]').html(object.html); 15273 }); 15274 15275 //$('select.js-targeting-dummy').select2({ placeholder: "An error occured -- please try again." }); 15276 15277 list_select_ajax = false;
15278 $('.js-create_action_toolbox input, .js-form_value_link, .js-preview_no_save, .js-sies_head').removeClass('disabled').attr('disabled', false); 15279 $(".js-form_value_link").fancybox({ 15280 margin: 15, 15281 hideOnOverlayClick: false 15282 }); 15283 15284 //targeting_set_filters(true); 15285 }); 15286 }; 15287 15288 var prepareForTargetingAjaxLoad = function(load_all) { 15289 $('.js-include-event-campaign-li select.can_select, .js-exclude-event-campaign-li select.can_select').not('.hasCustomSelect').customSelect({customClass:"can_select"}); 15290 if ($('select.js-email-email_list').val() != '') { 15291 if (!$('.js-no_targeting').length) { 15292 $('.js-include_exclude_wrap').animate({opacity: 1}, 1000).removeClass('disabled'); 15293 $('.js-multi_select').each(function(i,o) { 15294 $(o).select2('destroy'); 15295 }); 15296 $('.js-include_exclude_wrap select, .js-include_exclude_wrap input, .js-form_value input').attr('disabled', false ); 15297 15298 prev_include_val = $('select.js-email-include-letter').val(); 15299 prev_exclude_val = $('select.js-email-exclude-letter').val(); 15300 $('.js-targeting-dummy').siblings('.select2-container').not('.js-targeting-dummy').hide(); 15301 15302 if (list_select_ajax) { 15303 list_select_ajax.abort(); 15304 } 15305 15306 $('.js-dynamic_targeting_select').not('span').html('<option disabled value="">' + an_javascript_translation.loading + '</option>'); 15307 $('.js-dynamic_targeting_select span').html(an_javascript_translation.loading); 15308 $('.js-create_action_toolbox input, .js-form_value_link, .js-preview_no_save, .js-sies_head').addClass('disabled').attr('disabled',true); 15309 $(".js-form_value_link").unbind('click.fb'); 15310 $('select.js-query_import_select').attr('disabled','disabled').addClass('disabled'); 15311 15312 if ($('.js-builder').length) { 15313 $('.js-query_message').text(an_javascript_translation.loading).show(); 15314 } 15315 15316 targetingAjaxLoad(load_all); 15317 15318 if ($('select.js-email-email_list').val() == 'subscribers') { 15319 $('.js-include-event-campaign-li').hide(); 15320 $('.js-exclude-event-campaign-li').hide(); 15321 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-ladder-li, .js-include-carriers-li, .js-include-email_received_children-li').hide(); 15322 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-ladder-li, .js-exclude-carriers-li, .js-exclude-email_received_children-li').hide(); 15323 $('.js-include-tags-li').hide(); 15324 $('.js-exclude-tags-li').hide(); 15325 $('.js-always_include_tags_wrap').hide(); 15326 } else { 15327 $('.js-include-event-campaign-li').show(); 15328 $('.js-exclude-event-campaign-li').show(); 15329 $('.js-include-tags-li').show(); 15330 $('.js-exclude-tags-li').show(); 15331 $('.js-always_include_tags_wrap').show(); 15332 $('.js-include-ladder-li').show(); 15333 $('.js-exclude-ladder-li').show(); 15334 15335 if ($('.js-email-email_list option:selected').hasClass('js-carrier_enabled')) { 15336 $('.js-include-carriers-li, .js-exclude-carriers-li').show(); 15337 } else { 15338 $('.js-include-carriers-li, .js-exclude-carriers-li').hide(); 15339 } 15340 15341 if ($('.js-email-email_list option:selected').hasClass('network')) { 15342 $('.js-include-network-li, .js-include-email_received_children-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-email_received_children-li').show(); 15343 $('.js-exclude-network-li, .js-exclude-email_received_children-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-email_received_children-li').show(); 15344 } else { 15345 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-email_received_children-li').hide(); 15346 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-email_received_children-li').hide(); 15347 } 15348 } 15349 } 15350 15351 15352 } else { 15353 $('.js-include_exclude_wrap').animate({opacity: 0.3}, 1000).addClass('disabled'); 15354 $('.js-include_exclude_wrap select, .js-include_exclude_wrap input, .js-form_value input').attr('disabled', true ); 15355 $('.js-dynamic_targeting_select').html('<option disabled value="">' + an_javascript_translation.choose_an_email_list_above_to_get_started + '</option>'); 15356 $('.js-include-event-campaign-li').hide(); 15357 $('.js-exclude-event-campaign-li').hide(); 15358 $('.js-include-network-li, .js-include-email_open_children-li, .js-include-email_click_children-li, .js-include-mobile_message_click_children-li, .js-include-ladder-li, .js-include-carriers-l
15358i, .js-include-email_received_children-li').hide(); 15359 $('.js-exclude-network-li, .js-exclude-email_open_children-li, .js-exclude-email_click_children-li, .js-exclude-mobile_message_click_children-li, .js-exclude-ladder-li, .js-exclude-carriers-li, .js-exclude-email_received_children-li').hide(); 15360 $('.js-include-tags-li').hide(); 15361 $('.js-exclude-tags-li').hide(); 15362 $('.js-always_include_tags_wrap').hide(); 15363 $('.js-create_action_toolbox input, .js-form_value_link, .js-preview_no_save, .js-sies_head').removeClass('disabled').attr('disabled',false); 15364 $(".js-form_value_link").fancybox({ 15365 margin: 15, 15366 hideOnOverlayClick: false 15367 }); 15368 15369 if ($('.js-builder').length) { 15370 $('.js-query_message').text(an_javascript_translation.select_a_group_above_to_get_started).show(); 15371 } 15372 15373 $('select.js-query_import_select').select2('destroy').html('<option></option>').select2().attr('disabled','disabled').addClass('disabled'); 15374 } 15375 }; 15376 15377 $('.js-list_select_load_all').click(function() { 15378 var list_select_load_all = confirm(an_javascript_translation.list_select_load_all_warning); 15379 if (list_select_load_all == true) { 15380 prepareForTargetingAjaxLoad(true); 15381 } 15382 15383 }); 15384 15385 if ($('.js-email-email_list').length) { 15386 prepareForTargetingAjaxLoad(false); 15387 15388 $('select.js-email-email_list').change(function() { 15389 if ($('.js-builder').length) { 15390 $('.js-builder').queryBuilder('destroy'); 15391 $('.js-query_params').val(''); 15392 } 15393 15394 prepareForTargetingAjaxLoad(false); 15395 15396 }); 15397 } 15398 15399 $('.js-create_email2_form, .js-edit_mobile_form').areYouSure({'addRemoveFieldsMarksDirty':true}); 15400 15401 $('.js-import_query').click(function() { 15402 if ($('select.js-query_import_select').val() != '') { 15403 $.get($('select.js-query_import_select').val(), function(data) { 15404 $('select.js-query_import_select').select2('val',''); 15405 15406 $('.rule-filter-container select').each(function() { 15407 if ($(this).val() == -1) { 15408 $(this).parent().parent().remove(); 15409 } 15410 }); 15411 15412 $('.rule-value-container select.required, .rule-value-container input.required').each(function() { 15413 if ($(this).val() == '' || $(this).val() == null) { 15414 $(this).parentsUntil('.rule-container').parent().remove(); 15415 } 15416 }); 15417 15418 $('.rules-group-container .rules-group-container').each(function() { 15419 if (!$(this).find('.rule-filter-container').length) { 15420 $(this).remove(); 15421 } 15422 }); 15423 15424 var query_builder_rules = JSON.stringify($('.js-builder').queryBuilder('getRules')); 15425 query_builder_rules = query_builder_rules.replace(/\@\!\@/g, ','); 15426 query_builder_rules = JSON.parse(query_builder_rules); 15427 if (query_builder_rules.rules) { 15428 query_builder_rules.rules.push(JSON.parse(data)); 15429 } else { 15430 query_builder_rules = JSON.parse(data); 15431 } 15432 15433 15434 $('.js-builder').queryBuilder('setRules', query_builder_rules); 15435 15436 $('.js-builder .btn-group .active input').each(function() { 15437 if ($(this).val() == 'AND') { 15438 $(this).parent().parent().parent().parent().removeClass('query-builder-or-group'); 15439 $(this).parent().removeClass('query-builder-or-button'); 15440 } else { 15441 $(this).parent().parent().parent().parent().addClass('query-builder-or-group'); 15442 $(this).parent().addClass('query-builder-or-button'); 15443 } 15444 }); 15445 15446 }).error(function() { 15447 }); 15448 } 15449 15450 }); 15451 15452 15453 $('.js-create_email2_form .js-create_action_toolbox input').click(function() { 15454 $('select.js-form-country').each(function() { 15455 if ($(this).val() == '') { 15456 $(this).val('US'); 15457 } 15458 }); 15459 }); 15460 15461 $('.js-preview_and_save').click(function(e) { 15462 if (!$(this).parents('form').hasClass('dirty')) { 15463 e.preventDefault(); 15464 $('.js-targeting_recalculate_modal_trigger').fancybox({ 15465 margin: 15, 15466 hideOnOverlayClick: false 15467 }).trigger('click'); 15468 } 15469 }); 15470 15471 $('.js-preview_and_save_confirm').click(function() { 15472 $('.js-create_email2_form').submit(); 15473 }); 15474 15475 can_report_select_options = '<option value=""></option><option value="Option1">' + an_javascript_translation.option + ' 1</option><option value="Option2">' + an_javascript_translation.option + ' 2</option><option value="Option3">' + an_javascript_translation.option + ' 3</option>'; 15476 15477 /* Reports: Add a new data field button */ 15478 $('.js-add_more_report_fields').click(function() { 15479 15480 $('.js-report_field_options').append('<div class="js-report_option col3of12 report_option"><label>' + an_javascript_translation.field + ' ' + ($('.js-report_option').length + 1) + '</label><div class="relative"><i class="fas fa-grip-vertical"></i> <select class="append_select js-append_select js-select_search can_select" name="name' + ($('.js-report_option').length + 1) + '">' + can_report_select_options + '</select></div></div>'); 15481 15482 // init select2 on newly added fields 15483 $('select.js-append_select').not('select.select2-offscreen').each(function(){ 15484 select2_init($(this), true); 15485 }); 15486 }); 15487 15488 $(".js-copy_layout_button").on('click', function(ev) { 15489 if ($("select.js-copy_from").val() != '') { 15490 var confirm_layout = false;
15491 confirm_layout = confirm(an_javascript_translation.copying_another_reports_layout_will_overwrite_the_data_fields); 15492 if (confirm_layout) { 15493 submitClicked = "copy_layout_form" 15494 $("#copy_layout_form").submit() 15495 } else { 15496 ev.preventDefault(); 15497 return false; 15498 } 15499 } 15500 }); 15501 15502 /* Reports: Clear data fields */ 15503 15504 $('.js-clear_report_fields').click(function() { 15505 $("select.js-select_search").select2("val", ""); 15506 }); 15507 15508 // Make Reports fields draggable 15509 $( ".js-report_field_options" ).sortable({ 15510 handle: ".fa-grip-vertical", 15511 placeholder: "report_option--highlight" 15512 }); 15513 $( ".js-report_field_options" ).disableSelection(); 15514 15515 // AN-2188 Ranked Choice Sortable 15516 // Initialize sortable with the handle 15517 ranked_choice_sortable_init = function() { 15518 //console.log($(".js-rc_wrap")); 15519 var draggedItem = null; 15520 $(".js-rc_wrap").not('.js-visual_form_target .js-rc_wrap').each(function() { 15521 //console.log(this); 15522 if ($(this).hasClass('js-sortable')) { 15523 $(this).find('.js-rc_item').each(function() { 15524 $(this).off('dragstart, dragenter, dragend, dragover, dragleave, drop'); 15525 }); 15526 } 15527 15528 $(this).addClass('js-sortable'); 15529 var container = this; 15530 15531 15532 15533 15534 $(this).find('.js-rc_item').each(function() { 15535 // add class for extra padding on edit 15536 if ($(this).has($('.sample_field'))) { 15537 $(this).addClass('mb20'); 15538 } 15539 15540 $(this).on('dragstart', function() { 15541 //console.log('dragstart'); 15542 //console.log(this); 15543 draggedItem = this; 15544 container = $(this).parents('.js-rc_wrap'); 15545 //console.log(container); 15546 //console.log(draggedItem); 15547 15548 $(draggedItem).after('<div class="rc_option__placeholder" draggable="true" ondragover="event.preventDefault()" ondrop="handle_rc_drop(event)"></div>'); 15549 15550 setTimeout(function() {$(draggedItem).addClass('dragging').hide();}, 0); 15551 }); 15552 15553 $(this).on('dragend', function() { 15554 //console.log('dragend'); 15555 //console.log(draggedItem); 15556 draggedItem = null; 15557 $(this).show().removeClass('dragging'); 15558 15559 $('.rc_option__placeholder').remove(); 15560 15561 updateSelectValues($(this).parents(".js-rc_wrap")); 15562 }); 15563 15564 $(this).on('dragover', function(e) { 15565 15566 e.preventDefault(); 15567 //console.log('dragover'); 15568 $(this).addClass('drag-over'); 15569 }); 15570 15571 $(this).on('dragenter', function(e) { 15572 15573 e.preventDefault(); 15574 //console.log('dragenter'); 15575 $(this).addClass('drop'); 15576 $(this).removeClass('drag-over'); 15577 15578 var placeholder = $('.rc_option__placeholder'); 15579 if (!placeholder.length) return; 15580 15581 if ($(this).index() < $(placeholder).index()) { 15582 $(this).before(placeholder); 15583 } else { 15584 $(this).after(placeholder); 15585 } 15586 }); 15587 15588 $(this).on('dragleave', function(e) { 15589 e.preventDefault(); 15590 //console.log('dragleave'); 15591 //$(this).removeClass('drop drag-over'); 15592 }); 15593 15594 handle_rc_drop = function(e) { 15595 15596 //console.log(e); 15597 15598 e.preventDefault(); 15599 //console.log('drop'); 15600 //console.log(draggedItem); 15601 $(this).removeClass('drag-over'); 15602 $('.rc_option__placeholder').replaceWith(draggedItem); 15603 $(draggedItem).show(); 15604 container = $(draggedItem).parents('.js-rc_wrap'); 15605 15606 //console.log(container); 15607 //console.log(draggedItem); 15608 15609 if (draggedItem) { 15610 if (this === container.firstElementChild) { 15611 container.insertBefore(draggedItem, this); 15612 } else if (this === container.lastElementChild) { 15613 container.appendChild(draggedItem); 15614 } else if (this.nextSibling) { 15615 container.insertBefore(draggedItem, this); 15616 } 15617 } 15618 15619 draggedItem = null; 15620 } 15621 15622 $(this).on('drop', function(e) { 15623 //console.log($(this).parents('.js-rc_wrap')); 15624 container = $(this).parents('.js-rc_wrap'); 15625 handle_rc_drop(e, this); 15626 } ); 15627 15628 $(this).find('js-rc_select').on('mousedown', function() { 15629 e.stopPropagation(); 15630 }); 15631 }); 15632 }); 15633 } 15634 15635 ranked_choice_sortable_init(); 15636 15637 // when a select is changed, move the list item to the right spot 15638 $("body").on("change", ".js-rc_wrap select.js-rc_select", function () { 15639 var selectedValue = parseInt($(this).val()); // make sure it's a number 15640 var selectedItem = $(this).closest("li");
15641 var ul = $(selectedItem).closest(".js-rc_wrap"); 15642 var currentIndex = ul.find('li').index(selectedItem); // get current spot in the list 15643 15644 // move to the correct position in the ul 15645 if (selectedValue === ul.find('li.js-rc_item').length) { 15646 // if the selected value is the last position, append the item (wasn't working with the other logic if the last choice was selected) 15647 ul.append(selectedItem); 15648 } else if (selectedValue - 1 > currentIndex) { 15649 // if choosing a lower position in the list, prevents weirdness 15650 ul.find('li.js-rc_item').eq(selectedValue - 1).after(selectedItem); 15651 } else { 15652 ul.find('li.js-rc_item').eq(selectedValue - 1).before(selectedItem); 15653 } 15654 15655 updateSelectValues($(this).parents(".js-rc_wrap")); 15656 }); 15657 15658 15659 15660 // update all selects to the correct value when sorted/chosen 15661 updateSelectValues = function($element) { 15662 //console.log($element.find(".js-rc_option").length); 15663 $element.find(".js-rc_option").each(function (index) { 15664 $(this).find("select.js-rc_select").val(index + 1).trigger('keyup'); 15665 }); 15666 } 15667 15668 15669 15670 /* show/hide confirmation buttons for mass operation modals */ 15671 $('.js-report_mass_operation_start').click(function() { 15672 $(this).fadeOut(function() { 15673 $(this).siblings('.js-report_mass_operation_options').fadeIn(); 15674 }); 15675 }); 15676 15677 $('.js-report_mass_operation_option_cancel').click(function() { 15678 $(this).parent().fadeOut(function() { 15679 $(this).siblings('.js-report_mass_operation_start').fadeIn(); 15680 }); 15681 }); 15682 15683 if ($.isFunction($.fn.fancybox) ) { 15684 $("a.js-subscribe_all_modal_link, a.js-unsubscribe_all_modal_link, a.js-add_tags_all_link, a.js-remove_tags_all_link, a.js-rewrite_custom_fields_link, a.js-duplicate_modal_link").not('.disabled').fancybox({ 15685 onClosed: function() { 15686 $('.js-confirm_wrap').hide(); 15687 $('.js-start_button').show(); 15688 $('.js-report_subscribe_collection_modal, .js-apply_collection_modal').hide(); 15689 $('.js-report_subscribe_modal, .js-duplicate_modal').show(); 15690 $('.js-all_multi, .js-add_tags_select, .js-apply_collection_modal select').select2('val',''); 15691 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 15692 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 15693 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 15694 }, 15695 margin: 15, 15696 hideOnOverlayClick: false 15697 }); 15698 15699 $("a.js-add_tags_all_link_recurring, a.js-remove_tags_all_link_recurring").not('.disabled').fancybox({ 15700 onClosed: function() { 15701 $('.js-confirm_wrap').hide(); 15702 $('.js-start_button').show(); 15703 $('.js-report_subscribe_collection_modal, .js-apply_collection_modal').hide(); 15704 $('.js-report_subscribe_modal, .js-duplicate_modal').show(); 15705 $('.js-all_multi, .js-apply_collection_modal select').select2('val',''); 15706 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 15707 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 15708 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 15709 }, 15710 margin: 15, 15711 hideOnOverlayClick: false 15712 }); 15713 } 15714 15715 /* generic show/hide confirmation buttons */ 15716 $('body').on('click', '.js-launch_cancel_confirm', function() { 15717 $(this).parent().fadeOut(function() { 15718 $(this).siblings('.js-cancel_confirm_options').fadeIn(); 15719 }); 15720 }); 15721 15722 $('body').on('click', '.js-cancel_confirm_options-cancel', function() { 15723 $(this).parents('.js-cancel_confirm_options').fadeOut(function() { 15724 $(this).siblings('.js-launch_cancel_confirm-wrap').fadeIn(); 15725 }); 15726 }); 15727 15728 /* survey pages *************************************************/ 15729 15730 if ($('.js-survey_custom_field_autocomplete').length) { 15731 $('.js-survey_custom_field_autocomplete').devbridgeAutocomplete({ 15732 serviceUrl: '/groups/' + $('.js-survey_custom_field_autocomplete').data('group_id') + '/field_search' 15733 }); 15734 } 15735 15736 15737 $('.js-survey_add_condition').click(function() { 15738 $('.js-custom_field_autocomplete').devbridgeAutocomplete('dispose'); 15739 $('.js-survey_or_condition_box_template .js-survey_or_condition_box').clone().appendTo($('.js-survey_conditions_wrapper')); 15740 $('.js-survey_custom_field_autocomplete').devbridgeAutocomplete({ 15741 serviceUrl: '/groups/' + $('.js-survey_custom_field_autocomplete').data('group_id') + '/field_search' 15742 }); 15743 $('.js-survey_conditional_link-edit').show(); 15744 $('.js-survey_conditional_link-make').hide(); 15745 }); 15746 15747 $('body').on('click', '.js-survey_or_condition_box_remove', function() { 15748 $(this).parents('.js-survey_or_condition_box').remove(); 15749 if ($('.js-survey_or_condition_box').length <= 1) { //remember to account for the dummy in the modal we copy from.... 15750 $('.js-survey_conditional_link-edit').hide(); 15751 $('.js-survey_conditional_link-make').show(); 15752 } 15753 }); 15754 15755 15756 15757 /* unsubscribe change email section **************************************************/ 15758 15759 if ($('#subscription_single_update_form').length) { 15760 15761 if ($('.js-unsub_email_change_input').val().toLowerCase() != $('.js-unsub_email_change_input').data('current-email').toLowerCase()) { 15762 $('.js-unsub_email_change_submit').prop('disabled',false).removeClass('disabled'); 15763 } else { 15764 $('.js-unsub_email_change_submit').prop('disabled',true).addClass('disabled'); 15765 } 15766 15767 $('.js-unsub_email_change_input').on('keyup', function() { 15768 if ($(this).val().toLowerCase() != $(this).data('current-email').toLowerCase()) { 15769 $('.js-unsub_email_change_submit').prop('disabled',false).removeClass('disabled'); 15770 } else { 15771 $('.js-unsub_email_change_submit').prop('disabled',true).addClass('disabled'); 15772 } 15773 }); 15774 } 15775 15776 /* recurring reports validation */ 15777 15778 $(".js-recurring_report_email, .js-reccuring_report_datepick").on('focusin', function() { 15779 tooltipFunction($(this).parent().find( '.js-tooltip' )); 15780 }); 15781 15782 $(".js-recurring_report_email").on('focusout', function() { 15783 remove_tooltip(); 15784 }); 15785 15786 var form_builder_temp_render; 15787 var disabled_form_builder_output = function() { 15788 $('.js-visual_form_target input').addClass('disabled'); 15789 $('.js-visual_form_target textarea').addClass('disabled'); 15790 $('.js-visual_form_target select').addClass('disabled'); 15791 $('.js-visual_form_target label').addClass('disabled'); 15792 $('.js-visual_form_target input').attr('disabled','disabled'); 15793 $('.js-visual_form_target textarea').attr('disabled','disabled'); 15794 $('.js-visual_form_target select').attr('disabled','disabled'); 15795 $('.js-visual_form_target input[type=text]').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 15796 $('.js-visual_form_target textarea').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 15797 $('.js-visual_form_target select').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 15798 //$("html, body").css({'overflow':'visible'}); 15799 /* Remove the label if it's empty */ 15800 $('.js-visual_form_target label.check_radio_label').each(function() { 15801 if ($(this).html() == '') { 15802 $(this).hide(); 15803 $(this).next().css('width','100%'); 15804 } 15805 }); 15806 15807 if ($.isFunction($.fn.customSelect) ) { 15808 $("select.can_select").not('.hasCustomSelect').not('.js-form_builder_modal select.can_select').customSelect({customClass:"can_select"}); 15809 } 15810 15811 $('.js-create_action_form').trigger('checkform.areYouSure'); 15812 } 15813 15814 render_formbuilder = function () { 15815 //console.log($('')) 15816 $('.js-visual_form_target').html($('.js-render').val()); 15817 $('.js-visual_form_target #corecountry').parent().prev().before('<span class="international_link-wrap js-international_link-wrap disabled mb10"><a class="international_link js-international_link disabled">' + an_javascript_translation.not_in_the_us + '</a></span>').next().remove().next().remove(); 15818 15819 //sub our core field HTML for their backend representations 15820 //console.log('start');
15821 core_fields_temp_render = $('<div id="core_temp_render">' + $('.js-render').val() + '</div>'); 15822 15823 var first_name = core_fields_temp_render.find('#corefirstname').parent(); 15824 //console.log(first_name.find('input').data('always') == true); 15825 var first_name_required = ''; 15826 var first_name_always_show = ''; 15827 var first_name_regex = ''; 15828 var first_name_label = ''; 15829 var first_name_placeholder = ''; 15830 15831 if (first_name.find('.required').length) { 15832 first_name_required = '_required'; 15833 } 15834 15835 if (first_name.find('input').data('always') == true) { 15836 first_name_always_show = '_alwaysshow'; 15837 } 15838 15839 if (first_name.find('input').data('regex')) { 15840 first_name_regex = '_regex##' + first_name.find('input').data('regex') + '##'; 15841 } 15842 15843 if (first_name.find('input').parents('.control-group').find('label').length) { 15844 first_name_label = '_label%%' + first_name.find('input').parents('.control-group').find('label').text() + '%%'; 15845 } 15846 15847 if (first_name.find('input').attr('placeholder')) { 15848 first_name_placeholder = '_placeholder!!' + first_name.find('input').attr('placeholder') + '!!'; 15849 } 15850 15851 first_name.replaceWith("@@first_name" + first_name_required + first_name_always_show + first_name_regex + first_name_label + first_name_placeholder + "@@"); 15852 15853 var last_name = core_fields_temp_render.find('#corelastname').parent(); 15854 //console.log(last_name.find('input').data('always') == true); 15855 var last_name_required = ''; 15856 var last_name_always_show = ''; 15857 var last_name_regex = ''; 15858 var last_name_label = ''; 15859 var last_name_placeholder = ''; 15860 15861 if (last_name.find('.required').length) { 15862 last_name_required = '_required'; 15863 } 15864 15865 if (last_name.find('input').data('always') == true) { 15866 last_name_always_show = '_alwaysshow'; 15867 } 15868 15869 if (last_name.find('input').data('regex')) { 15870 last_name_regex = '_regex##' + last_name.find('input').data('regex') + '##'; 15871 } 15872 15873 if (last_name.find('input').parents('.control-group').find('label').length) { 15874 last_name_label = '_label%%' + last_name.find('input').parents('.control-group').find('label').text() + '%%'; 15875 } 15876 15877 if (last_name.find('input').attr('placeholder')) { 15878 last_name_placeholder = '_placeholder!!' + last_name.find('input').attr('placeholder') + '!!'; 15879 } 15880 15881 last_name.replaceWith("@@last_name" + last_name_required + last_name_always_show + last_name_regex + last_name_label + last_name_placeholder + "@@"); 15882 15883 15884 var email = core_fields_temp_render.find('#coreemail').parent(); 15885 //console.log(email.find('input').data('always') == true); 15886 var email_required = '_required'; //email must be required, no always show option 15887 var email_regex = ''; 15888 var email_label = ''; 15889 var email_placeholder = ''; 15890 15891 if (email.find('input').data('regex')) { 15892 email_regex = '_regex##' + email.find('input').data('regex') + '##'; 15893 } 15894 15895 if (email.find('input').parents('.control-group').find('label').length) { 15896 email_label = '_label%%' + email.find('input').parents('.control-group').find('label').text() + '%%'; 15897 } 15898 15899 if (email.find('input').attr('placeholder')) { 15900 email_placeholder = '_placeholder!!' + email.find('input').attr('placeholder') + '!!'; 15901 } 15902 15903 email.replaceWith("@@email" + email_required + email_regex + email_label + email_placeholder + "@@"); 15904 15905 var street = core_fields_temp_render.find('#corestreet').parent(); 15906 //console.log(street.find('input').data('always') == true); 15907 var street_required = ''; 15908 var street_always_show = ''; 15909 var street_regex = ''; 15910 var street_label = ''; 15911 var street_placeholder = ''; 15912 15913 if (street.find('.required').length) { 15914 street_required = '_required'; 15915 } 15916 15917 if (street.find('input').data('always') == true) { 15918 street_always_show = '_alwaysshow'; 15919 } 15920 15921 if (street.find('input').data('regex')) { 15922 street_regex = '_regex##' + street.find('input').data('regex') + '##'; 15923 } 15924 15925 if (street.find('input').parents('.control-group').find('label').length) { 15926 street_label = '_label%%' + street.find('input').parents('.control-group').find('label').text() + '%%'; 15927 } 15928 15929 if (street.find('input').attr('placeholder')) { 15930 street_placeholder = '_placeholder!!' + street.find('input').attr('placeholder') + '!!'; 15931 } 15932 15933 street.replaceWith("@@street" + street_required + street_always_show + street_regex + street_label + street_placeholder + "@@"); 15934 15935 var city = core_fields_temp_render.find('#corecity').parent(); 15936 //console.log(city.find('input').data('always') == true); 15937 var city_required = ''; 15938 var city_always_show = ''; 15939 var city_regex = ''; 15940 var city_label = ''; 15941 var city_placeholder = ''; 15942 15943 if (city.find('.required').length) { 15944 city_required = '_required'; 15945 } 15946 15947 if (city.find('input').data('always') == true) { 15948 city_always_show = '_alwaysshow'; 15949 } 15950 15951 if (city.find('input').data('regex')) { 15952 city_regex = '_regex##' + city.find('input').data('regex') + '##'; 15953 } 15954 15955 if (city.find('input').parents('.control-group').find('label').length) { 15956 city_label = '_label%%' + city.find('input').parents('.control-group').find('label').text() + '%%'; 15957 } 15958 15959 if (city.find('input').attr('placeholder')) { 15960 city_placeholder = '_placeholder!!' + city.find('input').attr('placeholder') + '!!'; 15961 } 15962 15963 city.replaceWith("@@city" + city_required + city_always_show + city_regex + city_label + city_placeholder + "@@"); 15964 15965 var zip_code = core_fields_temp_render.find('#corezipcode').parent(); 15966 //console.log(zip_code.find('input').data('always') == true); 15967 var zip_code_required = ''; 15968 var zip_code_always_show = ''; 15969 var zip_code_regex = ''; 15970 var zip_code_label = ''; 15971 var zip_code_placeholder = ''; 15972 15973 if (zip_code.find('.required').length) { 15974 zip_code_required = '_required'; 15975 } 15976 15977 if (zip_code.find('input').data('always') == true) { 15978 zip_code_always_show = '_alwaysshow'; 15979 } 15980 15981 if (zip_code.find('input').data('regex')) { 15982 zip_code_regex = '_regex##' + zip_code.find('input').data('regex') + '##'; 15983 } 15984 15985 if (zip_code.find('input').parents('.control-group').find('label').length) { 15986 zip_code_label = '_label%%' + zip_code.find('input').parents('.control-group').find('label').text() + '%%'; 15987 } 15988 15989 if (zip_code.find('input').attr('placeholder')) { 15990 zip_code_placeholder = '_placeholder!!' + zip_code.find('input').attr('placeholder') + '!!'; 15991 } 15992 15993 zip_code.replaceWith("@@zip_code" + zip_code_required + zip_code_always_show + zip_code_regex + zip_code_label + zip_code_placeholder + "@@"); 15994 15995 var phone = core_fields_temp_render.find('#corephone').parent();
15996 //console.log(phone.find('input').data('always') == true); 15997 var phone_required = ''; 15998 var phone_always_show = ''; 15999 var phone_regex = ''; // phones don't allow regex 16000 var phone_label = ''; 16001 var phone_placeholder = ''; // phones don't allow placeholder changes 16002 16003 if (phone.find('.required').length) { 16004 phone_required = '_required'; 16005 } 16006 16007 if (phone.find('input').data('always') == true) { 16008 phone_always_show = '_alwaysshow'; 16009 } 16010 16011 if (phone.find('input').parents('.control-group').find('label').length) { 16012 phone_label = '_label%%' + phone.find('input').parents('.control-group').find('label').text() + '%%'; 16013 } 16014 16015 phone.replaceWith("@@phone" + phone_required + phone_always_show + phone_regex + phone_label + phone_placeholder + "@@"); 16016 16017 16018 //console.log(core_fields_temp_render.html()); 16019 //console.log(core_fields_temp_render.find('#coresmscheckbox')); 16020 16021 //keep sms and country the old style code, since they don't expose these options 16022 var sms_checkbox = core_fields_temp_render.find('li[data-identifier="core_sms_checkbox"]'); 16023 //console.log(sms_checkbox); 16024 sms_checkbox.replaceWith("@@sms_checkbox@@"); 16025 16026 16027 var country = core_fields_temp_render.find('#corecountry').parent(); 16028 country.prev().remove(); 16029 country.replaceWith("@@country_required@@"); 16030 16031 //console.log(core_fields_temp_render.html()); 16032 16033 $('#visual_form_input').val(core_fields_temp_render.html()); 16034 16035 disabled_form_builder_output(); 16036 16037 //ranked_choice_sortable_init(); 16038 16039 var input_name_array = []; 16040 form_builder_temp_render = $('<div id="temp_render">' + $('#visual_form_input').val() + '</div>'); 16041 form_builder_temp_render.find('input[type="text"], textarea').each(function() { 16042 input_name_array.push($(this).attr('name')); 16043 }); 16044 16045 if (input_name_array.length) { 16046 get_regex_and_execute_callback("/groups/" + $('select.js-sponsor-group-select').val() + "/questions/field_validation", input_name_array, apply_fields_formbuilder_callback); 16047 } 16048 } 16049 16050 /* Fancybox */ 16051 if ($.isFunction($.fn.fancybox) ) { 16052 16053 /* For create survey page */ 16054 $(".js-form_builder").click(function(){ 16055 // go to the top of the page on click 16056 $('html, body').animate({scrollTop:0}, 0); 16057 return false; 16058 }); 16059 $(".js-form_builder").fancybox({ 16060 onComplete: function() { 16061 //console.log('show'); 16062 var fileref = document.createElement("link"); 16063 fileref.setAttribute("rel", "stylesheet"); 16064 fileref.setAttribute("type", "text/css"); 16065 fileref.setAttribute("href", "/css/bootstrap.min.css"); 16066 fileref.setAttribute("id", "bootstrap-css"); 16067 16068 var fileref2 = document.createElement("link"); 16069 fileref2.setAttribute("rel", "stylesheet"); 16070 fileref2.setAttribute("type", "text/css"); 16071 fileref2.setAttribute("href", "/css/bootstrap-responsive.min.css"); 16072 fileref2.setAttribute("id", "bootstrap-responsive-css"); 16073 16074 document.getElementsByTagName("head")[0].appendChild(fileref) 16075 document.getElementsByTagName("head")[0].appendChild(fileref2) 16076 16077 //$('#style-forms-css').remove(); 16078 16079 //$("html, body").css({'overflow':'hidden'}); 16080 $('body').addClass('form_builder_edit'); 16081 window.setTimeout(function() { 16082 $('#fancybox-wrap').css('top','20px'); 16083 }, 500); 16084 16085 //console.log('yes'); 16086 targets.bind( 'mouseenter', function() 16087 { 16088 tooltipFunction(this); 16089 }); 16090 //$('#main_css')[0].disabled = true; 16091 //$('#redactor_css')[0].disabled = true; 16092 //$('#fancybox_css')[0].disabled = true; 16093 }, 16094 onClosed: function() { 16095 //console.log('hide'); 16096 $('#bootstrap-css').remove(); 16097 $('#bootstrap-responsive-css').remove(); 16098 $('body').removeClass('form_builder_edit'); 16099 16100/* 16101 var fileref3 = document.createElement("link"); 16102 fileref3.setAttribute("rel", "stylesheet"); 16103 fileref3.setAttribute("type", "text/css"); 16104 fileref3.setAttribute("href", "/css/style-forms.css"); 16105 fileref3.setAttribute("id", "style-forms-css"); 16106 16107 document.getElementsByTagName("head")[0].appendChild(fileref3) 16108 */ 16109 16110 //$('#main_css')[0].disabled = false; 16111 //$('#redactor_css')[0].disabled = false; 16112 //$('#fancybox_css')[0].disabled = false; 16113 render_formbuilder(); 16114 }, 16115 width: '100%', 16116 height: 'auto', 16117 autoDimensions: false, 16118 centerOnScroll: false, 16119 margin: 15, 16120 hideOnOverlayClick: false 16121 }); 16122 16123 /* General */ 16124 fancy_link_general_init = function() { 16125 $(".js-fancylink").fancybox({ 16126 onComplete: function() { 16127 $('body').addClass('body_has_modal'); 16128 16129 if ($(this).data('controller') && $(this).data('controller').includes('fancybox')) { 16130 console.log('Default legacy Fancybox handler is being used instead. Ensure you are not using `js-fancylink` on elements for new Fancybox controllers.'); 16131 } 16132 }, 16133 onClosed: function() { 16134 $('.js-file_delete_link').css('display','inline'); 16135 $('.js-edit_confirm_delete').css('display','none'); 16136 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
16137 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 16138 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 16139 $('body').removeClass('form_builder_edit'); 16140 }, 16141 margin: 15, 16142 hideOnOverlayClick: false 16143 }); 16144 } 16145 16146 fancy_link_general_init(); 16147 16148 /* saved responses modal */ 16149 $(".js-fancylink-saved-responses").fancybox({ 16150 onComplete: function() { 16151 $('body').addClass('body_has_modal'); 16152 }, 16153 onClosed: function() { 16154 $('.js-saved_response_wrap').removeClass('hide'); 16155 $('.js-edit_response_wrap').addClass('hide'); 16156 $('.js-add_response_wrap').addClass('hide'); 16157 }, 16158 margin: 15, 16159 hideOnOverlayClick: false 16160 }); 16161 16162 /* START preview as another user *******************************************/ 16163 16164 $('.js-mobile_count_wrapper .js-mobile_body_count').each(function() { 16165 $(this).charCount({ 16166 allowed: 160, 16167 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 16168 wrapperSelector: '.js-email_body', 16169 hostname: $('.js-mobile_custom_shortlink').val(), 16170 regex: "url_strict" 16171 }); 16172 }); 16173 16174 // calls mobile_messages/:id/ajax_preview on /write page, outputs the preview partial for the phone number 16175 $('.js-preview_mobile_submit').click(function () { 16176 url = $(this).data('preview-url') + "?preview_as_mobile_number=" + encodeURIComponent($('.js-preview_as_mobile_number').val()); 16177 $('.js-preview_js_wrapper').html('<p class="centertext">' + an_javascript_translation.loading + '</p>'); 16178 $.get(url, function (data) { 16179 // console.log(url); 16180 $('.js-preview_js_wrapper').html(data); 16181 $('.js-preview_js_wrapper .js-mobile_body_count').each(function () { 16182 $(this).charCount({ 16183 allowed: 160, 16184 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 16185 wrapperSelector: '.js-email_body', 16186 hostname: $('.js-mobile_custom_shortlink').val(), 16187 regex: "url_strict" 16188 }); 16189 }); 16190 }); 16191 }); 16192 16193 $('.js-preview_email_submit').click(function() { 16194 url = $(this).data('preview-url') + "?sample_email=" + encodeURIComponent($('.js-preview_as_email_address').val()); 16195 $('.js-preview_js_wrapper').html('<p class="centertext">' + an_javascript_translation.loading + '</p>'); 16196 $.get(url, function(data) { 16197 //console.log(url); 16198 $('.js-preview_js_wrapper').html(data); 16199 // Stimulus automatically detects new controllers when elements are added to DOM 16200 // No need to manually call load() - it watches the document 16201 $('.js-preview_js_wrapper .js-mobile_body_count').each(function() { 16202 $(this).charCount({ 16203 allowed: 160, 16204 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 16205 wrapperSelector: '.js-email_body', 16206 hostname: $('.js-mobile_custom_shortlink').val(), 16207 regex: "url_strict" 16208 }); 16209 }); 16210 }); 16211 }); 16212 16213 // opens the preview modal on /write, preview 16214 if (getURLParameter('preview')) { 16215 $('.js-open_email_preview_modal').trigger('click'); 16216 $('.js-preview_email_submit').trigger('click'); 16217 $('.js-preview_mobile_submit').trigger('click'); 16218 } 16219 /* END preview as another user *******************/ 16220 16221 /* start preview query ************************************/ 16222 16223 var view_query_init = function() { 16224 var query_mount_loaded = false; 16225 $(".js-open_query_modal").each(function() { 16226 $that = $(this); 16227 $(this).fancybox({ 16228 onStart: function() { 16229 $('.js-view_query_loading, .js-view_query_loading_text').show(); 16230 $('.js-view_query').css('visibility','hidden'); 16231 }, 16232 onComplete: function() { 16233 $('body').addClass('body_has_modal'); 16234 var $query_params_input = $(this.orig[0]).find('.js-query_params'); 16235 if (!query_mount_loaded) { 16236 $.getScript($query_params_input.data('query_mount_url'), function(data) { 16237 //console.log('load'); 16238 query_mount_loaded = true; 16239 view_query_setup($query_params_input); 16240 }) 16241 .fail(function(jqxhr, settings, exception) { 16242 console.log(jqxhr); 16243 console.log(settings); 16244 console.log(exception); 16245 $('.js-view_query_error_text').show(); 16246 $('.js-view_query_loading_text').hide(); 16247 }); 16248 } else { 16249 view_query_setup($query_params_input); 16250 } 16251 }, 16252 onClosed: function() { 16253 $('.js-file_delete_link').css('display','inline'); 16254 $('.js-edit_confirm_delete').css('display','none'); 16255 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
16256 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 16257 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 16258 $('body').removeClass('form_builder_edit'); 16259 $('.js-view_query_error_text').hide(); 16260 $('.js-query_name').text(''); 16261 $('.js-edit_query_link').attr('href','javascript:void(0);'); 16262 if (query_mount_loaded) { 16263 $('.js-builder').queryBuilder('reset'); 16264 } 16265 }, 16266 margin: 15, 16267 hideOnOverlayClick: false, 16268 href: $that.data('modal') //this could also just be hardcoded as "#open_query_modal" 16269 }); 16270 }); 16271 } 16272 16273 view_query_init(); 16274 16275 var view_query_setup = function($query_params_input) { 16276 //console.log('hi'); 16277 $('.js-builder').queryBuilder('setRules', JSON.parse($query_params_input.val())); 16278 $('.js-view_query').css('visibility','visible'); 16279 $('.js-view_query_loading, .js-view_query_loading_text').hide(); 16280 $('.js-query_name').text($query_params_input.data('name')); 16281 $('.js-edit_query_link').attr('href',$query_params_input.data('query-edit-link')); 16282 $('#builder .btn-group .active input').each(function() { 16283 if ($(this).val() == 'AND') { 16284 $(this).parent().parent().parent().parent().removeClass('query-builder-or-group'); 16285 $(this).parent().removeClass('query-builder-or-button'); 16286 } else { 16287 $(this).parent().parent().parent().parent().addClass('query-builder-or-group'); 16288 $(this).parent().addClass('query-builder-or-button'); 16289 } 16290 }); 16291 $(".rule-operator-container *, .rule-filter-container *, .rule-value-container *, .rules-group-header *").prop("disabled", true); 16292 $(".rule-value-container a, #load_query button, .rules-group-body .drag-handle, .rule-value-container .js-uuid_uploaded_wrapper small").not('.select2-choice').remove(); 16293 }; 16294 16295 /* end preview query ************************************/ 16296 $(".js-fancylink.js-ladder-modal").fancybox({ 16297 centerOnScroll: true, 16298 hideOnOverlayClick: false, 16299 padding: 0, 16300 margin: 15, 16301 onStart: function() { 16302 $("#fancybox-wrap").addClass("fancybox-wrap-ladder"); 16303 $("#fancybox-overlay").addClass("fancybox-overlay-ladder"); 16304 }, 16305 hideOnOverlayClick: false 16306 }); 16307 16308 $(".js-new_upload_modal_btn").fancybox({ 16309 onClosed: function() { 16310 //console.log('closed'); 16311 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 16312 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 16313 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 16314 }, 16315 margin: 15, 16316 hideOnOverlayClick: false 16317 }); 16318 16319 $('.js-fancylink_change_default').fancybox({ 16320 onStart: function() { 16321 $('.js-menu_tapped, .js-navatar_wrap').removeClass('menu_tapped js-menu_tapped'); 16322 if ($('select.js-edit_profile_menu_group_homepage_select_loading').length) { 16323 $.get('/groups/select?mode=start_page', function(data) { 16324 selectmenu = data; 16325 $('select.js-edit_profile_menu_group_homepage_select').parent().replaceWith(data); 16326 $('select.js-edit_profile_menu_group_homepage_select').select2({ 16327 matcher: function (term, text, option) { 16328 if (term.length == 0) return true; 16329 16330 if(term.split(" ").length == 1){ 16331 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 16332 } 16333 16334 keywords=(term).split(/ |,|\[|\]|\(|\)/); 16335 // `data.text` is the text that is displayed for the data object 16336 // check if data.text contains all of keywords, if some is missing, return null 16337 for (var i = 0; i < keywords.length; i++) { 16338 16339 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 16340 // Return `null` if the term should not be displayed 16341 return null; 16342 16343 } 16344 // If here, data.text contains all keywords, so return it. 16345 return text; 16346 } 16347 }); 16348 }) 16349 .fail(function() { 16350 //change 16351 $('.js-edit_profile_menu_group_homepage_select .select2-chosen').html(an_javascript_translation.an_error_occurred_refresh_and_try_again); 16352 }); 16353 } 16354 }, 16355 onClosed: function() { 16356 $('.js-file_delete_link').css('display','inline'); 16357 $('.js-edit_confirm_delete').css('display','none'); 16358 }, 16359 margin: 15, 16360 hideOnOverlayClick: false 16361 }); 16362 16363 } 16364 16365 // email targeting form/value input UI 16366 formValueLinkClick = function() { 16367 $(".js-email-include-form_value, .js-email-exclude-form_value").on('click', '.js-form_value_link', function() { 16368 $form_value_link_clicked = $(this); 16369 if (typeof($form_value_link_clicked.data('name')) !== 'undefined') { 16370 $($form_value_link_clicked.attr('href') + ' select.js-form_value_targeting_name').val($form_value_link_clicked.data('name')); 16371 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_value').val($form_value_link_clicked.data('value')); 16372 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').html('Save'); 16373 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').addClass('form_value_targeting_save js-form_value_targeting_save'); 16374 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').removeClass('disabled'); 16375 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').attr('disabled', false); 16376 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').attr('onClick','parent.$.fancybox.close();'); 16377 //formValueEditButtonClick(); 16378 } else { 16379 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').removeClass('form_value_targeting_save js-form_value_targeting_save'); 16380 $($form_value_link_clicked.attr('href') + ' select.js-form_value_targeting_name').val(''); 16381 //$form_value_link_clickeds).attr('href') + ' span.js-form_value_targeting_name').html(''); 16382 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_value').val(''); 16383 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').html('Add'); 16384 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').addClass('disabled'); 16385 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').attr('disabled', true); 16386 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').attr('href','javascript:void(0);'); 16387 $($form_value_link_clicked.attr('href') + ' .js-form_value_targeting_add').attr('onClick',''); 16388 } 16389 16390 $($(this).attr('href') + ' select.js-form_value_targeting_name').trigger('update'); 16391 $('select.js-form_value_targeting_name').trigger('render').trigger('change'); 16392 }); 16393 16394 $('.js-form_value_targeting_entry_remove').click(function() { 16395 $(this).parent().remove(); 16396 targeting_set_filters(false); 16397 }); 16398 } 16399 16400 formValueLinkClick(); 16401 // if value field is filled out, activate button 16402 $('select.js-form_value_targeting_name, .js-form_value_targeting_value').on('keyup change', function() { 16403 var id = $(this).parent().parent().parent().attr('id'); 16404 16405 // Show field value suggestions 16406 var field = $('#' + id + ' select.js-form_value_targeting_name').val(); 16407 var fieldName = $('#' + id + ' .js-form_value_targeting_name .select2-chosen').text(); 16408 var value = $('#' + id + ' .js-form_value_targeting_value').val(); 16409 var suggestions = field_value_suggestions[field]; 16410 if(suggestions) { suggestions = suggestions.suggestions; } 16411 if (suggestions && value.length === 0) { 16412 // Show suggestions 16413 $('.js-field_name').html(field_value_suggestions[field].field_display); 16414 $('.js-field_value_suggestions').empty(); 16415 suggestions.forEach(function(suggestion) { 16416 var suggestionLink = $('<a>', { 16417 text: `${suggestion.name}`, 16418 }) 16419 suggestionLink.on('click, mousedown', function() { 16420 $('#' + id + ' .js-form_value_targeting_value').val(suggestion.value).trigger('change'); 16421 $('.js-field_value_suggestions_container').slideUp(); 16422 }) 16423 $('.js-field_value_suggestions').append(suggestionLink); 16424 }); 16425 $('.js-field_value_suggestions_container').slideDown(); 16426 } 16427 else { 16428 // Hide suggestions 16429 $('.js-field_value_suggestions_container').slideUp(); 16430 } 16431 // note: 'test' is the js-select_search dropdown value 16432 // var test = $('#' + id + ' .form_value_targeting_name .select2-chosen').text(); 16433 // console.log(test); 16434 // console.log($('#' + id + ' .form_value_targeting_name').val()); 16435 if ($('#' + id + ' select.js-form_value_targeting_name').val() == '' || $('#' + id + ' .js-form_value_targeting_value').val() == '') { 16436 $('#' + id + ' .js-form_value_targeting_add').addClass('disabled'); 16437 $('#' + id + ' .js-form_value_targeting_add').attr('disabled', true); 16438 $('#' + id + ' .js-form_value_targeting_add').attr('href','javascript:void(0);'); 16439 $('#' + id + ' .js-form_value_targeting_add').attr('onClick',''); 16440 } else { 16441 $('#' + id + ' .js-form_value_targeting_add').removeClass('disabled'); 16442 $('#' + id + ' .js-form_value_targeting_add').attr('disabled', false); 16443 $('#' + id + ' .js-form_value_targeting_add').attr('onClick','parent.$.fancybox.close();'); 16444 } 16445 }); 16446 // green button in modal 16447 $('.js-form_value_targeting_add').click(function() { 16448 16449 if (!$(this).hasClass('disabled')) { 16450 //console.log('click'); 16451 var id = $(this).parent().parent().attr('id'); 16452 var name_val = $('#' + id + ' select.js-form_value_targeting_name').val(); 16453 var value_val = $('#' + id + ' .js-form_value_targeting_value').val(); 16454 16455 if ($(this).hasClass('js-form_value_targeting_save')) { 16456 $form_value_link_clicked.html(an_javascript_translation.target_activists_who_filled_field + ' <span class="form_value_targeting_entry_name js-form_value_targeting_entry_name"><strong>' + name_val + '</strong></span> ' + an_javascript_translation.with_the_value + ' <span class="form_value_targeting_entry_value js-form_value_targeting_entry_value"><strong>' + value_val + '</strong></span> <a href="javascript:void(0);" class="form_value_targeting_entry_remove js-form_value_targeting_entry_remove"></a><input type="hidden" name="' + id + '[]" value="{' + name_val + '@-@' + value_val + '}" />'); 16457 //console.log(form_value_link_clicked.data('name')); 16458 $form_value_link_clicked.data('name', name_val); 16459 //console.log($form_value_link_clicked.data('name', name_val)); 16460 $form_value_link_clicked.data('value', value_val); 16461 } else { 16462 $('.' + id).append('<div href="#' + id + '" data-name="' + name_val + '" data-value="' + value_val + '" class="form_value_link js-form_value_link form_value_targeting_entry js-form_value_targeting_entry">' + an_javascript_translation.target_activists_who_filled_field + ' <span class="form_value_targeting_entry_name js-form_value_targeting_entry_name"><strong>' + name_val + '</strong></span> ' + an_javascript_translation.with_the_value + ' <span class="form_value_targeting_entry_value js-form_value_targeting_entry_value"><strong>' + value_val + '</strong></span> <a href="javascript:void(0);" class="form_value_targeting_entry_remove js-form_value_targeting_entry_remove"></a><input type="hidden" name="' + id + '[]" value="{' + name_val + '@-@' + value_val + '}" /></div>'); 16463 } 16464 16465 $(".js-form_value_link").fancybox({ 16466 margin: 15, 16467 hideOnOverlayClick: false 16468 }); 16469 //formValueLinkClick(); 16470
16471 $('.js-form_value_targeting_entry_remove').click(function() { 16472 $(this).parent().remove(); 16473 targeting_set_filters(false); 16474 }); 16475 16476 targeting_set_filters(false); 16477 } 16478 }); 16479 16480 $('a.js-form_value_link').click(function() { 16481 //$('.js-form_value_targeting_name').val('').trigger('render'); 16482 $('select.js-form_value_targeting_name').val('').trigger('change'); 16483 $('.js-form_value_targeting_value').val(''); 16484 $('.js-form_value_targeting_add').addClass('disabled'); 16485 $('.js-form_value_targeting_add').attr('disabled', true); 16486 $('.js-form_value_targeting_add').attr('href','javascript:void(0);'); 16487 $('.js-form_value_targeting_add').attr('onClick',''); 16488 $('.js-form_value_targeting_add').removeClass('form_value_targeting_save js-form_value_targeting_save'); 16489 }); 16490 16491 16492 //formValueEditButtonClick(); 16493 16494 //radio/checkbox no label fix 16495 $('form .control-group').each(function() { 16496 if ($(this).children('label.check_radio_label').html() == '' || $(this).children('label.check_radio_label').length == 0) { 16497 $(this).children('label.check_radio_label').hide(); 16498 $(this).children('.check_radio_field').css('width','100%'); 16499 } 16500 }); 16501 16502 /* Form builder and custom fields *********************************/ 16503 16504 $('.js-new_question_modal_btn').click(function() { 16505 $('.js-new_custom_field_modal .js-question_add').remove(); 16506 $('select.js-custom_field_modal_add').val(''); 16507 $('.js-new_custom_field_type_wrap .can_selectInner').html(an_javascript_translation.choose_field_type); 16508 }); 16509 16510 var load_prebuilt_questions = function() { 16511 //console.log('load questions'); 16512 if ($('.js-fill-petition-target-name').length) { 16513 var type = "signature"; 16514 } else if ($('.js-event_page, .js-event_campaign_step4').length) { 16515 var type = 'rsvp'; 16516 } else if ($('.js-sign-form-title').length) { 16517 var type = 'answer'; 16518 } else if ($('.js-call_target').length) { 16519 var type = 'call_campaign'; 16520 } else if ($('.js-letter_target').length) { 16521 var type = 'letter'; 16522 } else if ($('.js-survey_page_heading').length) { 16523 var type = 'survey_page'; 16524 } 16525 16526 var phone = { 16527 admin_title: an_javascript_translation.mobile_number, 16528 fields: { 16529 id: { 16530 label: "", 16531 name: "id", 16532 type: "hidden", 16533 value: "core_phone" 16534 16535 }, 16536 identifier: { 16537 name: "identifier", 16538 type: "hidden", 16539 value: "core_phone" 16540 }, 16541 label: { 16542 label: an_javascript_translation.label_optional, 16543 name: "label", 16544 type: "input", 16545 value: null 16546 }, 16547 placeholder: { 16548 label: an_javascript_translation.placeholder_optional, 16549 name: "placeholder", 16550 type: "hidden", 16551 value: an_javascript_translation.phone 16552 }, 16553 required: { 16554 label: an_javascript_translation.required, 16555 name: "required", 16556 type: "checkbox", 16557 value: false 16558 }, 16559 always: { 16560 label: an_javascript_translation.always_show, 16561 name: "always", 16562 type: "checkbox", 16563 value: false 16564 } 16565 }, 16566 question_id: "core_phone", 16567 question_type: "Text Field", 16568 title: "Text Input" 16569 } 16570 16571 var sms_checkbox = { 16572 admin_title: an_javascript_translation.mobile_opt_in, 16573 fields: { 16574 id: { 16575 label: "", 16576 name: "id", 16577 type: "hidden", 16578 value: "core_sms_checkbox" 16579 16580 }, 16581 identifier: { 16582 name: "identifier", 16583 type: "hidden", 16584 value: "core_sms_checkbox" 16585 }, 16586 label: { 16587 label: an_javascript_translation.label_optional, 16588 name: "label", 16589 type: "hidden", 16590 value: null 16591 }, 16592 checkboxes: { 16593 label: "Checkboxes", 16594 name: "checkboxes", 16595 type: "hidden", 16596 value: ["" + an_javascript_translation.sms_checkbox + " " + an_javascript_translation.sms_checkbox_data + "|core_sms_checkbox"] 16597 }, 16598 required: { 16599 label: an_javascript_translation.required, 16600 name: "required", 16601 type: "hidden", 16602 value: false 16603 }, 16604 checked: { 16605 label: an_javascript_translation.pre_checked, 16606 name: "checked", 16607 type: "hidden", 16608 value: false 16609 } 16610 }, 16611 question_id: "core_sms_checkbox", 16612 question_type: "Checkbox Group", 16613 title: "Multiple Checkboxes" 16614 } 16615 16616 16617 if (typeof prebuilt_questions == "undefined" || prebuilt_questions == null) { 16618 prebuilt_questions = []; 16619 } 16620
16621 if(!$('.js-sponsor-group-select option:selected').hasClass('js-allow_phone_false') && !$('.js-event_campaign_step4 .js-action_owner-select select option:selected').hasClass('js-allow_phone_false')) { 16622 prebuilt_questions.unshift(phone, sms_checkbox); 16623 } 16624 16625 if (type) { 16626 var first_name = { 16627 admin_title: an_javascript_translation.first_name, 16628 fields: { 16629 id: { 16630 label: "", 16631 name: "id", 16632 type: "hidden", 16633 value: "core_first_name" 16634 16635 }, 16636 identifier: { 16637 name: "identifier", 16638 type: "hidden", 16639 value: "core_first_name" 16640 }, 16641 label: { 16642 label: an_javascript_translation.label_optional, 16643 name: "label", 16644 type: "input", 16645 value: null 16646 }, 16647 placeholder: { 16648 label: an_javascript_translation.placeholder_optional, 16649 name: "placeholder", 16650 type: "input", 16651 value: an_javascript_translation.first_name 16652 }, 16653 required: { 16654 label: an_javascript_translation.required, 16655 name: "required", 16656 type: "checkbox", 16657 value: false 16658 }, 16659 always: { 16660 label: an_javascript_translation.always_show, 16661 name: "always", 16662 type: "checkbox", 16663 value: false 16664 }, 16665 regex: { 16666 label: an_javascript_translation.validation_regular_expression, 16667 name: "regex", 16668 type: "input", 16669 value: null 16670 } 16671 }, 16672 question_id: "core_first_name", 16673 question_type: "Text Field", 16674 title: "Text Input" 16675 } 16676 16677 var last_name = { 16678 admin_title: an_javascript_translation.last_name, 16679 fields: { 16680 id: { 16681 label: "", 16682 name: "id", 16683 type: "hidden", 16684 value: "core_last_name" 16685 16686 }, 16687 identifier: { 16688 name: "identifier", 16689 type: "hidden", 16690 value: "core_last_name" 16691 }, 16692 label: { 16693 label: an_javascript_translation.label_optional, 16694 name: "label", 16695 type: "input", 16696 value: null 16697 }, 16698 placeholder: { 16699 label: an_javascript_translation.placeholder_optional, 16700 name: "placeholder", 16701 type: "input", 16702 value: an_javascript_translation.last_name 16703 }, 16704 required: { 16705 label: an_javascript_translation.required, 16706 name: "required", 16707 type: "checkbox", 16708 value: false 16709 }, 16710 always: { 16711 label: an_javascript_translation.always_show, 16712 name: "always", 16713 type: "checkbox", 16714 value: false 16715 }, 16716 regex: { 16717 label: an_javascript_translation.validation_regular_expression, 16718 name: "regex", 16719 type: "input", 16720 value: null 16721 } 16722 }, 16723 question_id: "core_last_name", 16724 question_type: "Text Field", 16725 title: "Text Input" 16726 } 16727 16728 var email = { 16729 admin_title: an_javascript_translation.email, 16730 fields: { 16731 id: { 16732 label: "", 16733 name: "id", 16734 type: "hidden", 16735 value: "core_email" 16736 16737 }, 16738 identifier: { 16739 name: "identifier", 16740 type: "hidden", 16741 value: "core_email" 16742 }, 16743 label: { 16744 label: an_javascript_translation.label_optional, 16745 name: "label", 16746 type: "input", 16747 value: null 16748 }, 16749 placeholder: { 16750 label: an_javascript_translation.placeholder_optional, 16751 name: "placeholder", 16752 type: "input", 16753 value: an_javascript_translation.email 16754 }, 16755 required: { 16756 label: an_javascript_translation.required, 16757 name: "required", 16758 type: "checkbox-disabled", 16759 value: true 16760 }, 16761 regex: { 16762 label: an_javascript_translation.validation_regular_expression, 16763 name: "regex", 16764 type: "input", 16765 value: null 16766 } 16767 }, 16768 question_id: "core_email", 16769 question_type: "Text Field", 16770 title: "Text Input" 16771 } 16772 16773 var address = { 16774 admin_title: an_javascript_translation.street_address, 16775 fields: { 16776 id: { 16777 label: "", 16778 name: "id", 16779 type: "hidden", 16780 value: "core_street" 16781 16782 }, 16783 identifier: { 16784 name: "identifier", 16785 type: "hidden", 16786 value: "core_street" 16787 }, 16788 label: {
16789 label: an_javascript_translation.label_optional, 16790 name: "label", 16791 type: "input", 16792 value: null 16793 }, 16794 placeholder: { 16795 label: an_javascript_translation.placeholder_optional, 16796 name: "placeholder", 16797 type: "input", 16798 value: an_javascript_translation.street_address 16799 }, 16800 required: { 16801 label: an_javascript_translation.required, 16802 name: "required", 16803 type: "checkbox", 16804 value: false 16805 }, 16806 always: { 16807 label: an_javascript_translation.always_show, 16808 name: "always", 16809 type: "checkbox", 16810 value: false 16811 }, 16812 regex: { 16813 label: an_javascript_translation.validation_regular_expression, 16814 name: "regex", 16815 type: "input", 16816 value: null 16817 } 16818 }, 16819 question_id: "core_street", 16820 question_type: "Text Field", 16821 title: "Text Input" 16822 } 16823 16824 var city = { 16825 admin_title: an_javascript_translation.city, 16826 fields: { 16827 id: { 16828 label: "", 16829 name: "id", 16830 type: "hidden", 16831 value: "core_city" 16832 16833 }, 16834 identifier: { 16835 name: "identifier", 16836 type: "hidden", 16837 value: "core_city" 16838 }, 16839 label: { 16840 label: an_javascript_translation.label_optional, 16841 name: "label", 16842 type: "input", 16843 value: null 16844 }, 16845 placeholder: { 16846 label: an_javascript_translation.placeholder_optional, 16847 name: "placeholder", 16848 type: "input", 16849 value: an_javascript_translation.city 16850 }, 16851 required: { 16852 label: an_javascript_translation.required, 16853 name: "required", 16854 type: "checkbox", 16855 value: false 16856 }, 16857 always: { 16858 label: an_javascript_translation.always_show, 16859 name: "always", 16860 type: "checkbox", 16861 value: false 16862 }, 16863 regex: { 16864 label: an_javascript_translation.validation_regular_expression, 16865 name: "regex", 16866 type: "input", 16867 value: null 16868 } 16869 }, 16870 question_id: "core_city", 16871 question_type: "Text Field", 16872 title: "Text Input" 16873 } 16874 16875 var zip_code = { 16876 admin_title: an_javascript_translation.zip_postal_code, 16877 fields: { 16878 id: { 16879 label: "", 16880 name: "id", 16881 type: "hidden", 16882 value: "core_zip_code" 16883 16884 }, 16885 identifier: { 16886 name: "identifier", 16887 type: "hidden", 16888 value: "core_zip_code" 16889 }, 16890 label: { 16891 label: an_javascript_translation.label_optional, 16892 name: "label", 16893 type: "input", 16894 value: null 16895 }, 16896 placeholder: { 16897 label: an_javascript_translation.placeholder_optional, 16898 name: "placeholder", 16899 type: "input", 16900 value: an_javascript_translation.zip_code 16901 }, 16902 required: { 16903 label: an_javascript_translation.required, 16904 name: "required", 16905 type: "checkbox", 16906 value: false 16907 }, 16908 always: { 16909 label: an_javascript_translation.always_show, 16910 name: "always", 16911 type: "checkbox", 16912 value: false 16913 }, 16914 regex: { 16915 label: an_javascript_translation.validation_regular_expression, 16916 name: "regex", 16917 type: "input", 16918 value: null 16919 } 16920 }, 16921 question_id: "core_zip_code", 16922 question_type: "Text Field", 16923 title: "Text Input" 16924 } 16925 16926 16927 16928 var country = { 16929 admin_title: an_javascript_translation.country, 16930 fields: { 16931 id: { 16932 label: "", 16933 name: "id", 16934 type: "hidden", 16935 value: "core_country" 16936 16937 }, 16938 identifier: { 16939 name: "identifier", 16940 type: "hidden", 16941 value: "core_country" 16942 }, 16943 label: { 16944 label: an_javascript_translation.label_optional, 16945 name: "label", 16946 type: "hidden", 16947 value: null 16948 }, 16949 placeholder: { 16950 label: an_javascript_translation.placeholder_optional, 16951 name: "placeholder", 16952 type: "hidden", 16953 value: an_javascript_translation.country 16954 }, 16955 required: { 16956 label: an_javascript_translation.required, 16957 name: "required", 16958 type: "checkbox-disabled", 16959 value: true 16960 }, 16961 options: { 16962 label: "", 16963 type: "hidden", 16964 value: [an_javascript_translation.country + " *|country"] 16965 } 16966 }, 16967 question_id: "core_country", 16968 question_type: "Dropdown Menu", 16969 title: "Select Basic" 16970 } 16971 16972 if (!prebuilt_questions) { 16973 prebuilt_questions = []; 16974 } 16975 16976 if ($('.js-survey_questions_form_builder').length) { 16977 prebuilt_questions.unshift(first_name, last_name, address, city, zip_code); 16978 } else { 16979 prebuilt_questions.unshift(first_name, last_name, email, address, city, zip_code, country); 16980 } 16981 16982 } 16983 16984 16985 16986 $('.js-pre_built_questions option').remove(); 16987 16988/* 16989 if (type) { 16990 var append_html = '<option value="">[select a question to add, then drag it into your form]</option>' 16991 + '<option value="street">Address [Text Field]</option>' 16992 + '<option value="city">City [Text Field]</option>'; 16993 } else { 16994*/ 16995 var append_html = '<option value="">[' + an_javascript_translation.select_a_question_to_add_then_drag_it_into_y
16995our_form + ']</option>'; 16996 // } 16997 16998 $('select.js-pre_built_questions').append(append_html); 16999 $(prebuilt_questions).each(function() { 17000 var name =''; 17001 if (this.question_type == 'Text Area' || this.question_type == 'Text Field') { 17002 name = this.fields.id.value; 17003 } else if (this.question_type == 'Radio Button Group') { 17004 if (this.fields.name.value.indexOf('@!@tag@!@') != -1) { 17005 name = ''; 17006 $.each(this.fields.radios.value, function(i, e) { 17007 name = name + e.split('|')[1] + " "; 17008 }); 17009 17010 name = name.trim(); 17011 17012 } else { 17013 name = this.fields.name.value; 17014 } 17015 17016 } else if (this.question_type == 'Dropdown Menu') { 17017 if (this.fields.id.value.indexOf('@!@tag@!@') != -1) { 17018 name = ''; 17019 $.each(this.fields.options.value, function(i, e) { 17020 name = name + e.split('|')[1] + " "; 17021 }); 17022 17023 name = name.trim(); 17024 17025 } else { 17026 name = this.fields.id.value; 17027 } 17028 17029 } else if (this.question_type == 'Checkbox Group') { 17030 $(this.fields.checkboxes.value).each(function() { 17031 name = name + this.split('|')[1] + ' '; 17032 }); 17033 17034 name = name.trim(); 17035 } else if (this.question_type == 'Ranked Choice Group') { 17036 alert(this.question_type) 17037 name = name.trim(); 17038 } 17039 $('select.js-pre_built_questions').append('<option value="' + this.question_id + '">' + this.admin_title + ' (' + name + ') [' + this.question_type + ']</option>'); 17040 }); 17041 }; 17042 17043/* 17044 if (typeof(prebuilt_questions) != 'undefined') { 17045 load_prebuilt_questions(); 17046 } 17047*/ 17048 17049// if ($.isFunction($.fn.select2)) { 17050// $("select.js-question_tag_select").not('.select2-offscreen, .js-questions_templates select.js-question_tag_select').select2({ 17051// matcher: function (term, text, option) { 17052// if (term.length == 0) return true; 17053// 17054// if(term.split(" ").length == 1){ 17055// return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17056// } 17057// 17058// keywords=(term).split(/ |,|\[|\]|\(|\)/); 17059// // `data.text` is the text that is displayed for the data object 17060// // check if data.text contains all of keywords, if some is missing, return null 17061// for (var i = 0; i < keywords.length; i++) { 17062// 17063// if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17064// // Return `null` if the term should not be displayed 17065// return null; 17066// 17067// } 17068// // If here, data.text contains all keywords, so return it. 17069// return text; 17070// } 17071// }); 17072// } 17073 17074 if ($('.js-question_entry_wrap').length) { 17075 $('.js-network_custom_fields li .group_ac_draft').each(function() { 17076 //console.log($(this).text()); 17077 //replace tag question random names with tag question in the questions list 17078 if ($(this).text().indexOf('@!@tag@!@') != -1) { 17079 $(this).html('<strong>' + an_javascript_translation.tag_question + '</strong>'); 17080 if ($(this).parent().find('.group_ac_draft').length > 1) { 17081 var iterator = 0; 17082 $(this).parent().find('.group_ac_draft').each(function() { 17083 if (iterator > 0) { 17084 $(this).remove(); 17085 } 17086 17087 iterator++; 17088 }); 17089 } 17090 } 17091 }); 17092 } 17093 17094 // Make questions fields draggable 17095 var questions_sortable_init = function($that) { 17096 $that.sortable({ 17097 handle: ".fa-grip-vertical", 17098 placeholder: "question_sortable--highlight", 17099 axis: "y" 17100 }); 17101 } 17102 questions_sortable_init($( ".js-questions_sortable_wrap" )); 17103 17104 $('.js-edit_question_button').click(function() { 17105 var $that = $($(this).attr('href')); 17106 17107 //var tag_active = false; 17108 17109 if ($.isFunction($.fn.select2)) { 17110 $that.find("input.js-question_tag_select").not('.select2-offscreen, .js-questions_templates input.js-question_tag_select').select2({ 17111 data: select_tags_array, 17112 matcher: function (term, text, option) { 17113 if (term.length == 0) return true; 17114 17115 if(term.split(" ").length == 1){ 17116 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17117 } 17118 17119 keywords=(term).split(/ |,|\[|\]|\(|\)/); 17120 // `data.text` is the text that is displayed for the data object 17121 // check if data.text contains all of keywords, if some is missing, return null 17122 for (var i = 0; i < keywords.length; i++) { 17123 17124 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17125 // Return `null` if the term should not be displayed 17126 return null; 17127 17128 } 17129 // If here, data.text contains all keywords, so return it. 17130 return text; 17131 } 17132 }); 17133 } 17134
17135 $that.find('input:not(.select2-focusser, .select2-input, .button)').each(function() { 17136 // console.log($(this).attr('value').indexOf('@!@tag@!@')); 17137 //if this is a tag question, adjust things in the questions builder 17138 //onluy kind of works, sometimes this isn't firing when clicking edit, not picking up values for the selects from the hidden field properly -- probably shouldn't remove those hidden inputs actually until submission?f 17139 if ($(this).attr('value').indexOf('@!@tag@!@') != -1) { 17140 $(this).val(''); 17141 $(this).parents('.js-question_entry_wrap').find('.js-question_input_field').hide().find('input').removeClass('required error_input'); 17142 $(this).parents('.js-question_entry_wrap').find('.js-question_input_field').next().show(); 17143 //console.log($(this).parents('.js-question_entry_wrap').find('.js-question_add_checkbox').length); 17144 if ($(this).parents('.js-question_entry_wrap').find('.js-question_add_checkbox').length) { 17145 $(this).parents('.js-question_entry_wrap').find('input.js-question_tag_select').each(function() { 17146 //console.log($(this).parents('.js-question_input_wrap').find('.js-question_checkbox_tag_value').val()); 17147 $(this).val($(this).parents('.js-question_input_wrap').find('.js-question_checkbox_tag_value').val()).trigger('change'); 17148 }); 17149 } else { 17150 $(this).parents('.js-question_entry_wrap').find('input.js-question_tag_select').each(function() { 17151 $(this).val($(this).parents('.js-question_input_wrap').find('.js-question_input_field input').val()).trigger('change'); 17152 $(this).parents('.js-question_input_wrap').find('.js-question_input_field input').val(''); 17153 }); 17154 } 17155 17156 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_on').hide(); 17157 17158 } 17159 }); 17160 17161 }); 17162 17163 17164 17165 $('select.js-custom_field_modal_add').on('change', function() { 17166 if ($(this).val() != '') { 17167 $('.js-new_custom_field_modal .js-question_add').remove(); 17168 $('.js-custom_field_autocomplete').devbridgeAutocomplete('dispose'); 17169 switch($(this).val()) { 17170 case 'text': 17171 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_text').clone()); 17172 break; 17173 17174 case 'textarea': 17175 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_textarea').clone()); 17176 break; 17177 17178 case 'checkbox': 17179 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_checkbox').clone()); 17180 questions_sortable_init($( ".js-new_custom_field_entry_wrap .js-questions_sortable_wrap" )); 17181 break; 17182 17183 case 'radio': 17184 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_radio').clone()); 17185 questions_sortable_init($( ".js-new_custom_field_entry_wrap .js-questions_sortable_wrap" )); 17186 break; 17187 17188 case 'select': 17189 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_select').clone()); 17190 questions_sortable_init($( ".js-new_custom_field_entry_wrap .js-questions_sortable_wrap" )); 17191 break; 17192 17193 case 'html': 17194 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_html').clone()); 17195 break; 17196 17197 case 'rankedchoice': 17198 $('.js-new_custom_field_entry_wrap').append($('.js-questions_templates .js-question_add_rankedchoice').clone()); 17199 questions_sortable_init($( ".js-new_custom_field_entry_wrap .js-questions_sortable_wrap" )); 17200 break; 17201 } 17202 $('.js-custom_field_autocomplete').devbridgeAutocomplete({ 17203 serviceUrl: '/groups/' + $('.js-group_id').data('group_id') + '/field_search' 17204 }); 17205 17206 17207 if ($.isFunction($.fn.select2)) { 17208 $("#fancybox-content input.js-question_tag_select").not('.select2-offscreen').select2({ 17209 data: select_tags_array, 17210 matcher: function (term, text, option) { 17211 if (term.length == 0) return true; 17212 17213 if(term.split(" ").length == 1){ 17214 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17215 } 17216 17217 keywords=(term).split(/ |,|\[|\]|\(|\)/); 17218 // `data.text` is the text that is displayed for the data object 17219 // check if data.text contains all of keywords, if some is missing, return null 17220 for (var i = 0; i < keywords.length; i++) { 17221 17222 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17223 // Return `null` if the term should not be displayed 17224 return null; 17225 17226 } 17227 // If here, data.text contains all keywords, so return it. 17228 return text; 17229 } 17230 }); 17231 } 17232 17233 } else { 17234 $('.js-new_custom_field_modal .js-question_add').remove(); 17235 } 17236 }); 17237 17238 17239 if ($('.js-new_question_modal_btn').length) { 17240 $('body').on('click', '.js-use_tag_checkboxes_enable', function() {
17241 $(this).parents('.js-question_input_field').slideUp('fast', function() { 17242 $(this).find('input').removeClass('required error_input'); 17243 }); 17244 $(this).parents('.js-question_input_field').next().slideDown('fast'); 17245 17246 17247 //if ($(this).parents('.js-question_add_radio, .js-question_add_select').length) { 17248 $(this).parents('.js-question_entry_wrap').find('.js-question_input_field').hide().find('input').removeClass('required error_input'); 17249 $(this).parents('.js-question_entry_wrap').find('.js-question_input_field').next().show(); 17250 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_on').hide(); 17251 //} 17252 17253 }); 17254 17255 $('body').on('click', '.js-use_name_checkboxes_enable', function() { 17256 //console.log($(this)); 17257 $(this).parents('.js-question_input_tag').slideUp('fast') 17258 $(this).parents('.js-question_input_tag').prev().slideDown('fast', function() { 17259 //console.log($(this).parents('.js-question_add_select')); 17260 if ($(this).parents('.js-question_add_select').length > 0) { 17261 $(this).find('input').addClass('required'); 17262 } 17263 }); 17264 17265 //if ($(this).parents('.js-question_add_radio, .js-question_add_select').length) { 17266 $(this).parents('.js-question_entry_wrap').find('.js-question_input_tag').hide(); 17267 $(this).parents('.js-question_entry_wrap').find('.js-question_input_tag').prev().show().find('input:not(.select_value, .js-question_add_select .js-question_input_wrap input)').addClass('required'); 17268 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_on').show(); 17269 //} 17270 17271 }); 17272 } 17273 17274 //question options creation as text instead of inputs 17275 $('body').on('click', '.js-text_builder_on a', function() { 17276 $(this).parents('.js-question_entry_wrap').find('.js-option_group, .js-add_option, .js-text_builder_on, .js-use_tag_checkboxes_enable').hide(); 17277 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_entry').slideDown(function() { 17278 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_entry textarea').focus(); 17279 }); 17280 17281 17282 var textarea_value = ""; 17283 $(this).parents('.js-question_entry_wrap').find('.js-option_group').each(function() { 17284 if ($($(this).find('input')[0]).val() == $($(this).find('input')[1]).val()) { 17285 textarea_value = textarea_value + $($(this).find('input')[0]).val() + '\n'; 17286 } else { 17287 textarea_value = textarea_value + $($(this).find('input')[0]).val() + "|" + $($(this).find('input')[1]).val() + '\n'; 17288 } 17289 17290 }); 17291 textarea_value = textarea_value.replace(/\s+$/, ''); 17292 $(this).parents('.js-question_entry_wrap').find('.js-text_builder_entry textarea').val(textarea_value).addClass('required'); 17293 $(this).parents('.js-question_add').find('.js-option_group input').removeClass('required error_input'); 17294 }); 17295 17296 var text_builder_save = function($that) { 17297 17298 $that.parents('.js-question_entry_wrap').find('.js-text_builder_entry').hide(); 17299 17300 $that.parents('.js-question_entry_wrap').find('.js-option_group').slice(1).remove(); 17301 17302 $that.parents('.js-question_entry_wrap').find('.js-option_group, .js-add_option, .js-text_builder_on, .js-use_tag_checkboxes_enable').slideDown(); 17303 17304 $that.parents('.js-text_builder_entry').find('textarea').removeClass('required error_input'); 17305 17306 var textarea_value = $that.parents('.js-text_builder_entry').find('textarea').val(); 17307 var textarea_value_array = textarea_value.split('\n'); 17308 17309 $.each(textarea_value_array, function(i, e) { 17310 if (e.indexOf('|') != -1) { 17311 var array = e.split('|'); 17312 } else { 17313 var array = [e, e]; 17314 } 17315 17316 if (i != 0) { 17317 if ($that.parents('.js-question_add').hasClass('js-question_add_checkbox')) { 17318 add_checkbox_group($that.parents('.js-question_add').find('.js-add_checkbox_group')); 17319 } else if ($that.parents('.js-question_add').hasClass('js-question_add_radio')) { 17320 add_radio_group($that.parents('.js-question_add').find('.js-add_radio_group')); 17321 } else if ($that.parents('.js-question_add').hasClass('js-question_add_select')) { 17322 add_select_group($that.parents('.js-question_add').find('.js-add_select_group')); 17323 } else if ($that.parents('.js-question_add').hasClass('js-question_add_rankedchoice')) { 17324 add_rankedchoice_group($that.parents('.js-question_add').find('.js-add_rankedchoice_group')); 17325 } 17326 } 17327 17328 17329 17330 $($that.parents('.js-question_add').find('.js-option_group').last().find('input')[0]).val(array[0]); 17331 $($that.parents('.js-question_add').find('.js-option_group').last().find('input')[1]).val(array[1]); 17332 }); 17333 }; 17334 17335 $('body').on('click', '.js-text_builder_entry a:not(".tooltip")', function() { 17336 text_builder_save($(this)); 17337 17338 $(this).parents('.js-question_add').find('.js-option_group').first().find('input').not('.select2-container input').addClass('required'); 17339 $($(this).parents('.js-question_add').find('.js-select_group').first().find('input').not('.select2-container input')[1]).removeClass('required'); 17340 17341 $(this).parents('.js-question_add').find('.js-option_group input').not('.select2-container input').each(function() { 17342 checkbox_question_required($(this)); 17343 }); 17344 17345 $(this).parents('.js-question_add').find('.js-option_group input').not('.select2-container input').each(function() { 17346 radio_question_required($(this)); 17347 }); 17348 17349 $(this).parents('.js-question_add').find('.js-option_group input').not('.select2-container input').each(function() { 17350 select_question_required($(this)); 17351 }); 17352 }); 17353 17354 17355 $(".js-question_entry_wrap").on('focusin', 'input', function() { 17356 tooltipFunction($(this).siblings( '.js-tooltip' )); 17357 }); 17358 17359 $(".js-question_entry_wrap").on('focusout', 'input', function() { 17360 remove_tooltip(); 17361 }); 17362 17363 $('.js-edit_question_button').click(function() { 17364 options_count = $($(this).attr('href')).find('.js-option_group').length; 17365 }); 17366 17367 //looks at all checkbox/radio/dropdown option inputs in the current modal and pulls out the highest numeric count of all of their names (as they may not be in order), so we can add a new input with one higher when the user clicks to add another option to the question 17368 var max_question_option_input_name_count = function() { 17369 return Math.max( 17370 ...$('#fancybox-content .js-question_input_wrap').map(function() { 17371 var item_name = $(this).find('input').attr('name'); 17372 var item_number = parseInt(item_name.substring(item_name.lastIndexOf("_")+1,item_name.lastIndexOf("]"))) 17373 if (!isNaN(item_number)) { 17374 return item_number; 17375 } 17376 }) 17377 .get() 17378 ); 17379 } 17380 17381 var add_checkbox_group = function(that) { 17382 var option_count = max_question_option_input_name_count() + 1; 17383 17384 $(that).parents('.js-question_entry_wrap').find('.js-questions_sortable_wrap').append($('.js-questions_templates .js-checkbox_option_group').clone());
17385 $(that).parents('.js-question_entry_wrap').find('.js-custom_field_autocomplete').devbridgeAutocomplete({ 17386 serviceUrl: '/groups/' + $('.js-group_id').data('group_id') + '/field_search' 17387 }); 17388 17389 if ($.isFunction($.fn.select2)) { 17390 $("#fancybox-content input.js-question_tag_select").not('.select2-offscreen').select2({ 17391 data: select_tags_array, 17392 matcher: function (term, text, option) { 17393 if (term.length == 0) return true; 17394 17395 if(term.split(" ").length == 1){ 17396 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17397 } 17398 17399 keywords=(term).split(/ |,|\[|\]|\(|\)/); 17400 // `data.text` is the text that is displayed for the data object 17401 // check if data.text contains all of keywords, if some is missing, return null 17402 for (var i = 0; i < keywords.length; i++) { 17403 17404 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17405 // Return `null` if the term should not be displayed 17406 return null; 17407 17408 } 17409 // If here, data.text contains all keywords, so return it. 17410 return text; 17411 } 17412 }); 17413 } 17414 if ($(that).parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17415 $(that).parents('.js-question_add_checkbox').find('.js-question_input_field').hide(); 17416 $(that).parents('.js-question_add_checkbox').find('.js-question_input_field').next().show(); 17417 } 17418 $(that).parents('.js-question_entry_wrap').find('.js-checkbox_option').attr('name', 'question[settings][label_' + option_count + ']').removeClass('js-checkbox_option'); 17419 $(that).parents('.js-question_entry_wrap').find('.js-checkbox_key').attr('name', 'question[settings][key_' + option_count + ']').removeClass('js-checkbox_key'); 17420 }; 17421 17422 $(".js-question_entry_wrap").on('click', '.js-add_checkbox_group', function() { 17423 add_checkbox_group(this); 17424 }); 17425 17426 var add_rankedchoice_group = function(that) { 17427 var option_count = max_question_option_input_name_count() + 1; 17428 17429 $(that).parents('.js-question_entry_wrap').find('.js-questions_sortable_wrap').append($('.js-questions_templates .js-rankedchoice_option_group').clone()); 17430 $(that).parents('.js-question_entry_wrap').find('.js-custom_field_autocomplete').devbridgeAutocomplete({ 17431 serviceUrl: '/groups/' + $('.js-group_id').data('group_id') + '/field_search' 17432 }); 17433 17434 $(that).parents('.js-question_entry_wrap').find('.js-rankedchoice_option').attr('name', 'question[settings][label_' + option_count + ']').removeClass('js-rankedchoice_option'); 17435 $(that).parents('.js-question_entry_wrap').find('.js-rankedchoice_key').attr('name', 'question[settings][key_' + option_count + ']').removeClass('js-rankedchoice_key'); 17436 }; 17437 17438 $(".js-question_entry_wrap").on('click', '.js-add_rankedchoice_group', function() { 17439 add_rankedchoice_group(this); 17440 }); 17441 17442 var add_radio_group = function(that) { 17443 var option_count = max_question_option_input_name_count() + 1; 17444 $(that).parents('.js-question_entry_wrap').find('.js-questions_sortable_wrap').append($('.js-questions_templates .js-radio_option_group').clone()); 17445 if ($.isFunction($.fn.select2)) { 17446 $("#fancybox-content input.js-question_tag_select").not('.select2-offscreen').select2({ 17447 data: select_tags_array, 17448 matcher: function (term, text, option) { 17449 if (term.length == 0) return true; 17450 17451 if(term.split(" ").length == 1){ 17452 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17453 } 17454 17455 keywords=(term).split(/ |,|\[|\]|\(|\)/); 17456 // `data.text` is the text that is displayed for the data object 17457 // check if data.text contains all of keywords, if some is missing, return null 17458 for (var i = 0; i < keywords.length; i++) { 17459 17460 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17461 // Return `null` if the term should not be displayed 17462 return null; 17463 17464 } 17465 // If here, data.text contains all keywords, so return it. 17466 return text; 17467 } 17468 }); 17469 } 17470 if ($(that).parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17471 $(that).parents('.js-question_add_radio').find('.js-question_input_field').hide(); 17472 $(that).parents('.js-question_add_radio').find('.js-question_input_field').next().show(); 17473 } 17474 $(that).parents('.js-question_entry_wrap').find('.js-radio_option').attr('name', 'question[settings][label_' + option_count + ']').removeClass('js-radio_option'); 17475 $(that).parents('.js-question_entry_wrap').find('.js-radio_value').attr('name', 'question[settings][value_' + option_count + ']').removeClass('js-radio_value'); 17476 }; 17477 17478 $(".js-question_entry_wrap").on('click', '.js-add_radio_group', function() { 17479 add_radio_group(this); 17480 }); 17481 17482 17483 var add_select_group = function(that) { 17484 var option_count = max_question_option_input_name_count() + 1; 17485 $(that).parents('.js-question_entry_wrap').find('.js-questions_sortable_wrap').append($('.js-questions_templates .js-select_option_group').clone()); 17486 if ($.isFunction($.fn.select2)) { 17487 $("#fancybox-content input.js-question_tag_select").not('.select2-offscreen').select2({ 17488 data: select_tags_array, 17489 matcher: function (term, text, option) { 17490 if (term.length == 0) return true; 17491 17492 if(term.split(" ").length == 1){ 17493 return text.toUpperCase().indexOf(term.toUpperCase())!=-1; 17494 } 17495 17496 keywords=(term).split(/ |,|\[|\]|\(|\)/); 17497 // `data.text` is the text that is displayed for the data object 17498 // check if data.text contains all of keywords, if some is missing, return null 17499 for (var i = 0; i < keywords.length; i++) { 17500 17501 if (((text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 17502 // Return `null` if the term should not be displayed 17503 return null; 17504 17505 } 17506 // If here, data.text contains all keywords, so return it. 17507 return text; 17508 } 17509 }); 17510 } 17511 if ($(that).parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17512 $(that).parents('.js-question_add_select').find('.js-question_input_field').hide(); 17513 $(that).parents('.js-question_add_select').find('.js-question_input_field').next().show(); 17514 } 17515 $(that).parents('.js-question_entry_wrap').find('.js-select_option').attr('name', 'question[settings][label_' + option_count + ']').removeClass('js-select_option'); 17516 $(that).parents('.js-question_entry_wrap').find('.js-select_value').attr('name', 'question[settings][value_' + option_count + ']').removeClass('js-select_value'); 17517 }; 17518 17519 $(".js-question_entry_wrap").on('click', '.js-add_select_group', function() { 17520 add_select_group(this); 17521 }); 17522 17523 var checkbox_question_required = function($that) { 17524 if ($that.val() != '' && !$that.parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17525 $that.parent().siblings('.fifty').find( '.checkbox_name, .checkbox_option, .checkbox_key' ).addClass('required'); 17526 } else { 17527 $that.parent().siblings('.fifty').find( '.checkbox_name, .checkbox_option, .checkbox_key' ).removeClass('required error_input'); 17528 } 17529 } 17530 17531 $('.js-question_entry_wrap').on('keyup', '.checkbox_key, .checkbox_option, .checkbox_name', function() { 17532 checkbox_question_required($(this)); 17533 }); 17534 17535 var radio_question_required = function($that) { 17536 if ($that.val() != '' && !$that.parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17537 $that.parent().siblings('.fifty').find( '.radio_option, .radio_value' ).addClass('required'); 17538 } else { 17539 $that.parent().siblings('.fifty').find( '.radio_option, .radio_value' ).removeClass('required error_input'); 17540 } 17541 } 17542 17543 $('.js-question_entry_wrap').on('keyup', '.radio_value, .radio_option', function() { 17544 radio_question_required($(this)); 17545 }); 17546 17547 var select_question_required = function($that) { 17548 if ($that.val() != '' && !$that.parents('.js-question_entry_wrap').find('.js-question_input_tag:visible').length) { 17549 $that.parent().siblings('.fifty').find( '.select_option' ).addClass('required'); 17550 } else { 17551 $that.parent().siblings('.fifty').find( '.select_option' ).removeClass('required error_input'); 17552 } 17553 } 17554 17555 $('.js-question_entry_wrap').on('keyup', '.select_value', function() { 17556 select_question_required($(this)); 17557 }); 17558 17559 $('.edit_question input[type="submit"], .new_question input[type="submit"]').click(function(e) { 17560 if (($(this).parent().find('.textarea').length || $(this).parent().find('.text').length) && ($(this).parent().find('input[name="question[settings][label]"]').val() == '' && $(this).parent().find('input[name="question[settings][placeholder]"]').val() == '')) { 17561 var question_add_confirmation = confirm(an_javascript_translation.the_question_you_are_creating); 17562 if (question_add_confirmation != true) { 17563 e.preventDefault(); 17564 return false;
17565 } 17566 } 17567 }); 17568 17569 /* custom regex javascript *****************/ 17570 17571 /* javascript for questions and custom fields page, for the regex builder */ 17572 var show_hide_custom_regex_options = function($that) { 17573 if ($that.val() == "Custom") { 17574 $that.parents('.js-custom_regex_modal').find('.js-custom_regex_input_wrap').slideDown(); 17575 } else { 17576 $that.parents('.js-custom_regex_modal').find('.js-custom_regex_input_wrap').slideUp(); 17577 if ($that.val() != '') { 17578 $that.parents('.js-custom_regex_modal').find('.js-regex_input').val($that.val()); 17579 $that.parents('.js-custom_regex_modal').find('.js-regex_description_input').val($that.find('option:selected').data('description')); 17580 } 17581 } 17582 }; 17583 17584 $('select.js-regexp_type').each(function() { 17585 var selected_regex = $(this).parents('.js-custom_regex_modal').find('.js-regex_input').val(); 17586 //console.log(selected_regex); 17587 if (selected_regex) { 17588 var match = false; 17589 $(this).find('option').each(function() { 17590 //console.log($(this).val()); 17591 if ($(this).val() == selected_regex) { 17592 $(this).attr('selected', 'selected'); 17593 match = true; 17594 } 17595 }); 17596 17597 if (!match) { 17598 $(this).val('Custom'); 17599 } 17600 } 17601 17602 show_hide_custom_regex_options($(this)); 17603 }); 17604 17605 $('select.js-regexp_type').change(function() { 17606 show_hide_custom_regex_options($(this)); 17607 if ($(this).val() == "Custom") { 17608 $(this).parents('.js-custom_regex_modal').find('.js-regex_input').val(''); 17609 $(this).parents('.js-custom_regex_modal').find('.js-regex_description_input').val(''); 17610 } 17611 }); 17612 17613 17614 /* javascript for the user add/edit and action creation pages, to add validation to inputs */ 17615 var get_regex_and_execute_callback = function(url, fields_array, callback_function) { 17616 $.getJSON(url, { "fields": fields_array }, function(json) { 17617 callback_function(json); 17618 }); 17619 } 17620 17621 var apply_fields_user_view_callback = function(json) { 17622 $.each(json, function(key, value) { 17623 if (value) { 17624 $('.js-user_custom_fields select option:selected[value="' + key + '"], .js-user_custom_fields .js-user_edit_new_custom_field[value="' + key + '"]').parents('.js-single_user_result-custom_field').find('.js-create_action-editable').not('.js-user_edit_new_custom_field').each(function() { 17625 $(this).data('regex',value).rules("add", { regex: value }); 17626 }); 17627 } 17628 17629 }); 17630 } 17631 17632 var apply_fields_formbuilder_callback = function(json) { 17633 //console.log(json); 17634 $.each(json, function(key, value) { 17635 if (value) { 17636 //console.log(form_builder_temp_render); 17637 //console.log(value); 17638 //console.log(key); 17639 //console.log(form_builder_temp_render.find('input:text[name="' + key + '"], textarea[name="' + key + '"]')); 17640 form_builder_temp_render.find('input:text[name="' + key + '"], textarea[name="' + key + '"]').each(function() { 17641 $(this).attr('data-regex',value); 17642 }); 17643 } 17644 17645 }); 17646 17647 //$('.js-visual_form_target').html(form_builder_temp_render.html()); 17648 $('#visual_form_input').val(form_builder_temp_render.html()); 17649 //disabled_form_builder_output(); 17650 } 17651 17652 if ($('.js-user_edit_new_custom_field').length) { 17653 var input_name_array = []; 17654 $('.js-user_edit_new_custom_field').each(function() { 17655 input_name_array.push($(this).val()); 17656 }); 17657 17658 if (input_name_array.length) { 17659 get_regex_and_execute_callback($('.js-regex_pattern_link').val(), input_name_array, apply_fields_user_view_callback); 17660 } 17661 17662 17663 } 17664 17665 $('.js-user_custom_fields').on('change', 'select, .js-user_edit_new_custom_field', function() { 17666 var input_name_array = []; 17667 input_name_array.push($(this).val()); 17668 $(this).parents('.js-single_user_result-custom_field').find('.js-create_action-editable').not('.js-user_edit_new_custom_field').removeData('regex').rules("remove", "regex"); 17669 if (input_name_array.length) { 17670 get_regex_and_execute_callback($('.js-regex_pattern_link').val(), input_name_array, apply_fields_user_view_callback); 17671 } 17672 }); 17673 17674 17675 //form builder init code to deal with saved forms 17676 CAN_form_builder_initial_JSON = [ 17677 { "title" : "Form Name" 17678 , "fields": { 17679 "name" : { 17680 "label" : "Form Name" 17681 , "type" : "input" 17682 , "value" : "Form Name" 17683 } 17684 } 17685 } 17686 ]; 17687 17688 //going to need this later -- re-initialized the form builder app
17689 //require("app/app").initialize(); 17690 17691 17692 if ($('#visual_form_input_json').length) { 17693 //code for doing tag questions, which have names that start with @!@tag@!@ 17694 use_tags_checkboxes = function(that) { 17695 17696 //console.log(that); 17697 17698 $(that).parents('.js-use_name_checkboxes').hide(); 17699 $(that).parents('.js-use_name_checkboxes').find('input').val('@!@tag@!@'); 17700 $(that).parents('.js-use_name_checkboxes').next().show(); 17701 $(that).parents('.popover-content').find('.js-checkbox_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_checkboxes); 17702 17703 $(that).parents('.popover-content').find('.js-radio_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_radios); 17704 17705 $(that).parents('.popover-content').find('.js-select_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_select); 17706 17707 $(that).parents('.popover-content').find('.js-actions_only_checkbox, .js-add_other_checkbox').attr('checked', false).parents('.control-group').hide(); 17708 } 17709 17710 $('body').on('click', '.js-use_tag_checkboxes_enable', function() { 17711 $(this).parents('.js-use_name_checkboxes').slideUp('fast', function() { 17712 $(this).find('input').val('@!@tag@!@'); 17713 }); 17714 $(this).parents('.js-use_name_checkboxes').next().slideDown('fast'); 17715 $(this).parents('.popover-content').find('.js-checkbox_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_checkboxes); 17716 17717 $(this).parents('.popover-content').find('.js-radio_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_radios); 17718 17719 $(this).parents('.popover-content').find('.js-select_popover_tooltip').html(an_javascript_translation.add_tags_tooltip_select); 17720 17721 $(this).parents('.popover-content').find('.js-actions_only_checkbox, .js-add_other_checkbox').attr('checked', false).parents('.control-group').hide(); 17722 }); 17723 17724 $('body').on('click', '.js-use_name_checkboxes_enable', function() { 17725 //console.log($(this)); 17726 $(this).parents('.js-use_tag_checkboxes').slideUp('fast') 17727 $(this).parents('.js-use_tag_checkboxes').prev().slideDown('fast'); 17728 $(this).parents('.js-use_tag_checkboxes').prev().find('input').val($(this).parents('.js-use_tag_checkboxes').prev().find('input').data('original-value')); 17729 $(this).parents('.popover-content').find('.js-checkbox_popover_tooltip').html(an_javascript_translation.add_fields_tooltip_checkboxes); 17730 17731 $(this).parents('.popover-content').find('.js-radio_popover_tooltip').html(an_javascript_translation.add_fields_tooltip_radios); 17732 17733 $(this).parents('.popover-content').find('.js-select_popover_tooltip').html(an_javascript_translation.add_fields_tooltip_select); 17734 $(this).parents('.popover-content').find('.js-actions_only_checkbox, .js-add_other_checkbox').parents('.control-group').show(); 17735 }); 17736 17737 $('body').on('change', '.js-actions_only_checkbox, .js-add_other_checkbox', function() { 17738 //console.log($(this)); 17739 if ($(this).parents(".popover").find('.popover-title').text() == "Multiple Radios" || $(".popover").find('.popover-title').text() == "Multiple Checkboxes" || $(".popover").find('.popover-title').text() == "Select Basic") { 17740 if ($(this).is(':checked')) { 17741 $(this).parents('.popover').find('.js-use_tag_checkboxes_enable').hide(); 17742 } else { 17743 $(this).parents('.popover').find('.js-use_tag_checkboxes_enable').show(); 17744 } 17745 } 17746 }); 17747 } 17748 17749 17750 17751 if ($('#visual_form_input_json').length && $('#visual_form_input_json').val() != "") { 17752 //console.log('yes'); 17753 CAN_form_builder_initial_JSON = JSON.parse($('#visual_form_input_json').val()); 17754 } 17755 17756 $('.js-visual_form_target').show(); 17757 17758 17759 if ($('#visual_form_input_json').length && $('#visual_form_input_json').val() != "") { 17760 17761 //console.log($('#visual_form_input').val()); 17762 17763 //convert core field backend representation into frontend 17764 var core_fields_temp = $('#visual_form_input').val(); 17765 17766 //searches the special DSL from the form builder and outputs required, always show, and custom user regex html instead of the DSL. This code is repeated for each core field. Note that not all fields have all options, like phone doesn't allow regex 17767 var first_name_required = ""; 17768 var first_name_always_show = ""; 17769 var first_name_regex = ""; 17770 var first_name_label = ""; 17771 var first_name_placeholder = ""; 17772 if (core_fields_temp.match(/@@first_name(.*)@@/) != null) { 17773 var first_name_match = core_fields_temp.match(/@@first_name(.*)@@/)[0]; 17774 } 17775 17776 if (core_fields_temp.match(/@@first_name(.*)@@/) != null) { 17777 var first_name_options_match = core_fields_temp.match(/@@first_name(.*)@@/)[1]; 17778 } 17779 //console.log(first_name_options_match); 17780 17781 if (typeof(first_name_options_match) != 'undefined' && first_name_options_match.includes("_required")) { 17782 first_name_required = "required"; 17783 } 17784 17785 if (typeof(first_name_options_match) != 'undefined' && first_name_options_match.includes("_alwaysshow")) { 17786 first_name_always_show = 'data-always="true"'; 17787 } 17788 17789 if (typeof(first_name_options_match) != 'undefined' && first_name_options_match.match(/_regex##(.*)##/) != null && first_name_options_match.match(/_regex##(.*)##/)[1] != null) { 17790 first_name_regex = 'data-regex="' + first_name_options_match.match(/##(.*)##/)[1] + '"'; 17791 } 17792 17793 if (typeof(first_name_options_match) != 'undefined' && first_name_options_match.match(/_placeholder!!(.*)!!/) != null && first_name_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 17794 first_name_placeholder = first_name_options_match.match(/_placeholder!!(.*)!!/)[1]; 17795 //console.log(first_name_placeholder); 17796 } else { 17797 first_name_placeholder = an_javascript_translation.first_name; 17798 } 17799 17800 if (first_name_required == "required" && !first_name_placeholder.includes("*")) { 17801 first_name_placeholder = first_name_placeholder + " *"; 17802 } 17803 17804 if (typeof(first_name_options_match) != 'undefined' && first_name_options_match.match(/_label
17804%%(.*)%%/) != null && first_name_options_match.match(/_label%%(.*)%%/)[1] != null) { 17805 first_name_label = first_name_options_match.match(/_label%%(.*)%%/)[1]; 17806 //console.log(first_name_label); 17807 } 17808 17809 var first_name_html = '<li class="control-group" data-identifier="core_first_name"><label class="control-label" for="corefirstname">' + first_name_label + '</label><input id="corefirstname" name="core_first_name" type="text" placeholder="' + first_name_placeholder + '" class="input-xlarge ' + first_name_required + '" ' + first_name_always_show + ' ' + first_name_regex + '></li>'; 17810 17811 core_fields_temp = core_fields_temp.replace(first_name_match, first_name_html); 17812 17813 17814 var last_name_required = ""; 17815 var last_name_always_show = ""; 17816 var last_name_regex = ""; 17817 var last_name_label = ""; 17818 var last_name_placeholder = ""; 17819 17820 if (core_fields_temp.match(/@@last_name(.*)@@/) != null) { 17821 var last_name_match = core_fields_temp.match(/@@last_name(.*)@@/)[0]; 17822 } 17823 if (core_fields_temp.match(/@@last_name(.*)@@/) != null) { 17824 var last_name_options_match = core_fields_temp.match(/@@last_name(.*)@@/)[1]; 17825 } 17826 17827 //console.log(last_name_options_match); 17828 17829 if (typeof(last_name_options_match) != 'undefined' && last_name_options_match.includes("_required")) { 17830 last_name_required = "required"; 17831 } 17832 17833 if (typeof(last_name_options_match) != 'undefined' && last_name_options_match.includes("_alwaysshow")) { 17834 last_name_always_show = 'data-always="true"'; 17835 } 17836 17837 if (typeof(last_name_options_match) != 'undefined' && last_name_options_match.match(/_regex##(.*)##/) != null && last_name_options_match.match(/_regex##(.*)##/)[1] != null) { 17838 last_name_regex = 'data-regex="' + last_name_options_match.match(/##(.*)##/)[1] + '"'; 17839 } 17840 17841 if (typeof(last_name_options_match) != 'undefined' && last_name_options_match.match(/_placeholder!!(.*)!!/) != null && last_name_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 17842 last_name_placeholder = last_name_options_match.match(/_placeholder!!(.*)!!/)[1]; 17843 //console.log(last_name_placeholder); 17844 } else { 17845 last_name_placeholder = an_javascript_translation.last_name; 17846 } 17847 17848 if (last_name_required == "required" && !last_name_placeholder.includes("*")) { 17849 last_name_placeholder = last_name_placeholder + " *"; 17850 } 17851 17852 if (typeof(last_name_options_match) != 'undefined' && last_name_options_match.match(/_label%%(.*)%%/) != null && last_name_options_match.match(/_label%%(.*)%%/)[1] != null) { 17853 last_name_label = last_name_options_match.match(/_label%%(.*)%%/)[1]; 17854 //console.log(last_name_label); 17855 } 17856 17857 var last_name_html = '<li class="control-group" data-identifier="core_last_name"><label class="control-label" for="corelastname">' + last_name_label + '</label><input id="corelastname" name="core_last_name" type="text" placeholder="' + last_name_placeholder + '" class="input-xlarge ' + last_name_required + '" ' + last_name_always_show + ' ' + last_name_regex + '></li>'; 17858 17859 core_fields_temp = core_fields_temp.replace(last_name_match, last_name_html); 17860 17861 var email_required = ""; 17862 var email_regex = ""; 17863 var email_label = ""; 17864 var email_placeholder = ""; 17865 17866 if (core_fields_temp.match(/@@email(.*)@@/) != null) { 17867 var email_match = core_fields_temp.match(/@@email(.*)@@/)[0]; 17868 } 17869 17870 if (core_fields_temp.match(/@@email(.*)@@/) != null) { 17871 var email_options_match = core_fields_temp.match(/@@email(.*)@@/)[1]; 17872 } 17873 17874 if (typeof(email_options_match) != 'undefined' && email_options_match.includes("_required")) { 17875 email_required = "required"; 17876 } 17877 //console.log(email_options_match); 17878 if (typeof(email_options_match) != 'undefined' && email_options_match.match(/_regex##(.*)##/) != null && email_options_match.match(/_regex##(.*)##/)[1] != null) { 17879 email_regex = 'data-regex="' + email_options_match.match(/##(.*)##/)[1] + '"'; 17880 } 17881 17882 if (typeof(email_options_match) != 'undefined' && email_options_match.match(/_placeholder!!(.*)!!/) != null && email_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 17883 email_placeholder = email_options_match.match(/_placeholder!!(.*)!!/)[1]; 17884 } else { 17885 email_placeholder = an_javascript_translation.email; 17886 } 17887 17888 if (email_required == "required" && !email_placeholder.includes("*")) { 17889 email_placeholder = email_placeholder + " *"; 17890 } 17891 17892 if (typeof(email_options_match) != 'undefined' && email_options_match.match(/_label
17892%%(.*)%%/) != null && email_options_match.match(/_label%%(.*)%%/)[1] != null) { 17893 email_label = email_options_match.match(/_label%%(.*)%%/)[1]; 17894 } 17895 17896 var email_html = '<li class="control-group" data-identifier="core_email"><label class="control-label" for="coreemail">' + email_label + '</label><input id="coreemail" name="core_email" type="text" placeholder="' + email_placeholder + '" class="input-xlarge ' + email_required + '" ' + email_regex + '></li>'; 17897 17898 core_fields_temp = core_fields_temp.replace(email_match, email_html); 17899 17900 17901 var street_required = ""; 17902 var street_always_show = ""; 17903 var street_regex = ""; 17904 var street_label = ""; 17905 var street_placeholder = ""; 17906 17907 if (core_fields_temp.match(/@@street(.*)@@/) != null) { 17908 var street_match = core_fields_temp.match(/@@street(.*)@@/)[0]; 17909 } 17910 17911 if (core_fields_temp.match(/@@street(.*)@@/) != null) { 17912 var street_options_match = core_fields_temp.match(/@@street(.*)@@/)[1]; 17913 } 17914 17915 if (typeof(street_options_match) != 'undefined' && street_options_match.includes("_required")) { 17916 street_required = "required"; 17917 } 17918 17919 if (typeof(street_options_match) != 'undefined' && street_options_match.includes("_alwaysshow")) { 17920 street_always_show = 'data-always="true"'; 17921 } 17922 17923 if (typeof(street_options_match) != 'undefined' && street_options_match.match(/_regex##(.*)##/) != null && street_options_match.match(/_regex##(.*)##/)[1] != null) { 17924 street_regex = 'data-regex="' + street_options_match.match(/##(.*)##/)[1] + '"'; 17925 } 17926 17927 if (typeof(street_options_match) != 'undefined' && street_options_match.match(/_placeholder!!(.*)!!/) != null && street_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 17928 street_placeholder = street_options_match.match(/_placeholder!!(.*)!!/)[1]; 17929 } else { 17930 street_placeholder = an_javascript_translation.street_address; 17931 } 17932 17933 if (street_required == "required" && !street_placeholder.includes("*")) { 17934 street_placeholder = street_placeholder + " *"; 17935 } 17936 17937 if (typeof(street_options_match) != 'undefined' && street_options_match.match(/_label%%(.*)%%/) != null && street_options_match.match(/_label%%(.*)%%/)[1] != null) { 17938 street_label = street_options_match.match(/_label%%(.*)%%/)[1]; 17939 } 17940 17941 var street_html = '<li class="control-group" data-identifier="core_street"><label class="control-label" for="corestreet">' + street_label + '</label><input id="corestreet" name="core_street" type="text" placeholder="' + street_placeholder + '" class="input-xlarge ' + street_required + '" ' + street_always_show + ' ' + street_regex + '></li>'; 17942 17943 core_fields_temp = core_fields_temp.replace(street_match, street_html); 17944 17945 17946 var city_required = ""; 17947 var city_always_show = ""; 17948 var city_regex = ""; 17949 var city_label = ""; 17950 var city_placeholder = ""; 17951 17952 if (core_fields_temp.match(/@@city(.*)@@/) != null) { 17953 var city_match = core_fields_temp.match(/@@city(.*)@@/)[0]; 17954 } 17955 17956 if (core_fields_temp.match(/@@city(.*)@@/) != null) { 17957 var city_options_match = core_fields_temp.match(/@@city(.*)@@/)[1]; 17958 } 17959 17960 if (typeof(city_options_match) != 'undefined' && city_options_match.includes("_required")) { 17961 city_required = "required"; 17962 } 17963 17964 if (typeof(city_options_match) != 'undefined' && city_options_match.includes("_alwaysshow")) { 17965 city_always_show = 'data-always="true"'; 17966 } 17967 17968 if (typeof(city_options_match) != 'undefined' && city_options_match.match(/_regex##(.*)##/) != null && city_options_match.match(/_regex##(.*)##/)[1] != null) { 17969 city_regex = 'data-regex="' + city_options_match.match(/##(.*)##/)[1] + '"'; 17970 } 17971 17972 if (typeof(city_options_match) != 'undefined' && city_options_match.match(/_placeholder!!(.*)!!/) != null && city_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 17973 city_placeholder = city_options_match.match(/_placeholder!!(.*)!!/)[1]; 17974 } else { 17975 city_placeholder = an_javascript_translation.city; 17976 } 17977 17978 if (city_required == "required" && !city_placeholder.includes("*")) { 17979 city_placeholder = city_placeholder + " *"; 17980 } 17981 17982 if (typeof(city_options_match) != 'undefined' && city_options_match.match(/_label%%(.*)%%/) != null && city_options_match.match(/_label
17982%%(.*)%%/)[1] != null) { 17983 city_label = city_options_match.match(/_label%%(.*)%%/)[1]; 17984 } 17985 17986 var city_html = '<li class="control-group" data-identifier="core_city"><label class="control-label" for="corecity">' + city_label + '</label><input id="corecity" name="core_city" type="text" placeholder="' + city_placeholder + '" class="input-xlarge ' + city_required + '" ' + city_always_show + ' ' + city_regex + '></li>'; 17987 17988 core_fields_temp = core_fields_temp.replace(city_match, city_html); 17989 17990 17991 var zip_code_required = ""; 17992 var zip_code_always_show = ""; 17993 var zip_code_regex = ""; 17994 var zip_code_label = ""; 17995 var zip_code_placeholder = ""; 17996 17997 if (core_fields_temp.match(/@@zip_code(.*)@@/) != null) { 17998 var zip_code_match = core_fields_temp.match(/@@zip_code(.*)@@/)[0]; 17999 } 18000 18001 if (core_fields_temp.match(/@@zip_code(.*)@@/) != null) { 18002 var zip_code_options_match = core_fields_temp.match(/@@zip_code(.*)@@/)[1]; 18003 } 18004 18005 if (typeof(zip_code_options_match) != 'undefined' && zip_code_options_match.includes("_required")) { 18006 zip_code_required = "required"; 18007 } 18008 18009 if (typeof(zip_code_options_match) != 'undefined' && zip_code_options_match.includes("_alwaysshow")) { 18010 zip_code_always_show = 'data-always="true"'; 18011 } 18012 18013 if (typeof(zip_code_options_match) != 'undefined' && zip_code_options_match.match(/_regex##(.*)##/) != null && zip_code_options_match.match(/_regex##(.*)##/)[1] != null) { 18014 zip_code_regex = 'data-regex="' + zip_code_options_match.match(/##(.*)##/)[1] + '"'; 18015 } 18016 18017 if (typeof(zip_code_options_match) != 'undefined' && zip_code_options_match.match(/_placeholder!!(.*)!!/) != null && zip_code_options_match.match(/_placeholder!!(.*)!!/)[1] != null) { 18018 zip_code_placeholder = zip_code_options_match.match(/_placeholder!!(.*)!!/)[1]; 18019 } else { 18020 zip_code_placeholder = an_javascript_translation.zip_code; 18021 } 18022 18023 if (zip_code_required == "required" && !zip_code_placeholder.includes("*")) { 18024 zip_code_placeholder = zip_code_placeholder + " *"; 18025 } 18026 18027 if (typeof(zip_code_options_match) != 'undefined' && zip_code_options_match.match(/_label%%(.*)%%/) != null && zip_code_options_match.match(/_label%%(.*)%%/)[1] != null) { 18028 zip_code_label = zip_code_options_match.match(/_label%%(.*)%%/)[1]; 18029 } 18030 18031 var zip_code_html = '<li class="control-group" data-identifier="core_zip_code"><label class="control-label" for="corezipcode">' + zip_code_label + '</label><input id="corezipcode" name="core_zip_code" type="text" placeholder="' + zip_code_placeholder + '" class="input-xlarge ' + zip_code_required + '" ' + zip_code_always_show + ' ' + zip_code_regex + '></li>'; 18032 18033 core_fields_temp = core_fields_temp.replace(zip_code_match, zip_code_html); 18034 18035 18036 var phone_required = ""; 18037 var phone_always_show = ""; 18038 var phone_label = ""; 18039 var phone_placeholder_star = ""; 18040 18041 if (core_fields_temp.match(/@@phone(.*)@@/) != null) { 18042 var phone_match = core_fields_temp.match(/@@phone(.*)@@/)[0]; 18043 } 18044 18045 if (core_fields_temp.match(/@@phone(.*)@@/) != null) { 18046 var phone_options_match = core_fields_temp.match(/@@phone(.*)@@/)[1]; 18047 } 18048 18049 if (typeof(phone_options_match) != 'undefined' && phone_options_match.includes("_required")) { 18050 phone_required = "required"; 18051 phone_placeholder_star = " *"; 18052 } 18053 18054 if (typeof(phone_options_match) != 'undefined' && phone_options_match.includes("_alwaysshow")) { 18055 phone_always_show = 'data-always="true"'; 18056 } 18057 18058 if (typeof(phone_options_match) != 'undefined' && phone_options_match.match(/_label%%(.*)%%/) != null && phone_options_match.match(/_label%%(.*)%%/)[1] != null) { 18059 phone_label = phone_options_match.match(/_label%%(.*)%%/)[1]; 18060 } 18061 18062 var phone_html = '<li class="control-group" data-identifier="core_phone"><label class="control-label" for="corephone">' + phone_label + '</label><input id="corephone" name="core_phone" type="text" placeholder="' + an_javascript_translation.phone + phone_placeholder_star + '" class="input-xlarge ' + phone_required + '" ' + phone_always_show + '></li>'; 18063 18064 core_fields_temp = core_fields_temp.replace(phone_match, phone_html); 18065 18066 18067 //old style code but these ones have no user options 18068 core_fields_temp = core_fields_temp.replace(/@@sms_checkbox@@/g, '<li class="control-group checkbox_group_wrap" data-identifier="core_sms_checkbox"><label class="control-label check_radio_label"></label><span class="controls check_radio_field"><label class="checkbox"><input type="checkbox" name="core_sms_checkbox" value="1" class=" checkbox_group">' + an_javascript_translation.sms_checkbox + " " + an_javascript_translation.sms_checkbox_data + '</label></span></li>'); 18069 18070 core_fields_temp = core_fields_temp.replace(/@@country_required@@/g, '<label class="control-label" for="corecountry"></label><li class="control-group" data-identifier="core_country"><select id="corecountry" name="core_country" class="input-xlarge required can_select js-form_select2"><option value="country">' + an_javascript_translation.country + ' *</option></select></li>'); 18071 18072 //should never happen 18073 core_fields_temp = core_fields_temp.replace(/@@country@@/g, '<label class="control-label" for="corecountry"></label><li class="control-group" data-identifier="core_country"><select id="corecountry" name="core_country" class="input-xlarge required can_select js-form_select2"><option value="country">' + an_javascript_translation.country + ' *</option></select></li>'); 18074 18075 //$('#visual_form_input').val(core_fields_temp.html()); 18076 18077 $('.js-visual_form_target').html(core_fields_temp); 18078 $('.js-visual_form_target #corecountry').parent().prev().before('<span class="international_link-wrap js-international_link-wrap disabled mb10"><a class="international_link js-international_link disabled">' + an_javascript_translation.not_in_the_us + '</a></span>').next().remove().next().remove(); 18079 //console.log($('#visual_form_input').val()); 18080 //$('#visual_form_input').val($('#render').val()); 18081 $('.js-visual_form_target input').addClass('disabled'); 18082 $('.js-visual_form_target textarea').addClass('disabled'); 18083 $('.js-visual_form_target select').addClass('disabled'); 18084 $('.js-visual_form_target label').addClass('disabled'); 18085 $('.js-visual_form_target input').attr('disabled','disabled'); 18086 $('.js-visual_form_target textarea').attr('disabled','disabled'); 18087 $('.js-visual_form_target select').attr('disabled','disabled'); 18088 $('.js-visual_form_target input[type=text]').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 18089 $('.js-visual_form_target textarea').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 18090 $('.js-visual_form_target select').after('<span class="sample_field">'+ an_javascript_translation.sample +'</span>'); 18091 18092 //ranked_choice_sortable_init(); 18093 //$("html, body").css({'overflow':'visible'}); 18094 /* Remove the label if it's empty */ 18095 $('.js-visual_form_target label.check_radio_label').each(function() { 18096 if ($(this).html() == '') { 18097 $(this).hide(); 18098 $(this).next().css('width','100%'); 18099 } 18100 }); 18101 18102 if ($.isFunction($.fn.customSelect) ) { 18103 $("select.can_select").not('.hasCustomSelect').not('.js-form_builder_modal select.can_select').customSelect({customClass:"can_select"}); 18104 } 18105 18106 18107 } 18108 18109 if ($('.js-action_owner-select select').length) { 18110 form_builder_sponsor = $('.js-action_owner-select select').val(); 18111 form_builder_sponsor_name = $('.js-action_owner-select select').find('option:selected').html(); 18112 } 18113 18114 $('.js-action_owner-select select').click(function() { 18115 form_builder_sponsor = $(this).val(); 18116 form_builder_sponsor_name = $(this).find('option:selected').html(); 18117 }); 18118 18119 var get_questions = function($element) { 18120 // $.each(snippets_collection.models, function(i, e) { 18121 // console.log(e.attributes.title); 18122 //}); 18123 //window.setTimeout(function() { 18124 if ($element.val() != '') { 18125 //setTimeout(function() { 18126 $.getJSON('/groups/' + $element.val() + '/questions/data', function(data) { 18127 18128 prebuilt_questions = data; 18129 18130 load_prebuilt_questions(); 18131 18132 if (typeof(form_builder_first_open) != 'undefined') { 18133 //don't remove core fields 18134
18135 //var form_builder_sample_output = $('<div id="temp_render_sample_output">' + $('.js-visual_form_target') + '</div>'); 18136 var form_builder_html_output = $('<div id="temp_render_html_output">' + $('#visual_form_input').val() + '</div>'); 18137 var form_builder_json_output = JSON.parse($('#visual_form_input_json').val()); 18138 18139 //this needs to be more specific 18140 $('.js-visual_form_target .control-group').not('[data-identifier*=core_first_name], [data-identifier*=core_last_name], [data-identifier*=core_email], [data-identifier*=core_street], [data-identifier*=core_city], [data-identifier*=core_zip_code], [data-identifier*=core_phone], [data-identifier*=core_sms_checkbox]').each(function() { 18141 //console.log(this); 18142 //console.log($(this).find('.can_select').length); 18143 if ($(this).find('.can_select').length) { 18144 $(this).prev().remove(); 18145 } 18146 18147 $(this).remove(); 18148 }); 18149 18150 form_builder_html_output.find('.control-group').remove(); 18151 $('#visual_form_input').val(form_builder_html_output.html()); 18152 18153 var form_builder_json_output_edited = []; 18154 $.each(form_builder_json_output, function() { 18155 if (this.question_id && (this.question_id.indexOf('core_first_name') != -1 || this.question_id.indexOf('core_last_name') != -1 || this.question_id.indexOf('core_email') != -1 || this.question_id.indexOf('core_street') != -1 || this.question_id.indexOf('core_city') != -1 || this.question_id.indexOf('core_zip_code') != -1 || this.question_id.indexOf('core_phone') != -1 || this.question_id.indexOf('core_sms_checkbox') != -1 || this.question_id.indexOf('core_country') != -1)) { 18156 form_builder_json_output_edited.push(this); 18157 } 18158 }); 18159 18160 18161 //console.log(CAN_form_builder_initial_JSON); 18162 CAN_form_builder_initial_JSON = form_builder_json_output_edited; 18163 $('#visual_form_input_json').val(JSON.stringify(CAN_form_builder_initial_JSON)); 18164 //console.log(CAN_form_builder_initial_JSON); 18165 18166 //$('.js-visual_form_target').html(''); 18167 //$('#visual_form_input').val(''); 18168 //console.log(snippets_collection.length); 18169 //$.each(snippets_collection.models, function(i, e) { 18170 //console.log(e.attributes.title); 18171 //}); 18172 var destroy_array = []; 18173 $.each(snippets_collection.models, function(i, e) { 18174 //debugger; 18175 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18176 //console.log(e); 18177 //console.log(e.attributes.title); 18178 //console.log(e.attributes); 18179 //console.log(this.attributes.title); 18180 //console.log(this.attributes.question_id); 18181 //this.undelegateEvents().removeData().unbind().destroy(); 18182 //console.log(this.undelegateEvents()); 18183 //console.log(this.removeData().unbind()); 18184 if (typeof(e) == 'undefined' || 18185 (e && e.attributes && e.attributes.title != "Form Name" && 18186 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_first_name') == -1) && 18187 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_last_name') == -1) && 18188 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_email') == -1) && 18189 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_street') == -1) && 18190 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_city') == -1) && 18191 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_zip_code') == -1) && 18192 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_phone') == -1) && 18193 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_sms_checkbox') == -1) && 18194 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_country') == -1) 18195 ) 18196 ) { 18197 //console.log('destroy'); 18198 //console.log(e.attributes.title); 18199 destroy_array.push(e); 18200 18201 //delete snippets_collection.models[i]; 18202 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18203 //return false; 18204 } //else { 18205 //console.log('leave'); 18206 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18207 //console.log(e.attributes.title); 18208 //return true; 18209 //} 18210 18211 }); 18212 18213 $.each(destroy_array, function(i, e) { 18214 this.destroy(); 18215 }); 18216 18217 //console.log(snippets_collection.length); 18218 //$.each(snippets_collection.models, function(i, e) { 18219 //console.log(e.attributes.title); 18220 //}); 18221 //console.log(tab_view_collection); 18222 $(tab_view_collection.models).each(function() { 18223 //console.log(this); 18224 //this.undelegateEvents().removeData().unbind().destroy(); 18225 //console.log(this.undelegateEvents()); 18226 //console.log(this.removeData().unbind()); 18227 this.destroy(); 18228 }); 18229 18230 //form_view.undelegateEvents(); 18231/* 18232 18233 CAN_form_builder_initial_JSON = [ 18234 { "title" : "Form Name", 18235 "fields": { 18236 "name" : { 18237 "label" : "Form Name" 18238 , "type" : "input" 18239 , "value" : "Form Name" 18240 } 18241 } 18242 } 18243 ]; 18244*/ 18245 18246 if (typeof(form_view) != 'undefined') { 18247 //form_view.destroy_view(); 18248 //$('#form_builder_modal #build #target fieldset').remove();
18249 //snippets_collection.invoke('destroy'); 18250 //delete form_view; 18251 } 18252 //console.log(snippets_collection.length); 18253 //$.each(snippets_collection.models, function(i, e) { 18254 //console.log(e.attributes.title); 18255 //}); 18256 18257 } 18258 18259 require("app/app").initialize(); 18260 //console.log(snippets_collection.length); 18261 //$.each(snippets_collection.models, function(i, e) { 18262 //console.log(e.attributes.title); 18263 //}); 18264 18265 18266 18267 /* 18268form_view.undelegateEvents(); 18269 18270 form_view.$el.removeData().unbind(); 18271 18272 // Remove view from DOM 18273 form_view.remove(); 18274 Backbone.View.prototype.remove.call(form_view); 18275 delete(form_view); 18276*/ 18277/* 18278 18279 tab_view1.undelegateEvents(); 18280 18281 tab_view1.$el.removeData().unbind(); 18282 18283 // Remove view from DOM 18284 tab_view1.remove(); 18285 Backbone.View.prototype.remove.call(tab_view1); 18286 18287 tab_view2.undelegateEvents(); 18288 18289 tab_view2.$el.removeData().unbind(); 18290 18291 // Remove view from DOM 18292 tab_view2.remove(); 18293 Backbone.View.prototype.remove.call(tab_view2); 18294*/ 18295 //$('#target fieldset')[0].remove(); 18296 18297 }); 18298 //}, 5000); 18299 } else { 18300 //if (typeof(form_builder_first_open) != 'undefined') { 18301 prebuilt_questions = []; 18302 load_prebuilt_questions(); 18303 //$('.js-visual_form_target').html(''); 18304 //$('#visual_form_input').val(''); 18305 //don't remove core fields 18306 18307 //don't remove core fields 18308 //don't remove core fields 18309 18310 //var form_builder_sample_output = $('<div id="temp_render_sample_output">' + $('.js-visual_form_target') + '</div>'); 18311 var form_builder_html_output = $('<div id="temp_render_html_output">' + $('#visual_form_input').val() + '</div>'); 18312 var form_builder_json_output = JSON.parse($('#visual_form_input_json').val()); 18313 18314 //this needs to be more specific 18315 $('.js-visual_form_target .control-group').not('[data-identifier*=core_first_name], [data-identifier*=core_last_name], [data-identifier*=core_email], [data-identifier*=core_street], [data-identifier*=core_city], [data-identifier*=core_zip_code], [data-identifier*=core_phone], [data-identifier*=core_sms_checkbox]').each(function() { 18316 //console.log(this); 18317 //console.log($(this).find('.can_select').length); 18318 if ($(this).find('.can_select').length) { 18319 $(this).prev().remove(); 18320 } 18321 18322 $(this).remove(); 18323 }); 18324 18325 form_builder_html_output.find('.control-group').remove(); 18326 $('#visual_form_input').val(form_builder_html_output.html()); 18327 18328 var form_builder_json_output_edited = []; 18329 $.each(form_builder_json_output, function() { 18330 if (this.question_id && (this.question_id.indexOf('core_first_name') != -1 || this.question_id.indexOf('core_last_name') != -1 || this.question_id.indexOf('core_email') != -1 || this.question_id.indexOf('core_street') != -1 || this.question_id.indexOf('core_city') != -1 || this.question_id.indexOf('core_zip_code') != -1 || this.question_id.indexOf('core_phone') != -1 || this.question_id.indexOf('core_sms_checkbox') != -1 || this.question_id.indexOf('core_country') != -1)) { 18331 form_builder_json_output_edited.push(this); 18332 } 18333 }); 18334 18335 18336 //console.log(CAN_form_builder_initial_JSON); 18337 CAN_form_builder_initial_JSON = form_builder_json_output_edited; 18338 $('#visual_form_input_json').val(JSON.stringify(CAN_form_builder_initial_JSON)); 18339 //console.log(CAN_form_builder_initial_JSON); 18340 18341 //$('.js-visual_form_target').html(''); 18342 //$('#visual_form_input').val(''); 18343 //console.log(snippets_collection.length); 18344 //$.each(snippets_collection.models, function(i, e) { 18345 //console.log(e.attributes.title); 18346 //}); 18347 var destroy_array = []; 18348 $.each(snippets_collection.models, function(i, e) { 18349 //debugger; 18350 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18351 //console.log(e); 18352 //console.log(e.attributes.title); 18353 //console.log(e.attributes); 18354 //console.log(this.attributes.title); 18355 //console.log(this.attributes.question_id); 18356 //this.undelegateEvents().removeData().unbind().destroy(); 18357 //console.log(this.undelegateEvents()); 18358 //console.log(this.removeData().unbind()); 18359 if (typeof(e) == 'undefined' || 18360 (e && e.attributes && e.attributes.title != "Form Name" && 18361 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_first_name') == -1) && 18362 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_last_name') == -1) && 18363 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_email') == -1) && 18364 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_street')
18364== -1) && 18365 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_city') == -1) && 18366 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_zip_code') == -1) && 18367 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_phone') == -1) && 18368 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_sms_checkbox') == -1) && 18369 (!e.attributes.question_id || e.attributes.question_id.indexOf('core_country') == -1) 18370 ) 18371 ) { 18372 //console.log('destroy'); 18373 //console.log(e.attributes.title); 18374 destroy_array.push(e); 18375 18376 //delete snippets_collection.models[i]; 18377 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18378 //return false; 18379 } //else { 18380 //console.log('leave'); 18381 //console.log(snippets_collection.models.map(function(item) { return item.attributes.title }).join()); 18382 //console.log(e.attributes.title); 18383 //return true; 18384 //} 18385 18386 }); 18387 18388 $.each(destroy_array, function(i, e) { 18389 this.destroy(); 18390 }); 18391 18392 //console.log(snippets_collection.length); 18393 //$.each(snippets_collection.models, function(i, e) { 18394 //console.log(e.attributes.title); 18395 //}); 18396 //console.log(tab_view_collection); 18397 $(tab_view_collection.models).each(function() { 18398 //console.log(this); 18399 //this.undelegateEvents().removeData().unbind().destroy(); 18400 //console.log(this.undelegateEvents()); 18401 //console.log(this.removeData().unbind()); 18402 this.destroy(); 18403 }); 18404 18405 //form_view.undelegateEvents(); 18406/* 18407 18408 CAN_form_builder_initial_JSON = [ 18409 { "title" : "Form Name", 18410 "fields": { 18411 "name" : { 18412 "label" : "Form Name" 18413 , "type" : "input" 18414 , "value" : "Form Name" 18415 } 18416 } 18417 } 18418 ]; 18419*/ 18420 18421 if (typeof(form_view) != 'undefined') { 18422 //form_view.destroy_view(); 18423 //$('#form_builder_modal #build #target fieldset').remove(); 18424 //snippets_collection.invoke('destroy'); 18425 //delete form_view; 18426 } 18427 //console.log(snippets_collection.length); 18428 //$.each(snippets_collection.models, function(i, e) { 18429 //console.log(e.attributes.title); 18430 //}); 18431 18432 18433 18434 18435 18436 require("app/app").initialize(); 18437 //} 18438 } 18439 //}, 3000); 18440 } 18441 18442 var get_custom_html_permissions = function($element) { 18443 if ($element.val() != '') { 18444 $.getJSON('/groups/' + $element.val() + '/check_permissions', function(data) { 18445 if (data.custom_fields && data.enable_ad_hoc_form_builder) { 18446 if ($('.js-custom_form_html textarea').val() != '') { 18447 $('.js-add_custom_form_html-close, .js-custom_form_html').show().css('display','inline-block'); 18448 $('.js-add_custom_form_html').hide(); 18449 } else { 18450 $('.js-add_custom_form_html').show(); 18451 $('.js-add_custom_form_html-close, .js-custom_form_html').hide(); 18452 } 18453 $('.js-blank_questions').show(); 18454 $('.js-locked_customs').hide(); 18455 custom_fields_network_lock = false; 18456 } else { 18457 $('.js-add_custom_form_html, .js-add_custom_form_html-close, .js-custom_form_html').hide(); 18458 $('.js-locked_customs').show(); 18459 18460 custom_fields_network_lock = true; 18461 //$('.js-custom_form_html textarea').val(''); 18462 } 18463 $('.js-qustions_edit_link').show() 18464 .attr('href', '/groups/' + data.permalink + '/questions') 18465 // Prevent collapsing section when clicking edit link 18466 .click(e => { e.stopPropagation(); }); 18467 }); 18468 } else { 18469 if ($('.js-custom_form_html textarea').val() != '') { 18470 $('.js-add_custom_form_html-close, .js-custom_form_html').show().css('display','inline-block'); 18471 $('.js-add_custom_form_html').hide(); 18472 } else { 18473 $('.js-add_custom_form_html').show(); 18474 $('.js-add_custom_form_html-close, .js-custom_form_html').hide(); 18475 } 18476 $('.js-blank_questions').show(); 18477 $('.js-locked_customs').hide(); 18478 $('.js-qustions_edit_link').hide().attr('href', 'javascript:void(0);'); 18479 custom_fields_network_lock = false; 18480 } 18481 } 18482 18483 $('.js-action_owner-select select').change(function() { 18484 var change_sponsor_confirmation_keywords = true; 18485 if ($('.js-has_keywords').length) { 18486 change_sponsor_confirmation_keywords = confirm(an_javascript_translation.changing_the_sponsoring_group_for_this_action); 18487 } 18488 18489 if (change_sponsor_confirmation_keywords == true) { 18490 if ($('.js-visual_form_target .control-group').not('.js-visual_form_target .control-group[data-identifier*="core_"]').length || ($('.js-custom_form_html textarea').val() != '' && typeof($('.js-custom_form_html textarea').val()) != "undefined")) { 18491 var change_sponsor_confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_change_the_sponsor); 18492 if (change_sponsor_confirmation == true) { 18493 if (typeof(form_builder_first_open) == 'undefined') { 18494 form_builder_first_open = true; 18495 } 18496 get_questions($(this)); 18497 get_custom_html_permissions($(this)); 18498 18499 /* show/hide preview section */ 18500 if ($('.js-action_owner-select select').find('option:selected').attr('class') != '' && $('.js-action_owner-select select').find('option:selected').attr('class') != undefined && !$('.js-save_and_view').length) { 18501 $('.js-create_action_toolbox div.left').fadeOut(); 18502 } else { 18503 $('.js-create_action_toolbox div.left').fadeIn(); 18504 } 18505 18506 form_builder_sponsor = $(this).val(); 18507 form_builder_sponsor_name = $(this).find('option:selected').html(); 18508 18509 $('.js-clear_survey_pages').val('true'); 18510 } else { 18511 if (typeof(form_builder_sponsor) != "undefined") { 18512 $(this).val(form_builder_sponsor).select2("val", form_builder_sponsor); 18513 } else { 18514 $(this).val('').select2("val", ""); 18515 } 18516 18517 //$(this).siblings( 'span.can_select' ).find('.can_selectInner').html(form_builder_sponsor_name); 18518 } 18519 } else { 18520 if ($('.js-call_target').length) { 18521 $.post('/call_campaigns/refresh_phone_numbers', "group_id=" + $('.js-action_owner-select select').val() + "&permalink=" + $('select.js-call-campaign_call_campaign_phone_number').data('permalink'), function(data) { 18522 $('select.js-call-campaign_call_campaign_phone_number').val(''); 18523 $('select.js-call-campaign_call_campaign_phone_number options').remove(); 18524 $('select.js-call-campaign_call_campaign_phone_number').html('<option value="">' + an_javascript_translation.select_a_phone_number + ' *</option>'); 18525 18526 $.each(data, function(i, data) { 18527 //console.log(data); 18528 //datavar = data; 18529 //console.log(data["current_call_campaign_owner_permalink"]); 18530 if(data.current_phone_number_owner_permalink) { 18531 //console.log('if'); 18532 i = i + " [in use]" 18533 } 18534 //console.log(i); 18535 18536 option = new Option(i, `["${data.phone_number}","${data.sid}"]`, false, false); 18537 if(data.current_phone_number_owner_permalink){ 18538 option.dataset["permalink"] = data.current_phone_number_owner_permalink 18539 option.dataset["title"] = data.current_phone_number_owner_title 18540 } 18541 18542 $('select.js-call-campaign_call_campaign_phone_number').append(option); 18543 }); 18544 $('select.js-call-campaign_call_campaign_phone_number').trigger('change'); 18545 }); 18546 if ($('.js-switch-enabled').length) { 18547 if (typeof(form_builder_first_open) == 'undefined') { 18548 form_builder_first_open = true; 18549 } 18550 get_questions($(this)); 18551 get_custom_html_permissions($(this)); 18552 18553 /* show/hide preview section */ 18554 if ($('.js-action_owner-select select').find('option:selected').attr('class') != '' && $('.js-action_owner-select select').find('option:selected').attr('class') != undefined && !$('.js-save_and_view').length) { 18555 $('.js-create_action_toolbox div.left').fadeOut(); 18556 } else { 18557 $('.js-create_action_toolbox div.left').fadeIn(); 18558 } 18559 } 18560 } else { 18561 if (typeof(form_builder_first_open) == 'undefined') { 18562 form_builder_first_open = true; 18563 } 18564 get_questions($(this)); 18565 get_custom_html_permissions($(this)); 18566 18567 /* show/hide preview section */ 18568 if ($('.js-action_owner-select select').find('option:selected').attr('class') != '' && $('.js-action_owner-select select').find('option:selected').attr('class') != undefined && !$('.js-save_and_view').length) { 18569 $('.js-create_action_toolbox div.left').fadeOut(); 18570 } else { 18571 $('.js-create_action_toolbox div.left').fadeIn(); 18572 } 18573 } 18574 } 18575 } else { 18576 if (typeof(form_builder_sponsor) != "undefined") { 18577 $(this).val(form_builder_sponsor).select2("val", form_builder_sponsor); 18578 } else { 18579 $(this).val('').select2("val", ""); 18580 } 18581 } 18582 18583 }); 18584 18585 if ($('.js-action_owner-select select').length) { 18586 get_custom_html_permissions($('.js-action_owner-select select')); 18587 if ($('.js-action_owner-select select').val() != '') { 18588 get_questions($('.js-action_owner-select select')); 18589 } else { 18590 load_prebuilt_questions(); 18591 } 18592 } else { 18593 if (typeof(prebuilt_questions) != 'undefined') { 18594 load_prebuilt_questions(); 18595 } 18596 } 18597 18598 18599 if ($('.js-custom_field_text_input_show').length) { 18600 $('.js-single_user_view-districts').on('click', '.js-custom_field_text_input_show a', function() { 18601 $(this).fadeOut(); 18602 $(this).parent().parent().find('.can_select').val('').hide().attr('name',''); 18603 $(this).parent().parent().find('input').fadeIn().attr('name','custom_fields[NEW_ITEM_' + new_custom_field_count + '][key]'); 18604 }); 18605 } 18606 18607 if ($('.js-upload_audio_message').length) { 18608 if (!$('.js-audio_player-wrap').length) { 18609 $('.js-upload_audio_message .js_audiofile_upload').addClass('required'); 18610 } 18611
18612 $('.js-replace_audio_file').click(function() { 18613 $('.js-audio_player-wrap').slideUp(function() { 18614 $('.js-upload_audio_message').show(); 18615 }); 18616 }); 18617 } 18618 18619 // fundraising without email permissions checks 18620 function customFieldShowHide(permalink, change) { 18621 //console.log(change); 18622 $.getJSON('/groups/' + permalink + '/check_permissions', function(data) { 18623 //console.log(change); 18624 if (data.settings) { 18625 $('.js-bypass_email_wrap').slideDown('fast'); 18626 } else { 18627 $('.js-bypass_email_wrap').slideUp('fast'); 18628 if (change) { 18629 //console.log('fire'); 18630 $('#fundraising_donations_without_email').attr('checked',false); 18631 $('.js-fundraising_default_email').removeClass('required'); 18632 } 18633 } 18634 }) 18635 .error(function() { 18636 //console.log('error'); 18637 $('.js-bypass_email_wrap').slideUp('fast'); 18638 if (change) { 18639 $('#fundraising_donations_without_email').attr('checked',false); 18640 $('.js-fundraising_default_email').removeClass('required'); 18641 } 18642 }); 18643 } 18644 18645 18646 18647 //$('link[href="//clients.designcrumbs.com/can/_mock/_skeleton/includes/js/form_builder_assets/css/lib/bootstrap.min.css"]')[0].disabled = true; 18648 //$('link[href="//clients.designcrumbs.com/can/_mock/_skeleton/includes/js/form_builder_assets/css/lib/bootstrap-responsive.min.css"]')[0].disabled = true; 18649 18650 18651 form_submit_init = function() { 18652 //console.log('hi'); 18653 codemirror_error_flag = false; 18654 checkboxErrorFlag = false; 18655 donation_recipient_error_flag = false; 18656 donation_amount_error_flag = false; 18657 letter_targets_error_flag = false; 18658 syndication_targets_error_flag = false; 18659 email_chosen_error_flag = false; 18660 uuid_chosen_error_flag = false; 18661 transaction_chosen_error_flag = false; 18662 alternate_body_title_error_flag = false; 18663 noemailaddress_flag = false; 18664 signature_error_flag = false; 18665 18666 18667 $('form').submit(function (e) { 18668 if ($('.js-form_signature_field').length) { 18669 var $signature_pad = $('.js-signature-pad') 18670 var signature_pad_element = $signature_pad[0]; 18671 if (signature_pad_element.signaturePadInstance.isEmpty()) { 18672 $signature_pad.addClass('error_input'); 18673 signature_error_flag = true; 18674 return false; 18675 } else { 18676 signature_error_flag = false; 18677 $signature_pad.removeClass('error_input'); 18678 } 18679 } 18680 18681 if ($('.js-replyto_add_new_warning').length) { 18682 if (submitClicked == 'email-next_step') { 18683 alert(an_javascript_translation.your_group_has_not_set_up_a_verified_replyto_nopass); 18684 return false; 18685 } else { 18686 alert(an_javascript_translation.your_group_has_not_set_up_a_verified_replyto); 18687 } 18688 18689 } 18690 18691 if ($('.js-recording_upload').length) { 18692 //console.log($('.js-recording_upload').val()); 18693 //console.log($('.js-recording_upload').val() != ''); 18694 if ($('.js-recording_upload').val() != '') { 18695 $('.js_audiofile_upload').remove(); 18696 } else { 18697 $('.js-recording_upload').remove(); 18698 } 18699 } 18700 18701 if ($('.js-letter_variant_slider').length) { 18702 //console.log('start'); 18703 var variant_error = false; 18704 var variant_error_number = -1; 18705 $('.js-single_variant_slide').each(function() { 18706 if (!variant_error) { 18707 if (($(this).find('.js-letter_template_subject').val() == '' && $(this).find('.js-letter_template_subject').hasClass('required')) || ($(this).find('.js-letter_template_message').val() == '' && $(this).find('.js-letter_template_message').hasClass('required'))) { 18708 //console.log('true'); 18709 variant_error = true; 18710 variant_error_number = $(this).data('variant'); 18711 } 18712 } 18713 18714 }); 18715 18716 if (variant_error_number != -1) { 18717 //console.log(variant_error_number); 18718 $('.js-letter_variant_slider').data('flexslider').flexslider(variant_error_number); 18719 flexslider_button_visibility(true); 18720 } 18721 18722 } 18723 if (typeof(detected_country) == 'undefined' || detected_country == '') { 18724 detected_country = 'US'; 18725 } 18726 //console.log(detected_country); 18727 18728 if ($('.js-event-province').length) { 18729 if (!$('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').hasClass('hasCustomSelect')) { 18730 $('.js-create-event-state-drop_down select, .js-cc_state_drop_wrap select').customSelect({customClass:"can_select"}); 18731 } 18732 if ($('.js-country_drop_wrap select').not('.js-suggested_modal .js-country_drop_wrap select').val() == 'CA') { 18733 //console.log('ca'); 18734 $(this).parent().parent().parent().find('.js-event-province, .js-event-state-select-wrap').show(); 18735 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 18736 $(this).parent().parent().parent().find('select.js-event-province').attr('disabled', false).addClass('required'); 18737 } 18738 18739 $(this).parent().parent().parent().find('.js-event-state').hide(); 18740 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 18741 $(this).parent().parent().parent().find('select.js-event-state').attr('disabled', 'disabled').removeClass('required'); 18742 } 18743 } else if ($('.js-country_drop_wrap select').not('.js-suggested_modal .js-country_drop_wrap select').val() == 'US') { 18744 //console.log('us'); 18745 $(this).parent().parent().parent().find('.js-event-province').hide(); 18746 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 18747 $(this).parent().parent().parent().find('select.js-event-province').attr('disabled', 'disabled').removeClass('required'); 18748 } 18749 18750 $(this).parent().parent().parent().find('.js-event-state, .js-event-state-select-wrap').show(); 18751 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 18752 $(this).parent().parent().parent().find('select.js-event-state').attr('disabled', false).addClass('required'); 18753 } 18754 } else { 18755 //console.log('else'); 18756 $(this).parent().parent().parent().find('.js-event-province, .js-event-state, .js-event-state-select-wrap').hide(); 18757 if (!($('.js-event_physical_location_toggle-enabled').length || $('.js-event_physical_location_toggle-enabled').length)) { 18758 $(this).parent().parent().parent().find('select.js-event-province, select.js-event-state').attr('disabled', 'disabled').removeClass('required'); 18759 } 18760 } 18761 18762 } else if ($('.js-donate_form, .js-event_end_date, .js-single_include_exclude_section, .js-user-state-drop_down, .js-profile-form-country, .js-buy_tickets_form').length) { 18763 if ( ($('.js-country_drop_wrap select').not('.js-suggested_modal .js-country_drop_wrap select').val() == 'US') && !$('.js-event_physical_location_toggle-enabled').length) { 18764 $(this).removeClass('required'); 18765 $('.js-country_drop_wrap').hide(); 18766 18767 if (!$('.js-tab_comp').length) { 18768 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').addClass('required'); 18769 } 18770 $('.js-cc_state_drop_wrap').show(); 18771 $('.js-international_link-wrap').show(); 18772 $(".js-create-event-state-drop_down").show(); 18773 } 18774 } else { 18775 if ( ($('.js-country_drop_wrap select').not('.js-suggested_modal .js-country_drop_wrap select').val() == detected_country) && !$('.js-event_physical_location_toggle-enabled').length) { 18776 $(this).removeClass('required'); 18777 $('.js-country_drop_wrap').hide(); 18778 18779 if (!$('.js-tab_comp').length) { 18780 $('.js-cc_state_drop_wrap select, .js-create-event-state-drop_down select').addClass('required'); 18781 } 18782 $('.js-cc_state_drop_wrap').show(); 18783 $('.js-international_link-wrap').show(); 18784 $(".js-create-event-state-drop_down").show(); 18785 } 18786 } 18787 18788 18789 // any button with the submit_new_tab class will submit the form in a new tab 18790 if ((/submit_new_tab/).test($('#' + submitClicked).attr('class'))) { 18791 $('#' + submitClicked).parents('form').attr('target', '_blank'); 18792 } else { 18793 $('#' + submitClicked).parents('form').attr('target', '_self'); 18794 } 18795 18796 donation_return_flag = false;
18797 18798 if (!(/cancel/).test($('#' + submitClicked).attr('class'))) { 18799 //console.log(submitClicked); 18800 //console.log((/cancel/).test($('#petition-save_draft').attr('class'))); 18801 if ($('.js-html-textarea.required, .js-mobile-codemirror-textarea.required').length) { 18802 $('.js-html-textarea.required, .js-mobile-codemirror-textarea.required').each(function() { 18803 if ($(this).val() == '') { 18804 codemirror_error_flag = true; 18805 return false; 18806 } else { 18807 $(this).parent().find('.CodeMirror-wrap').removeClass('error_input'); 18808 codemirror_error_flag = false; 18809 } 18810 }); 18811 } 18812 18813 //this deals with other options on custom questions and required fields 18814 $('.js-form_builder_other_input').each(function() { 18815 if ($(this).is(':visible') && $(this).val() == '' && $(this).parents('.control-group').find('.required, .required_checkboxes').length) { 18816 $(this).parents('.control-group').find('.js-other_option').attr('checked', false).trigger('change'); 18817 $(this).parents('.control-group').find('select').val('').trigger('change'); 18818 } 18819 }); 18820 18821 18822 if ($('.checkbox_group_wrap .required_checkboxes').length && !$('.js-form_create').length) { 18823 //console.log($('.checkbox_group_wrap .required').parent().parent().parent()); 18824 $('.checkbox_group_wrap .required_checkboxes').parent().parent().parent().each(function() { 18825 //console.log(this); 18826 if ($(this).find('span').find('label').find('.required_checkboxes:checked').length == 0) { 18827 checkboxErrorFlag = true; 18828 return false; 18829 } else { 18830 $(this).find('span').find('label').find('.required_checkboxes').each(function() { 18831 $(this).removeClass('error_input'); 18832 $(this).parent().removeClass('error_checkbox'); 18833 }); 18834 18835 checkboxErrorFlag = false; 18836 //console.log(checkboxErrorFlag); 18837 18838 } 18839 }); 18840 18841 //return false; 18842 } 18843 18844 18845 if ($('.js-donate_add_dollar_amount').length || $('.js-add_ticket_option').length) { 18846 18847 if ($('.js-single_recipient-create').length) { 18848 $('.js-please_add_recipient').removeClass('error_input'); 18849 } else { 18850 donation_recipient_error_flag = true; 18851 donation_return_flag = true; 18852 } 18853 18854 $('.js-donate_amount_enter').val(''); 18855 18856 18857 if (donation_return_flag) { 18858 return false; 18859 } 18860 } 18861 18862 //target letter version error checking 18863 if ($('.js-target_selection_input').length) { 18864 if ($('.js-target_selection_input').val() == '') { 18865 letter_targets_error_flag = true; 18866 } else { 18867 $('.js-target_count_wrap').removeClass('error_input'); 18868 letter_targets_error_flag = false; 18869 } 18870 18871 if (letter_targets_error_flag) { 18872 return false; 18873 } 18874 } 18875 18876 //target syndication error checking 18877 if ($('.js-syndicate_group_list_wrap').length) { 18878 if ($('.js-group_syndication_selection').val() == '') { 18879 syndication_targets_error_flag = true; 18880 } else { 18881 $('.js-syndicate_group_list_wrap .empty').removeClass('error_input'); 18882 syndication_targets_error_flag = false; 18883 } 18884 18885 if (syndication_targets_error_flag) { 18886 return false; 18887 } 18888 } 18889 18890 18891 $('input.js-required_noname, select.js-required_noname').each(function(i) { 18892 cc_info_validation($(this)); 18893 }); 18894 18895 //upload error validation 18896 18897 18898 if ($('form .js-edit_list').length){ 18899 email_chosen_error_flag = true; 18900 Noty.closeAll(); 18901 $('select.js-select_search').each(function() { 18902 18903 if ($(this).val() == 'email') { 18904 email_chosen_error_flag = false; 18905 18906 } 18907 //console.log(email_chosen); 18908 }); 18909 18910 if (email_chosen_error_flag) { 18911 new Noty({ 18912 theme: 'metroui', 18913 type: 'error', 18914 closeWith: ['button'], 18915 text: "<span class='noty_icon'><i class='far fa-exclamation-circle'></i></span> " + an_javascript_translation.upload_you_must_choose_email 18916 }).show(); 18917 return false; 18918 } else { 18919 $('select.can').removeClass('error_input'); 18920 } 18921 } 18922 18923 if ($('form .js-edit_list_uuid').length){ 18924 uuid_chosen_error_flag = true; 18925 Noty.closeAll(); 18926 $('select.js-select_search').each(function() { 18927 18928 if ($(this).val() == 'uuid') { 18929 uuid_chosen_error_flag = false;
18930 18931 } 18932 //console.log(email_chosen); 18933 }); 18934 18935 if (uuid_chosen_error_flag) { 18936 new Noty({ 18937 theme: 'metroui', 18938 type: 'error', 18939 closeWith: ['button'], 18940 text: "<span class='noty_icon'><i class='far fa-exclamation-circle'></i></span> " + an_javascript_translation.upload_uuid_required 18941 }).show(); 18942 return false; 18943 } else { 18944 $('select.can').removeClass('error_input'); 18945 } 18946 } 18947 18948 if ($('form .js-edit_list_transaction').length){ 18949 transaction_chosen_error_flag = true; 18950 18951 var transaction_chosen_email = false; 18952 var transaction_chosen_amount = false; 18953 var transaction_chosen_recurring = false; 18954 18955 Noty.closeAll(); 18956 $('select.js-select_search').each(function() { 18957 18958 if ($(this).val() == 'amount') { 18959 transaction_chosen_amount = true; 18960 } else if ($(this).val() == 'email') { 18961 transaction_chosen_email = true; 18962 } else if ($(this).val() == 'recurring') { 18963 transaction_chosen_recurring = true; 18964 } 18965 //console.log(email_chosen); 18966 }); 18967 18968 if (transaction_chosen_amount && transaction_chosen_email && transaction_chosen_recurring) { 18969 transaction_chosen_error_flag = false; 18970 } 18971 18972 if (transaction_chosen_error_flag) { 18973 new Noty({ 18974 theme: 'metroui', 18975 type: 'error', 18976 closeWith: ['button'], 18977 text: "<span class='noty_icon'><i class='far fa-exclamation-circle'></i></span> " + an_javascript_translation.upload_email_amount_recurring 18978 }).show(); 18979 return false; 18980 } else { 18981 $('select.can').removeClass('error_input'); 18982 } 18983 } 18984 18985 //alternate body visual editor error check 18986 if ($('form .js-alternate_body_title_wrap').length){ 18987 alternate_body_title_error_flag = false; 18988 if ($('.js-email_redactor_wrap').length) { 18989 $('.js-email_redactor_wrap').each(function() { 18990 // console.log($(this).find('.js-alternate_body_title_wrap').length); 18991 // console.log($(this).find('.js-redactor').redactor('code.get') != ""); 18992 // console.log(!(/redactor_placeholder/).test($(this).find('.js-redactor').redactor('code.get'))); 18993 // console.log($(this).find('.js-alternate_body_title_wrap input').val() == ''); 18994 if ($(this).find('.js-alternate_body_title_wrap').length && $(this).find('.js-redactor').redactor('code.get') != "" && !(/redactor_placeholder/).test($(this).find('.js-redactor').redactor('code.get')) && $(this).find('.js-alternate_body_title_wrap input').val() == '') { 18995 $(this).find('.js-alternate_body_title_wrap input').addClass('error_input'); 18996 alternate_body_title_error_flag = true; 18997 } else { 18998 $(this).find('.js-alternate_body_title_wrap input').removeClass('error_input'); 18999 } 19000 }); 19001 19002 if (alternate_body_title_error_flag) { 19003 return false; 19004 } 19005 } else { 19006 $('.js-sms_body_textarea').each(function() { 19007 //console.log($(this).find('.js-alternate_body_title_wrap').length); 19008 // console.log($(this).find('.js-redactor').redactor('code.get') != ""); 19009 // console.log(!(/redactor_placeholder/).test($(this).find('.js-redactor').redactor('code.get'))); 19010 //console.log($(this).find('.js-alternate_body_title_wrap input').val() == ''); 19011 //console.log($(this).find('.js-mobile_message_body').val() != ""); 19012 if ($(this).find('.js-alternate_body_title_wrap').length && $(this).find('.js-mobile_message_body').val() != "" && $(this).find('.js-alternate_body_title_wrap input').val() == '') { 19013 //console.log('tre'); 19014 $(this).find('.js-alternate_body_title_wrap input').addClass('error_input'); 19015 alternate_body_title_error_flag = true; 19016 } else { 19017 $(this).find('.js-alternate_body_title_wrap input').removeClass('error_input'); 19018 } 19019 }); 19020 19021 if (alternate_body_title_error_flag) { 19022 return false; 19023 } 19024 } 19025 19026 } 19027 19028 } 19029 19030 noemailaddress_flag = false; 19031 //console.log('start'); 19032 $(".js-noemailaddress").each(function() { 19033 //console.log($(this)); 19034 //console.log($(this).val()); 19035 //console.log($(this).val().includes('@')); 19036 if ($(this).val().includes('@')) { 19037 $(this).addClass('error_input'); 19038 noemailaddress_flag = true; 19039 } else { 19040 $(this).removeClass('error_input'); 19041 } 19042 }); 19043 19044 //console.log(noemailaddress_flag); 19045 //console.log(checkboxErrorFlag); 19046 }); 19047 } 19048 form_submit_init(); 19049 19050 19051 //mobile phone error checking 19052 $("form input[type='submit']").click(function (e) { 19053 mobile_phone_error_flag = false;
19054 if ($.isFunction($.fn.intlTelInput)) { 19055 if ($("#form-phone").length) { 19056 if ($("#form-phone").val() == '' || $("#form-phone").intlTelInput('isValidNumber') || $("#form-phone").hasClass('cancel')) { 19057 $("#form-phone").removeClass('error_input'); 19058 mobile_phone_error_flag = false; 19059 } else { 19060 setTimeout(function() { 19061 $("#form-phone").addClass('error_input'); 19062 }, 1); 19063 mobile_phone_error_flag = true; 19064 } 19065 //console.log(mobile_phone_error_flag); 19066 if (mobile_phone_error_flag) { 19067 //console.log('stop'); 19068 $("form").valid(); 19069 return false; 19070 } else if ($("form").valid()) { 19071 19072 if ($("#form-phone").val() != '' && !$("#form-phone").hasClass('cancel')) { 19073 //console.log('go'); 19074 $("#form-phone").val($("#form-phone").intlTelInput('getNumber')); 19075 } 19076 } 19077 } 19078 19079/* this doesn't quite work how it needs to, things like "jason 9148061939" validate when they shouldn't... 19080 if ($(".js-search_user_field").length) { 19081 19082 if ($(".js-search_user_field").val() != '' && $(".js-search_user_field").intlTelInput('isValidNumber') ) { 19083 //console.log('go'); 19084 $(".js-search_user_field").val($(".js-search_user_field").intlTelInput('getNumber')); 19085 } 19086 } 19087*/ 19088 } 19089 19090 19091 }); 19092 19093 $('.required_checkboxes').change(function () { 19094 $('.checkbox_group_wrap').each(function() { 19095 if ($(this).find('.required_checkboxes').length) { 19096 //console.log(this); 19097 if ($(this).find('span').find('label').find('.required_checkboxes:checked').length > 0) { 19098 //console.log('true2'); 19099 $(this).find('span').find('label').find('.required_checkboxes').each(function() { 19100 //console.log(this); 19101 $(this).removeClass('error_input'); 19102 $(this).parent().removeClass('error_checkbox'); 19103 }); 19104 19105 checkboxErrorFlag = false; 19106 if (typeof(form_id) != 'undefined' && $('#' + form_id).is('form')) { 19107 $('#' + form_id).valid(); 19108 } 19109 } else { 19110 //console.log('false2'); 19111 checkboxErrorFlag = true; 19112 if (typeof(form_id) != 'undefined' && $('#' + form_id).is('form')) { 19113 $('#' + form_id).valid(); 19114 } 19115 } 19116 } 19117 19118 }); 19119 }); 19120 19121 $('.required:radio').change(function () { 19122 if ($(this).attr('checked')) { 19123 $(this).parents(".check_radio_field").find('label').removeClass("error_checkbox"); 19124 } 19125 }); 19126 19127 // Show/hide Email Notification text fields 19128 settings_checkbox_init = function() { 19129 if ($('.js-notification_checkbox').is(':checked')) { 19130 $('.js-notification_checkbox').parent().siblings(".js-notification_email_wrap").show().find('input').addClass('required'); 19131 $('.js-notification_checkbox').parents('.js-notification_wrap').find('.js-notification_stats_checkbox').show(); 19132 } 19133 $('.js-notification_checkbox').click(function() { 19134 if( $(this).is(':checked')) { 19135 $(this).parents('.js-notification_wrap').find(".js-notification_email_wrap").fadeIn('100').find('input').addClass('required'); 19136 $(this).parents('.js-notification_wrap').find('.js-notification_stats_checkbox').fadeIn('100'); 19137 } else { 19138 $(this).parents('.js-notification_wrap').find(".js-notification_email_wrap").hide().find('input').removeClass('required error_input'); 19139 $(this).parents('.js-notification_wrap').find('.js-notification_stats_checkbox').hide(); 19140 } 19141 }); 19142 19143 // Show/hide delayed/failed notification text fields 19144 if ($('.js-delayed_notification_checkbox').is(':checked')) { 19145 $('.js-delayed_notification_checkbox').parent().siblings(".js-notification_email_wrap").show().find('input').addClass('required'); 19146 } 19147 $('.js-delayed_notification_checkbox').click(function () { 19148 if ($(this).is(':checked')) { 19149 $(this).parents('.js-notification_wrap').find(".js-notification_email_wrap").fadeIn('100').find('input').addClass('required'); 19150 } else { 19151 $(this).parents('.js-notification_wrap').find(".js-notification_email_wrap").hide().find('input').val("").removeClass('required error_input'); 19152 } 19153 }); 19154 19155 // Enable/Disable deliverability notification text fields (Group Settings) 19156 $('.js-deliverability_notification_checkbox').change(function () { 19157 if ($(this).is(':checked')) { 19158 $(this).closest('.js-deliverability_notif_fields_wrap').find('.js-deliverability_notif_text_field').attr('disabled', false).removeClass('disabled'); 19159 } else { 19160 $(this).closest('.js-deliverability_notif_fields_wrap').find('.js-deliverability_notif_text_field').attr('disabled', true).addClass('disabled'); 19161 } 19162 }); 19163 19164 // Show/hide donation cancellation text fields 19165 if (!$('.js-allow_cancel_checkbox').is(':checked')) { 19166 $('.js-allow_cancel_checkbox').parent().siblings(".js-allow_cancel_wrap").show().find('input').addClass('required'); 19167 } 19168 $('.js-allow_cancel_checkbox').click(function() { 19169 if( $(this).is(':checked')) { 19170 $(this).parent().siblings(".js-allow_cancel_wrap").hide().find('input').removeClass('required'); 19171 } else { 19172 $(this).parent().siblings(".js-allow_cancel_wrap").fadeIn('100').find('input').addClass('required'); 19173 } 19174 }); 19175 19176 // carrier lookup warning checkbox 19177 $('.js-carrier_lookup_checkbox').change(function() { 19178 if ($(this).is(':checked')) { 19179 alert(an_javascript_translation.carrier_warning); 19180 } 19181 }); 19182 } 19183 settings_checkbox_init(); 19184 19185/* 19186 $.validator.addMethod("checkbox_group", function(value, element) { 19187 if ($('.checkbox_group:checked').length > 0) { 19188 console.log(element); 19189 return element; 19190 } 19191 19192 }); 19193*/ 19194 19195 19196 /* ======================= dashboard js ========================= */ 19197 19198 function setCookie(key, value) { 19199 var expires = new Date(); 19200 expires.setTime(expires.getTime() + (5000 * 24 * 60 * 60 * 1000)); // 5000 days 19201 document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; 19202 } 19203 19204 function getCookie(key) { 19205 var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); 19206 return keyValue ? keyValue[2] : null; 19207 } 19208 19209 if ($('.js-dashboard').length && typeof(hopscotch) != "undefined") { 19210 // Show the tour when... 19211 if ( 19212 // ...no cookie... 19213 !getCookie('seen_dashboard_tour' + $('.js-dashboard_profile_link').attr('href')) && 19214 // ...no groups... 19215 $('#dashboard_groups .js-nothing_yet').length 19216 ) { 19217 var width; 19218 var group_width; 19219 var organizing_menu; 19220 var profile_menu; 19221 var organizing_width; 19222 19223 if (under1024Flag) { 19224 width = 200; 19225 group_width = 200; 19226 organizing_width = 180; 19227 } else { 19228 width = 280; 19229 group_width = 400; 19230 organizing_width = 280; 19231 } 19232 19233 var tour = { 19234 id: "dashboard-tour", 19235 steps: [ 19236 {
19237 title: an_javascript_translation.welcome_to_action_network, 19238 content: `<p>${an_javascript_translation.were_glad_youre_here}</p><p>${an_javascript_translation.as_you_get_started_we_wanted_to_show_you_a_bit_about_our_toolset}</p><p>${an_javascript_translation.this_is_the_dashboard_your_homepage_for_your_work_on_action_network}</p>`, 19239 target: document.querySelector(".js-action_head h2"), 19240 placement: "bottom", 19241 width: width 19242 }, 19243 { 19244 title: an_javascript_translation.get_started_with_a_group, 19245 content: `<p>${an_javascript_translation.most_organizers_use_groups_to_represent_their_organization_campaign_or_coalition}</p><p>${an_javascript_translation.each_group_comes_with_its_own_list_and_can_sponsor_actions}</p><p>${an_javascript_translation.once_youve_made_or_joined_a_group_itll_show_up_here_click_the_button_next}</p>`, 19246 target: document.querySelector(".js-dashboard_groups .js-nothing_yet"), 19247 placement: "bottom", 19248 width: group_width 19249 }, 19250 { 19251 title: an_javascript_translation.then_start_organizing, 19252 content: `<p>${an_javascript_translation.links_to_create_different_actions_like_petitions_or_fundraising_pages_our_mass_mailer_and_all_kinds_of_other_settings}</p>`, 19253 target: document.querySelector(".js-mega_button"), 19254 placement: "bottom", 19255 width: organizing_width 19256 }, 19257 { 19258 title: an_javascript_translation.edit_your_profile, 19259 content: `<p>${an_javascript_translation.if_you_need_to_edit_your_profile_for_any_reason_log_out}</p>`, 19260 target: document.querySelector(".js-navatar_wrap"), 19261 placement: "left", 19262 width: 180 19263 }, 19264 { 19265 title: an_javascript_translation.find_your_stuff, 19266 content: `<p>${an_javascript_translation.if_youve_created_actions_or_emails_that_arent_sponsored_by_a_group}</p><p>${an_javascript_translation.otherwise_theyll_be_in_your_groups_manage_page_accessible_by}</p>`, 19267 target: document.querySelector(".js-dashboard-emails .js-nothing_yet"), 19268 placement: "bottom", 19269 width: width 19270 }, 19271 { 19272 title: an_javascript_translation.thats_it, 19273 content: `<p>${an_javascript_translation.you_re_ready_to_go}</p><p>${an_javascript_translation.if_you_need_help_or_have_questions_links_to_support_documents_video_tutorials}</p>`, 19274 target: document.querySelector(".js-action_head h2"), 19275 placement: "bottom", 19276 width: width 19277 } 19278 ], 19279 i18n: { 19280 nextBtn: an_javascript_translation.next, 19281 doneBtn: an_javascript_translation.done 19282 } 19283 }; 19284 19285 hopscotch.endTour(true); 19286 hopscotch.startTour(tour); 19287 } 19288 19289 setCookie('seen_dashboard_tour' + $('.js-dashboard_profile_link').attr('href'),'1'); 19290 } 19291 19292 if ($('.js-basejump_icon_trigger').length && $('.js-group_admin_page').length && typeof(hopscotch) != "undefined") { 19293 // Show the tour when... 19294 if ( 19295 !getCookie('seen_actionbot_tour') 19296 ) { 19297 var width; 19298 var group_width; 19299 var organizing_menu; 19300 var profile_menu; 19301 var organizing_width; 19302 19303 if (under1024Flag) { 19304 width = 200; 19305 group_width = 200; 19306 organizing_width = 180; 19307 } else { 19308 width = 280; 19309 group_width = 400; 19310 organizing_width = 280; 19311 } 19312 19313 var tour = { 19314 id: "actionbot-tour", 19315 steps: [ 19316 { 19317 title: an_javascript_translation.interact_with_your_data_with_databot, 19318 content: an_javascript_translation.databot_is_a_powerful_tool_that_lets_you_explore, 19319 target: document.querySelector(".js-basejump_icon_trigger"), 19320 placement: "left", 19321 width: width 19322 } 19323 ], 19324 i18n: { 19325 nextBtn: an_javascript_translation.next, 19326 doneBtn: an_javascript_translation.done 19327 } 19328 }; 19329 19330 hopscotch.endTour(true); 19331 hopscotch.startTour(tour); 19332 } 19333 19334 setCookie('seen_actionbot_tour','1'); 19335 } 19336 19337 /* better select inputs */ 19338 can_select_init = function() { 19339 if ($.isFunction($.fn.customSelect) ) { 19340 $("select.can_select").not('.hasCustomSelect').not("select.can_select.js-form_select2").customSelect({customClass:"can_select"}); 19341 } 19342 } 19343 19344 can_select_init(); 19345 19346 19347 19348 19349 19350 19351 /* ======================= start ladders ======================= */ 19352
19353 if ($('.js-ladders-edit, .js-ladders-manage').length) { 19354 /* Show/Hide Ladder Deletion Confirmation */ 19355 $(".js-delete_ladder_step-btn").click(function() { 19356 $(this).closest(".js-ladder_modal_create").fadeOut(300); 19357 $.smoothScroll($('#fancybox-wrap .js-ladder_modal').offset().top - 100); 19358 $(this).closest(".js-ladder_modal_create").siblings(".js-delete_ladder_step_wrap, .js-delete_ladder_path_wrap").delay(300).fadeIn(300); 19359 19360 }); 19361 $(".js-cancel_delete_ladder_step-btn").click(function() { 19362 $(this).parents(".js-delete_ladder_step_wrap, .js-delete_ladder_path_wrap").fadeOut(300); 19363 $(this).parents(".js-delete_ladder_step_wrap, .js-delete_ladder_path_wrap").siblings(".js-ladder_modal_create").delay(300).fadeIn(300); 19364 }); 19365 19366 $(".js-cancel_decision_add").click(function() { 19367 $(".js-add_ladder_path_wrap").fadeOut(300); 19368 $('.js-modal_decision_wrap, .js-modal_wait_validate_wrap').delay(300).fadeIn(300); 19369 }); 19370 19371 /* Show/Hide Ladder PATH Deletion Confirmation */ 19372 $(".js-delete_ladder_path-btn").click(function() { 19373 $(this).parent(".js-delete_ladder_step_wrap").fadeOut(300); 19374 $(this).parent(".js-delete_ladder_step_wrap").siblings(".js-delete_ladder_path_wrap").delay(300).fadeIn(300); 19375 }); 19376 19377 /* regex validation for custom fields */ 19378 var apply_fields_ladder_callback = function(json) { 19379 $.each(json, function(key, value) { 19380 if (value) { 19381 $('.js-custom_fields_value').data('regex',value).rules("add", { regex: value }); 19382 } 19383 19384 }); 19385 } 19386 19387 $('body').on('change', 'select.js-custom_fields_select', function() { 19388 //console.log('change'); 19389 var input_name_array = []; 19390 input_name_array.push($('select.js-custom_fields_select option:selected[value="' + $(this).val() + '"]').text()); 19391 $('.js-custom_fields_value').removeData('regex').rules("remove", "regex"); 19392 if (input_name_array.length) { 19393 get_regex_and_execute_callback($(this).data('regex-link'), input_name_array, apply_fields_ladder_callback); 19394 } 19395 }); 19396 19397 19398 //RANDOM FORK BEGIN 19399 19400 var firstPathValueSpan = $(".js-random-ladder-first-path" ); 19401 var secondPathValueSpan = $(".js-random-ladder-second-path"); 19402 var random_slider = $( ".js-randomizer-slider" ); 19403 19404 resetRandomizerValues = function(){ 19405 firstPathValueSpan.text("50%"); 19406 secondPathValueSpan.text("50%"); 19407 random_slider.slider( "value", 50 ); 19408 } 19409 19410 onSlide = function( event, ui ) { 19411 firstPathValueSpan.text(ui.value+"%"); 19412 secondPathValueSpan.text((100 - ui.value)+"%"); 19413 } 19414 19415 random_slider.slider({ 19416 value:50, 19417 slide: onSlide, 19418 min: 0, 19419 max: 100, 19420 }); 19421 19422 var add_randomizer_callback = function($node) { 19423 $insert_after_node = $node.parents('.js-ladder_plus_wrap'); 19424 resetRandomizerValues(); 19425 }; 19426 19427 $(document).on('click', '.js-add_randomizer', function(e) { 19428 if (!$(this).data().fancybox) { 19429 fancify_link($(this), add_randomizer_callback); 19430 } 19431 e.preventDefault(); 19432 }); 19433 19434 $(document).on('click', '.js-ladder_modal_random_form .js-save_randomizer', function() { 19435 //console.log('save'); 19436 if ($('.js-ladder_modal_random_form').valid()) { 19437 //console.log('valid'); 19438 19439 //var title = $('.js-randomizer_title').val(); 19440 var step = {}; 19441 var next_step_chance = parseFloat(firstPathValueSpan.text().split("%").join('')); 19442 //console.log(next_step_chance); 19443 //if(!next_step_chance){return;} 19444 step.type = "fork"; 19445 step.rules = { 19446 "type": "fork", 19447 //"title": title, 19448 "next_step_chance": next_step_chance 19449 }; 19450 19451 if ($editing_node) { 19452 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 19453 step.uuid = $editing_node.data('ladder-json').uuid; 19454 } 19455 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 19456 step.note = $editing_node.data('ladder-json').note; 19457 } 19458 $editing_node.data('ladder-json', step); 19459 edit_step_dom(step, $editing_node); 19460 $.smoothScroll($editing_node.offset().top - 150); 19461 $.fancybox.close(); 19462 } else { 19463 if (!$insert_after_node.next().hasClass('js-ladderbox_exit')) { 19464 $('.js-modal_random_wrap').fadeOut(300); 19465 19466 $.smoothScroll($('#fancybox-wrap .js-ladder_modal').offset().top - 150); 19467 19468 $(".js-add_ladder_path_wrap").delay(300).fadeIn(300); 19469 19470 $('.js-yes_path').off('click').on('click', function () { 19471 load_step(step, $insert_after_node); 19472 add_exits(); 19473 $.smoothScroll($insert_after_node.next().offset().top - 150); 19474 $.fancybox.close(); 19475 }); 19476 19477 $('.js-no_path').off('click').on('click', function () { 19478 load_step(step, $insert_after_node); 19479 $insert_after_node.next().next().nextUntil('.js-ladderbox_exit').insertAfter($insert_after_node.next().next().find('.js-ladder_plus_wrap')); 19480 19481 add_exits(); 19482 $.smoothScroll($insert_after_node.next().offset().top - 150); 19483 $.fancybox.close(); 19484 }); 19485 } else { 19486 load_step(step, $insert_after_node); 19487 add_exits(); 19488 $.smoothScroll($insert_after_node.next().offset().top - 150); 19489 $.fancybox.close(); 19490 } 19491 } 19492 19493 } 19494 }); 19495 19496 var edit_random_callback = function($node) { 19497 //console.log('trigger'); 19498 $data_node = $node.parent().parent(); 19499 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 19500
19501 $('.js-add_edit').text(an_javascript_translation.edit); 19502 //$('.js-randomizer_title').val(data.rules.title); 19503 $('#fancybox-content .js-delete_ladder_step-btn').show(); 19504 add_randomizer_callback($node); 19505 firstPathValueSpan.text(data.rules.next_step_chance+"%"); 19506 secondPathValueSpan.text((100-data.rules.next_step_chance)+"%"); 19507 random_slider.slider( "value", data.rules.next_step_chance ); 19508 } 19509 19510 19511 //RANDOM FORK END 19512 19513 19514 19515 if ($('.js-select_actions input.js-rung_actions_select').length) { 19516 $('.js-select_actions input.js-rung_actions_select').select2({ 19517 data: trigger_action_json_data, 19518 multiple : false, 19519 separator: '@!@', 19520 closeOnSelect: false, 19521 // text for loading more results 19522 //formatLoadMore : 'Loading more...', 19523 query : function (q) { 19524 // pageSize is number of results to show in dropdown 19525 var pageSize, 19526 results; 19527 pageSize = 500; 19528 results = $.grep(this.data, function (e) { 19529 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 19530 if (typeof(q.term) !== 'undefined') { 19531 if (q.term.length == 0) return true; 19532 19533 if(q.term.split(" ").length == 1){ 19534 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 19535 } 19536 19537 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 19538 // `data.text` is the text that is displayed for the data object 19539 // check if data.text contains all of keywords, if some is missing, return null 19540 for (var i = 0; i < keywords.length; i++) { 19541 19542 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 19543 // Return `null` if the term should not be displayed 19544 return null; 19545 19546 } 19547 } 19548 // If here, data.text contains all keywords, so return it. 19549 return e; 19550 }); 19551 q.callback({ 19552 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 19553 // retrieve more when user hits bottom 19554 more : results.length >= q.page * pageSize 19555 }); 19556 19557 //console.log(q.term); 19558 //console.log(this.data); 19559 }, 19560 placeholder: an_javascript_translation.choose_action 19561 }); 19562 19563 init_rung_emails = function(data) { 19564 $('.js-select_emails input.js-rung_emails_select').select2('destroy'); 19565 $('.js-select_emails input.js-rung_emails_select').select2({ 19566 data: data, 19567 multiple : false, 19568 separator: '@!@', 19569 closeOnSelect: false, 19570 // text for loading more results 19571 //formatLoadMore : 'Loading more...', 19572 query : function (q) { 19573 // pageSize is number of results to show in dropdown 19574 var pageSize, 19575 results; 19576 pageSize = 500; 19577 results = $.grep(this.data, function (e) { 19578 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 19579 if (typeof(q.term) !== 'undefined') { 19580 if (q.term.length == 0) return true; 19581 19582 if(q.term.split(" ").length == 1){ 19583 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 19584 } 19585 19586 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 19587 // `data.text` is the text that is displayed for the data object 19588 // check if data.text contains all of keywords, if some is missing, return null 19589 for (var i = 0; i < keywords.length; i++) { 19590 19591 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 19592 // Return `null` if the term should not be displayed 19593 return null; 19594 19595 } 19596 } 19597 // If here, data.text contains all keywords, so return it. 19598 return e; 19599 }); 19600 q.callback({ 19601 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 19602 // retrieve more when user hits bottom 19603 more : results.length >= q.page * pageSize 19604 }); 19605 19606 //console.log(q.term); 19607 //console.log(this.data); 19608 19609 19610 }, 19611 placeholder: an_javascript_translation.choose_email 19612 }); 19613 } 19614 19615 init_rung_emails(trigger_email_json_data); 19616 19617 init_rung_mobile = function(data) { 19618 $('.js-select_mobile input.js-rung_mobile_select').select2('destroy'); 19619 $('.js-select_mobile input.js-rung_mobile_select').select2({ 19620 data: data, 19621 multiple : false, 19622 separator: '@!@', 19623 closeOnSelect: false, 19624 // text for loading more results 19625 //formatLoadMore : 'Loading more...', 19626 query : function (q) { 19627 // pageSize is number of results to show in dropdown 19628 var pageSize, 19629 results; 19630 pageSize = 500; 19631 results = $.grep(this.data, function (e) { 19632 // return (q.term === "" || e.text.toUpperCase().indexOf(q.term.toUpperCase()) >= 0); 19633 if (typeof(q.term) !== 'undefined') { 19634 if (q.term.length == 0) return true; 19635 19636 if(q.term.split(" ").length == 1){ 19637 return e.text.toUpperCase().indexOf(q.term.toUpperCase())!=-1; 19638 } 19639 19640 keywords=(q.term).split(/ |,|\[|\]|\(|\)/); 19641 // `data.text` is the text that is displayed for the data object 19642 // check if data.text contains all of keywords, if some is missing, return null 19643 for (var i = 0; i < keywords.length; i++) { 19644 19645 if (((e.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) 19646 // Return `null` if the term should not be displayed 19647 return null; 19648 19649 } 19650 } 19651 // If here, data.text contains all keywords, so return it. 19652 return e; 19653 }); 19654 q.callback({ 19655 results: results.slice((q.page - 1) * pageSize, q.page * pageSize), 19656 // retrieve more when user hits bottom 19657 more : results.length >= q.page * pageSize 19658 }); 19659 19660 //console.log(q.term); 19661 //console.log(this.data); 19662 19663 19664 }, 19665 placeholder: an_javascript_translation.choose_mobile_message 19666 }); 19667 } 19668 19669 init_rung_mobile(trigger_mobile_json_data); 19670 } 19671 19672 19673 19674 //helper functions 19675 var fancify_link = function($node, callback) { 19676 $.fancybox.center = function(){}; 19677 $node.fancybox({ 19678 centerOnScroll: false, 19679 hideOnOverlayClick: false, 19680 padding: 0, 19681 margin: 15, 19682 enableKeyboardNav: false, 19683 onStart: function() { 19684 $("#fancybox-wrap").addClass("fancybox-wrap-ladder"); 19685 $("#fancybox-overlay").addClass("fancybox-overlay-ladder"); 19686 $('.js-ladder .js-ladders_explainer').hide(); 19687 }, 19688 onComplete: function() { 19689 19690 ladderRemoveStickyForks(); 19691 19692 $insert_after_node = false;
19693 setTimeout(function() { 19694 $('.js-builder').queryBuilder('reset'); 19695 }, 100); 19696 if (callback) { 19697 callback($node); 19698 } 19699 19700 $('#fancybox-content input, #fancybox-content textarea, #fancybox-content select, #fancybox-content .redactor-box, #fancybox-content .js-action_select, .js-error_input-select_wrap').removeClass('error_input error_input-select_wrap js-error_input-select_wrap'); 19701 $('#fancybox-content .js-ladder_modal_form').fadeIn('fast', function() { 19702 $('.js-ladder_modal_create').find('.floatlabel-redactor').css('margin-top', ($('.js-ladder_modal_create').find('.redactor-toolbar').outerHeight() - 5)); 19703 //setTimeout(function() { 19704 //console.log($('.js-ladder_modal-action').find('div.redactor-editor')); 19705 $('.js-ladder_modal-action').find('div.redactor-editor').trigger('change'); 19706 //}, 10000); 19707 }); 19708 19709 $('#fancybox-content .js-test_mobile').each(function() { 19710 var phone_placeholder = $(this).attr('placeholder').trim(); 19711 // $(this).intlTelInput({ 19712 // utilsScript: "/includes/js/intl-tel-input/js/utils.js", 19713 // allowDropdown: false, 19714 // customPlaceholder: function(selectedCountryPlaceholder, selectedCountryData) { 19715 // return phone_placeholder + ', ' + selectedCountryPlaceholder; 19716 // }, 19717 // initialCountry: $(this).parent().find('.js-form-country').val(), 19718 // autoPlaceholder: "aggressive" 19719 // }); 19720 }); 19721 $('#fancybox-wrap').css('top', $(document).scrollTop() + 100); 19722 19723 if ($('.js-message_body').length) { 19724 $(".js-message_body").each(function() { 19725 $(this).charCount({ 19726 allowed: 160, 19727 counterText: ' ' + an_javascript_translation.characters_left_before_splitting, 19728 wrapperSelector: '.js-ladder_action_sms_write', 19729 hostname: $('.js-mobile_custom_shortlink').val(), 19730 regex: "url_strict" 19731 }); 19732 }); 19733 } 19734 19735 //$('.js-action_select').change(function() { 19736 //console.log('fire'); 19737 //if ($(this).val() == "email") { 19738 19739 //} 19740 //}); 19741 19742 19743 }, 19744 onCleanup: function() { 19745 $('#fancybox-content .js-ladder_modal_form').fadeOut('fast', function() { 19746 $('#fancybox-content input, #fancybox-content textarea').not('input[type="submit"], .js-test_email, .js-test_mobile, .js-default_email_wrapper_id, .js-default_email_from, .js-default_email_replyto, .js-groups_select_hidden, .js-builder input, .js-relative_day_picker-days input, .js-form-country, .js-mobile_custom_shortlink').val('').attr('checked', false); 19747 $('.js-validation_rule_wrap').html(''); 19748 $('.js-relative_day_picker-days input').each(function() { 19749 $(this).attr('checked',false).parent().removeClass('selected'); 19750 }); 19751 $('#fancybox-content select, #fancybox-content .js-rung_actions_select, #fancybox-content .js-rung_emails_select, #fancybox-content .js-rung_mobile_select, #fancybox-content input.js-tags_select, #fancybox-content input.js-rung_tags_select').select2('val',''); 19752 $('.js-ladder_trigger_warning').remove(); 19753 $('#fancybox-content input, #fancybox-content textarea, #fancybox-content select, #fancybox-content .redactor-box, #fancybox-content .js-action_select, .js-error_input-select_wrap, .js-relative_day_picker-days label').removeClass('error_input error_input-select_wrap js-error_input-select_wrap'); 19754 $('#fancybox-content .js-delete_ladder_step-btn, #fancybox-content .js-delete_ladder_step_wrap, #fancybox-content .js-delete_ladder_path_wrap, #fancybox-content .js-relative-wait-option').hide(); 19755 $('#fancybox-content .js-ladder_modal_create').show(); 19756 $('#fancybox-content .js-delete_ladder_step-btn-trigger').html('<i class="far fa-times"></i> ' + an_javascript_translation.delete_this_trigger_rung); 19757 $('#fancybox-content .js-delete_trigger_confirm_text').text(an_javascript_translation.are_you_sure_you_want_to_delete_this_trigger_and_rung); 19758 // Cleanup for AN-2373 filter by sent date option 19759 $('#fancybox-content .js-email_sent_date_modal').hide(); 19760 $('#fancybox-content .js-ladder_modal').show(); 19761 }); 19762 }, 19763 onClosed: function() { 19764 $('.js-modal_decision_wrap').show(); 19765 $(".js-add_ladder_path_wrap").hide(); 19766 $('.js-builder').queryBuilder('reset'); 19767 $('.js-rung_modal_options').hide();
19768 $('.js-redactor').redactor('code.set',''); 19769 $('.rule-container span.customSelect').removeClass('error_input'); 19770 $('.js-add_edit').text(an_javascript_translation.add); 19771 $('.js-ladders_collection_modal').hide(); 19772 $('.js-apply_collection_modal').hide(); 19773 $('.js-builder').show(); 19774 $editing_node = false; 19775 var ladder_data = save_ladder(); 19776 $('.js-ladder_params').val(JSON.stringify(ladder_data)); 19777 $('form.js-create_ladder_form').trigger('checkform.areYouSure'); 19778 if ($('.js-ladder .js-ladder_rung').length == 0) { 19779 $('.js-ladder .js-ladders_explainer').show(); 19780 } 19781 19782 $('.js-mobile_clips_ladder').hide(); 19783 $('.js-ladder_modal_action_form').show(); 19784 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 19785 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 19786 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 19787 $('.js-ladder_modal_action_form').removeClass('show_preview'); 19788 $('.js-mobile_clips').hide(); 19789 19790 } 19791 }); 19792 19793 $node.trigger('click'); 19794 } 19795 19796 var add_object_id = function(object, id) { 19797 object.id = id; 19798 id++; 19799 var return_obj = { 19800 "id": id, 19801 "object": object, 19802 "break": false 19803 } 19804 return return_obj; 19805 } 19806 19807 var find_object = function(object, id) { 19808 var return_obj = { 19809 "id": id, 19810 "object": object, 19811 "break": false 19812 } 19813 if (object.id == id) { 19814 return_obj.break = true; 19815 } 19816 19817 return return_obj; 19818 } 19819 19820 var create_dom = function($node_to_clone, $add_after_node, append) { 19821 if (append) { 19822 if (append == "insert_before") { 19823 return $node_to_clone.clone().insertBefore($add_after_node); 19824 } else { 19825 return $node_to_clone.clone().appendTo($add_after_node); 19826 } 19827 19828 } else { 19829 return $node_to_clone.clone().insertAfter($add_after_node); 19830 } 19831 } 19832 19833 var add_exits = function() { 19834 19835 19836 //add missing exists 19837 $('.js-ladder_plus_wrap').not('.js-ladder_assets .js-ladder_plus_wrap').map(function() { 19838 if ($(this).next().hasClass('js-ladderbox_answer-yes') || $(this).next().length == 0) { 19839 var $exit_dom = create_dom($('.js-ladder_assets .js-ladderbox_exit'), $(this)); 19840 19841 var $previous_action = $exit_dom.prevUntil('.js-ladder_step').prev().filter('.js-ladder_step'); 19842 if (!$previous_action.length) { 19843 $previous_action = $exit_dom.parent().prev(); 19844 } 19845 var previous_action_json = $previous_action.data('ladder-json'); 19846 if (previous_action_json.stats && previous_action_json.stats.exit_count > 0) { 19847 if (previous_action_json.stats.exit_count == 1) { 19848 $exit_dom.html('<i class="far fa-arrow-left"></i> ' + an_javascript_translation.exit + ' <div class="exited_users"><small>' + previous_action_json.stats.exit_count + ' ' + an_javascript_translation.activist_exited + '</small></div>'); 19849 } else { 19850 $exit_dom.html('<i class="far fa-arrow-left"></i> ' + an_javascript_translation.exit + ' <div class="exited_users"><small>' + previous_action_json.stats.exit_count + ' ' + an_javascript_translation.activists_exited + '</small></div>'); 19851 } 19852 } 19853 } 19854 }); 19855 19856 //add missing plusses 19857 $('.js-ladderbox_exit').map(function() { 19858 if (!$(this).prev().hasClass('js-ladder_plus_wrap')) { 19859 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $(this), "insert_before"); 19860 } 19861 }); 19862 19863 $('.js-ladder .js-ladder_step').map(function() { 19864 if (!$(this).prev().hasClass('js-ladder_entrance') && !$(this).prev().hasClass('js-ladder_step') && !$(this).prev().hasClass('js-ladder_plus_wrap')) { 19865 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $(this), "insert_before"); 19866 } 19867 }); 19868 19869 }; 19870 19871 19872 19873 //load functions 19874 19875 /////// load ladder functions 19876 var load_ladder = function(ladder_data) { 19877 if (typeof(ladder_paste_remove_array) != 'undefined') {
19878 $paste_ladder_shadow_dom = $('<div class="js-paste_ladder_wrap"></div>'); 19879 load_rungs(ladder_data, $paste_ladder_shadow_dom, true); 19880 } else { 19881 create_dom($('.js-ladder_assets .js-add_new_rung_container'), $('.js-ladder'), true); 19882 load_rungs(ladder_data, $('.js-ladder'), true); 19883 } 19884 19885 //traverse_tree(ladder_data, add_object_id, 0); 19886 19887 add_exits(); 19888 19889 if ($('.js-ladder .js-ladder_rung').length == 0) { 19890 $('.js-ladder .js-ladders_explainer').show(); 19891 } 19892 getActionsOnlyFields(); 19893 }; 19894 19895 /////// load rung functions 19896 var load_rungs = function(rungs, $append_target, append) { 19897 $.each(rungs, function(i, rung) { 19898 var $rung_dom = create_rung_dom(rung, $append_target, append); 19899 load_triggers($rung_dom, rung); 19900 var rung_json = rung; 19901 if (rung.next_step) { 19902 load_step(rung.next_step, $rung_dom.find('.js-ladder_plus_wrap')); 19903 } 19904 19905 create_dom($('.js-ladder_assets .js-add_new_rung_container'), $rung_dom); 19906 }); 19907 }; 19908 19909 var create_rung_dom = function(rung, $append_target, append) { 19910 var $rung_dom = create_dom($('.js-ladder_assets .js-ladder_rung_container'), $append_target, append); 19911 19912 if ($rung_dom.data('ladder-json') && $rung_dom.data('ladder-json').uuid) { 19913 rung.uuid = $rung_dom.data('ladder-json').uuid; 19914 } 19915 19916 $rung_dom.data('ladder-json', rung); 19917 19918 return $rung_dom; 19919 } 19920 19921 19922 /////// load trigger functions 19923 var load_triggers = function($rung_dom, rung) { 19924 19925 $.each(rung.triggers.reverse(), function(i, trigger) { 19926 load_step(trigger, $rung_dom.find('.js-ladder_entrance')); 19927 }); 19928 19929 //typically done for each step but triggers are special 19930 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $rung_dom.find('.js-add_condition')); 19931 }; 19932 19933 19934 /////// load step functions 19935 var load_step = function(step, $add_after_node, append) { 19936 19937 //console.log('before create'); 19938 //console.log(step); 19939 var $step_dom = create_step_dom(step, $add_after_node, append); 19940 edit_step_dom(step, $step_dom); 19941 //console.log('after create'); 19942 //console.log(step); 19943 var step_json = step; 19944 19945 //recursive! 19946 if (step_json.next_step) { 19947 load_step(step_json.next_step, $step_dom.next()); 19948 } 19949 19950 if (step_json.if_false && step_json.if_false.next_step) { 19951 //console.log($step_dom.next()); 19952 load_step(step_json.if_false.next_step, $step_dom.next().find('.js-ladderbox_answer-yes-second') , "insert_before"); 19953 } 19954 19955 if (step_json.if_true && step_json.if_true.next_step) { 19956 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $step_dom.next()); 19957 load_step(step_json.if_true.next_step, $step_dom.next().next()); 19958 } else if (step_json.if_true) { 19959 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $step_dom.next()); 19960 } 19961 19962 if (typeof(ladder_paste_remove_array) != 'undefined' && !step.copy) { 19963 ladder_paste_remove_array.push($step_dom); 19964 } 19965 }; 19966 19967 // editing functions 19968 var edit_step_dom = function(step, $step_dom) { 19969 //console.log('start'); 19970 var step_data = step, 19971 $rule_type = $step_dom.find('.js-rule_type'), 19972 $rule_param = $step_dom.find('.js-rule_param'); 19973 19974 $rule_type.text(''); 19975 $rule_param.text(''); 19976 //console.log(step_data.note); 19977 if (step_data.note) { 19978 $step_dom.find('.js-edit_note span').html(step_data.note + '<br/>' + an_javascript_translation.click_to_edit_notes_about_this_step); 19979 $step_dom.find('.js-view_note span').html(step_data.note); 19980 //console.log(step_data); 19981 //console.log(step_data.type != 'fork'); 19982 //console.log(typeof(step_data.rules.next_step_chance) != 'undefined'); 19983 if (step_data.type != 'fork' || typeof(step_data.rules.next_step_chance) != 'undefined') { 19984 $step_dom.find('.js-open_query_modal').addClass('hidei'); 19985 } 19986 } else { 19987 if ($('.js-ladders-manage').length) { 19988 if (step_data.type == 'fork' && typeof(step_data.rules.next_step_chance) == 'undefined') { 19989 $step_dom.find('.js-edit_ladder_box .js-view_note').addClass('hidei'); 19990 } else { 19991 $step_dom.find('.js-edit_ladder_box').addClass('hidei'); 19992 } 19993 19994 $step_dom.addClass('js-ladder_no_note ladder_no_note'); 19995 } 19996 } 19997 19998 //console.log(step_data); 19999 if (step_data.rules) { 20000 switch(step_data.type) { 20001 case 'wait': 20002 $step_dom.addClass('ladder_wait js-ladder_wait'); 20003 $step_dom.find('.js-edit_link').attr('href','#ladder_modal-wait'); 20004 break; 20005 case 'wait_validate': 20006 $step_dom.addClass('ladder_wait_reply js-ladder_wait_validate'); 20007 $step_dom.find('.js-edit_link').attr('href','#ladder_modal-wait_validate'); 20008 break; 20009 case 'action': 20010 $step_dom.addClass('ladder_action js-ladder_action'); 20011 $step_dom.find('.js-edit_link').attr('href','#ladder_modal-action'); 20012 break; 20013 case 'fork': 20014 if(typeof(step_data.rules.next_step_chance) == 'undefined' ) { 20015 $step_dom.addClass('ladder_fork js-ladder_fork'); 20016 $step_dom.find('.js-edit_link').attr('href', '#ladder_modal-fork'); 20017 break; 20018 }else{ 20019 $step_dom.addClass('ladder_random js-ladder_random'); 20020 $step_dom.find('.js-edit_link').attr('href', '#ladder_modal-random'); 20021 break; 20022 } 20023 } 20024 20025 //does this need edits for wait_validate? not sure 20026 switch(step_data.rules.type) { 20027 case 'voter_location': 20028 $rule_type.html(an_javascript_translation.wait + ' ' + step_data.rules.hours + ' ' + an_javascript_translation.hour + ((step_data.rules.hours != 1) ? 's' : '' ) + ' ' + an_javascript_translation.for_mobile_reply_find_polling_place_store); 20029 $rule_param.text(an_javascript_translation.polling_location + ' ' + step_data.rules.polling_locations_field + ', ' + an_javascript_translation.early_vote_location + ' ' + step_data.rules.early_vote_locations_field + ', ' + an_javascript_translation.drop_off_location + ' ' + step_data.rules.drop_off_locations_field); 20030 if ($('.js-ladders-manage').length) { 20031 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20032 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20033 if (step_data.stats && step_data.stats.waiting) { 20034 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20035 } else { 20036 $stats_dom.find('.js-wait_stats').text("0"); 20037 } 20038 20039 } 20040 break; 20041 case 'validate_voter_address': 20042 $rule_type.html(an_javascript_translation.wait + ' ' + step_data.rules.hours + ' ' + an_javascript_translation.hour + ((step_data.rules.hours != 1) ? 's' : '' ) + ' ' + an_javascript_translation.for_mobile_reply_find_polling_place_store); 20043 $rule_param.text(an_javascript_translation.polling_location + ' ' + step_data.rules.polling_locations_field + ', ' + an_javascript_translation.early_vote_location + ' ' + step_data.rules.early_vote_locations_field + ', ' + an_javascript_translation.drop_off_location + ' ' + step_data.rules.drop_off_locations_field); 20044 if ($('.js-ladders-manage').length) { 20045 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20046 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20047 if (step_data.stats && step_data.stats.waiting) { 20048 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20049 } else { 20050 $stats_dom.find('.js-wait_stats').text("0"); 20051 } 20052 20053 } 20054 break; 20055 case 'reply': 20056 $rule_type.html(an_javascript_translation.wait + ' ' + step_data.rules.hours + ' ' + an_javascript_translation.hour + ((step_data.rules.hours != 1) ? 's' : '' ) + ' ' + an_javascript_translation.for_mobile_reply_store_response_in); 20057 $rule_param.text(step_data.rules.field); 20058 if ($('.js-ladders-manage').length) { 20059 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20060 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20061 if (step_data.stats && step_data.stats.waiting) { 20062 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20063 } else { 20064 $stats_dom.find('.js-wait_stats').text("0"); 20065 } 20066 20067 } 20068 break; 20069 case 'valid_response': 20070 $rule_type.html(an_javascript_translation.wait + ' ' + step_data.rules.hours + ' ' + an_javascript_translation.hour + ((step_data.rules.hours != 1) ? 's' : '' ) + ' ' + an_javascript_translation.for_mobile_reply_store_response_in); 20071 $rule_param.text(step_data.rules.field); 20072 if ($('.js-ladders-manage').length) { 20073 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20074 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20075 if (step_data.stats && step_data.stats.waiting) { 20076 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20077 } else { 20078 $stats_dom.find('.js-wait_stats').text("0"); 20079 } 20080 20081 } 20082 break; 20083 case 'days': 20084 $rule_type.text(an_javascript_translation.wait_for); 20085 $rule_param.text(step_data.rules.days + ' ' + an_javascript_translation.day + ((step_data.rules.days > 1) ? 's' : '' )); 20086 if ($('.js-ladders-manage').length) { 20087 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20088 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20089 if (step_data.stats && step_data.stats.waiting) { 20090 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20091 } else { 20092 $stats_dom.find('.js-wait_stats').text("0"); 20093 } 20094 20095 } 20096 break; 20097 case 'hours': 20098 $rule_type.text(an_javascript_translation.wait_for); 20099 $rule_param.text(step_data.rules.hours + ' ' + an_javascript_translation.hour + ((step_data.rules.hours > 1) ? 's' : '' )); 20100 if ($('.js-ladders-manage').length) { 20101 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20102 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20103 if (step_data.stats && step_data.stats.waiting) { 20104 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20105 } else { 20106 $stats_dom.find('.js-wait_stats').text("0"); 20107 } 20108 20109 } 20110 break; 20111 case 'custom_field': 20112 $rule_type.text(an_javascript_translation.wait_until_date_in_custom_field); 20113 $rule_param.text(step_data.rules.custom_field_name); 20114 if ($('.js-ladders-manage').length) { 20115 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20116 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20117 if (step_data.stats && step_data.stats.waiting) { 20118 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20119 } else { 20120 $stats_dom.find('.js-wait_stats').text("0"); 20121 } 20122 } 20123 break; 20124 case 'date': 20125 $rule_type.text(an_javascript_translation.wait_until); 20126 $rule_param.text(step_data.rules.date); 20127 if ($('.js-ladders-manage').length) { 20128 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20129 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20130 if (step_data.stats && step_data.stats.waiting) { 20131 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20132 } else { 20133 $stats_dom.find('.js-wait_stats').text("0"); 20134 } 20135 } 20136 break; 20137 case 'relative': 20138 $rule_type.text(an_javascript_translation.wait_until_the_next); 20139 var text = ''; 20140 if (step_data.rules.relative_type == 'weekday') {
20141 text = an_javascript_translation.weekday; 20142 } 20143 20144 if (step_data.rules.relative_type == 'day_of_week') { 20145 text = step_data.rules.day_of_week.join(', '); 20146 } 20147 20148 if (step_data.rules.relative_type == 'day_of_month') { 20149 var day_of_month_suffix = ''; 20150 if (step_data.rules.day_of_month.match(/1$/) && step_data.rules.day_of_month != '11') { 20151 day_of_month_suffix = an_javascript_translation.suffix_st; 20152 } else if (step_data.rules.day_of_month.match(/2$/) && step_data.rules.day_of_month != '12') { 20153 day_of_month_suffix = an_javascript_translation.suffix_nd; 20154 } else if (step_data.rules.day_of_month.match(/3$/) && step_data.rules.day_of_month != '13') { 20155 day_of_month_suffix = an_javascript_translation.suffix_rd; 20156 } else { 20157 day_of_month_suffix = an_javascript_translation.suffix_th; 20158 } 20159 20160 text = step_data.rules.day_of_month + day_of_month_suffix + ' ' + an_javascript_translation.of_the_month; 20161 } 20162 20163 if (step_data.rules.relative_type == 'day_of_year') { 20164 var day_of_month_suffix = ''; 20165 if (step_data.rules.day_of_year_day.match(/1$/) && step_data.rules.day_of_year_day != '11') { 20166 day_of_month_suffix = an_javascript_translation.suffix_st; 20167 } else if (step_data.rules.day_of_year_day.match(/2$/) && step_data.rules.day_of_year_day != '12') { 20168 day_of_month_suffix = an_javascript_translation.suffix_nd; 20169 } else if (step_data.rules.day_of_year_day.match(/3$/) && step_data.rules.day_of_year_day != '13') { 20170 day_of_month_suffix = an_javascript_translation.suffix_rd; 20171 } else { 20172 day_of_month_suffix = an_javascript_translation.suffix_th; 20173 } 20174 20175 var month_to_text = ''; 20176 if (step_data.rules.day_of_year_month == '1') { 20177 month_to_text = an_javascript_translation.january; 20178 } else if (step_data.rules.day_of_year_month == '2') { 20179 month_to_text = an_javascript_translation.february; 20180 } else if (step_data.rules.day_of_year_month == '3') { 20181 month_to_text = an_javascript_translation.march; 20182 } else if (step_data.rules.day_of_year_month == '4') { 20183 month_to_text = an_javascript_translation.april; 20184 } else if (step_data.rules.day_of_year_month == '5') { 20185 month_to_text = an_javascript_translation.may; 20186 } else if (step_data.rules.day_of_year_month == '6') { 20187 month_to_text = an_javascript_translation.june; 20188 } else if (step_data.rules.day_of_year_month == '7') { 20189 month_to_text = an_javascript_translation.july; 20190 } else if (step_data.rules.day_of_year_month == '8') { 20191 month_to_text = an_javascript_translation.august; 20192 } else if (step_data.rules.day_of_year_month == '9') { 20193 month_to_text = an_javascript_translation.september; 20194 } else if (step_data.rules.day_of_year_month == '10') { 20195 month_to_text = an_javascript_translation.october; 20196 } else if (step_data.rules.day_of_year_month == '11') { 20197 month_to_text = an_javascript_translation.november; 20198 } else if (step_data.rules.day_of_year_month == '12') { 20199 month_to_text = an_javascript_translation.december; 20200 } 20201 20202 text = month_to_text + " " + step_data.rules.day_of_year_day + day_of_month_suffix; 20203 } 20204 20205 text = text + ' ' + an_javascript_translation.at + ' ' + step_data.rules.time + ' ' + an_javascript_translation.us_eastern; 20206 20207 $rule_param.text(text); 20208 20209 if ($('.js-ladders-manage').length) { 20210 create_dom($('.js-ladder_assets .js-view_ladder_stats_wait_button'), $rule_param); 20211 var $stats_dom = create_dom($('.js-ladder_assets .js-ladder_action_stats'), $rule_param.next()); 20212 if (step_data.stats && step_data.stats.waiting) { 20213 $stats_dom.find('.js-wait_stats').text(step_data.stats.waiting); 20214 } else { 20215 $stats_dom.find('.js-wait_stats').text("0"); 20216 } 20217 } 20218 break; 20219 case 'email': 20220 $step_dom.find('.js-ladder_step_tabs, .js-ladder_step_tab_content_email').remove(); 20221 $rule_type.text(an_javascript_translation.send_an_email + ':'); 20222 if (step_data.rules.administrative_title != '') { 20223 $rule_param.text(step_data.rules.administrative_title); 20224 } else { 20225 $rule_param.text(step_data.rules.subject); 20226 } 20227 20228 create_dom($('.js-ladder_assets .js-ladder_step_tabs'), $step_dom, true); 20229 20230 $step_tabs_dom = create_dom($('.js-ladder_assets .js-ladder_step_tab_content_email'), $step_dom, true); 20231 20232 $step_tabs_dom.find('.js-ladder_step_tab_content_subject').text(step_data.rules.subject); 20233 $step_tabs_dom.find('.js-ladder_step_tab_content_from').text(step_data.rules.from_line); 20234 $step_tabs_dom.find('.js-ladder_step_tab_content_replyto').text(step_data.rules.reply_to); 20235 $step_tabs_dom.find('.js-ladder_step_tab_content_body').html(step_data.rules.body_text); 20236 if (step_data.rules.pre_header) { 20237 $step_tabs_dom.find('.js-ladder_step_tab_content_pre_header_label').show(); 20238 $step_tabs_dom.find('.js-ladder_step_tab_content_pre_header').html(step_data.rules.pre_header); 20239 } else { 20240 $step_tabs_dom.find('.js-ladder_step_tab_content_pre_header_label').hide(); 20241 } 20242 20243 20244 if ($('.js-ladders-manage').length) { 20245 //console.log($rule_param); 20246 $step_dom.addClass('ladder_email'); 20247 20248 $step_tabs_stats_dom = $step_tabs_dom.find('.js-stats_tab'); 20249 //console.log($step_tabs_dom); 20250 //console.log($step_tabs_stats_dom); 20251 20252 //console.log(step_data.stats); 20253 if (step_data.stats) { 20254 if (step_data.stats.email_stats) { 20255 create_dom($($.parseHTML(step_data.stats.email_stats)), $step_tabs_stats_dom, true); 20256 } else { 20257 create_dom($($.parseHTML(step_data.stats)), $step_tabs_stats_dom, true); 20258 } 20259 20260 } else { 20261 create_dom($('.js-ladder_assets .js-dummy-email-stats'), $step_tabs_stats_dom, true); 20262 } 20263 } 20264 break; 20265 case 'mobile_message': 20266 20267 $step_dom.find('.js-ladder_step_tabs, .js-ladder_step_tab_content_mobile').remove(); 20268 $rule_type.text(an_javascript_translation.send_a_mobile_message + ':'); 20269 $rule_param.text(step_data.rules.title); 20270 20271 create_dom($('.js-ladder_assets .js-ladder_step_tabs'), $step_dom, true); 20272 20273 $step_tabs_dom = create_dom($('.js-ladder_assets .js-ladder_step_tab_content_mobile'), $step_dom, true); 20274 20275 $step_tabs_dom.find('.js-ladder_step_tab_content_body').text(step_data.rules.message_text); 20276 20277 if ($('.js-ladders-manage').length) { 20278 //console.log($rule_param); 20279 $step_dom.addClass('ladder_sms'); 20280 20281 $step_tabs_stats_dom = $step_tabs_dom.find('.js-stats_tab'); 20282 20283 //console.log(step_data.stats); 20284 if (step_data.stats) { 20285 if (step_data.stats.sms_stats) { 20286 create_dom($($.parseHTML(step_data.stats.sms_stats)), $step_tabs_stats_dom, true); 20287 } else { 20288 create_dom($($.parseHTML(step_data.stats)), $step_tabs_stats_dom, true); 20289 } 20290 20291 } else { 20292 create_dom($('.js-ladder_assets .js-dummy-sms-stats'), $step_tabs_stats_dom, true); 20293 } 20294 } 20295 break; 20296 case 'add_tags': 20297 $rule_type.text(an_javascript_translation.add_tag + ((step_data.rules.tags.length > 1) ? 's' : '' ) + ':'); 20298 $rule_param.text(step_data.rules.tags.join(', ')); 20299 break; 20300 case 'remove_tags': 20301 $rule_type.text(an_javascript_translation.remove_tag + ((step_data.rules.tags.length > 1) ? 's' : '' ) + ':'); 20302 $rule_param.text(step_data.rules.tags.join(', ')); 20303 break; 20304 case 'subscribe': 20305 $rule_type.text(an_javascript_translation.subscribe_to + ' ' + ((step_data.rules.titles && step_data.rules.titles.length > 1) ? an_javascript_translation.groups_email : an_javascript_translation.group_email ) + ((step_data.rules.titles) ? ':' : '' )); 20306 $rule_param.text((step_data.rules.titles) ? step_data.rules.titles.join(', ') + ((step_data.rules.dont_resubscribe) ? '' : ' ' + an_javascript_translation.resubscribe) : ''); 20307 break; 20308 case 'unsubscribe': 20309 $rule_type.text(an_javascript_translation.unsubscribe_from + ' ' + ((step_data.rules.titles && step_data.rules.titles.length > 1) ? an_javascript_translation.groups_email : an_javascript_translation.group_email ) + ((step_data.rules.titles) ? ':' : '' )); 20310 $rule_param.text((step_data.rules.titles) ? step_data.rules.titles.join(', ') : ''); 20311 break; 20312 case 'mobile_subscribe': 20313 $rule_type.text(an_javascript_translation.subscribe_to + ' ' + ((step_data.rules.titles && step_data.rules.titles.length > 1) ? an_javascript_translation.groups_mobile : an_javascript_translation.group_mobile ) + ((step_data.rules.titles) ? ':' : '' )); 20314 $rule_param.text((step_data.rules.titles) ? step_data.rules.titles.join(', ') + ((step_data.rules.dont_resubscribe) ? '' : ' ' + an_javascript_translation.resubscribe) : ''); 20315 break; 20316 case 'mobile_unsubscribe': 20317 $rule_type.text(an_javascript_translation.unsubscribe_from + ' ' + ((step_data.rules.titles && step_data.rules.titles.length > 1) ? an_javascript_translation.groups_mobile : an_javascript_translation.group_mobile ) + ((step_data.rules.titles) ? ':' : '' )); 20318 $rule_param.text((step_data.rules.titles) ? step_data.rules.titles.join(', ') : ''); 20319 break; 20320 case 'fork': 20321 if(typeof(step_data.rules.next_step_chance) == 'undefined'){ 20322 $rule_type.text(an_javascript_translation.decision); 20323 $rule_param.text(step_data.rules.title); 20324 $step_dom.find('.js-query_params').data('name', step_data.rules.title); 20325 $step_dom.find('.js-query_params').val(step_data.rules.query_params); 20326 break; 20327 }else{ 20328 $rule_type.text(an_javascript_translation.randomizer); 20329 $rule_param.text((step_data.rules.next_step_chance)+"% / "+(100-step_data.rules.next_step_chance)+"%"); 20330 break; 20331 } 20332 case 'set_custom_field': 20333 $rule_type.text(an_javascript_translation.write_to_custom_field); 20334 $rule_param.html(an_javascript_translation.write + ' <em>' + ((step_data.rules.custom_field_value) ? step_data.rules.custom_field_value.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') : an_javascript_translation.blank ) + '</em> ' + an_javascript_translation.in_field + ' <em>' + step_data.rules.custom_field_name + '</em>'); 20335 break; 20336 20337 } 20338 20339 if (step_data.type == 'wait' || step_data.type == 'wait_validate'){ 20340 set_skip_flag_class($step_dom,!!step_data.rules.skip); 20341 } 20342 20343 if ($step_dom.next().hasClass('js-decision_container')) { 20344 set_skip_flag_class($step_dom.next(),!!step_data.rules.skip); 20345 } 20346 20347 if ((step_data.type == 'fork' || step_data.type == 'wait_validate') && !$editing_node) { 20348 var $fork_dom = create_dom($('.js-ladder_assets .js-decision_container'), $step_dom); 20349 set_skip_flag_class($fork_dom,!!step_data.rules.skip); 20350 //Replaces "Y" and "N" answers with the randomizer percentages/validation icons 20351 if(typeof(step_data.rules.next_step_chance) != 'undefined') { //Random fork 20352 var answer_yes = $fork_dom.children('.js-ladderbox_answer-yes'); 20353 var answer_no = $fork_dom.children('.js-ladderbox_answer-no'); 20354 20355 answer_yes.addClass('ladderbox_percentage'); 20356 answer_yes.html(step_data.rules.next_step_chance+"%"); 20357 20358 answer_no.addClass('ladderbox_percentage'); 20359 answer_no.html(( 100 - step_data.rules.next_step_chance )+"%"); 20360 20361 } else if (step_data.type == 'wait_validate') { // wait_validate form 20362 var answer_yes = $fork_dom.children('.js-ladderbox_answer-yes'); 20363 var answer_no = $fork_dom.children('.js-ladderbox_answer-no'); 20364 20365 answer_yes.addClass('ladderbox_percentage'); 20366 answer_yes.html(`<i class="fal fa-comment-check"></i>`); 20367 20368 answer_no.addClass('ladderbox_percentage'); 20369 answer_no.html(`<i class="fal fa-comment-slash"></i>`); 20370 } 20371 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $fork_dom.find('.js-ladderbox_answer-no')); 20372 } else if (!$editing_node) { 20373 create_dom($('.js-ladder_assets .js-ladder_plus_wrap'), $step_dom); 20374 } else if ((step_data.type == 'fork' || step_data.type == 'wait_validate') && $editing_node) { 20375 //console.log($editing_node); 20376 //Replaces "Y" and "N" answers with the randomizer percentages/validation icons 20377 if(typeof(step_data.rules.next_step_chance) != 'undefined') { //Random fork 20378 var answer_yes = $editing_node.next().children('.js-ladderbox_answer-yes'); 20379 var answer_no = $editing_node.next().children('.js-ladderbox_answer-no'); 20380 20381 answer_yes.addClass('ladderbox_percentage'); 20382 answer_yes.html(step_data.rules.next_step_chance+"%"); 20383 20384 answer_no.addClass('ladderbox_percentage'); 20385 answer_no.html(( 100 - step_data.rules.next_step_chance )+"%"); 20386 } else if (step_data.type == 'wait_validate') { // wait_validate form 20387 var answer_yes = $editing_node.children('.js-ladderbox_answer-yes'); 20388 var answer_no = $editing_node.children('.js-ladderbox_answer-no'); 20389 20390 answer_yes.addClass('ladderbox_percentage'); 20391 answer_yes.html(`<i class="fal fa-comment-check"></i>`); 20392 20393 answer_no.addClass('ladderbox_percentage'); 20394 answer_no.html(`<i class="fal fa-comment-slash"></i>`); 20395 } 20396 } 20397 20398 20399 } else { 20400 $step_dom.addClass('ladder_rung js-ladder_rung'); 20401 20402 switch(step_data.type) { 20403 case 'received_email': 20404 if (step_data.permalink) { 20405 $rule_type.text(an_javascript_translation.received_email); 20406 if(step_data.url) { 20407 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20408 } else { 20409 $rule_param.text(step_data.title); 20410 } 20411 20412 } else { 20413 $rule_type.text(an_javascript_translation.received_any_email); 20414 } 20415 20416 break; 20417 case 'received_mobile': 20418 if (step_data.permalink) { 20419 $rule_type.text(an_javascript_translation.received_mobile_message); 20420 if(step_data.url) { 20421 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20422 } else { 20423 $rule_param.text(step_data.title); 20424 } 20425 } else { 20426 $rule_type.text(an_javascript_translation.received_any_mobile_message); 20427 } 20428 20429 break; 20430 case 'opened_email': 20431 if (step_data.permalink) { 20432 $rule_type.text(an_javascript_translation.opened_email); 20433 if(step_data.url) { 20434 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20435 } else { 20436 $rule_param.text(step_data.title); 20437 } 20438 } else { 20439 $rule_type.text(an_javascript_translation.opened_any_email); 20440 } 20441 20442 break; 20443 case 'clicked_email': 20444 if (step_data.permalink) { 20445 $rule_type.text(an_javascript_translation.clicked_email); 20446 if(step_data.url) { 20447 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20448 } else { 20449 $rule_param.text(step_data.title); 20450 } 20451 } else { 20452 $rule_type.text(an_javascript_translation.clicked_any_email); 20453 } 20454 20455 break; 20456 case 'clicked_mobile': 20457 if (step_data.permalink) { 20458 $rule_type.text(an_javascript_translation.clicked_mobile_message); 20459 if(step_data.url) { 20460 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20461 } else { 20462 $rule_param.text(step_data.title); 20463 } 20464 } else { 20465 $rule_type.text(an_javascript_translation.clicked_any_mobile_message); 20466 } 20467 20468 break; 20469 case 'took_action': 20470 if (step_data.permalink) { 20471 $rule_type.text(an_javascript_translation.took_action); 20472 if(step_data.url) { 20473 $rule_param.html('<a target="_blank" href="' + step_data.url + '">' + step_data.title + '</a>'); 20474 } else { 20475 $rule_param.text(step_data.title); 20476 } 20477 if (step_data.only_text_to_join) { 20478 $rule_param.text($rule_param.text() + ' ' + an_javascript_translation.only_activists_who_took_action_via_mobile_message); 20479 } 20480 if (step_data.include_recurring) { 20481 $rule_param.text($rule_param.text() + ' ' + an_javascript_translation.including_recurrences); 20482 } 20483 if (step_data.exclude_one_time) { 20484 $rule_param.text($rule_param.text() + ' ' + an_javascript_translation.excluding_one_time_donations); 20485 } 20486 } else if (step_data.action_type) { 20487 $rule_type.text(an_javascript_tran
20487slation.took_an_action_of_a_specific_type); 20488 //console.log(step_data.action_type); 20489 switch(step_data.action_type) { 20490 case 'ticketed_events': 20491 $rule_param.text(an_javascript_translation.ticketed_events); 20492 break; 20493 case 'letters': 20494 $rule_param.text(an_javascript_translation.letter_campaigns); 20495 break; 20496 case 'event_campaigns': 20497 $rule_param.text(an_javascript_translation.event_campaigns); 20498 break; 20499 case 'fundraisings': 20500 $rule_param.text(an_javascript_translation.fundraisers); 20501 if (step_data.include_recurring) { 20502 $rule_param.text($rule_param.text() + ' ' + an_javascript_translation.including_recurrences); 20503 } 20504 if (step_data.exclude_one_time) { 20505 $rule_param.text($rule_param.text() + ' ' + an_javascript_translation.excluding_one_time_donations); 20506 } 20507 break; 20508 case 'lists': 20509 $rule_param.text(an_javascript_translation.uploads); 20510 break; 20511 case 'call_campaigns': 20512 $rule_param.text(an_javascript_translation.call_campaigns); 20513 break; 20514 case 'events': 20515 $rule_param.text(an_javascript_translation.events); 20516 break; 20517 case 'petitions': 20518 $rule_param.text(an_javascript_translation.petitions); 20519 break; 20520 case 'forms': 20521 $rule_param.text(an_javascript_translation.forms); 20522 break; 20523 case 'shifts': 20524 $rule_param.text(an_javascript_translation.shift_events); 20525 break; 20526 default: 20527 $rule_param.text(step_data.action_type.charAt(0).toUpperCase() + step_data.action_type.slice(1)); 20528 break; 20529 } 20530 } else { 20531 $rule_type.text(an_javascript_translation.took_any_action); 20532 if (!step_data.exclude_uploads) { 20533 $rule_param.text(an_javascript_translation.including_uploads); 20534 } 20535 20536 20537 20538 } 20539 20540 break; 20541 case 'added_tag': 20542 if (step_data.permalink) { 20543 $rule_type.text(an_javascript_translation.added_tag); 20544 $rule_param.text(step_data.title); 20545 } 20546 break; 20547 case 'subscribed': 20548 $rule_type.text(an_javascript_translation.subscribed_to_email_list); 20549 break; 20550 case 'subscribed_mobile': 20551 $rule_type.text(an_javascript_translation.subscribed_to_mobile_list); 20552 break; 20553 } 20554 } 20555 } 20556 20557 var $editing_node = false; 20558 20559 $(document).on('click', '.js-ladder_step_tabs a', function(e) { 20560 $tab_content = $(this).closest('.js-ladder_step').find('.js-ladder_step_tab_content'); 20561 20562 $(this).siblings().removeClass('selected'); 20563 $(this).toggleClass('selected'); 20564 20565 if ($(this).hasClass('selected')) { 20566 if (!$tab_content.is(':visible')) { 20567 $tab_content.show(); 20568 } 20569 20570 } else { 20571 $tab_content.hide(); 20572 } 20573 20574 if ($(this).hasClass('js-ladder_step_tab_preview')) { 20575 $tab_content.find('.js-ladder_step_tab_content_tab').hide(); 20576 $tab_content.find('.js-preview_tab').show(); 20577 } 20578 20579 if ($(this).hasClass('js-ladder_step_tab_stats')) { 20580 $tab_content.find('.js-ladder_step_tab_content_tab').hide(); 20581 $tab_content.find('.js-stats_tab').show(); 20582 } 20583 }); 20584 20585 20586 20587 $(document).on('click', '.js-edit_link', function(e) { 20588 $editing_node = $(this).parent().parent(); 20589 20590 if (!$(this).data().fancybox) { 20591 if ($editing_node.hasClass('js-ladder_rung')) { 20592 fancify_link($(this), edit_trigger_callback); 20593 } else if ($editing_node.hasClass('js-ladder_wait')) { 20594 fancify_link($(this), edit_wait_callback); 20595 } else if ($editing_node.hasClass('js-ladder_wait_validate')) { 20596 fancify_link($(this), edit_wait_validate_callback); 20597 } else if ($editing_node.hasClass('js-ladder_fork')) { 20598 fancify_link($(this), edit_decision_callback); 20599 } else if ($editing_node.hasClass('js-ladder_random')) { 20600 fancify_link($(this), edit_random_callback); 20601 } else { 20602 fancify_link($(this), edit_action_callback); 20603 } 20604 } 20605 20606 e.preventDefault(); 20607 }); 20608 20609 var edit_trigger_callback = function($node) { 20610 $data_node = $node.parent().parent(); 20611 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 20612 20613 $('.js-add_edit').text(an_javascript_translation.edit); 20614 20615 if ($editing_node.parents('.js-ladder_rung_container').find('.js-ladder_rung').length > 1) { 20616 $('#fancybox-content .js-delete_ladder_step-btn').html('<i class="far fa-times"></i> ' + an_javascript_translation.delete_this_trigger); 20617 //if ($('.ladder_published').length) { 20618 $('#fancybox-content .js-delete_ladder_step-btn').show(); 20619 //} 20620 $('#fancybox-content .js-delete_trigger_confirm_text').text(an_javascript_translation.are_you_sure_you_want_to_delete_this_trigger); 20621 } else { 20622 if (!$('.ladder_published').length) { 20623 $('#fancybox-content .js-delete_ladder_step-btn').show(); 20624 } 20625 } 20626 20627 if (data.type == 'received_email' && !data.permalink) { 20628 data.type = 'received_any_email'; 20629 } 20630 20631 if (data.type == 'received_mobile' && !data.permalink) { 20632 data.type = 'received_any_mobile'; 20633 } 20634 20635 if (data.type == 'opened_email' && !data.permalink) { 20636 data.type = 'opened_any_email'; 20637 } 20638 20639 if (data.type == 'clicked_email' && !data.permalink) { 20640 data.type = 'clicked_any_email'; 20641 } 20642 20643 if (data.type == 'clicked_mobile' && !data.permalink) { 20644 data.type = 'clicked_any_mobile'; 20645 } 20646 20647 if (data.type == 'took_action' && !data.permalink && !data.action_type) { 20648 data.type = 'took_any_action'; 20649 } 20650 20651 if (data.type == 'took_action' && data.action_type) { 20652 data.type = 'took_action_type'; 20653 } 20654 20655 $('select.js-rung_trigger_select').val(data.type).trigger("change"); 20656 $select_actions = $('.js-select_actions input.js-rung_actions_select'); 20657 $select_emails = $('.js-select_emails input.js-rung_emails_select'); 20658 $select_mobile = $('.js-select_mobile input.js-rung_mobile_select'); 20659 $select_tags = $('input.js-rung_tags_select'); 20660 20661 if ((data.type == 'received_email' || data.type == 'opened_email' || data.type == 'clicked_email') && data.permalink) { 20662 if (data.type == 'opened_email' || data.type == 'clicked_email') { 20663 init_rung_emails(trigger_email_with_laddersyndicated_json_data); 20664 var match = $.grep(trigger_email_with_laddersyndicated_json_data, function(n, i){ // just use arr 20665 return n.id == data.permalink; 20666 }); 20667 if (!match.length) { 20668 match = $.grep(trigger_email_with_laddersyndicated_json_data, function(n, i){ // just use arr 20669 return n.permalink == data.permalink; 20670 }); 20671 } 20672 } else if (data.type == 'received_email') { 20673 init_rung_emails(trigger_email_json_data); 20674 var match = $.grep(trigger_email_json_data, function(n, i){ // just use arr 20675 return n.id == data.permalink; 20676 }); 20677 if (!match.length) { 20678 match = $.grep(trigger_email_json_data, function(n, i){ // just use arr 20679 return n.permalink == data.permalink; 20680 }); 20681 } 20682 } 20683 20684 //console.log(match); 20685 20686 if (match.length) { 20687 $('.js-select_emails input.js-rung_emails_select').select2('data', { "id": data.permalink, "text": data.title }); 20688 } else if (!match.length) { 20689 $('.js-select_emails input.js-rung_emails_select').select2('data', '').val(''); 20690 } 20691 20692 } 20693 20694 if ((data.type == 'received_mobile' || data.type == 'clicked_mobile') && data.permalink) { 20695 if (data.type == 'clicked_mobile') { 20696 init_rung_mobile(trigger_mobile_with_laddersyndicated_json_data); 20697 var match = $.grep(trigger_mobile_with_laddersyndicated_json_data, function(n, i){ // just use arr 20698 return n.id == data.permalink; 20699 }); 20700 if (!match.length) { 20701 match = $.grep(trigger_mobile_with_laddersyndicated_json_data, function(n, i){ // just use arr 20702 return n.permalink == data.permalink; 20703 }); 20704 } 20705 } else if (data.type == 'received_mobile') { 20706 init_rung_mobile(trigger_mobile_json_data); 20707 var match = $.grep(trigger_mobile_json_data, function(n, i){ // just use arr 20708 return n.id == data.permalink; 20709 }); 20710 if (!match.length) { 20711 match = $.grep(trigger_mobile_json_data, function(n, i){ // just use arr 20712 return n.permalink == data.permalink; 20713 }); 20714 } 20715 } 20716 20717 //console.log(match); 20718 20719 if (match.length) { 20720 $('.js-select_mobile input.js-rung_mobile_select').select2('data', { "id": data.permalink, "text": data.title }); 20721 } else if (!match.length) { 20722 $('.js-select_mobile input.js-rung_mobile_select').select2('data', '').val(''); 20723 } 20724 20725 } 20726 20727 if (data.type == 'took_action' && data.permalink) { 20728 $('.js-select_actions input.js-rung_actions_select').select2('data', { "id": data.permalink, "text": data.title }); 20729 $('.js-text_to_join input').attr('checked', data.only_text_to_join); 20730 if (data.title.includes(an_javascript_translation.petition_brackets) || data.title.includes(an_javascript_translation.form_brackets) || data.title.includes(an_javascript_translation.event_brackets) || data.title.includes(an_javascript_translation.call_campaign_brackets)) { 20731 $('.js-text_to_join').show(); 20732 } else { 20733 $('.js-text_to_join input').attr('checked', false); 20734 $('.js-text_to_join').hide(); 20735 } 20736 //console.log(data.title.includes(an_javascript_translation.fundraising_brackets)); 20737 if (data.title.includes(an_javascript_translation.fundraising_brackets)) { 20738 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 20739 20740 if (data.include_recurring) { 20741 $('.js-trigger_recurring_options input').attr('checked', true); 20742 } else { 20743 $('.js-trigger_recurring_options input').attr('checked', false); 20744 } 20745 20746 if (data.exclude_one_time) { 20747 $('.js-trigger_onetime_options input').attr('checked', true); 20748 } else { 20749 $('.js-trigger_onetime_options input').attr('checked', false); 20750 } 20751 } else { 20752 $('.js-trigger_recurring_options input, .js-trigger_onetime_options input').attr('checked', false); 20753 $('.js-trigger_recurring_options, .js-trigger_onetime_options').hide(); 20754 } 20755 $('.js-ladder_trigger_warning').remove(); 20756 20757 20758 checkDuplicateTriggerActions(data.permalink); 20759 } 20760 20761 if (data.type == 'took_any_action') { 20762 $('.js-exclude_options input').attr('checked', !data.exclude_uploads); 20763 } 20764 20765 if (data.type == 'took_action_type') { 20766 $('.js-action_type_options_select').val(data.action_type).trigger("change"); 20767 //console.log(data.action_type); 20768 if (data.action_type == 'fundraisings') { 20769 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 20770 20771 if (data.include_recurring) { 20772 $('.js-trigger_recurring_options input').attr('checked', true); 20773 } else { 20774 $('.js-trigger_recurring_options input').attr('checked', false); 20775 } 20776 20777 if (data.exclude_one_time) { 20778 $('.js-trigger_onetime_options input').attr('checked', true); 20779 } else { 20780 $('.js-trigger_onetime_options input').attr('checked', false); 20781 } 20782 } 20783 20784 } 20785 if (data.type == 'added_tag') { 20786 $('input.js-rung_tags_select').val(data.permalink).trigger("change"); 20787 } 20788 20789 //$('#fancybox-content .js-delete_ladder_step-btn').show(); 20790 add_trigger_callback($node); 20791 } 20792 20793 20794 // AN-2018 20795 /* enable/disable skip wait */ 20796 var skipCheckbox = $('.js-skip_wait input#skip_wait, .js-skip_wait input#skip_wait_validate'); 20797 20798 skipCheckbox.on('click', function() { 20799 // if skip this wait is checked 20800 if ($(this).is(':checked')) { 20801 // confirmation 20802 $(this).closest('.js-skip_wait').fadeOut(300); 20803 $(".js-ladder_modal_create").fadeOut(300); 20804 $.smoothScroll($('#fancybox-wrap .js-ladder_modal').offset().top - 100); 20805 $('.js-skip_wait_dialog').delay(300).fadeIn(300); 20806 20807 $('.js-confirm_skip').on('click', function() { 20808 console.log('checked'); 20809 // disable inputs once toggle is enabled
20810 $("#modal-wait div, #modal-wait_validate div").not('.js-save_wait_btn_wrap').addClass('disabled'); 20811 $("#modal-wait input, #modal-wait_validate input").prop("disabled", true); 20812 $(".js-wait_select").select2("enable", false); 20813 20814 // close modal 20815 $(".js-skip_wait_dialog").fadeOut(300); 20816 $(".js-ladder_modal_create").delay(300).fadeIn(300); 20817 $('.js-skip_wait').delay(300).fadeIn(300); 20818 }); 20819 20820 $('.js-cancel_skip_wait_step_btn').on('click', function() { 20821 // Uncheck the checkbox 20822 $(skipCheckbox).prop('checked', false); 20823 20824 // Close the modal 20825 $('.js-skip_wait_dialog').fadeOut(300); 20826 $(".js-ladder_modal_create").delay(300).fadeIn(300); 20827 $('.js-skip_wait').delay(300).fadeIn(300); 20828 20829 // Remove the click event handler for "No" to avoid multiple executions 20830 $(this).off('click'); 20831 }); 20832 20833 // Cleanup if "esc" is clicked while warning is up 20834 $(document).on('keyup', function(e) { 20835 if (e.key === 'Escape') { 20836 // Close warning 20837 $('.js-skip_wait_dialog').fadeOut(300); 20838 $(".js-ladder_modal_create").delay(300).fadeIn(300); 20839 $('.js-skip_wait').delay(300).fadeIn(300); 20840 20841 $(document).off('keyup'); 20842 } 20843 }); 20844 20845 } else { 20846 console.log('unchecked'); 20847 $(this).closest('.js-skip_wait').delay(300).fadeIn(300); 20848 $("#modal-wait div, #modal-wait_validate div").removeClass('disabled'); 20849 $("#modal-wait input, #modal-wait_validate input").prop("disabled", false); 20850 $(".js-wait_select").select2("enable", true); 20851 } 20852 }); 20853 20854 var disable_wait_fields = function(){ 20855 console.log("disable_wait_fields"); 20856 $("#modal-wait div, #modal-wait_validate div").not('.js-save_wait_btn_wrap').addClass('disabled'); 20857 $("#modal-wait input, #modal-wait_validate input").prop("disabled", true); 20858 $(".js-wait_select").select2("enable", false); 20859 } 20860 20861 var enable_wait_fields = function(){ 20862 //console.log("enable_wait_fields"); 20863 $("#modal-wait div, #modal-wait_validate div").not('.js-save_wait_btn_wrap').removeClass('disabled'); 20864 $("#modal-wait input, #modal-wait_validate input").prop("disabled", false); 20865 $(".js-wait_select").select2("enable", true); 20866 } 20867 20868 var set_skip_fields = function(skip_wait){ 20869 $('.js-skip_wait input#skip_wait, .js-skip_wait input#skip_wait_validate').attr('checked',skip_wait); 20870 20871 if(skip_wait){ 20872 disable_wait_fields(); 20873 } else { 20874 enable_wait_fields(); 20875 } 20876 } 20877 20878 var set_skip_flag_class = function($step,skip_wait){ 20879 if (skip_wait) { 20880 $step.addClass('ladder_skip_wait'); 20881 } else { 20882 $step.removeClass('ladder_skip_wait'); 20883 } 20884 } 20885 20886 var edit_wait_callback = function($node) { 20887 $data_node = $node.parent().parent(); 20888 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 20889 20890 $('.js-add_edit').text(an_javascript_translation.edit); 20891 $('select.js-wait_select .js-wait_reply_depreciated').remove(); 20892 if (data.rules.type == 'voter_location' || data.rules.type == 'reply') { 20893 $('select.js-wait_select') 20894 .append('<option class="js-wait_reply_depreciated" value="reply">' + an_javascript_translation.wait_for_mobile_response_store + '</option>') 20895 .append('<option class="js-wait_reply_depreciated" value="voter_location">' + an_javascript_translation.wait_for_address_via_mobile_response_find_polling_place_store + '</option>'); 20896 } 20897 20898 if (data.rules.type == 'days' || data.rules.type == 'hours') { 20899 $('select.js-wait_select').val('days_or_hours').trigger("change"); 20900 $('select.js-time_period_select').val(data.rules.type).trigger("change"); 20901 } else { 20902 $('select.js-wait_select').val(data.rules.type).trigger("change"); 20903 } 20904 20905 set_skip_fields(!!data.rules.skip); 20906 20907 if (data.rules.type == 'voter_location') { 20908 $('.js-voter_location_wait_hours').val(data.rules.hours); 20909 $('select.js-wait_polling_locations_field').val(data.rules.polling_locations_field).trigger("change"); 20910 $('select.js-wait_early_vote_locations_field').val(data.rules.early_vote_locations_field).trigger("change"); 20911 $('select.js-wait_drop_off_locations_field').val(data.rules.drop_off_locations_field).trigger("change"); 20912 } 20913 20914 if (data.rules.type == 'reply') { 20915 $('.js-reply_wait_hours').val(data.rules.hours); 20916 $('select.js-wait_field').val(data.rules.field).trigger("change"); 20917 if ($('select.js-wait_field').val() == "email") { 20918 $('.js-wait_field_email_warning').show(); 20919 } else { 20920 $('.js-wait_field_email_warning').hide(); 20921 } 20922 } 20923 20924 if (data.rules.type == 'days') { 20925 $('.js-wait_days input').val(data.rules.days); 20926 } 20927 20928 if (data.rules.type == 'hours') { 20929 $('.js-wait_hours input').val(data.rules.hours); 20930 } 20931 20932 if (data.rules.type == 'date') { 20933 $('.js-wait_date input').val(data.rules.date); 20934 } 20935 20936 if (data.rules.type == 'custom_field') { 20937 $('.js-wait_custom_field_select').select2('val', data.rules.custom_field).trigger('change'); 20938 } 20939 20940 if (data.rules.type == 'relative') { 20941 //$('.js-wait_date input').addClass('required'); 20942 $('select.js-relative-wait').val(data.rules.relative_type).trigger("change"); 20943 $('.js-relative_wait_time').val(data.rules.time); 20944 $('.js-relative_day_picker-monthly select').val(data.rules.day_of_month).trigger("change"); 20945 $('select.js-day_of_year-month').val(data.rules.day_of_year_month).trigger("change"); 20946 $('select.js-day_of_year-day').val(data.rules.day_of_year_day).trigger("change"); 20947 if (data.rules.day_of_week) { 20948 $.each(data.rules.day_of_week, function(i, e) { 20949 $('.js-relative_day_picker-days input[value=' + e + ']').attr('checked','checked').parent().addClass('selected'); 20950 }); 20951 } 20952 } 20953 20954 $('#fancybox-content .js-delete_ladder_step-btn').show(); 20955 add_wait_callback($node); 20956 } 20957 20958 var edit_wait_validate_callback = function($node) { 20959 $data_node = $node.parent().parent(); 20960 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 20961
20962 $('.js-add_edit').text(an_javascript_translation.edit); 20963 $('select.js-wait_validate_select').val(data.rules.type).trigger("change"); 20964 $('.js-invalid_response_message').val(data.rules.invalid_reply); 20965 20966 if (data.rules.type == 'validate_voter_address') { 20967 $('.js-voter_location_wait_hours').val(data.rules.hours); 20968 $('select.js-wait_polling_locations_field').val(data.rules.polling_locations_field).trigger("change"); 20969 $('select.js-wait_early_vote_locations_field').val(data.rules.early_vote_locations_field).trigger("change"); 20970 $('select.js-wait_drop_off_locations_field').val(data.rules.drop_off_locations_field).trigger("change"); 20971 } 20972 20973 set_skip_fields(!!data.rules.skip); 20974 20975 if (data.rules.type == 'valid_response') { 20976 $('.js-reply_wait_hours').val(data.rules.hours); 20977 $('select.js-wait_field').val(data.rules.field).trigger("change"); 20978 if ($('select.js-wait_field').val() == "email") { 20979 $('.js-wait_field_email_warning').show(); 20980 } else { 20981 $('.js-wait_field_email_warning').hide(); 20982 } 20983 if (data.rules.validation_rules.length > 0) { 20984 $('.js-validation_rule_wrap').html(''); 20985 $.each(data.rules.validation_rules, function(i, e) { 20986 var $rule = create_dom($('.js-ladder_assets .js-validation_rule'), $('.js-validation_rule_wrap'), true); 20987 $rule.val(e); 20988 }); 20989 $('.js-invalid_response_message').addClass('required'); 20990 $('.js-invalid_response_wrap').show(); 20991 } else { 20992 $('.js-validation_rule_wrap').html(''); 20993 create_dom($('.js-ladder_assets .js-validation_rule'), $('.js-validation_rule_wrap'), true); 20994 $('.js-invalid_response_message').removeClass('required'); 20995 $('.js-invalid_response_wrap').hide(); 20996 } 20997 20998 } 20999 21000 $('#fancybox-content .js-delete_ladder_step-btn').show(); 21001 add_wait_validate_callback($node); 21002 } 21003 21004 var edit_action_callback = function($node) { 21005 $data_node = $node.parent().parent(); 21006 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 21007 21008 $('.js-add_edit').text(an_javascript_translation.edit); 21009 $('select.js-action_select').val(data.rules.type).trigger("change"); 21010 21011 if (data.rules.type == 'email') { 21012 $('select.js-email_wrapper_id_select').val(data.rules.wrapper_id).trigger('change'); 21013 $('.js-email_admin_title').val(data.rules.administrative_title); 21014 $('.js-email_subject').val(data.rules.subject); 21015 $('.js-email_from').val(data.rules.from_line); 21016 $('.js-email_replyto').val(data.rules.reply_to); 21017 $('.js-input_with_default').find('.js-display_input_reply_to_text').text(data.rules.reply_to); 21018 $('.js-input_with_default').find('select.js-email_replyto').select2("val", data.rules.reply_to).trigger('change'); 21019 $('.js-email_pre_header').val(data.rules.pre_header); 21020 $('textarea.js-email_body').redactor('codemirror.hide').redactor('code.set',data.rules.body_text).redactor('observe.load'); 21021 } 21022 21023 if (data.rules.type == 'mobile_message') { 21024 $('.js-sms_admin_title').val(data.rules.title); 21025 $('textarea.js-message_body').val(data.rules.message_text).trigger('change'); 21026 } 21027 21028 if (data.rules.type == 'add_tags' || data.rules.type == 'remove_tags') { 21029 //console.log(data.rules.tags); 21030 $('input.js-tags_select').select2('val', data.rules.tags).trigger('change'); 21031 } 21032 21033 if ((data.rules.type == 'subscribe' || data.rules.type == 'unsubscribe' || data.rules.type == 'mobile_subscribe' || data.rules.type == 'mobile_unsubscribe') && $('select.js-groups_select').length) { 21034 var permalinkGroups = $('select.js-groups_select option') 21035 .filter((i, option) => { 21036 return data.rules.groups.includes($(option).data('permalink')) 21037 }) 21038 .map((i, o) => o.value) 21039 if (permalinkGroups.length > 0) { 21040 $('select.js-groups_select').val(permalinkGroups).trigger('change'); 21041 } else { 21042 $('select.js-groups_select').val(data.rules.groups).trigger('change'); 21043 } 21044 if ((data.rules.type == 'subscribe' || data.rules.type == 'mobile_subscribe') && data.rules.dont_resubscribe) { 21045 $('input.js-dont_resubscribe').prop('checked', false); 21046 } else { 21047 $('input.js-dont_resubscribe').prop('checked', true); 21048 } 21049 } 21050 21051 if (data.rules.type == 'set_custom_field') { 21052 $('select.js-custom_fields_select').val(data.rules.custom_field_id).trigger('change'); 21053 $('.js-custom_fields_value').val(data.rules.custom_field_value); 21054 21055 } 21056 21057 $('#fancybox-content .js-delete_ladder_step-btn').show(); 21058 add_action_callback($node, $data_node); 21059 } 21060 21061 var edit_decision_callback = function($node) { 21062 $data_node = $node.parent().parent(); 21063 data = jQuery.extend(true, {}, $data_node.data('ladder-json')); 21064
21065 $('.js-add_edit').text(an_javascript_translation.edit); 21066 $('.js-decision_title').val(data.rules.title); 21067 $('#fancybox-content .js-delete_ladder_step-btn').show(); 21068 add_decision_callback($node); 21069 setTimeout(function() { 21070 $('.js-builder').queryBuilder('setRules', JSON.parse(data.rules.query_params)); 21071 $('.js-builder .btn-group .active input').each(function() { 21072 if ($(this).val() == 'AND') { 21073 $(this).parent().parent().parent().parent().removeClass('query-builder-or-group'); 21074 $(this).parent().removeClass('query-builder-or-button'); 21075 } else { 21076 $(this).parent().parent().parent().parent().addClass('query-builder-or-group'); 21077 $(this).parent().addClass('query-builder-or-button'); 21078 } 21079 }); 21080 }, 200); 21081 } 21082 21083 21084 //delete functions 21085 $('.js-confirm_delete').click(function() { 21086 if ($editing_node.hasClass('js-ladder_rung')) { 21087 if ($editing_node.parents('.js-ladder_rung_container').find('.js-ladder_rung').length == 1) { 21088 $editing_node.parents('.js-ladder_rung_container').prev().remove(); 21089 $editing_node.parents('.js-ladder_rung_container').remove(); 21090 } else { 21091 $editing_node.remove(); 21092 } 21093 } else { 21094 $editing_node.prev().remove(); 21095 $editing_node.remove(); 21096 } 21097 21098 $.fancybox.close(); 21099 }); 21100 21101 $('.js-confirm_delete_yes').click(function() { 21102 21103 $editing_node.prev().remove(); 21104 $editing_node.next().nextUntil('.js-ladderbox_exit').remove(); 21105 $editing_node.next().children().unwrap(); 21106 $editing_node.next().remove(); 21107 $editing_node.next().remove(); 21108 if($editing_node.hasClass('js-ladder_random') || $editing_node.hasClass('js-ladder_wait_validate')){ 21109 $editing_node.siblings( ".js-ladderbox_answer-yes-second" ).remove(); 21110 } 21111 $editing_node.remove(); 21112 $('.js-ladder .js-ladderbox_exit').remove(); 21113 add_exits(); 21114 21115 $.fancybox.close(); 21116 }); 21117 21118 $('.js-confirm_delete_no').click(function() { 21119 21120 $editing_node.prev().remove(); 21121 $editing_node.next().remove(); 21122 $editing_node.remove(); 21123 21124 $.fancybox.close(); 21125 }); 21126
21127 var validation_rules_to_array = function() { 21128 return $('.js-validation_rule').map(function() { return $(this).val(); }).get().filter(item => item); 21129 } 21130 21131 $('.js-add_validation_rule').click(function() { 21132 create_dom($('.js-ladder_assets .js-validation_rule'), $('.js-validation_rule_wrap'), true); 21133 }); 21134 21135 $('body').on('keyup', '.js-validation_rule', function() { 21136 if (validation_rules_to_array().length > 0) { 21137 $('.js-invalid_response_message').addClass('required'); 21138 $('.js-invalid_response_wrap').show(); 21139 } else { 21140 $('.js-invalid_response_message').removeClass('required error_input'); 21141 $('.js-invalid_response_wrap').hide(); 21142 } 21143 }); 21144 21145 21146 //adding functions 21147 var $insert_after_node; 21148 21149 //////// add rung functions 21150 $(document).on('click', '.js-add_new_rung', function(e) { 21151 21152 if (!$(this).data().fancybox) { 21153 fancify_link($(this), add_rung_callback); 21154 } 21155 e.preventDefault(); 21156 }); 21157 21158 var add_rung_callback = function($node) { 21159 $insert_after_node = $node.parent(); 21160 $('.js-rung_trigger_select').addClass( 'required' ); 21161 $('.js-save_trigger').addClass( 'js-save_rung' ).removeClass('js-save_trigger'); 21162 $('.js-rung_trigger').html(an_javascript_translation.rung_trigger); 21163 $('.js-save_rung').html(an_javascript_translation.save_rung_trigger); 21164 }; 21165 21166 $(document).on('click', '.js-save_rung', function() { 21167 if ($('.js-ladder_modal_rung_form').valid()) { 21168 var rung_trigger_select_val = $('select.js-rung_trigger_select').val(), 21169 rung_trigger_email_permalink = $('.js-select_emails input').select2('val'), 21170 rung_trigger_mobile_permalink = $('.js-select_mobile input').select2('val'), 21171 rung_trigger_action_permalink = $('.js-select_actions input').select2('val'), 21172 rung_trigger_exclude_options = !$('.js-exclude_options input').attr('checked'), 21173 rung_trigger_recurring_options = !!$('.js-trigger_recurring_options input').attr('checked'), 21174 rung_trigger_onetime_options = !!$('.js-trigger_onetime_options input').attr('checked'), 21175 rung_trigger_only_text_to_join = $('.js-text_to_join input')[0].checked, 21176 rung_trigger_action_type = $('select.js-action_type_options_select').val(), 21177 rung_trigger_tag_permalink = $('input.js-rung_tags_select').val(); 21178 21179 //console.log(rung_trigger_select_val); 21180 //console.log(rung_trigger_action_permalink); 21181 21182 var rung = { 21183 "type": "rung", 21184 "triggers": [ 21185 {} 21186 ] 21187 }; 21188 21189 if (rung_trigger_select_val == 'received_email' 21190 || rung_trigger_select_val == 'clicked_email' 21191 || rung_trigger_select_val == 'opened_email' 21192 || rung_trigger_select_val == 'took_action' 21193 ) { 21194 rung.triggers[0].permalink = rung_trigger_email_permalink; 21195 rung.triggers[0].title = $('.js-select_emails .select2-chosen').text(); 21196 } 21197 21198 if (rung_trigger_select_val == 'received_mobile' 21199 || rung_trigger_select_val == 'clicked_mobile' 21200 ) { 21201 rung.triggers[0].permalink = rung_trigger_mobile_permalink; 21202 rung.triggers[0].title = $('.js-select_mobile .select2-chosen').text(); 21203 } 21204 21205 if (rung_trigger_select_val == 'took_action') { 21206 21207 rung.triggers[0].permalink = rung_trigger_action_permalink; 21208 rung.triggers[0].title = $('.js-select_actions .select2-chosen').text(); 21209 if (rung_trigger_only_text_to_join) { 21210 rung.triggers[0].only_text_to_join = true; 21211 } 21212 21213 if (rung_trigger_recurring_options) { 21214 rung.triggers[0].include_recurring = true; 21215 } 21216 21217 if (rung_trigger_onetime_options) { 21218 rung.triggers[0].exclude_one_time = true; 21219 } 21220 21221 //checkDuplicateTriggerActions(rung_trigger_action_permalink) 21222 } 21223 21224 if (rung_trigger_select_val == 'took_any_action') { 21225 if (rung_trigger_exclude_options) { 21226 rung.triggers[0].exclude_uploads = true; 21227 } 21228 21229 21230 rung_trigger_select_val = 'took_action'; 21231 } 21232 if (rung_trigger_select_val == 'took_action_type') { 21233 rung.triggers[0].action_type = rung_trigger_action_type; 21234 21235 rung_trigger_select_val = 'took_action'; 21236 21237 if (rung_trigger_recurring_options) { 21238 rung.triggers[0].include_recurring = true; 21239 } 21240 21241 if (rung_trigger_onetime_options) {
21242 rung.triggers[0].exclude_one_time = true; 21243 } 21244 } 21245 21246 if (rung_trigger_select_val == 'added_tag') { 21247 rung.triggers[0].permalink = rung_trigger_tag_permalink; 21248 rung.triggers[0].title = rung_trigger_tag_permalink; 21249 } 21250 21251 if (rung_trigger_select_val == 'received_any_email') { 21252 rung_trigger_select_val = 'received_email'; 21253 } 21254 21255 if (rung_trigger_select_val == 'received_any_mobile') { 21256 rung_trigger_select_val = 'received_mobile'; 21257 } 21258 21259 if (rung_trigger_select_val == 'opened_any_email') { 21260 rung_trigger_select_val = 'opened_email'; 21261 } 21262 21263 if (rung_trigger_select_val == 'clicked_any_email') { 21264 rung_trigger_select_val = 'clicked_email'; 21265 } 21266 21267 if (rung_trigger_select_val == 'clicked_any_mobile') { 21268 rung_trigger_select_val = 'clicked_mobile'; 21269 } 21270 21271 rung.triggers[0].type = rung_trigger_select_val; 21272 //console.log(rung); 21273 //console.log(rung); 21274 //var dupes = check_dupes(rung.triggers[0]); 21275 //if (!dupes) { 21276 load_rungs([rung], $insert_after_node); 21277 add_exits(); 21278 $.smoothScroll($insert_after_node.next().offset().top - 150); 21279 $.fancybox.close(); 21280 //} 21281 21282 } 21283 }); 21284 21285 21286 //////// add trigger functions 21287 $(document).on('click', '.js-add_condition', function(e) { 21288 if (!$(this).data().fancybox) { 21289 fancify_link($(this), add_trigger_callback); 21290 } 21291 21292 e.preventDefault(); 21293 }); 21294 21295 var add_trigger_callback = function($node) { 21296 $insert_after_node = $node.prev(); 21297 $('.js-rung_trigger_select').addClass( 'required' ); 21298 $('.js-save_rung').addClass( 'js-save_trigger' ).removeClass('js-save_rung'); 21299 $('.js-rung_trigger').text(an_javascript_translation.trigger); 21300 $('.js-save_trigger').text(an_javascript_translation.save_trigger); 21301 }; 21302 21303 $(document).on('click', '.js-ladder_modal-rung .js-save_trigger', function() { 21304 if ($('.js-ladder_modal_rung_form').valid()) { 21305 var trigger_select_val = $('select.js-rung_trigger_select').val(), 21306 trigger_email_permalink = $('.js-select_emails input').select2('val'), 21307 trigger_mobile_permalink = $('.js-select_mobile input').select2('val'), 21308 trigger_action_permalink = $('.js-select_actions input').select2('val'), 21309 trigger_exclude_options = !$('.js-exclude_options input').attr('checked'), 21310 trigger_recurring_options = !!$('.js-trigger_recurring_options input').attr('checked'), 21311 trigger_onetime_options = !!$('.js-trigger_onetime_options input').attr('checked'), 21312 trigger_only_text_to_join = $('.js-text_to_join input').attr('checked'), 21313 trigger_action_type = $('select.js-action_type_options_select').val(), 21314 trigger_tag_permalink = $('input.js-rung_tags_select').val(); 21315 21316 var trigger = {}; 21317 21318 if (trigger_select_val == 'received_email' 21319 || trigger_select_val == 'clicked_email' 21320 || trigger_select_val == 'opened_email' 21321 || trigger_select_val == 'took_action' 21322 ) { 21323 trigger.permalink = trigger_email_permalink; 21324 trigger.title = $('.js-select_emails .select2-chosen').text(); 21325 } 21326 21327 if (trigger_select_val == 'received_mobile' 21328 || trigger_select_val == 'clicked_mobile' 21329 ) { 21330 trigger.permalink = trigger_mobile_permalink; 21331 trigger.title = $('.js-select_mobile .select2-chosen').text(); 21332 } 21333 21334 if (trigger_select_val == 'took_action') { 21335 21336 trigger.permalink = trigger_action_permalink; 21337 trigger.title = $('.js-select_actions .select2-chosen').text(); 21338 if (trigger_only_text_to_join) { 21339 trigger.only_text_to_join = true; 21340 } 21341 21342 if (trigger_recurring_options) { 21343 trigger.include_recurring = true; 21344 } 21345 21346 if (trigger_onetime_options) { 21347 trigger.exclude_one_time = true; 21348 } 21349 21350 //checkDuplicateTriggerActions(trigger_action_permalink) 21351 } 21352 21353 if (trigger_select_val == 'took_any_action') { 21354 if (trigger_exclude_options) { 21355 trigger.exclude_uploads = true; 21356 } 21357 21358 21359 21360 trigger_select_val = 'took_action'; 21361 } 21362 21363 if (trigger_select_val == 'took_action_type') { 21364 trigger.action_type = trigger_action_type; 21365 21366 trigger_select_val = 'took_action'; 21367 21368 if (trigger_recurring_options) { 21369 trigger.include_recurring = true; 21370 } 21371 21372 if (trigger_onetime_options) { 21373 trigger.exclude_one_time = true; 21374 } 21375 } 21376 21377 if (trigger_select_val == 'added_tag') { 21378 21379 trigger.permalink = trigger_tag_permalink; 21380 trigger.title = trigger_tag_permalink; 21381 } 21382 21383 if (trigger_select_val == 'received_any_email') { 21384 trigger_select_val = 'received_email'; 21385 } 21386 21387 if (trigger_select_val == 'received_any_mobile') { 21388 trigger_select_val = 'received_mobile'; 21389 } 21390 21391 if (trigger_select_val == 'opened_any_email') { 21392 trigger_select_val = 'opened_email'; 21393 } 21394 21395 if (trigger_select_val == 'clicked_any_email') { 21396 trigger_select_val = 'clicked_email'; 21397 } 21398 21399 if (trigger_select_val == 'clicked_any_mobile') { 21400 trigger_select_val = 'clicked_mobile'; 21401 } 21402 21403 trigger.type = trigger_select_val; 21404 21405 //var dupes = check_dupes(trigger); 21406 //if (!dupes) { 21407 21408 if ($editing_node) { 21409 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 21410 trigger.uuid = $editing_node.data('ladder-json').uuid; 21411 } 21412 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 21413 trigger.note = $editing_node.data('ladder-json').note; 21414 } 21415 $editing_node.data('ladder-json', trigger); 21416 edit_step_dom(trigger, $editing_node); 21417 $.smoothScroll($editing_node.offset().top - 150); 21418 } else { 21419 load_step(trigger, $insert_after_node); 21420 $.smoothScroll($insert_after_node.next().offset().top - 150); 21421 } 21422 21423 //add_exits(); 21424 21425 $.fancybox.close(); 21426 21427 //} 21428 } 21429 getActionsOnlyFields(); 21430 }); 21431 21432 $('input.js-rung_actions_select').on('change', function() { 21433 if ($(this).val().includes("Petition") || $(this).val().includes("Form") || $(this).val().includes("Event") || $(this).val().includes("CallC
21433ampaign")) { 21434 $('.js-text_to_join').show(); 21435 } else { 21436 $('.js-text_to_join input').attr('checked', false); 21437 $('.js-text_to_join').hide(); 21438 } 21439 $('.js-ladder_trigger_warning').remove(); 21440 21441 if ($(this).val().includes("Fundraising")) { 21442 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 21443 } else { 21444 $('.js-trigger_recurring_options input, .js-trigger_onetime_options input').attr('checked', false); 21445 $('.js-trigger_recurring_options, .js-trigger_onetime_options').hide(); 21446 } 21447 checkDuplicateTriggerActions($(this).val()); 21448 getActionsOnlyFields(); 21449 }); 21450 21451 actions_only_fields_to_append = []; 21452 21453 var getActionsOnlyFields = function() { 21454 var action_fields_array = []; 21455 $('.js-ladder_rung').each(function() { 21456 if ($(this).data()['ladderJson'].permalink && $(this).data()['ladderJson'].type == 'took_action' && action_fields_array.length < 5) { 21457 action_fields_array.push($(this).data()['ladderJson'].permalink) 21458 } 21459 }); 21460 //console.log('start'); 21461 $.each(action_fields_array, function(i2, e2) { 21462 $.getJSON(window.location.pathname.replace('/edit','/action_field_info?trigger_permalink=' + e2), function(data) { 21463 if (data && data.action_fields && data.action_fields.length > 0) { 21464 $.each(data.action_fields, function(i, e) { 21465 actions_only_fields_to_append.push(e[1].trim().replace("\"","\\\"").replace("\n","").replace("\r","")); 21466 }); 21467 21468 actions_only_fields_to_append = [...new Set(actions_only_fields_to_append)]; 21469 } 21470 }).error(function() { 21471 //console.log('error'); 21472 }); 21473 }); 21474 21475 } 21476 21477 21478 //////// combined trigger/rung functions 21479 $('select.js-rung_trigger_select').on('change', function() { 21480 //console.log($(this).val()); 21481 $('.js-ladder_trigger_warning').remove(); 21482 $('.js-rung_modal_options').hide(); 21483 var $select_actions = $('.js-select_actions input.js-rung_actions_select'); 21484 var $select_emails = $('.js-select_emails input.js-rung_emails_select'); 21485 var $select_mobile = $('.js-select_mobile input.js-rung_mobile_select'); 21486 var $select_action_types = $('select.js-action_type_options_select'); 21487 var $select_tags = $('input.js-rung_tags_select'); 21488 21489 $('#fancybox-content input, #fancybox-content select').not('select.js-rung_trigger_select').removeClass('required'); 21490 $('#fancybox-content input, #fancybox-content select').removeClass('error_input'); 21491 21492 if ($(this).val() == 'received_email' || $(this).val() == 'clicked_email' || $(this).val() == 'opened_email') { 21493 var data = $select_emails.select2('data'); 21494 if ($(this).val() == 'opened_email' || $(this).val() == 'clicked_email') { 21495 init_rung_emails(trigger_email_with_laddersyndicated_json_data); 21496 var match = $.grep(trigger_email_with_laddersyndicated_json_data, function(n, i){ // just use arr 21497 return n.id == $select_emails.select2('val'); 21498 }); 21499 } else if ($(this).val() == 'received_email') { 21500 init_rung_emails(trigger_email_json_data); 21501 var match = $.grep(trigger_email_json_data, function(n, i){ // just use arr 21502 return n.id == $select_emails.select2('val'); 21503 }); 21504 } 21505 21506 //console.log(match); 21507 21508 if (!match.length) { 21509 $select_emails.select2('data', '').val(''); 21510 } else if (match.length) { 21511 $select_emails.select2('data', data); 21512 } 21513 21514 $select_emails.addClass('required'); 21515 $('.js-select_emails').slideDown('fast'); 21516 } 21517 21518 if ($(this).val() == 'received_mobile' || $(this).val() == 'clicked_mobile') { 21519 var data = $select_mobile.select2('data'); 21520 if ($(this).val() == 'clicked_mobile') { 21521 init_rung_mobile(trigger_mobile_with_laddersyndicated_json_data); 21522 var match = $.grep(trigger_mobile_with_laddersyndicated_json_data, function(n, i){ // just use arr 21523 return n.id == $select_mobile.select2('val'); 21524 }); 21525 } else if ($(this).val() == 'received_mobile') { 21526 init_rung_mobile(trigger_mobile_json_data); 21527 var match = $.grep(trigger_mobile_json_data, function(n, i){ // just use arr 21528 return n.id == $select_mobile.select2('val'); 21529 }); 21530 } 21531 21532 //console.log(match); 21533 21534 if (!match.length) { 21535 $select_mobile.select2('data', '').val(''); 21536 } else if (match.length) { 21537 $select_mobile.select2('data', data); 21538 } 21539 21540 $select_mobile.addClass('required'); 21541 $('.js-select_mobile').slideDown('fast'); 21542 } 21543 21544 if ($(this).val() == 'took_action') { 21545 $select_actions.addClass('required'); 21546 $('.js-select_actions').slideDown('fast'); 21547 if ($('input.js-rung_actions_select').val().includes("Petition") || $('input.js-rung_actions_select').val().includes("Form") || $('input.js-rung_actions_select').val().includes("Event") || $('input.js-rung_actions_select').val().includes("CallC
21547ampaign")) { 21548 $('.js-text_to_join').show(); 21549 } else { 21550 $('.js-text_to_join input').attr('checked', false); 21551 $('.js-text_to_join').hide(); 21552 } 21553 21554 if ($('input.js-rung_actions_select').val().includes("Fundraising")) { 21555 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 21556 } else { 21557 $('.js-trigger_recurring_options input, .js-trigger_onetime_options input').attr('checked', false); 21558 $('.js-trigger_recurring_options, .js-trigger_onetime_options').hide(); 21559 } 21560 21561 21562 21563 checkDuplicateTriggerActions($('input.js-rung_actions_select').val()); 21564 } 21565 21566 if ($(this).val() == 'took_any_action') { 21567 $('.js-exclude_options').slideDown('fast'); 21568 } 21569 21570 if ($(this).val() == 'took_action_type') { 21571 $select_action_types.addClass('required'); 21572 $('.js-action_type_options').slideDown('fast'); 21573 //console.log($('select.js-action_type_options_select').val()); 21574 21575 if ($('select.js-action_type_options_select').val() == 'fundraisings') { 21576 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 21577 } else { 21578 $('.js-trigger_recurring_options input, .js-trigger_onetime_options input').attr('checked', false); 21579 $('.js-trigger_recurring_options, .js-trigger_onetime_options').hide(); 21580 } 21581 21582 } 21583 21584 if ($(this).val() == 'added_tag') { 21585 $select_tags.addClass('required'); 21586 $('.js-select_tags').slideDown('fast'); 21587 21588 } 21589 }); 21590 21591 $('select.js-action_type_options_select').on('change', function() { 21592 if ($('select.js-action_type_options_select').val() == 'fundraisings') { 21593 $('.js-trigger_recurring_options, .js-trigger_onetime_options').show(); 21594 } else { 21595 $('.js-trigger_recurring_options input, .js-trigger_onetime_options input').attr('checked', false); 21596 $('.js-trigger_recurring_options, .js-trigger_onetime_options').hide(); 21597 } 21598 }); 21599 21600 var check_dupes = function(ladder_json) { 21601 var dupes = false; 21602 var trigger_array = []; 21603 // console.log(ladder_json); 21604 if (ladder_json) { 21605 $.each(ladder_json, function(rung_i, rung) { 21606 $.each(rung.triggers, function(trigger_i, trigger) { 21607 var trigger_item = trigger.type; 21608 21609 if (trigger.permalink) { 21610 trigger_item = trigger_item + '@!@' + trigger.permalink; 21611 } 21612 21613 if (trigger.action_type) { 21614 trigger_item = trigger_item + '_type@!@' + trigger.action_type; 21615 } 21616 21617 trigger_array.push(trigger_item); 21618 }); 21619 }); 21620 } 21621 21622 21623 //console.log(trigger_array); 21624 var subscribed_count = 0; 21625 var subscribed_mobile_count = 0; 21626 var received_email_count = 0; 21627 var received_mobile_count = 0; 21628 var opened_email_count = 0; 21629 var clicked_email_count = 0; 21630 var clicked_mobile_count = 0; 21631 var took_action_count = 0; 21632 var added_tag_count = 0; 21633 var permalink_object = []; 21634 var action_type_object = []; 21635 21636 21637 21638 $.each(trigger_array, function(trigger_i, trigger) { 21639 21640 21641 if (trigger.match(/subscribed$/)) { 21642 subscribed_count++; 21643 } 21644 21645 if (trigger.match(/subscribed_mobile/)) { 21646 subscribed_mobile_count++; 21647 } 21648 21649 if (trigger.match(/received_email/)) { 21650 if (trigger.match(/received_email@!@/)) { 21651 if (!permalink_object["received_email_" + trigger.split('@!@')[1]]) { 21652 permalink_object["received_email_" + trigger.split('@!@')[1]] = 1; 21653 } else { 21654 permalink_object["received_email_" + trigger.split('@!@')[1]]++; 21655 } 21656 } else { 21657 received_email_count++; 21658 } 21659 } 21660 21661 if (trigger.match(/received_mobile/)) { 21662 if (trigger.match(/received_mobile@!@/)) { 21663 if (!permalink_object["received_mobile_" + trigger.split('@!@')[1]]) { 21664 permalink_object["received_mobile_" + trigger.split('@!@')[1]] = 1; 21665 } else { 21666 permalink_object["received_mobile_" + trigger.split('@!@')[1]]++; 21667 } 21668 } else { 21669 received_mobile_count++; 21670 } 21671 } 21672 21673 if (trigger.match(/opened_email/)) { 21674 if (trigger.match(/opened_email@!@/)) { 21675 if (!permalink_object["opened_email_" + trigger.split('@!@')[1]]) { 21676 permalink_object["opened_email_" + trigger.split('@!@')[1]] = 1; 21677 } else { 21678 permalink_object["opened_email_" + trigger.split('@!@')[1]]++; 21679 } 21680 } else { 21681 opened_email_count++; 21682 } 21683 } 21684 21685 if (trigger.match(/clicked_email/)) { 21686 if (trigger.match(/clicked_email@!@/)) { 21687 if (!permalink_object["clicked_email_" + trigger.split('@!@')[1]]) { 21688 permalink_object["clicked_email_" + trigger.split('@!@')[1]] = 1; 21689 } else { 21690 permalink_object["clicked_email_" + trigger.split('@!@')[1]]++; 21691 } 21692 } else { 21693 clicked_email_count++; 21694 } 21695 } 21696 21697 if (trigger.match(/clicked_mobile/)) { 21698 if (trigger.match(/clicked_mobile@!@/)) { 21699 if (!permalink_object["clicked_mobile_" + trigger.split('@!@')[1]]) { 21700 permalink_object["clicked_mobile_" + trigger.split('@!@')[1]] = 1; 21701 } else { 21702 permalink_object["clicked_mobile_" + trigger.split('@!@')[1]]++; 21703 } 21704 } else { 21705 clicked_mobile_count++; 21706 } 21707 } 21708 21709 if (trigger.match(/took_action/)) { 21710 if (trigger.match(/took_action@!@/)) { 21711 if (!permalink_object["took_action_" + trigger.split('@!@')[1]]) { 21712 permalink_object["took_action_" + trigger.split('@!@')[1]] = 1; 21713 } else { 21714 permalink_object["took_action_" + trigger.split('@!@')[1]]++; 21715 } 21716 } else if (trigger.match(/took_action_type@!@/)) { 21717 if (!action_type_object["took_action_type_" + trigger.split('@!@')[1]]) { 21718 action_type_object["took_action_type_" + trigger.split('@!@')[1]] = 1; 21719 } else { 21720 action_type_object["took_action_type_" + trigger.split('@!@')[1]]++; 21721 } 21722 } else { 21723 took_action_count++; 21724 } 21725 } 21726 21727 if (trigger.match(/added_tag/)) { 21728 if (trigger.match(/added_tag@!@/)) { 21729 if (!permalink_object["added_tag" + trigger.split('@!@')[1]]) { 21730 permalink_object["added_tag" + trigger.split('@!@')[1]] = 1; 21731 } else { 21732 permalink_object["added_tag" + trigger.split('@!@')[1]]++; 21733 } 21734 } 21735 } 21736 21737 }); 21738 21739 if ( 21740 subscribed_count > 1 21741 || subscribed_mobile_count > 1 21742 || received_email_count > 1 21743 || received_mobile_count > 1 21744 || opened_email_count > 1 21745 || clicked_email_count > 1 21746 || clicked_mobile_count > 1 21747 || took_action_count > 1 21748 ) { 21749 dupes = true; 21750 } 21751 21752 21753 // console.log(subscribed_count); 21754 // console.log(subscribed_mobile_count); 21755 // console.log(received_email_count); 21756 // console.log(received_mobile_count); 21757 // console.log(opened_email_count); 21758 // console.log(clicked_email_count); 21759 // console.log(clicked_mobile_count); 21760 // console.log(took_action_count); 21761 // console.log(permalink_object); 21762 // console.log(action_type_object); 21763 // console.log(dupes); 21764 21765 21766 if (Object.keys(permalink_object).length > 0) { 21767 $.each(Object.keys(permalink_object), function(i,e) { 21768 if (permalink_object[e] > 1) { 21769 dupes = true; 21770 } 21771 }); 21772 } 21773 21774 //console.log(dupes); 21775 21776 if (Object.keys(action_type_object).length > 0) { 21777 $.each(Object.keys(action_type_object), function(i,e) { 21778 //console.log(action_type_object[e]); 21779 if (action_type_object[e] > 1) { 21780 dupes = true; 21781 } 21782 }); 21783 } 21784 21785 //console.log(dupes); 21786 21787 return dupes; 21788 }; 21789 21790 //////// add action functions 21791 $(document).on('click', '.js-add_action', function(e) { 21792 if (!$(this).data().fancybox) { 21793 fancify_link($(this), add_action_callback); 21794 } 21795 21796 e.preventDefault(); 21797 }); 21798 21799 var add_action_callback = function($node, $data_node) { 21800 $insert_after_node = $node.parents('.js-ladder_plus_wrap'); 21801 $('.js-action_select').addClass( 'required' ); 21802 if (!$data_node || !$data_node.data('ladder-json').rules.wrapper_id) { 21803 $('.js-email_wrapper_id_select').select2('val', $('.js-default_email_wrapper_id').val()); 21804 } 21805 21806 if (!$data_node || !$data_node.data('ladder-json').rules.subject) { 21807 $('.js-email_from').val($('.js-default_email_from').val()); 21808 } 21809 21810 //console.log(!$data_node); 21811 //console.log(!$data_node.data('ladder-json').rules.reply_to); 21812 //console.log($('.js-ladder_assets').find('.js-display_input_reply_to_text').text()); 21813 21814 if (!$data_node || !$data_node.data('ladder-json').rules.reply_to) { 21815 //console.log('true'); 21816 if ($('.js-email_replyto option:selected').length) { 21817 $('.js-email_replyto').val($('.js-default_email_replyto').val()).trigger('change'); 21818 $('.js-input_with_default').find('.js-display_input_reply_to_text').text($('.js-email_replyto option:selected').text()); 21819 } else { 21820 //console.log($('.js-display_input_reply_to_text').text()); 21821 $('.js-email_replyto').val($('.js-display_input_reply_to_text').text()); 21822 //console.log($('.js-email_replyto').val()); 21823 } 21824 21825 } 21826 21827 }; 21828 21829 $('select.js-action_select').on('change', function() { 21830 $('.js-rung_modal_options').hide(); 21831 $('#fancybox-content input, #fancybox-content select, #fancybox-content textarea').not('select.js-action_select').removeClass('required error_input'); 21832 $('.js-save_and_preview_mobile, .js-save_and_preview_email').hide(); 21833 21834 if ($(this).val() == 'email') { 21835 $('.js-ladder_action_emails input, .js-ladder_action_emails textarea.js-redactor').not('.select2-focusser, .select2-input, .js-test_email, .js-email_pre_header, .js-email_admin_title').addClass('required'); 21836 $('.js-ladder_action_emails').slideDown('fast'); 21837 $('.js-save_and_preview_email').show(); 21838 } 21839 21840 if ($(this).val() == 'mobile_message') { 21841 if ($('.js-ladder_action_sms textarea').val().length == 0) { 21842 let mobile_message_template = $('.js-mobile_message_input').attr('data-template'); 21843 $('.js-message_body').val(mobile_message_template); 21844 } 21845 $('.js-ladder_action_sms input, .js-ladder_action_sms textarea').not('.select2-focusser, .select2-input, .js-test_mobile, .js-mobile_message_input').addClass('required'); 21846 $('.js-ladder_action_sms').slideDown('fast'); 21847 $('.js-save_and_preview_mobile').show(); 21848 } 21849 21850 if ($(this).val() == 'add_tags' || $(this).val() == 'remove_tags') { 21851 $('.js-ladder_action_tags .select2-offscreen').addClass('required'); 21852 $('.js-ladder_action_tags').slideDown('fast'); 21853 } 21854 21855 if ($(this).val() == 'set_custom_field' ) { 21856 $('.js-ladder_action_custom_fields select').addClass('required'); 21857 $('.js-ladder_action_custom_fields').slideDown('fast'); 21858 } 21859 21860 if ($(this).val() == 'subscribe' || $(this).val() == 'unsubscribe' || $(this).val() == 'mobile_subscribe' || $(this).val() == 'mobile_unsubscribe') { 21861 $('.js-ladder_action_groups select').addClass('required'); 21862 $('.js-ladder_action_groups').slideDown('fast'); 21863 if ($(this).val() == 'subscribe' || $(this).val() == 'mobile_subscribe') { 21864 $('.js-subscribe-explain').show(); 21865 $('label.js-dont_resubscribe_container').show(); 21866 } else { 21867 $('.js-subscribe-explain').hide(); 21868 $('label.js-dont_resubscribe_container').hide(); 21869 } 21870 } 21871 }); 21872 21873 $(document).on('click', '.js-ladder_action_sms .js-sms_add-clips', function() { 21874 $('.js-ladder_modal_action_form').fadeOut(function() { 21875 $('.js-mobile_clips_ladder').show(); 21876 }); 21877 }); 21878 21879 $(document).on('click', '.js-ladder_action_sms .js-sms_add-snippet', function() { 21880 $('.js-ladder_modal_action_form').fadeOut(function() { 21881 $('.js-mobile_clips').parent().show(); 21882 $('.js-mobile_clips').show(); 21883 }); 21884 }); 21885 21886 $(document).on('click','.js-mobile_clips_ladder .js-redactor_clip_link', function() { 21887 var $textarea = $('.js-message_body');
21888 var cursorPos = $textarea.prop('selectionStart'); 21889 var v = $textarea.val(); 21890 var textBefore = v.substring(0, cursorPos); 21891 var textAfter = v.substring(cursorPos, v.length); 21892 var textInsert = $(this).parent().find('.js-redactor_clip').text(); 21893 //console.log(textInsert); 21894 if ($(this).hasClass('page_target_clip')) { 21895 var $clip = $(this).next(); 21896 regex = new RegExp($(this).data('regex')); 21897 if (regex.test($textarea.val())) { 21898 textInsert = $clip.data('match'); 21899 } else { 21900 textInsert = $clip.data('nomatch'); 21901 } 21902 } 21903 21904 $textarea.val(textBefore + textInsert + textAfter); 21905 $('.js-mobile_clips_ladder').hide(); 21906 $('.js-ladder_modal_action_form').show(); 21907 $.smoothScroll($('.js-ladder_action_sms_write').offset().top - 200); 21908 }); 21909 21910 $(document).on('click', '.js-ladder_clips_close', function() { 21911 $('.js-mobile_clips_ladder').hide(); 21912 $('.js-ladder_modal_action_form').show(); 21913 $.smoothScroll($('.js-ladder_action_sms_write').offset().top - 200); 21914 }); 21915 21916 if ($('.js-ladder_modal_action_form').length) { 21917 $('.js-ladder_snippets_close').show(); 21918 } 21919 21920 $(document).on('click', '.js-ladder_snippets_close', function() { 21921 $('.js-mobile_clips').hide(); 21922 $('.js-mobile_clips').parent().hide(); 21923 $('.js-ladder_modal_action_form').show(); 21924 $.smoothScroll($('.js-ladder_action_sms_write').offset().top - 200); 21925 }); 21926 21927 $(document).on('click', '.js-ladder_modal_action_form .js-save_action', function() { 21928 $('#fancybox-content .js-test_email, #fancybox-content .js-test_mobile').removeClass('required error_input'); 21929 21930 if ($('.js-noemailaddress').val().includes('@')) { 21931 $('.js-noemailaddress').addClass('error_input'); 21932 return false; 21933 } else { 21934 $('.js-noemailaddress').removeClass('error_input'); 21935 } 21936 21937 if ($('.js-ladder_modal_action_form').valid()) { 21938 var select_val = $('select.js-action_select').val(), 21939 email_wrapper_id = $('select.js-email_wrapper_id_select').val(), 21940 subject = $('.js-email_subject').val(), 21941 administrative_title = $('.js-email_admin_title').val(), 21942 title = $('.js-sms_admin_title').val(), 21943 from_line = $('.js-email_from').val(), 21944 reply_to = $('.js-email_replyto_default input').val() || $('.js-email_replyto').val(), 21945 pre_header = $('.js-email_pre_header').val(), 21946 body_text = $('.js-email_body').val(), 21947 message_text = $('.js-message_body').val(), 21948 tags = $('input.js-tags_select').val(), 21949 custom_field_id = $('select.js-custom_fields_select').val(), 21950 custom_field_name = $('select.js-custom_fields_select option:checked').text(), 21951 custom_field_value = $('.js-custom_fields_value').val(); 21952 21953 if ($editing_node && $editing_node.data('ladder-json') && $editing_node.data('ladder-json').rules && $editing_node.data('ladder-json').rules.uuid) { 21954 var email_uuid = $editing_node.data('ladder-json').rules.uuid; 21955 } 21956 21957 if ($('.js-groups_select_hidden').length) { 21958 var groups = []; 21959 groups[0] = $('.js-groups_select_hidden').val(); 21960 } else { 21961 var groups = $('select.js-groups_select').val(); 21962 } 21963 21964 var step = {}; 21965 step.type = "action"; 21966 step.rules = { 21967 "type": select_val 21968 }; 21969 21970 if (select_val == 'email') { 21971 step.rules.wrapper_id = email_wrapper_id; 21972 step.rules.subject = subject; 21973 step.rules.administrative_title = administrative_title; 21974 step.rules.from_line = from_line; 21975 step.rules.reply_to = reply_to; 21976 step.rules.pre_header = pre_header; 21977 step.rules.body_text = body_text; 21978 if (email_uuid) { 21979 step.rules.uuid = email_uuid; 21980 } 21981 } 21982 21983 if (select_val == 'mobile_message') { 21984 step.rules.title = title; 21985 step.rules.message_text = message_text; 21986 if (email_uuid) { 21987 step.rules.uuid = email_uuid; 21988 } 21989 } 21990 21991 if (select_val == 'add_tags' || select_val == 'remove_tags') { 21992 step.rules.tags = tags.split('@!@'); 21993 } 21994 21995 if (select_val == 'set_custom_field') { 21996 step.rules.custom_field_id = custom_field_id; 21997 step.rules.custom_field_value = custom_field_value; 21998 step.rules.custom_field_name = custom_field_name; 21999 } 22000 22001 step.rules.groups = groups; 22002 22003 if ((select_val == 'subscribe' || select_val == 'unsubscribe' || select_val == 'mobile_unsubscribe' || select_val == 'mobile_subscribe') && $('select.js-groups_select').length) { 22004 22005 step.rules.titles = []; 22006 22007 if (select_val == 'subscribe' || select_val == 'mobile_subscribe') { 22008 if ($('input.js-dont_resubscribe').prop('checked')) { 22009 step.rules.dont_resubscribe = false;
22010 } else { 22011 step.rules.dont_resubscribe = true; 22012 } 22013 } 22014 22015 $.each(groups, function(i, group) { 22016 step.rules.titles.push($('select.js-groups_select option[value="' + group + '"]').text()); 22017 }); 22018 } 22019 22020 if ($editing_node) { 22021 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 22022 step.uuid = $editing_node.data('ladder-json').uuid; 22023 } 22024 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 22025 step.note = $editing_node.data('ladder-json').note; 22026 } 22027 $editing_node.data('ladder-json', step); 22028 edit_step_dom(step, $editing_node); 22029 $.smoothScroll($editing_node.offset().top - 150); 22030 } else { 22031 load_step(step, $insert_after_node); 22032 $.smoothScroll($insert_after_node.next().offset().top - 150); 22033 } 22034 22035 $.fancybox.close(); 22036 } 22037 }); 22038 22039 ///////////// email send test functions 22040 $(document).on('click', '.js-email_send_test', function() { 22041 $('.js-test_email').addClass('required'); 22042 22043 if ($('.js-ladder_modal_action_form').valid()) { 22044 var data = $('.js-ladder_modal_action_form').serialize(); 22045 var $that = $(this); 22046 var url = $that.data('url') || $that.parents('form').attr('action'); 22047 22048 $that.addClass('disabled').attr('disabled','true').html('<i class="fas fa-spinner fa-pulse"></i> ' + an_javascript_translation.sending_suspension_points); 22049 22050 $.post(url, data) 22051 .done(function(data) { 22052 $that.removeClass('disabled').attr('disabled','false').html(an_javascript_translation.send_a_test_email); 22053 }).error(function() { 22054 //console.log('error'); 22055 $that.removeClass('disabled').attr('disabled','false').html(an_javascript_translation.send_a_test_email); 22056 }); 22057 } 22058 22059 $('.js-test_email').removeClass('required'); 22060 22061 }); 22062 22063 $(document).on('click', '.js-mobile_send_test', function() { 22064 $('.js-test_mobile').addClass('required'); 22065 $phone_input = $(this).parent().find(".js-test_mobile"); 22066 if ($phone_input.val() !== '') { 22067 $phone_input.removeClass('error_input'); 22068 // $($phone_input).val($($phone_input).intlTelInput('getNumber')); 22069 if ($('.js-ladder_modal_action_form').valid()) { 22070 var data = $('.js-ladder_modal_action_form').serialize(); 22071 var $that = $(this); 22072 var url = $that.parents('form').attr('action').replace(/preview_email/,'preview_message'); 22073 22074 $that.addClass('disabled').attr('disabled','true').html('<i class="fas fa-spinner fa-pulse"></i> ' + an_javascript_translation.sending_suspension_points); 22075 console.log(data) 22076 $.post(url, data) 22077 .done(function(data) { 22078 $that.removeClass('disabled').attr('disabled','false').html(an_javascript_translation.send_test_mobile); 22079 }).error(function(e) { 22080 console.log('error'); 22081 $that.removeClass('disabled').attr('disabled','false').html(an_javascript_translation.send_test_mobile); 22082 }); 22083 } 22084 22085 } else { 22086 $phone_input.addClass('error_input'); 22087 } 22088 22089 $('.js-test_mobile').removeClass('required'); 22090 }); 22091 22092 22093 //////// add wait functions 22094 $(document).on('click', '.js-add_wait', function(e) { 22095 set_skip_fields(false); 22096 if (!$(this).data().fancybox) { 22097 fancify_link($(this), add_wait_callback); 22098 } 22099 e.preventDefault(); 22100 }); 22101 22102 var add_wait_callback = function($node) { 22103 $insert_after_node = $node.parents('.js-ladder_plus_wrap'); 22104 $('.js-wait_select').addClass( 'required' ); 22105 }; 22106 22107 $('select.js-wait_select').on('change', function() { 22108 $('.js-rung_modal_options').hide(); 22109 $('#fancybox-content input, #fancybox-content .js-relative-wait, #fancybox-content .js-relative_wait_time, .js-relative_day_picker-days label, select.js-wait_field, select.js-wait_polling_locations_field, select.js-wait_early_vote_locations_field, select.js-wait_drop_off_locations_field, .js-invalid_response_message').removeClass('required error_input'); 22110 if ($('select.js-wait_field').val() == "email") { 22111 $('.js-wait_field_email_warning').show(); 22112 } else { 22113 $('.js-wait_field_email_warning').hide(); 22114 } 22115 $('#fancybox-content .js-relative_wait_wrap .js-error_input-select_wrap').removeClass('js-error_input-select_wrap, error_input-select_wrap') 22116 22117 if ($(this).val() == 'days_or_hours') { 22118 $('.js-wait_days, .js-wait_time_period').slideDown('fast'); 22119 $('.js-wait_hours input').removeClass('required'); 22120 $('.js-wait_days input').addClass('required'); 22121 } 22122 22123 if ($(this).val() == 'custom_field') { 22124 $('.js-wait_custom_field_select').addClass('required');
22125 $('.js-custom_field, .js-custom_field').slideDown('fast'); 22126 } else { 22127 $('.js-wait_custom_field_select').removeClass('required'); 22128 $('.js-custom_field, .js-custom_field').hide(); 22129 } 22130 22131 if ($(this).val() == 'date') { 22132 $('.js-wait_date input').addClass('required'); 22133 $('.js-wait_date').slideDown('fast'); 22134 } 22135 22136 if ($(this).val() == 'relative') { 22137 $('.js-relative-wait, .js-relative_wait_time').addClass('required'); 22138 $('.js-relative_wait_wrap').slideDown('fast'); 22139 } 22140 22141 if ($(this).val() == 'voter_location') { 22142 $('.js-voter_location_wait_hours, select.js-wait_polling_locations_field, select.js-wait_early_vote_locations_field, select.js-wait_drop_off_locations_field').addClass('required'); 22143 $('.js-wait_voter_location').slideDown('fast'); 22144 } 22145 22146 if ($(this).val() == 'reply') { 22147 $('.js-reply_wait_hours, select.js-wait_field').addClass('required'); 22148 $('.js-wait_sms').slideDown('fast'); 22149 } 22150 }); 22151 22152 // AN-1975: swap the hours/days input based on the length of time selected 22153 $('select.js-time_period_select').on('change', function() { 22154 if ($(this).val() == "hours") { 22155 $('.js-wait_days input').removeClass('required'); 22156 $('.js-wait_days').hide(); 22157 $('.js-wait_hours input').addClass('required'); 22158 $('.js-wait_hours').show(); 22159 } else { 22160 $('.js-wait_hours input').removeClass('required'); 22161 $('.js-wait_hours').hide(); 22162 $('.js-wait_days input').addClass('required'); 22163 $('.js-wait_days').show(); 22164 } 22165 }); 22166 22167 $('select.js-wait_field').on('change', function() { 22168 if ($(this).val() == "email") { 22169 $('.js-wait_field_email_warning').show(); 22170 } else { 22171 $('.js-wait_field_email_warning').hide(); 22172 } 22173 }); 22174 22175 $('.js-relative-wait').on('change', function() { 22176 $('.js-relative-wait-option').hide(); 22177 $('.js-relative_day_picker-days label').removeClass('error_input'); 22178 //$('#fancybox-content input').removeClass('required error_input'); 22179 22180 if ($(this).val() == 'weekday') { 22181 //$('.js-wait_days input').addClass('required'); 22182 $('.js-relative_time_picker_wrap').slideDown('fast'); 22183 } 22184 22185 if ($(this).val() == 'day_of_week') { 22186 //$('.js-wait_days input').addClass('required'); 22187 $('.js-relative_day_picker-weekly_wrap, .js-relative_time_picker_wrap').slideDown('fast'); 22188 } 22189 22190 if ($(this).val() == 'day_of_month') { 22191 //$('.js-wait_date input').addClass('required'); 22192 $('.js-relative_day_picker-monthly_wrap, .js-relative_time_picker_wrap').slideDown('fast'); 22193 } 22194 22195 if ($(this).val() == 'day_of_year') { 22196 //$('.js-wait_date input').addClass('required'); 22197 $('.js-relative_day_picker-yearly_wrap, .js-relative_time_picker_wrap').slideDown('fast'); 22198 } 22199 22200 $('.js-relative_time_picker_wrap input').removeClass('error_input') 22201 }); 22202 22203 $('.js-relative_day_picker-days input').click(function() { 22204 if ($(this).is(':checked')) { 22205 $(this).parent().addClass('selected'); 22206 } else { 22207 $(this).parent().removeClass('selected') 22208 } 22209 22210 $('.js-relative_day_picker-days label').removeClass('error_input'); 22211 }); 22212 22213 $(document).on('click', '.js-ladder_modal_wait_form .js-save_wait', function() { 22214 if ($('select.js-wait_select').val() == 'relative' && $('select.js-relative-wait').val() == 'day_of_week' && !$('.js-relative_day_picker-days input:checked').length) { 22215 $('.js-relative_day_picker-days label').addClass('error_input'); 22216 $('.js-ladder_modal_wait_form').valid(); 22217 } else { 22218 if ($('.js-ladder_modal_wait_form').valid()) { 22219 var select_val = $('select.js-wait_select').val(), 22220 select_time = $('select.js-time_period_select').val(), 22221 wait_custom_field = $('select.js-wait_custom_field_select').val(), 22222 wait_custom_field_name = $('select.js-wait_custom_field_select').find(':selected').text(), 22223 days = $('.js-wait_days input').val(), 22224 hours = $('.js-wait_hours input').val(), 22225 skip = $('.js-skip_wait input#skip_wait').is(':checked'), 22226 date = $('.js-wait_date input').val(), 22227 sms_hours = $('.js-ladder_modal_wait_form .js-reply_wait_hours').val(), 22228 sms_field = $('.js-ladder_modal_wait_form select.js-wait_field').val(), 22229 voter_location_hours = $('.js-ladder_modal_wait_form .js-voter_location_wait_hours').val(), 22230 polling_locations_field = $('.js-ladder_modal_wait_form select.js-wait_polling_locations_field').val(), 22231 early_vote_locations_field = $('.js-ladder_modal_wait_form select.js-wait_early_vote_locations_field').val(), 22232 drop_off_locations_field = $('.js-ladder_modal_wait_form select.js-wait_drop_off_locations_field').val(), 22233 relative_type = $('select.js-relative-wait').val(),
22234 day_of_month = $('.js-relative_day_picker-monthly select').val(), 22235 day_of_year_month = $('select.js-day_of_year-month').val(), 22236 day_of_year_day = $('select.js-day_of_year-day').val(), 22237 relative_time = $('.js-relative_wait_time').val(); 22238 22239 if (select_val == 'days_or_hours') { 22240 select_val = select_time 22241 } 22242 22243 var step = {}; 22244 step.type = "wait"; 22245 step.rules = { 22246 "type": select_val, 22247 "skip": !!skip 22248 }; 22249 22250 if (select_time == 'days') { 22251 step.rules.days = days; 22252 } 22253 if (select_time == 'hours') { 22254 step.rules.hours = hours; 22255 } 22256 22257 if (select_val == 'date') { 22258 step.rules.date = date; 22259 } 22260 22261 if (select_val == 'voter_location') { 22262 step.rules.hours = voter_location_hours; 22263 step.rules.polling_locations_field = polling_locations_field; 22264 step.rules.early_vote_locations_field = early_vote_locations_field; 22265 step.rules.drop_off_locations_field = drop_off_locations_field; 22266 } 22267 22268 if (select_val == 'reply') { 22269 step.rules.hours = sms_hours; 22270 step.rules.field = sms_field; 22271 } 22272 22273 if (select_val == 'relative') { 22274 step.rules.relative_type = relative_type; 22275 22276 if (relative_type == 'day_of_week') { 22277 var day_of_week_array = []; 22278 $('.js-relative_day_picker-days input:checked').each(function() { 22279 day_of_week_array.push($(this).val()); 22280 }); 22281 step.rules.day_of_week = day_of_week_array; 22282 } 22283 22284 if (relative_type == 'day_of_month') { 22285 step.rules.day_of_month = day_of_month; 22286 } 22287 22288 if (relative_type == 'day_of_year') { 22289 step.rules.day_of_year_month = day_of_year_month; 22290 step.rules.day_of_year_day = day_of_year_day; 22291 } 22292 22293 step.rules.time = relative_time; 22294 } 22295 22296 if (select_val == 'custom_field') { 22297 step.rules.custom_field = wait_custom_field; 22298 step.rules.custom_field_name = wait_custom_field_name; 22299 } 22300 22301 22302 if ($editing_node) { 22303 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 22304 step.uuid = $editing_node.data('ladder-json').uuid; 22305 } 22306 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 22307 step.note = $editing_node.data('ladder-json').note; 22308 } 22309 $editing_node.data('ladder-json', step); 22310 edit_step_dom(step, $editing_node); 22311 $.smoothScroll($editing_node.offset().top - 150); 22312 } else { 22313 load_step(step, $insert_after_node); 22314 $.smoothScroll($insert_after_node.next().offset().top - 150); 22315 } 22316 22317 $.fancybox.close(); 22318 } 22319 } 22320 }); 22321 22322 //////// add wait validate functions 22323 $(document).on('click', '.js-add_wait_validate', function(e) { 22324 set_skip_fields(false); 22325 if (!$(this).data().fancybox) { 22326 fancify_link($(this), add_wait_validate_callback); 22327 } 22328 e.preventDefault(); 22329 }); 22330 22331 var add_wait_validate_callback = function($node) { 22332 $insert_after_node = $node.parents('.js-ladder_plus_wrap'); 22333 $('.js-wait_validate_select').addClass( 'required' ); 22334 if (!$('.js-validation_rule').length) { 22335 $('.js-validation_rule_wrap').html(''); 22336 create_dom($('.js-ladder_assets .js-validation_rule'), $('.js-validation_rule_wrap'), true); 22337 } 22338 }; 22339 22340 $('select.js-wait_validate_select').on('change', function() { 22341 $('.js-rung_modal_options').hide(); 22342 22343 $('#fancybox-content input, select.js-wait_field, select.js-wait_polling_locations_field, select.js-wait_early_vote_locations_field, select.js-wait_drop_off_locations_field, .js-invalid_response_message').removeClass('required error_input'); 22344 if ($('select.js-wait_field').val() == "email") { 22345 $('.js-wait_field_email_warning').show(); 22346 } else { 22347 $('.js-wait_field_email_warning').hide(); 22348 } 22349 22350 if ($(this).val() == 'validate_voter_address') { 22351 $('.js-voter_location_wait_hours, select.js-wait_polling_locations_field, select.js-wait_early_vote_locations_field, select.js-wait_drop_off_locations_field, .js-invalid_response_message').addClass('required'); 22352 22353 $('.js-wait_voter_location').slideDown('fast'); 22354 $('.js-invalid_response_wrap').show(); 22355 } 22356 22357 if ($(this).val() == 'valid_response') { 22358 $('.js-reply_wait_hours, select.js-wait_field').addClass('required'); 22359 $('.js-wait_sms').slideDown('fast'); 22360 if (validation_rules_to_array().length > 0) { 22361 $('.js-invalid_response_message').addClass('required'); 22362 $('.js-invalid_response_wrap').show(); 22363 } else { 22364 $('.js-invalid_response_wrap').hide(); 22365 $('.js-validation_rule_wrap').html(''); 22366 create_dom($('.js-ladder_assets .js-validation_rule'), $('.js-validation_rule_wrap'), true); 22367 } 22368 22369 } 22370 }); 22371 22372 $('select.js-wait_field').on('change', function() { 22373 if ($(this).val() == "email") { 22374 $('.js-wait_field_email_warning').show(); 22375 } else { 22376 $('.js-wait_field_email_warning').hide(); 22377 } 22378 }); 22379 22380 $(document).on('click', '.js-ladder_modal_wait_validate_form .js-save_wait', function() { 22381 if ($('.js-ladder_modal_wait_validate_form').valid()) { 22382 var select_val = $('.js-ladder_modal_wait_validate_form select.js-wait_validate_select').val(), 22383 skip = $('.js-skip_wait input#skip_wait_validate').is(':checked'), 22384 sms_hours = $('.js-ladder_modal_wait_validate_form .js-reply_wait_hours').val(), 22385 sms_field = $('.js-ladder_modal_wait_validate_form select.js-wait_field').val(), 22386 voter_location_hours = $('.js-ladder_modal_wait_validate_form .js-voter_location_wait_hours').val(), 22387 polling_locations_field = $('.js-ladder_modal_wait_validate_form select.js-wait_polling_locations_field').val(), 22388 early_vote_locations_field = $('.js-ladder_modal_wait_validate_form select.js-wait_early_vote_locations_field').val(), 22389 drop_off_locations_field = $('.js-ladder_modal_wait_validate_form select.js-wait_drop_off_locations_field').val(), 22390 invalid_response_message = $('.js-ladder_modal_wait_validate_form .js-invalid_response_message').val(), 22391 validation_rules = validation_rules_to_array(); 22392 22393 var step = {}; 22394 step.type = "wait_validate"; 22395 step.rules = { 22396 "type": select_val, 22397 "skip": !!skip 22398 }; 22399 //console.log(select_val); 22400 22401 if (select_val == 'validate_voter_address') { 22402 step.rules.hours = voter_location_hours; 22403 step.rules.polling_locations_field = polling_locations_field; 22404 step.rules.early_vote_locations_field = early_vote_locations_field; 22405 step.rules.drop_off_locations_field = drop_off_locations_field; 22406 step.rules.invalid_reply = invalid_response_message; 22407 } 22408 22409 if (select_val == 'valid_response') { 22410 step.rules.hours = sms_hours; 22411 step.rules.field = sms_field; 22412 step.rules.validation_rules = validation_rules; 22413 step.rules.invalid_reply = invalid_response_message; 22414 } 22415 22416 22417 22418 if ($editing_node) { 22419 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 22420 step.uuid = $editing_node.data('ladder-json').uuid; 22421 } 22422 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 22423 step.note = $editing_node.data('ladder-json').note; 22424 } 22425 $editing_node.data('ladder-json', step); 22426 edit_step_dom(step, $editing_node); 22427 $.smoothScroll($editing_node.offset().top - 150); 22428 $.fancybox.close(); 22429 } else { 22430 //console.log($insert_after_node.next().hasClass('js-ladderbox_exit')); 22431 if (!$insert_after_node.next().hasClass('js-ladderbox_exit')) { 22432 //console.log('in2'); 22433 $('.js-modal_wait_validate_wrap').fadeOut(300); 22434 22435 $.smoothScroll($('#fancybox-wrap .js-ladder_modal').offset().top - 150); 22436 22437 $(".js-add_ladder_path_wrap").delay(300).fadeIn(300); 22438 22439 $('.js-yes_path').off('click').on('click', function() { 22440 load_step(step, $insert_after_node); 22441 add_exits(); 22442 $.smoothScroll($insert_after_node.next().offset().top - 150); 22443 $.fancybox.close(); 22444 }); 22445 22446 22447 $('.js-no_path').off('click').on('click', function() { 22448 load_step(step, $insert_after_node); 22449 $insert_after_node.next().next().nextUntil( '.js-ladderbox_exit').insertAfter($insert_after_node.next().next().find('.js-ladder_plus_wrap')); 22450 22451 add_exits(); 22452 $.smoothScroll($insert_after_node.next().offset().top - 150); 22453 $.fancybox.close(); 22454 }); 22455 22456 } else { 22457 load_step(step, $insert_after_node); 22458 add_exits(); 22459 $.smoothScroll($insert_after_node.next().offset().top - 150); 22460 $.fancybox.close(); 22461 } 22462 } 22463 22464 //$.fancybox.close(); 22465 } 22466 22467 }); 22468 22469 22470 //////// add decision functions 22471 $(document).on('click', '.js-add_decision', function(e) { 22472 if (!$(this).data().fancybox) { 22473 fancify_link($(this), add_decision_callback); 22474 } 22475 22476 e.preventDefault(); 22477 }); 22478 22479 var add_decision_callback = function($node) { 22480 $insert_after_node = $node.parents('.js-ladder_plus_wrap'); 22481 $('.js-decision_title').addClass( 'required' ); 22482 }; 22483 22484 $(document).on('click', '.js-ladder_modal_decision_form .js-save_decision', function() { 22485 if ($('.js-ladder_modal_decision_form').valid() && !$.isEmptyObject($('.js-builder').queryBuilder('getRules'))) { 22486 $('.rule-filter-container select').each(function() { 22487 if ($(this).val() == -1) { 22488 $(this).parent().parent().remove(); 22489 } 22490 }); 22491 22492 $('.rule-value-container select.required, .rule-value-container input.required').each(function() { 22493 if ($(this).val() == '' || $(this).val() == null) { 22494 $(this).parentsUntil('.rule-container').parent().remove(); 22495 } 22496 }); 22497 22498 $('.rules-group-container .rules-group-container').each(function() { 22499 if (!$(this).find('.rule-filter-container').length) { 22500 $(this).remove(); 22501 } 22502 }); 22503 22504 var query_params = JSON.stringify($('.js-builder').queryBuilder('getRules')); 22505 var title = $('.js-decision_title').val(); 22506 22507 var step = {}; 22508 22509 step.type = "fork"; 22510 step.rules = { 22511 "type": "fork", 22512 "title": title, 22513 "query_params": query_params 22514 }; 22515 22516 if ($editing_node) { 22517 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').uuid) { 22518 step.uuid = $editing_node.data('ladder-json').uuid; 22519 } 22520 if ($editing_node.data('ladder-json') && $editing_node.data('ladder-json').note) { 22521 step.note = $editing_node.data('ladder-json').note; 22522 } 22523 $editing_node.data('ladder-json', step); 22524 edit_step_dom(step, $editing_node); 22525 $.smoothScroll($editing_node.offset().top - 150); 22526 $.fancybox.close(); 22527 } else { 22528 //console.log($insert_after_node.next().hasClass('js-ladderbox_exit')); 22529 22530 if (!$insert_after_node.next().hasClass('js-ladderbox_exit')) { 22531 //console.log('in'); 22532 $('.js-modal_decision_wrap').fadeOut(300); 22533 22534 $.smoothScroll($('#fancybox-wrap .js-ladder_modal').offset().top - 150); 22535 22536 $(".js-add_ladder_path_wrap").delay(300).fadeIn(300); 22537 22538 $('.js-yes_path').off('click').on('click', function() { 22539 load_step(step, $insert_after_node); 22540 add_exits(); 22541 $.smoothScroll($insert_after_node.next().offset().top - 150); 22542 $.fancybox.close(); 22543 }); 22544 22545 22546 $('.js-no_path').off('click').on('click', function() { 22547 load_step(step, $insert_after_node); 22548 $insert_after_node.next().next().nextUntil( '.js-ladderbox_exit').insertAfter($insert_after_node.next().next().find('.js-ladder_plus_wrap')); 22549 22550 add_exits(); 22551 $.smoothScroll($insert_after_node.next().offset().top - 150); 22552 $.fancybox.close(); 22553 }); 22554 } else { 22555 load_step(step, $insert_after_node); 22556 add_exits(); 22557 $.smoothScroll($insert_after_node.next().offset().top - 150); 22558 $.fancybox.close(); 22559 } 22560 } 22561 22562 } else { 22563 $('.rule-container select').each(function() { 22564 if ($(this).val() == -1) { 22565 $(this).parent().find('span.customSelect').addClass('error_input'); 22566 } else { 22567 $(this).parent().find('span.customSelect').removeClass('error_input'); 22568 } 22569 }); 22570 } 22571 22572 22573 }); 22574 22575 //save functions 22576 22577 /////// save ladder functions 22578 var save_ladder = function() { 22579 ladderRemoveStickyForks(); 22580 var ladder_data = []; 22581 22582 ladder_data = save_rungs($('.js-ladder .js-ladder_rung_container'), ladder_data); 22583 ladderAddStickyForks(); 22584 22585 if (ladder_data.length) { 22586 return ladder_data; 22587 } else { 22588 return []; 22589 } 22590 22591 }; 22592 22593 /////// load rung functions 22594 var save_rungs = function($rungs, ladder_data) { 22595 $rungs.each(function(i, rung) { 22596 //console.log($(rung)); 22597 var ladder_json = jQuery.extend(true, {}, $(rung).data('ladder-json')); 22598 22599 var rung_object = { 22600 "type": "rung" 22601 }; 22602 22603 if (ladder_json.uuid) { 22604 rung_object.uuid = ladder_json.uuid; 22605 } 22606 22607 rung_object.triggers = save_triggers(rung); 22608 22609 rung_object = save_steps(rung_object, $(rung).find('.js-ladder_rung').last()); 22610 22611 ladder_data.push(rung_object); 22612 22613 }); 22614 22615 return ladder_data; 22616 }; 22617 22618 22619 /////// save trigger functions 22620 var save_triggers = function(rung) { 22621 22622 var triggers_array = []; 22623 22624 $(rung).find('.js-ladder_rung').each(function(i, trigger) { 22625 var trigger_object = jQuery.extend(true, {}, $(trigger).data('ladder-json')); 22626 triggers_array.push(trigger_object); 22627 }); 22628 22629 return triggers_array; 22630 }; 22631 22632 22633 /////// save step functions 22634 var save_steps = function(json_object, $step) { 22635 22636 var $next_step, 22637 $if_false_next_step, 22638 $if_true_next_step; 22639 22640 if ($step.next().hasClass('js-decision_container')) { 22641 json_object.if_false = {}; 22642 json_object.if_true = {}; 22643 //console.log($step); 22644 22645 $if_false_next_step = $step.next().children('.js-ladder_step').first(); 22646 if ($if_false_next_step.length) { 22647 json_object.if_false.next_step = jQuery.extend(true, {}, $if_false_next_step.data('ladder-json')); 22648 //console.log($if_false_next_step.find('.js-copy_step_checkbox:checked')); 22649 if ($if_false_next_step.find('.js-copy_step_checkbox:checked').length) { 22650 json_object.if_false.next_step.copy = true; 22651 json_object.if_false.next_step.uuid = null; 22652 json_object.if_false.next_step.rules.uuid = null; 22653 // console.log(json_object.if_false.next_step); 22654 } 22655 save_steps(json_object.if_false.next_step, $if_false_next_step); 22656 } 22657 22658 //$if_true_next_step = $step.nextUntil('.js-ladder_step').next().last(); 22659 $if_true_next_step = $step.next().next().next(); 22660 //console.log($if_true_next_step); 22661 if ($if_true_next_step.hasClass('js-ladder_step')) { 22662 json_object.if_true.next_step = jQuery.extend(true, {}, $if_true_next_step.data('ladder-json')); 22663 if ($if_true_next_step.find('.js-copy_step_checkbox:checked').length) { 22664 json_object.if_true.next_step.copy = true; 22665 json_object.if_true.next_step.uuid = null; 22666 json_object.if_true.next_step.rules.uuid = null; 22667 // console.log(json_object.if_true.next_step); 22668 } 22669 save_steps(json_object.if_true.next_step, $if_true_next_step); 22670 } 22671 } else { 22672 $next_step = $step.nextUntil('.js-ladder_step').next().last(); 22673 if ($next_step.hasClass('js-ladder_step')) { 22674 json_object.next_step = jQuery.extend(true, {}, $next_step.data('ladder-json')); 22675 if ($next_step.find('.js-copy_step_checkbox:checked').length) { 22676 json_object.next_step.copy = true; 22677 json_object.next_step.uuid = null; 22678 json_object.next_step.rules.uuid = null; 22679 // console.log(json_object.next_step); 22680 } 22681 save_steps(json_object.next_step, $next_step); 22682 } 22683 } 22684 22685 return json_object; 22686 }; 22687 22688 var create_step_dom = function(step, $add_after_node, append) { 22689 var $step_dom = create_dom($('.js-ladder_assets .js-ladder_step'), $add_after_node, append); 22690 22691 if ($step_dom.data('ladder-json') && $step_dom.data('ladder-json').uuid) { 22692 step.uuid = $editing_node.data('ladder-json').uuid; 22693 } 22694 if ($step_dom.data('ladder-json') && $step_dom.data('ladder-json').note) { 22695 step.note = $editing_node.data('ladder-json').note; 22696 } 22697 22698 var step_pruned = jQuery.extend(true, {}, step); 22699 if (step_pruned.copy) { 22700 delete step_pruned.copy; 22701 } 22702 delete step_pruned.next_step 22703 22704 $step_dom.data('ladder-json', step_pruned); 22705 return $step_dom; 22706 }; 22707 22708 22709 22710 // notes functions 22711 $(document).on('click', '.js-edit_note', function(e) { 22712 $editing_node = $(this).parent().parent(); 22713 22714 if (!$(this).data().fancybox) { 22715 fancify_link($(this), edit_note_callback); 22716 } 22717 22718 e.preventDefault(); 22719 }); 22720 22721 var edit_note_callback = function($node) { 22722 var note = jQuery.extend(true, {}, $editing_node.data('ladder-json')).note; 22723 if (note) { 22724 $('#fancybox-content textarea').
22724val(note); 22725 } 22726 }; 22727 22728 $(document).on('click', '.js-save_notes', function() { 22729 var note = $('#fancybox-content textarea').val(); 22730 22731 if (note != '') { 22732 $editing_node.data('ladder-json').note = note; 22733 $editing_node.find('.js-edit_note span').html(note + '<br/>' + an_javascript_translation.click_to_edit_notes_about_this_step); 22734 } else { 22735 delete $editing_node.data('ladder-json').note; 22736 $editing_node.find('.js-edit_note span').text(an_javascript_translation.click_to_edit_notes_about_this_step); 22737 } 22738 22739 $.fancybox.close(); 22740 }); 22741 22742 var ladderAddStickyForks = function() { 22743 //console.log('start'); 22744 if ( $('.js-content > .js-container').width() > 960) { 22745 var forks = $('.js-ladder_fork, .js-ladder_random, .js-ladder_wait_validate'); 22746 forks.each(function() { 22747 var $fork = $(this); 22748 $fork.trigger('detach.ScrollToFixed'); 22749 $fork.scrollToFixed({ 22750 limit: function() { 22751 var $ladderPath = $fork.next().next('.js-decision_container'); 22752 22753 var $limitRelease = $ladderPath.offset().top + $ladderPath.outerHeight(true); 22754 return $limitRelease; 22755 }, 22756 removeOffsets: true 22757 }) 22758 }); 22759 } 22760 } 22761 22762 var ladderRemoveStickyForks = function() { 22763 var forks = $('.js-ladder_fork, .js-ladder_random, .js-ladder_wait_validate'); 22764 forks.each(function() { 22765 var $fork = $(this); 22766 $fork.trigger('detach.ScrollToFixed'); 22767 }); 22768 } 22769 22770 22771 /* ladders copy steps ******************************/ 22772 22773 $('.js-button_enter_copy_mode').on('click', function(e) { 22774 // add class to #ladder 22775 $(this).parents('.js-create_action_page').find('.js-ladder').addClass('ladder_copy_mode'); 22776 // add class to action_toolbox 22777 $(this).parents('.js-create_action_toolbox').addClass('copy-mode-active'); 22778 // remove hide class from copy mode elements 22779 $('.js-button_exit_copy_mode, .js-button_copy_paste, .js-copy-mode-active__title').show(); 22780 // swap title/notes with helper text in header 22781 $(this).parents('.js-create_action_page').find('.js-edit_ladder_head').addClass('ladder_copy_mode'); 22782 22783 $('.js-create_action_toolbox input').attr('disabled','disabled'); 22784 22785 ladderRemoveStickyForks(); 22786 }); 22787 22788 var show_hide_prev_next_copy_checkbox = function($this, $clicked) { 22789 var $parent_step = $($this.parents('.js-ladder_step')); 22790 var $prev_checkbox = $($parent_step.prevAll('.js-ladder_step:first').find('.js-copy_step_checkbox')); 22791 var $next_checkbox = $($parent_step.nextAll('.js-ladder_step:first').find('.js-copy_step_checkbox')); 22792 22793 var $next_decision_container = $($parent_step.next('.js-decision_container')); 22794 var $next_decision_step = $($next_decision_container.find('.js-ladder_step:first')); 22795 var $next_decision_step_checkbox = $($next_decision_step.find('.js-copy_step_checkbox')); 22796 22797 var $clicked_parent_step = $($clicked.parents('.js-ladder_step')); 22798 var $clicked_next_decision_container = $($clicked_parent_step.next('.js-decision_container')); 22799 22800 var $prev_decision_container = $($parent_step.parent('.js-decision_container')); // the previous decision step, if there is one 22801 var $prev_decision_step = $($prev_decision_container.prevAll('.js-ladder_step:first')); 22802 var $prev_decision_step_checkbox = $($prev_decision_step.find('.js-copy_step_checkbox')); 22803 22804 if ( 22805 ($this.is(':checked') && $next_checkbox.is(':checked') && $prev_checkbox.is(':checked')) 22806 || ($this.is(':checked') && $next_checkbox.is(':checked') && $prev_decision_step_checkbox.is(':checked')) 22807 || ($this.is(':checked') && $prev_checkbox.is(':checked') && $next_decision_step_checkbox.is(':checked')) 22808 || ($this.is(':checked') && $prev_decision_step_checkbox.is(':checked') && $next_decision_step_checkbox.is(':checked')) 22809 ) { 22810 $this.addClass('disabled').attr('disabled','disabled'); 22811 } else { 22812 $this.removeClass('disabled').attr('disabled',false); 22813 } 22814 22815 if ( 22816 (!$this.is(':checked') && $next_checkbox.is(':checked')) //if this is next to a checked checkbox, show it 22817 || (!$this.is(':checked') && $prev_checkbox.is(':checked')) 22818 || (!$this.is(':checked') && $prev_decision_step_checkbox.is(':checked') && $prev_decision_container.find('.js-ladder_step')[0] == $parent_step[0]) 22819 || (!$this.is(':checked') && $next_decision_step_checkbox.is(':checked')) 22820 ) { 22821 $this.show(); 22822 } 22823 22824 if ($this.is(':checked')) { // if this is checked itself, show it 22825 $this.show(); 22826 } 22827 22828 if (typeof($clicked_next_decision_container != 'undefined') && !$clicked.is(':checked')) { //if this is a decision and the checkbox that was clicked was unchecked, uncheck all inner decision steps 22829 $clicked_next_decision_container.find('.js-copy_step_checkbox').prop( "checked", false ); 22830 $clicked_next_decision_container.find('.js-ladder_step').removeClass('ladder-step-to-copy'); 22831 if (!$('.js-copy_step_checkbox:checked').length) { 22832 $('.js-copy_step_checkbox').show(); 22833 } 22834 } 22835 22836 22837 22838 } 22839 22840 $(document).on("change", ".js-copy_step_checkbox", function() { 22841 if ($('.js-copy_step_checkbox:checked').length) { 22842 $clicked = $(this); 22843 $('.js-copy_step_checkbox').hide(); 22844 $('.js-copy_step_checkbox').each(function() { 22845 show_hide_prev_next_copy_checkbox($(this), $clicked); 22846 }); 22847 22848 } else { 22849 $('.js-copy_step_checkbox').show(); 22850 } 22851 22852 if( $(this).is(":checked") ) { 22853 $(this).parents('.js-ladder_step').addClass('ladder-step-to-copy'); 22854 } else { 22855 $(this).parents('.js-ladder_step').removeClass('ladder-step-to-copy'); 22856 } 22857 }); 22858 22859 var cleanup_copy_mode = function() { 22860 // remove class from #ladder 22861 $('.js-create_action_page').find('.js-ladder').removeClass('ladder_paste_mode ladder_copy_mode'); 22862 // remove class from action_toolbox 22863 $('.js-create_action_toolbox').removeClass('copy-mode-active'); 22864 // remove hide class from copy mode elements 22865 $('.js-button_exit_copy_mode, .js-button_copy_paste, .js-copy-mode-active__title').hide(); 22866 // swap title/notes with helper text in header 22867 $('.js-create_action_page').find('.js-edit_ladder_head').removeClass('ladder_copy_mode'); 22868
22869 $('.js-copy_step_checkbox').prop( "checked", false ).attr('disabled',false).removeClass('disabled').show(); 22870 $('.js-ladder_step').removeClass('ladder-step-to-copy'); 22871 22872 $('.js-ladderbox_paste_button').hide(); 22873 $('.js-button_copy_paste').removeClass('disabled').attr('disabled',false); 22874 22875 $('.js-create_action_toolbox input').attr('disabled',false); 22876 22877 ladderAddStickyForks(); 22878 } 22879 22880 $('.js-button_exit_copy_mode').on('click', function(e) { 22881 cleanup_copy_mode(); 22882 }); 22883 22884 $('.js-button_copy_paste').on('click', function(e) { 22885 $('.js-ladderbox_paste_button').show(); 22886 $('.js-button_copy_paste').addClass('disabled').attr('disabled','disabled'); 22887 $(this).parents('.js-create_action_page').find('.js-ladder').addClass('ladder_paste_mode'); 22888 }); 22889 22890 $(document).on("click", ".js-ladderbox_paste_button", function() { 22891 //what we're doing here is building a full ladder into a shadow dom node, marking any steps that don't have the copy parameter (and thus were not chosen to be copied), and deleting them at the end, before pasting the remaining steps into the correct place 22892 var ladder_data_to_copy = save_ladder(); 22893 //console.log(ladder_data_to_copy); 22894 ladder_paste_remove_array = []; 22895 load_ladder(ladder_data_to_copy); 22896 //console.log($paste_ladder_shadow_dom.find('.js-ladder_step')); 22897 //console.log($paste_ladder_shadow_dom); 22898 //console.log(ladder_paste_remove_array); 22899 $.each(ladder_paste_remove_array, function(i, e) { 22900 e.remove(); 22901 }); 22902 22903 $paste_ladder_shadow_dom.find('.js-ladder_rung_container').each(function() { 22904 if (!$(this).find('.js-ladder_step').length) { 22905 $(this).remove(); 22906 } else { 22907 $(this).find(">:first-child").find(">:first-child").unwrap(); 22908 $(this).find(">:first-child").unwrap(); 22909 } 22910 }); 22911 $paste_ladder_shadow_dom.find('.js-decision_container').not('.js-ladder_step + .js-decision_container').each(function() { 22912 if (!$(this).find('.js-ladder_step').length) { 22913 $(this).remove(); 22914 } 22915 }); 22916 $paste_ladder_shadow_dom.find('.js-decision_container').not('.js-ladder_step + .js-decision_container').find(">:first-child").unwrap(); 22917 $paste_ladder_shadow_dom.find('.js-ladder_entrance, .js-add_new_rung_container, .js-copy_step_checkbox__topper, .js-add_condition').remove(); 22918 $paste_ladder_shadow_dom.find('.js-ladderbox_answer-yes, .js-ladderbox_answer-no').not('.js-decision_container > .js-ladderbox_answer-yes, .js-decision_container > .js-ladderbox_answer-no').remove(); 22919 $paste_ladder_shadow_dom.find('.js-ladder_plus_wrap').not('.js-ladder_step + .js-ladder_plus_wrap').not('.js-ladderbox_answer-no + .js-ladder_plus_wrap').each(function() { 22920 if (!$(this).prev().hasClass('js-decision_container')) { 22921 $(this).remove(); 22922 } 22923 }); 22924 $(this).parents('.js-ladderbox_exit').before($paste_ladder_shadow_dom); 22925 $('.js-ladder').find('.js-paste_ladder_wrap').find(">:first-child").unwrap(); 22926 add_exits(); 22927 $('form').trigger('rescan.areYouSure'); 22928 cleanup_copy_mode(); 22929 delete ladder_paste_remove_array; 22930 //to do: areyousure 22931 }); 22932 22933 // generic functions 22934 22935 /////////// kick it off on load 22936 if ($('.js-ladder_params').val() != '' && $('.js-ladder_params').val() != '[]') { 22937 var ladder_data = JSON.parse($('.js-ladder_params').val()); 22938 22939 load_ladder(ladder_data); 22940 22941 ladderAddStickyForks(); 22942 22943 if ($('.js-ladders-manage').length && (getURLParameter('start_date') || getURLParameter('end_date'))) { 22944 $('.js-wait_stats, .js-wait_stats_total').html('--'); 22945 } 22946 22947 if ($('.js-ladders-manage').length) { 22948 view_query_init(); 22949 } 22950 22951 } else { 22952 create_dom($('.js-ladder_assets .js-add_new_rung_container'), $('.js-ladder'), true); 22953 $('.js-ladder .js-ladders_explainer').show(); 22954 } 22955 22956 } 22957 22958 $(document).on('click', '.js-ladder_list_stat_button', function(e) { 22959 $(this).closest('li').find(".js-ladder_user_stats").slideToggle(100); 22960 }); 22961 22962 22963 $('.js-ladder_notes_toggle').click(function() { 22964 $('.js-ladder_notes').slideToggle('fast'); 22965 }); 22966 22967 22968 /* ladder tour js *************************************************/ 22969 if ($('.js-manage_wrappers_wrap').length && typeof(hopscotch) != "undefined") { 22970 //if we're new, show the tour 22971 //console.log(getCookie('seen_ladder_manage_tour')); 22972 if (!getCookie('seen_ladder_manage_tour')) { 22973 var width; 22974 var group_width; 22975 var organizing_menu; 22976 var profile_menu; 22977 var organizing_width; 22978 22979 if (under1024Flag) { 22980 width = 200; 22981 } else { 22982 width = 280; 22983 } 22984 22985 var tour = { 22986 id: "ladders-manage-tour", 22987 steps: [ 22988 {
22989 title: an_javascript_translation.welcome_to_action_network_ladders, 22990 content: `<p>${an_javascript_translation.ladders_as_in_ladders_of_engagement_are_sophisticated_automated_series_of_actions}</p><p>${an_javascript_translation.for_example_you_could_send_every_activist_who_subscribes_to_your_list_an_automated_series_of}</p>`, 22991 target: document.querySelector(".js-ladders-manage-headline"), 22992 placement: "bottom", 22993 width: width 22994 }, 22995 { 22996 title: an_javascript_translation.get_started_with_ladders, 22997 content: `<p>${an_javascript_translation.lets_see_how_they_work}</p>`, 22998 target: document.querySelector(".js-ladder-tour-add"), 22999 placement: "bottom", 23000 width: width 23001 } 23002 ], 23003 i18n: { 23004 nextBtn: an_javascript_translation.next, 23005 doneBtn: an_javascript_translation.done 23006 } 23007 }; 23008 hopscotch.endTour(true); 23009 hopscotch.startTour(tour); 23010 } 23011 //getCookie('seen_ladder_manage_tour') 23012 setCookie('seen_ladder_manage_tour','1'); 23013 //getCookie('seen_ladder_manage_tour') 23014 } 23015 23016 if ($('.js-create_ladder_form').length && !$('.js-ladder .js-ladder_step').length && $('.js-ladder-tour-title').val() == '' && typeof(hopscotch) != "undefined") { 23017 //if we're new, show the tour 23018 //console.log(getCookie('seen_ladder_manage_tour')); 23019 if (!getCookie('seen_ladder_edit_tour')) { 23020 var width; 23021 var group_width; 23022 var organizing_menu; 23023 var profile_menu; 23024 var organizing_width; 23025 23026 if (under1024Flag) { 23027 width = 245; 23028 } else { 23029 width = 580; 23030 } 23031 23032 var nextOnCallback = function(callback) { 23033 var currentStep = window.hopscotch.getCurrStepNum(); 23034 callback(function() { 23035 window.hopscotch.startTour(tour, currentStep); 23036 }); 23037 }; 23038 23039 var waitForElementVisible = function(element, callback) { 23040 var checkExist = setInterval(function() { 23041 $element = typeof element == "function" ? $(element()) : $(element); 23042 //console.log($element); 23043 //console.log($element.is(':visible')); 23044 //console.log($element.length); 23045 if ($element.is(':visible')) { 23046 clearInterval(checkExist); 23047 if (typeof callback == "function") { 23048 callback(); 23049 } 23050 } 23051 }, 100); 23052 }; 23053 23054 var tour = { 23055 id: "ladders-edit-tour", 23056 onClose: function() { 23057 $('.js-ladder .js-ladder_plus_wrap > div > div').attr("style",""); 23058 $('.js-ladder .js-ladder_plus_wrap > div > div > span').attr("style",""); 23059 $('.js-ladder .js-ladder_plus_wrap > div > div > div').attr("style",""); 23060 }, 23061 steps: [ 23062 { 23063 title: an_javascript_translation.its_time_to_make_your_first_ladder, 23064 content: `<p>${an_javascript_translation.lets_set_up_a_welcome_series_so_new_subscribers_to_your_list}</p><p>${an_javascript_translation.well_title_our_ladder_welcome_series}</p><p><strong>${an_javascript_translation.click_next_to_continue_setting_up_a_welcome_series}</strong></p>`, 23065 target: document.querySelector(".js-ladder-tour-title"), 23066 placement: "bottom", 23067 width: width, 23068 onNext: function() { 23069 //$('.js-ladder-tour-title').val('Welcome series'); 23070 }, 23071 onShow: function() { 23072 $('.js-ladder-tour-title').val(an_javascript_translation.welcome_series); 23073 } 23074 }, 23075 { 23076 title: an_javascript_translation.add_the_first_rung, 23077 content: `<p>${an_javascript_translation.rungs_are_the_heart_of_automated_logic_in_ladders_description}</p><p><strong>${an_javascript_translation.click_next_and_well_add_a_rung_for_you}</strong></p>`, 23078 target: document.querySelector(".js-add_new_rung"), 23079 placement: "bottom", 23080 width: width, 23081 onNext: function() { 23082 $('.js-add_new_rung').trigger('click'); 23083 } 23084 }, 23085 { 23086 title: an_javascript_translation.trigger_your_rung, 23087 content: `<p>${an_javascript_translation.rungs_can_have_one_or_more_triggers}</p><p>${an_javascript_translation.because_were_setting_up_a_welcome_series_we_should_trigger_activists_to_enter_this_ladder}</p><p><strong>${an_javascript_translation.click_next_and_well_add_this_rung_for_you}</strong></p>`, 23088 target: document.querySelector(".js-ladder_modal_rung_form div.js-rung_trigger_select"), 23089 placement: "bottom", 23090 width: width, 23091 delay: 600, 23092 onNext: function() { 23093 //$('.js-ladder_modal_rung_form select.js-rung_trigger_select').val('subscribed'); 23094 $('.js-ladder_modal_rung_form .js-save_rung').trigger('click'); 23095 nextOnCallback(function(callback) { 23096 waitForElementVisible(function() { 23097 return $('.js-ladder .js-ladder_plus_wrap'); 23098 }, callback); 23099 }); 23100 }, 23101 onShow: function() { 23102 $('.js-ladder_modal_rung_form select.js-rung_trigger_select').val('subscribed').trigger('change'); 23103 }, 23104 multipage: true 23105 }, 23106 {
23107 title: an_javascript_translation.now_add_a_wait_step, 23108 content: `<p>${an_javascript_translation.as_you_can_see_your_rung_and_trigger_has_been_added_to_your_ladder}</p><p>${an_javascript_translation.next_lets_add_a_step_well_have_activists_wait_1_day}</p><p>${an_javascript_translation.to_add_a_step_youd_hover_over_the_plus_icon}</p><p><strong>${an_javascript_translation.click_next_and_well_add_a_wait_step_for_you}</strong></p>`, 23109 target: ".js-ladder .js-ladder_plus_wrap", 23110 placement: "bottom", 23111 width: width, 23112 //delay: 1000, 23113 onNext: function() { 23114 $('.js-ladder .js-ladder_plus_wrap .js-add_wait').trigger('click'); 23115 $('.js-ladder_modal_wait_form select.js-wait_select').val('days').trigger('change'); 23116 $('.js-ladder .js-ladder_plus_wrap > div > div').attr("style",""); 23117 $('.js-ladder .js-ladder_plus_wrap > div > div > span').attr("style",""); 23118 $('.js-ladder .js-ladder_plus_wrap > div > div > div').attr("style",""); 23119 }, 23120 onShow: function() { 23121 $('.js-ladder .js-ladder_plus_wrap > div > div').css({ 'overflow': 'visible', 'background-color': '#E7390E', 'width': '88px' }); 23122 $('.js-ladder .js-ladder_plus_wrap > div > div > span').css({ 'opacity': '1', 'left': '20px' }); 23123 $('.js-ladder .js-ladder_plus_wrap > div > div > div').css('opacity','1'); 23124 } 23125 }, 23126 { 23127 title: an_javascript_translation.set_your_wait_time, 23128 content: `<p>${an_javascript_translation.you_can_have_two_different_kinds_of_waits}</p><p>${an_javascript_translation.for_our_welcome_series_well_have_them_wait_1_day}<p><strong>${an_javascript_translation.click_next_and_well_save_the_wait_step_for_you}</strong></p>`, 23129 target: document.querySelector(".js-ladder_modal_wait_form .js-wait_days input"), 23130 placement: "bottom", 23131 width: width, 23132 delay: 600, 23133 onNext: function() { 23134 //$('.js-ladder_modal_wait_form select.js-wait_select').val('days'); 23135 $('.js-ladder_modal_wait_form .js-wait_days input').val('1'); 23136 $('.js-ladder_modal_wait_form .js-save_wait').trigger('click'); 23137 nextOnCallback(function(callback) { 23138 waitForElementVisible(function() { 23139 return $('.js-ladder .js-ladder_wait + .js-ladder_plus_wrap'); 23140 }, callback); 23141 }); 23142 }, 23143 onShow: function() { 23144 23145 }, 23146 multipage: true 23147 }, 23148 { 23149 title: an_javascript_translation.and_an_action_step, 23150 content: `<p>${an_javascript_translation.after_the_activist_waits_1_day_they_should_receive_an_email_welcoming_them_to_the_list}</p><p><strong>${an_javascript_translation.click_next_and_well_add_an_action_step_step_for_you}</strong></p>`, 23151 target: ".js-ladder .js-ladder_wait + .js-ladder_plus_wrap", 23152 placement: "bottom", 23153 width: width, 23154 //delay: 1000, 23155 onNext: function() { 23156 $($('.js-ladder .js-ladder_plus_wrap .js-add_action')[1]).trigger('click'); 23157 $('.js-ladder_modal_action_form select.js-action_select').val('email').trigger('change'); 23158 $('.js-ladder .js-ladder_plus_wrap > div > div').attr("style",""); 23159 $('.js-ladder .js-ladder_plus_wrap > div > div > span').attr("style",""); 23160 $('.js-ladder .js-ladder_wait + .js-ladder_plus_wrap > div > div > div').attr("style",""); 23161 23162 }, 23163 onShow: function() { 23164 $('.js-ladder .js-ladder_plus_wrap > div > div').css({ 'overflow': 'visible', 'background-color': '#E7390E', 'width': '88px' }); 23165 $('.js-ladder .js-ladder_plus_wrap > div > div > span').css({ 'opacity': '1', 'left': '20px' }); 23166 $('.js-ladder .js-ladder_wait + .js-ladder_plus_wrap > div > div > div').css('opacity','1'); 23167 } 23168 }, 23169 { 23170 title: an_javascript_translation.set_up_your_email, 23171 content: `<p>${an_javascript_translation.now_were_going_to_set_up_your_email_action_by_choosing_send_an_email}</p><p>${an_javascript_translation.for_now_well_write_a_quick_email_for_you}</p><p><strong>${an_javascript_translation.click_next_and_well_add_the_email_and_save}</strong></p>`, 23172 target: document.querySelector(".js-ladder_modal_action_form .js-email_wrapper_id_select"), 23173 placement: "bottom", 23174 width: width, 23175 delay: 600, 23176 onNext: function() { 23177 //$('.js-ladder_modal_action_form select.js-action_select').val('email'); 23178 $('.js-ladder_modal_action_form .js-email_subject').val(an_javascript_translation.welcome_to_our_organization); 23179 $('.js-ladder_modal_action_form .js-email_from').val(an_javascript_translation.your_name); 23180 $('.js-ladder_modal_action_form .js-email_replyto').val('[email protected]'); //test this 23181 $('.js-ladder_modal_action_form .js-email_body').val(`<p>${an_javascript_translation.welcome_to_our_organization} ${an_javascript_translation.were_glad_youre_here}</p>`); 23182 $('.js-ladder_modal_action_form .js-save_action').trigger('click'); 23183 nextOnCallback(function(callback) { 23184 waitForElementVisible(function() { 23185 return $('.js-ladder .js-ladder_action + .js-ladder_plus_wrap'); 23186 }, callback); 23187 }); 23188 }, 23189 onShow: function() { 23190 23191 }, 23192 multipage: true 23193 }, 23194 {
23195 title: an_javascript_translation.thats_it, 23196 content: `<p>${an_javascript_translation.weve_got_a_ladder_but_you_can_get_much_more_fancy}</p><p>${an_javascript_translation.all_activists_eventually_exit_a_ladder_when_they_run_out_of_steps}</p><p>${an_javascript_translation.you_could_add_another_rung_and_trigger_for_when_an_activist_opens_any_email_with_no_action_steps_after}</p><p><strong>${an_javascript_translation.we_hoped_you_enjoyed_the_ladder_tour}</strong></p>`, 23197 target: '.js-ladder .js-ladder_action + .js-ladder_plus_wrap', 23198 placement: "bottom", 23199 width: width, 23200 //delay: 1000 23201 } 23202 ], 23203 i18n: { 23204 nextBtn: an_javascript_translation.next, 23205 doneBtn: an_javascript_translation.done 23206 } 23207 }; 23208 23209 hopscotch.endTour(true); 23210 hopscotch.startTour(tour); 23211 } 23212 //getCookie('seen_ladder_manage_tour') 23213 setCookie('seen_ladder_edit_tour','1'); 23214 //getCookie('seen_ladder_manage_tour') 23215 } 23216 23217 /* ======================= end ladders ======================= */ 23218 23219 23220 ///////////// email send test functions 23221/* 23222 $(document).on('click', '.js-email_send_test', function() { 23223 //$('.js-test_email').addClass('required email'); 23224 23225 //if ($('.js-ladder_modal_action_form').valid()) { 23226 //var data = $('.js-test_email').serialize(); 23227 23228 // var $that = $(this); 23229 // var url = $that.parents('form').attr('action'); 23230 23231 // $that.addClass('disabled').attr('disabled','true').html('<i class="fas fa-spinner fa-pulse"></i> Sending...'); 23232 23233 //console.log(data); 23234 $.post("/share_options/test_autoresponse", data) 23235 .done(function(data) { 23236 //$that.removeClass('disabled').attr('disabled','false').html('Send A Test Email'); 23237 }).error(function() { 23238 console.log('error'); 23239 //$that.removeClass('disabled').attr('disabled','false').html('Send A Test Email'); 23240 }); 23241 //} 23242 23243 //$('.js-test_email').removeClass('required email'); 23244 23245 }); 23246*/ 23247 23248 23249 $('.js-step_one').click(function() { 23250 $('.js-config_email').show(); 23251 $('.js-step_two').show(); 23252 }); 23253 23254 //store the submit button that's clicked 23255 submitClicked_init = function() { 23256 $('input[type=submit], .js-stripe_submit_button, .js-wrapper_duplicate_button, .js-edit_donation_submit, .js-van_sync_button, .js-send-message-button, .js-rsvp_button_label, .js-hardware_challenge_submit, .js-create_test_button, button').click(function() { 23257 submitClicked = $(this).attr('id'); 23258 //console.log(submitClicked); 23259 }); 23260 } 23261 submitClicked_init(); 23262 23263 //affirmative opt in required class/value manipulations 23264 var affirmative_opt_in_submit = function() { 23265 if ($('.js-affirmative_optin_control_group').length) { 23266 $('.js-affirmative_optin_control_group .js-affirmative_optin_radio_no').val('').attr('name',''); 23267 } 23268 } 23269 23270 /* form validation */ 23271 23272 var stripe_tokenize = function(stripe_response, form, donation_submit_val, $donate_submit_button) { 23273 Stripe.card.createToken(stripe_response, stripeResponseHandler); 23274 23275 function stripeResponseHandler(status, response) { 23276 23277 if (response.error) { // Problem! 23278 23279 // Show the errors on the form 23280 Noty.closeAll(); 23281 23282 new Noty({ 23283 theme: 'metroui', 23284 type: 'error', 23285 closeWith: ['button'], 23286 text: '<span class="noty_content">' + response.error.message + '<br/>' + an_javascript_translation.your_card_has_not_been_charged_please_try_again_or + ' <a href="/contact" target="_blank">' + an_javascript_translation.contact_us + '</a> ' + an_javascript_translation.if_it_keeps_happening + '.' + '</span>', 23287 }).show(); 23288 23289 // early error handling 23290/* 23291 if ((/Invalid credit card number/).test(data.error_description)) { 23292 $('#form-card_number').addClass('error_input_cc js-error_input_cc'); 23293 } else if ((/That credit card expiration date has already passed./).test(data.error_description)) { 23294 $('#form-month').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 23295 $('#form-year').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 23296 } 23297*/ 23298 23299 $donate_submit_button.attr('disabled',false).removeClass('disabled').val(donation_submit_val); 23300 23301 return false;
23302 23303 } else { // Token was created! 23304 affirmative_opt_in_submit(); 23305 // Get the token ID: 23306 var token = response.id; 23307 23308 // Insert the token into the form so it gets submitted to the server: 23309 var input = $("<input>").attr("type", "hidden").attr("name","stripe_credit_card_token" ).val(token); 23310 $('.js-donate_form').append($(input)); 23311 form.submit(); 23312 23313 } 23314 } 23315 } 23316 23317 jQuery.validator.addMethod("require_from_group", function (value, element, options) { 23318 var numberRequired = options[0]; 23319 var selector = options[1]; 23320 var fields = $(selector, element.form); 23321 var filled_fields = fields.filter(function () { 23322 // it's more clear to compare with empty string 23323 return $(this).val() != ""; 23324 }); 23325 var empty_fields = fields.not(filled_fields); 23326 // we will mark only first empty field as invalid 23327 if (filled_fields.length < numberRequired && empty_fields[0] == element) { 23328 return false; 23329 } 23330 return true; 23331 // {0} below is the 0th item in the options field 23332 }, jQuery.format(an_javascript_translation.please_enter_either_username_email_address)); 23333 23334 jQuery.validator.addMethod("phone_parens", function(value, element) { 23335 return this.optional(element) || /(\d{3}[-]\d{3}[-]\d{4})/.test(value); 23336 }, an_javascript_translation.please_specify_the_correct_domain_for_your_documents); 23337 23338 jQuery.validator.addMethod("pipe_url", function(value, element) { 23339 // allow this to work locally 23340 if (value.includes('https://localhost')) { 23341 return true; 23342 } 23343 return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?|\|)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); 23344 }, an_javascript_translation.please_enter_a_valid_email_address); 23345 23346 jQuery.validator.addMethod("pipe_url_https", function(value, element) { 23347 // allow this to work locally 23348 if (value.includes('https://localhost')) { 23349 return true; 23350 } 23351 // allow any non-whitespace characters as the host part 23352 return this.optional(element) || /^(https):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?|\|)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); 23353 }, an_javascript_translation.please_enter_a_valid_email_address); 23354 23355 $.extend($.validator.prototype, 23356 { 23357 23358 optional: function (element) { 23359 return !$.validator.methods.required.call(this, $.trim(element.value), element); // && "dependency-mismatch"; 23360 } 23361 }); 23362 23363 jQuery.validator.addMethod( 23364 "regex", 23365 function(value, element, regexp) { 23366 var re = new RegExp(regexp, 'i'); 23367 return this.optional(element) == true || re.test(value); 23368 }, 23369 an_javascript_translation.please_check_your_input 23370 ); 23371 23372 //fundraising groups 23373 var getGroups = function() { 23374 var result = ''; 23375 if ($('.js-donation_info_split input').length) { 23376 $('.js-donation_info_split input').each(function(i) { 23377 result = result + $(this).attr('name') + ' '; 23378 }); 23379 } else { 23380 $('.js-ticketed_event_ticket_number').each(function(i) { 23381 result = result + $(this).attr('name') + ' '; 23382 //console.log(result); 23383 }); 23384 } 23385 return result; 23386 } 23387 23388/* 23389 url: function(value, element) { 23390 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ 23391 return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); 23392 }, 23393*/ 23394 23395 var errorCount = ''; 23396 23397 var can_id_test = function(html) { 23398 can_id_test_confirmation = true; 23399 if (((/can_id=/i).test(html) && !(/can_id={{ CanID/i).test(html)) || (/click.actionnetwork.org/i).test(html) || (/u1584542.ct.
23399sendgrid.net/i).test(html)) { 23400 can_id_test_confirmation = confirm(an_javascript_translation.you_appear_to_have_a_link_with_an_action_network_id_attached); 23401 } 23402 } 23403 23404 canValidate = function(redactor) { 23405 //console.trace('validate'); 23406 23407 if ($('.js-redactor').length && !$('.js-withclips').length) { 23408 $('form').submit(function (e) { 23409 if ($(this).find('.js-redactor').length) { 23410 if ((/src="http:/i).test(redactor.code.get()) || (/src='http:/i).test(redactor.code.get()) || (/src=http:/i).test(redactor.code.get()) || (/link href="http:/i).test(redactor.code.get()) || (/link href='http:/i).test(redactor.code.get()) || (/link href=http:/i).test(redactor.code.get())) { 23411 var confirmation = confirm(an_javascript_translation.you_have_added_insecure_content_in_your_text_editor_this_can_cause_page); 23412 if (confirmation == true) { 23413 redactor.code.set(redactor.code.get().replace(/src="http:/ig,'src="https:').replace(/src=\'http:/ig,'src=\'https:').replace(/src=http:/i,'src=https:').replace(/link href="http:/ig, 'link href="https:').replace(/link href=\'http:/ig, 'link href=\'https:').replace(/link href=http:/ig, 'link href=https:')); 23414 //console.log(redactor.get()); 23415 } 23416 } 23417 } 23418 }); 23419 } else if ($('.js-redactor').length) { 23420 $('form').submit(function (e) { 23421 if ($(this).find('.js-redactor').length) { 23422 can_id_test(redactor.code.get()); 23423 } 23424 }); 23425 } 23426 23427 if ($('.js-unlayer_editor, .js-unlayer_editor_layout').length) { 23428 var unlayer_one_submit_variable = false; 23429 } 23430 23431 $("form").each(function () { 23432 // Add class "no-validate" to forms that should not be validated 23433 // This will skip jquery validation 23434 if ($(this).hasClass('no-validate')) { 23435 console.info('Validation disabled for form with no-validate class: '); 23436 return; 23437 } 23438 23439 // Add `validate_number_required` this class to number inputs 23440 // this version of validator is too old to support modern HTML5 23441 // number inputs. 23442 $.validator.addClassRules("validate_number_required", { 23443 required: true, 23444 number: true 23445 }); 23446 23447 $(this).validate({ 23448 23449 23450 ignore: ".ignore", 23451 23452 // highlight the errors 23453 highlight: function(element) { 23454 //console.log(element); 23455 // Highlight the element with error_input if it does not already have an alert_message class. 23456 if (!$(element).hasClass('alert_message')) { 23457 $(element).addClass('error_input'); 23458 } 23459 23460 if (errorCount > 0) { 23461 if ($('.js-tab_response').length || $('.js-tab_sharing').length || $('.js-tabs-settings').length) { 23462 $('.js-error_tab').removeClass('error_tab js-error_tab'); 23463 $('.js-error_icon').remove(); 23464 $('.error_input').each(function() { 23465 $('a[name="#' + $(this).parents('div.tab').attr('id') + '"]').addClass('error_tab js-error_tab').after('<span class="noti_icon fas fa-circle js-error_icon"><i class="far fa-exclamation-circle"></i></span>'); 23466 }); 23467 } 23468 } 23469 //console.log(element); 23470 //console.log($(element).hasClass('js-action_photo_upload')); 23471 if ($(element).hasClass('js-action_photo_upload') || $(element).hasClass('js_audiofile_upload') || $(element).hasClass('js_upload_file')) { 23472 $(element).parents('.js-upload_label_box').addClass('error_input'); 23473 } 23474 23475 if ($('.js-share_option_wrapper .error_input').length) { 23476 $('.js-edit_sharing_options_button, .js-add_ty_sidebar_button').addClass('error_input'); 23477 } 23478 23479 }, 23480 unhighlight: function(element) { 23481 $(element).removeClass("error_input"); 23482 23483 if (errorCount > 0) { 23484 if ($('.js-tab_response').length || $('.js-tab_sharing').length || $('.js-tabs-settings').length) { 23485 $('.js-error_tab').removeClass('error_tab js-error_tab'); 23486 $('.js-error_icon').remove(); 23487 $('.error_input').each(function() { 23488 $('a[name="#' + $(this).parents('div.tab').attr('id') + '"]').addClass('error_tab js-error_tab').after('<span class="noti_icon fas fa-circle js-error_icon"><i class="far fa-exclamation-circle"></i></span>'); 23489 }); 23490 } 23491 } else { 23492 $('.js-error_taberror_tab').removeClass('error_tab js-error_tab'); 23493 $('.js-error_icon').remove(); 23494 } 23495 23496 //console.log(element); 23497 if ($(element).hasClass('js-action_photo_upload') || $(element).hasClass('js_audiofile_upload')) { 23498 $(element).parents('.js-upload_label_box').removeClass('error_input'); 23499 } 23500 23501 if (!$('.js-share_option_wrapper .error_input').length) { 23502 $('.js-edit_sharing_options_button, .js-add_ty_sidebar_button').removeClass('error_input'); 23503 } 23504 23505 }, 23506 23507 // remove the error messages 23508 errorPlacement: function(error,element) { 23509 if (element.context && element.is(':checkbox, :radio')) { 23510 //console.log('error'); 23511 $(element).parents(".check_radio_field").find('label').addClass("error_checkbox"); 23512 } else { 23513 return true; 23514 } 23515 }, 23516 23517 /* groups: getGroups(), */ 23518 groups: { 23519 names: getGroups() 23520 }, 23521 23522/* 23523 groups: { 23524 checkbox_group: "checkboxes_Option_one checkboxes_Option_two" 23525 }, 23526 23527 rules: { 23528 'idofacheckbox' : { checkbox_group: true } 23529 }, 23530*/ 23531 23532 // Error message 23533 showErrors: function(errorMap, errorList) { 23534 23535 //console.log('showerrors'); 23536 //console.log(errorMap); 23537 //console.log(errorList); 23538 //console.log(form_id_error); 23539 /* 23540if ($('.redactor').length) { 23541 if (redactorErrorFlag) { 23542 errorCount = this.numberOfInvalids() + $('.redactor').length; 23543 //console.log(errorList); 23544 redactorErrorObject = { 23545 "element" : $('.redactor') , 23546 "message" : "This field is required." 23547 } 23548 errorList.push(redactorErrorObject); 23549 //console.log(errorList); 23550 } else { 23551 errorCount = this.numberOfInvalids(); 23552 } 23553 } else { 23554 23555*/ 23556 23557 23558 if (typeof(signature_error_flag) != 'undefined' && (signature_error_flag) && ($(this.currentForm).find('.js-form_signature_field').length)) { 23559 errorCount = this.numberOfInvalids(); 23560 errorCount = errorCount + 1; 23561 errorList.push({ 23562 message: 'error', 23563 element: this 23564 }); 23565 } else { 23566 errorCount = this.numberOfInvalids(); 23567 } 23568 23569 //console.log(codemirror_error_flag); 23570 if ((codemirror_error_flag) && ($(this.currentForm).find('.js-html-textarea.required, .js-mobile-codemirror-textarea.required').length)) { 23571 errorCount = this.numberOfInvalids();
23572 $('.js-html-textarea.required, .js-mobile-codemirror-textarea.required').each(function() { 23573 if ($(this).val() == '') { 23574 errorCount = errorCount + 1; 23575 $(this).parent().find('.CodeMirror-wrap').addClass('error_input'); 23576 errorList.push({ 23577 message: 'error', 23578 element: this 23579 }); 23580 } 23581 }); 23582 } else { 23583 errorCount = this.numberOfInvalids(); 23584 } 23585 23586 if ((checkboxErrorFlag) && ($(this.currentForm).find('input[type=checkbox].required_checkboxes').length)) { 23587 errorCount = this.numberOfInvalids(); 23588 $('.checkbox_group_wrap').each(function() { 23589 if ($(this).find('.required_checkboxes').length) { 23590 //console.log(this); 23591 if ($(this).find('span').find('label').find('.required_checkboxes:checked').length == 0) { 23592 errorCount = errorCount + 1; 23593 23594 $(this).find('span').find('label').find('.required_checkboxes').each(function() { 23595 errorList.push({ 23596 message: 'error', 23597 element: this 23598 }); 23599 }); 23600 23601 } 23602 } 23603 }); 23604 } else { 23605 errorCount = this.numberOfInvalids(); 23606 } 23607 //} 23608 23609 if (donation_recipient_error_flag) { 23610 errorCount = errorCount + 1; 23611 $('.js-please_add_recipient').each(function() { 23612 errorList.push({ 23613 message: 'error', 23614 element: this 23615 }); 23616 }); 23617 } 23618 23619 if (letter_targets_error_flag) { 23620 errorCount = errorCount + 1; 23621 $('.js-target_count_wrap').not('.js-letter_select_targets_modal .js-target_count_wrap').each(function() { 23622 errorList.push({ 23623 message: 'error', 23624 element: this 23625 }); 23626 }); 23627 } 23628 23629 if (syndication_targets_error_flag) { 23630 errorCount = errorCount + 1; 23631 $('.js-syndicate_group_list_wrap .empty').each(function() { 23632 errorList.push({ 23633 message: 'error', 23634 element: this 23635 }); 23636 23637 $(this).addClass('alert_message red_alert').removeClass('empty'); 23638 }); 23639 } 23640 23641 if (email_chosen_error_flag) { 23642 errorCount = errorCount + 1; 23643 $('select.can_select').each(function() { 23644 errorList.push({ 23645 message: 'error', 23646 element: this 23647 }); 23648 }); 23649 } 23650 23651 if (uuid_chosen_error_flag) { 23652 errorCount = errorCount + 1; 23653 $('select.can_select').each(function() { 23654 errorList.push({ 23655 message: 'error', 23656 element: this 23657 }); 23658 }); 23659 } 23660 23661 if (transaction_chosen_error_flag) { 23662 errorCount = errorCount + 1; 23663 $('select.can_select').each(function() { 23664 errorList.push({ 23665 message: 'error', 23666 element: this 23667 }); 23668 }); 23669 } 23670 23671 if (alternate_body_title_error_flag) { 23672 errorCount = errorCount + 1; 23673 $('.js-alternate_body_title_wrap input.error_input').each(function() { 23674 errorList.push({ 23675 message: 'error', 23676 element: this 23677 }); 23678 }); 23679 } 23680 23681 if (typeof(mobile_phone_error_flag) !== 'undefined' && mobile_phone_error_flag) { 23682 errorCount = errorCount + 1; 23683 $('#form-phone').each(function() { 23684 errorList.push({ 23685 message: 'error', 23686 element: this 23687 }); 23688 }); 23689 } 23690 23691 23692 23693 //console.log(errorList); 23694 23695 if (errorList.length) { 23696 form_id = this.currentForm.id; 23697 //console.log(this.currentForm); 23698 form_id_error = '#' + form_id + " .js-error_message"; 23699 } else if (cc_info_error_number > 0) { 23700 form_id = this.currentForm.id; 23701 form_id_error = '#' + form_id + " .js-error_message"; 23702 } 23703 23704 errorCount = errorCount + cc_info_error_number; 23705 23706 if (errorCount > 0) { 23707 unlayer_one_submit_variable = false; // needed to properly save changes on the drag and drop editor 23708 if (errorCount < 2) { 23709 //console.log(errorList); 23710 $(form_id_error).html(an_javascript_translation.oops_you_have + " <strong>1</strong> " + an_javascript_translation.error + ".").slideDown(); 23711 } else { 23712 $(form_id_error).html(an_javascript_translation.oops_you_have + " <strong>" + errorCount + "</strong> " + an_javascript_translation.errors + ".").slideDown(); 23713 } 23714 23715 } else { 23716 if (typeof(form_id_error) !== 'undefined') {
23717 $(form_id_error).slideUp(); 23718 } 23719 } 23720 23721 //console.log(errorList); 23722 23723 $.each(errorList, function(i, object) { 23724 if ( 23725 $(object.element).prop("tagName") == 'SELECT' || 23726 // Or an input[multiple=true], .i.e views/tags/_select.html.erb 23727 ( 23728 $(object.element).prop("tagName") == 'INPUT' && 23729 $(object.element).attr('multiple') == 'multiple' 23730 ) 23731 ) { 23732 //console.log('true'); 23733 //console.log(object); 23734 //console.log($(object.element).parent().attr('id')); 23735 $(object.element).parent().addClass('error_input-select_wrap js-error_input-select_wrap'); 23736 } else { 23737 23738 } 23739 }); 23740 23741 //if ($('.js-builder_body_title_text.error_input').length) { 23742 23743 //} 23744 23745 23746 23747 this.defaultShowErrors(); 23748 23749 $('.js-create_email2_form').trigger('checkform.areYouSure'); 23750 $('.js-redactor, .js-unlayer_editor, .js-unlayer_editor_layout').parents('form').trigger('checkform.areYouSure'); 23751 23752 CanJsEventBridge.EmitValidationDone(errorList); 23753 23754 }, 23755 //why is this not firing?? 23756 submitHandler: function(form) { 23757 //console.log('fire'); 23758 //console.log(noemailaddress_flag); 23759 if (!$(form).parents().hasClass('can_embed')) { 23760 23761 if ($('.js-unlayer_editor, .js-unlayer_editor_layout').length) { 23762 23763 if (!unlayer_one_submit_variable) { 23764 23765 //event.preventDefault(); 23766 var that = form; 23767 //console.log('stop'); 23768 23769 unlayer.exportHtml(function(data) { 23770 //console.log('design', data.design); 23771 if (JSON.stringify(data.design) != '' && typeof(JSON.stringify(data.design)) != 'undefined') { 23772 $('.js-email_builder_json').eq(unlayer_body_active).val(JSON.stringify(data.design)); 23773 23774 $('.js-email_builder_html').eq(unlayer_body_active).val(data.html.replace(/'/g,"'").replace(/"/g,'"').replace(/&#039;/g,"'").replace(/&quot;/g,'"')); 23775 $('.js-email_builder_title_hidden').eq(unlayer_body_active).val($('.js-builder_body_title_text').val()); 23776 } 23777 23778 //console.log($('#email_builder_html').val()); 23779 // console.log($(that).valid()); 23780 //if ($(that).valid()) { 23781 23782 can_id_test(data.html); 23783 23784 $(that).submit(); 23785 //} 23786 }); 23787 23788 unlayer_one_submit_variable = true; 23789 23790 return false; 23791 } 23792 23793 } 23794 } 23795 if (typeof(can_id_test_confirmation) != "undefined" && can_id_test_confirmation == false) { 23796 unlayer_one_submit_variable = false; 23797 return false; 23798 } 23799 if (typeof(noemailaddress_flag) != "undefined" && noemailaddress_flag == true) { 23800 $(".js-noemailaddress").each(function() { 23801 if ($(this).val().includes('@')) { 23802 $(this).addClass('error_input'); 23803 } else { 23804 $(this).removeClass('error_input'); 23805 } 23806 }); 23807 alert(an_javascript_translation.noemailaddress_warning); 23808 return false; 23809 } 23810 23811 if ($('form.js-edit_query').length || $('.js-single_power_toggle').length) { 23812 //$(document).on('validationError.queryBuilder', function(e) { 23813 23814 if ($('form.js-edit_query').length) { 23815 var empty_rules = false; 23816 $('.rule-filter-container select').each(function() { 23817 if ($(this).val() == -1) { 23818 $(this).parent().find('span.customSelect').addClass('error_input'); 23819 empty_rules = true; 23820 } else { 23821 $(this).parent().find('span.customSelect').removeClass('error_input'); 23822 } 23823 }); 23824 23825 if (empty_rules) { 23826 $.fancybox.close(); 23827 return false; 23828 } 23829 } 23830 23831 if ($('.js-single_power_toggle').length) { 23832 $('.rule-filter-container select').each(function() { 23833 if ($(this).val() == -1) { 23834 $(this).parent().parent().remove(); 23835 } 23836 }); 23837 } 23838 23839 23840 $('.rule-value-container select.required, .rule-value-container input.required').each(function() { 23841 if ($(this).val() == '' || $(this).val() == null) { 23842 $(this).parentsUntil('.rule-container').parent().remove(); 23843 } 23844 }); 23845 23846 $('.rules-group-container .rules-group-container').each(function() { 23847 if (!$(this).find('.rule-filter-container').length) { 23848 $(this).remove(); 23849 } 23850 }); 23851 } 23852 23853 // Medialess MMS 23854 if (typeof(submitClicked) != 'undefined' && $(form).find('#' + submitClicked).hasClass('js-submit_mms_no_media')) { 23855 // Store form so it can be submitted from the modal 23856 mmsForm = form; 23857 // Trigger modal 23858 $.fancybox.close(); 23859 $('.js-trigger_mms_no_media_modal').click(); 23860 submitClicked = false;
23861 return false; 23862 } 23863 23864 if (typeof(submitClicked) != 'undefined' && $('#' + submitClicked).hasClass('js-email-save')) { 23865 if ($('.js-builder').length) { 23866 if ($.isEmptyObject($('.js-builder').queryBuilder('getRules')) && !$('.js-no_target_warning_checkbox:checked').length) { 23867 if ($('.js-random_limit_input').val() == '') { 23868 $('.js-no_target_warning').show(); 23869 $.smoothScroll($('.js-no_target_warning').offset().top - 40, {afterScroll: $('.js-no_target_warning').addClass('error_input') }); 23870 $.fancybox.close(); 23871 return false; 23872 } else { 23873 $('.js-no_target_warning').hide(); 23874 $('.js-no_target_warning').removeClass('error_input'); 23875 $('.js-no_target_warning_checkbox').attr('checked', false); 23876 } 23877 23878 } else { 23879 $('.js-no_target_warning').hide(); 23880 } 23881 } else { 23882 if ($('.js-no_target_warning_checkbox:visible').length && !$('.js-no_target_warning_checkbox:checked').length) { 23883 if ($('.js-random_limit_input').val() == '') { 23884 $.smoothScroll($('.js-no_target_warning').offset().top - 40, {afterScroll: $('.js-no_target_warning').addClass('error_input') }); 23885 $.fancybox.close(); 23886 return false; 23887 } else { 23888 $('.js-no_target_warning').hide(); 23889 $('.js-no_target_warning').removeClass('error_input'); 23890 $('.js-no_target_warning_checkbox').attr('checked', false); 23891 } 23892 23893 } 23894 } 23895 23896 23897 if ($('#' + submitClicked).hasClass('disabled')) { 23898 if (typeof(unlayer_one_submit_variable) != "undefined" && unlayer_one_submit_variable == true) { 23899 } else { 23900 return false; 23901 } 23902 } else { 23903 $('.js-email-save').addClass('disabled'); 23904 setTimeout(function(){ $('.js-email-save').removeClass('disabled'); }, 3000); 23905 } 23906 } 23907 23908 23909 23910 if (!$(form).parents().hasClass('can_embed')) { 23911 //generate HTML and JSON design on form submit 23912 23913 23914 if ($('.js-action_owner-select').length) { 23915 if ($('select.js-sponsor-group-select').val() == 0) { 23916 if ($('.js-shift-sponsor-group-select').length) { 23917 var alert = window.alert(an_javascript_translation.you_cannot_create_a_shift_event_without_a_sponsoring_group); 23918 return false; 23919 } else { 23920 var confirmation = confirm(an_javascript_translation.are_you_sure_you_want_to_create_an_action_without_a_sponsoring_group); 23921 23922 if (confirmation != true) { 23923 return false; 23924 } 23925 } 23926 } 23927 } 23928 23929 if (errorCount > 0 && !$('#' + submitClicked).hasClass('cancel')) { 23930 $('.js-create_email2_form').trigger('checkform.areYouSure'); 23931 $('.js-redactor, .js-unlayer_editor, .js-unlayer_editor_layout').parents('form').trigger('checkform.areYouSure'); 23932 } else { 23933 $('.js-create_email2_form').trigger('reinitialize.areYouSure'); 23934 $('.js-redactor, .js-unlayer_editor, .js-unlayer_editor_layout').parents('form').not('.js-ladder_modal_action_form').trigger('reinitialize.areYouSure'); 23935 } 23936 23937 if ($('#fancybox-content div .js-upload_logo_modal form.js-edit_email_wrapper, #fancybox-content div .js-upload_logo_modal form.js-autogenerate_page_wrapper').length) { 23938 if ($('.js-accent_color').length && $('.js-accent_color').val().toLowerCase() == "#ffffff") { 23939 var accent_confirmation = confirm(an_javascript_translation.you_have_set_your_accent_color_to_white_the_accent_color_is_used_for_buttons_and_links); 23940 23941 if (accent_confirmation != true) { 23942 return false; 23943 } 23944 } 23945 23946 var confirmation = confirm(an_javascript_translation.auto_generating_a_wrapper_will_overwrite_your_current_wrapper_any_customizations_you_have_made_will_be_lost_continue); 23947 23948 if (confirmation != true) { 23949 return false; 23950 } 23951 } 23952 23953 if ($(form).hasClass('new_custom_regex_form')) { 23954 //console.log('regex form'); 23955 var isValid = true; 23956 try { 23957 new RegExp($(form).find('.js-regex_input').val()); 23958 } catch(e) { 23959 isValid = false; 23960 } 23961 23962 if(!isValid) { 23963 alert(an_javascript_translation.your_regular_expression_
23963is_not_valid); 23964 return false; 23965 } 23966 } 23967 23968 23969 if ($('form.js-edit_query').length || $('.js-single_power_toggle').length) { 23970 if ($('.js-builder').length) { 23971 $('.js-query_params').val(JSON.stringify($('.js-builder').queryBuilder('getRules'))); 23972 $('form.js-edit_query').trigger('reinitialize.areYouSure'); 23973 23974 if ($('.js-single_power_toggle').length) { 23975 $('.js-builder').queryBuilder('destroy'); 23976 } 23977 } 23978 23979 } 23980 23981 if ($('.js-create_ladder_form').length) { 23982 var ladder_data = save_ladder(); 23983 23984 $('.js-ladder_params').val(JSON.stringify(ladder_data)); 23985 23986 23987 23988 var dupes = check_dupes(ladder_data); 23989 if (dupes) { 23990 alert(an_javascript_translation.whoops_your_ladder_has_more_than_one_trigger_with_the_exact_same_parameters); 23991 return false; 23992 } 23993 23994 var ladder_invalid = false; 23995 //$('.js-ladder .js-ladder_rung_container').each(function() { 23996 if ($('.js-ladder .js-ladder_rung').length < 1 || $('.js-ladder .js-ladder_action').length < 1) { 23997 ladder_invalid = true; 23998 } 23999 //}); 24000 24001 if (ladder_invalid) { 24002 alert(an_javascript_translation.whoops_each_ladder_must_have_at_least); 24003 return false; 24004 } 24005 24006 //$('form.js-create_ladder_form').trigger('checkform.areYouSure'); 24007 } 24008 24009 // clear placeholder html if it exists before submit 24010 //console.log('submit'); 24011 //console.log(redactor.get()); 24012 /* 24013 if (redactor) { 24014 if ((/redactor_placeholder/).test(redactor.get())) { 24015 24016 redactor.set('<span></span>'); 24017 //console.log(redactor.get()); 24018 } 24019 } 24020 24021 24022 */ 24023 24024 //on submit, if we're building a question in the questions page and it has tag questions in it, make random question names and prepare inputs for submission 24025 if ($('.js-question_entry_wrap').length && $('.js-question_entry_wrap .js-question_tag_select:visible').length) { 24026 //console.log('fire'); 24027 if ($('#fancybox-content .js-add_checkbox_group').length) { 24028 var random_seed = Math.floor((1 + Math.random()) * 0x10000).toString(16); 24029 } 24030 24031 //var option_count = 0; 24032 24033 var tag_valid = true; 24034 24035 $('#fancybox-content input.js-question_tag_select').each(function() { 24036 24037 // if ($(this).val() == '') { 24038 // //console.log($(this).parents('div.js-question_tag_select')); 24039 // $(this).parents('.js-question_input_tag').find('div.js-question_tag_select').addClass('error_input'); 24040 // tag_valid = false; 24041 // } else { 24042 // $(this).parents('.js-question_input_tag').find('div.js-question_tag_select').removeClass('error_input'); 24043 // } 24044 //option_count = option_count + 1; 24045 /* 24046 if ($(this).parents('.js-question_input_wrap').hasClass('js-question_input_wrap_name')) { 24047 $(this).parents('.js-question_input_tag').prev().find('input').val('@!@tag@!@' + Math.floor((1 + Math.random()) * 0x10000).toString(16)); 24048 } 24049 */ 24050 if ($('#fancybox-content .js-add_checkbox_group').length) { 24051 $(this).parents('.js-question_input_wrap').find('.js-question_checkbox_tag_value').remove(); 24052 var $input = $(this).parents('.js-question_input_tag').prev().find('input'); 24053 $input.val('@!@tag@!@' + random_seed); 24054 var count = $input.attr('name').replace(/\D/g,''); 24055 $input.after('<input name="question[settings][value_' + count + ']" type="hidden" value="' + $(this).val() + '"/>'); 24056 } else { 24057 //console.log('fire2'); 24058 $(this).parents('.js-question_input_tag').prev().find('input').val($(this).val()); 24059 $(this).parents('.js-question_add_radio, .js-question_add_select').find('.js-question_input_wrap_name input').val('@!@tag@!@' + Math.floor((1 + Math.random()) * 0x10000).toString(16)); 24060 //console.log($(this).parents('.js-question_add_radio, .js-question_add_select').find('.js-question_input_wrap_name input').val()); 24061 } 24062 }); 24063 24064 if (!tag_valid) { 24065 return false; 24066 } 24067 24068 //return false; 24069 } 24070 24071 //on submit, if we're building a question via textarea options, create the inputs before save 24072 if ($('.js-question_entry_wrap').length && $('.js-question_entry_wrap .js-text_builder_textarea:visible').length) { 24073 //console.log('fire'); 24074 text_builder_save($('.js-question_entry_wrap .js-text_builder_textarea:visible')); 24075 } 24076 24077 24078 //on submit, if custom fields are present, look for ones who's name starts with "@!@tag@!@, which indicates this is a tag question, and if it's checked/selected, add it to the tags array on the form. 24079 if ($('.js-form_builder_output').length || $('.js-custom_fields').length) { 24080 //console.log('start'); 24081 24082 var tag_list_to_array = function() { 24083 if ($('.js-tag_list').val() == '') { 24084 $('.js-tag_list').val("[]"); 24085 } 24086 return JSON.parse($('.js-tag_list').val()); 24087 } 24088 24089 var unique_array = function(list) { 24090 var result = []; 24091 $.each(list, function(i, e) { 24092 if ($.inArray(e, result) == -1) result.push(e); 24093 }); 24094 return result; 24095 } 24096 24097 var array_to_tag_list = function(array) { 24098 return JSON.stringify(unique_array(array)); 24099 } 24100 24101 24102 $('form input[type="checkbox"]:checked, form input[type="radio"]:checked, form select').each(function() { 24103 //console.log($(this)); 24104 if ($(this).attr('name') && $(this).attr('name').indexOf('@!@tag@!@') != -1) { 24105 if ($(this).val() != '') { 24106 var $tag_list_input = $('.js-tag_list'); 24107 var tag_list_array = tag_list_to_array(); 24108 tag_list_array.push($(this).val()); 24109 //console.log(tag_list_array); 24110 24111 //need to dedupe array too 24112 $tag_list_input.val(array_to_tag_list(tag_list_array)); 24113 //console.log($tag_list_input.val()); 24114 24115 } 24116 } 24117 }); 24118 24119 // This handles blanking out names from other inputs if they are not checked/open, so as not to overwrite 24120 $('form .control-group').each(function() { 24121 var other_selected = false;
24122 $(this).find('input[type="checkbox"]:checked, input[type="radio"]:checked, select option:selected').each(function() { 24123 if ($(this).hasClass('js-other_option')) { 24124 other_selected = true; 24125 } 24126 }); 24127 //console.log(this); 24128 //console.log(other_selected); 24129 if (!other_selected) { 24130 $(this).find('.js-form_builder_other_input').attr('name', ''); 24131 } else if ($(this).find('input[type="radio"]:checked').length) { 24132 $(this).find('input[type="radio"]:checked').attr('name', ''); 24133 } else if ($(this).find('select option:selected').length) { 24134 $(this).find('select').attr('name', ''); 24135 } 24136 }); 24137 24138 24139 24140 //return false; 24141 } 24142 24143 24144 $('.js-letter_submit').attr('disabled',true).addClass('disabled').val(an_javascript_translation.sending + '...'); 24145 24146 //handle mobile phone input formatting 24147/* 24148 if ($.isFunction($.fn.intlTelInput) && $("#form-phone").length) { 24149 if ($("#form-phone").val() != '') { 24150 $("#form-phone").val($("#form-phone").intlTelInput('getNumber')); 24151 } 24152 } 24153*/ 24154 24155 /* 24156 if ($('#include_exclude_wrap').length) { 24157 $('.js-hidden-targeting-select').each(function() { 24158 if ($(this).val() != '') { 24159 $(this).val($(this).val().split(',')); 24160 } 24161 }); 24162 } 24163 */ 24164 if (cc_info_error_number == 0) { 24165 //console.log(cc_info_error_number); 24166 if (typeof(wepay_form) != 'undefined') { 24167 //console.log(wepay_form); 24168 24169 if ($('.js-ticketed_event_form_button').length) { 24170 var $donate_submit_button = $('.js-ticketed_event_form_button'); 24171 24172 } else { 24173 var $donate_submit_button = $('.js-donate_form_button'); 24174 } 24175 24176 var donation_submit_val = $donate_submit_button.val(); 24177 $donate_submit_button.attr('disabled',true).addClass('disabled').val(an_javascript_translation.processing + '...'); 24178 24179 if (wepay_form && $('.js-form-card_number').length) { 24180 var client_id = wepay_client_id, 24181 user_name = document.getElementById('form-first_name').value+" "+document.getElementById('form-last_name').value, 24182 cc_number = document.getElementById('form-card_number').value, 24183 cvv = document.getElementById('form-card_sec').value, 24184 expiration_month = document.getElementById('form-month').value, 24185 expiration_year = document.getElementById('form-year').value; 24186 24187 var stripe_response = { 24188 "number": cc_number, 24189 "cvc": cvv, 24190 "exp_month": expiration_month, 24191 "exp_year": expiration_year, 24192 "address_zip": document.getElementById('form-zip_code').value, 24193 "name": user_name, 24194 "address_line1": document.getElementById('form-address').value, 24195 "address_city": document.getElementById('form-city').value 24196 } 24197 24198 if ($('#form-country').val() == 'US' || $('#form-country').val() == 'United States') { 24199 var address = { 24200 "address1":document.getElementById('form-address').value, 24201 "city":document.getElementById('form-city').value, 24202 "state":document.getElementById('form-state').value, 24203 "country":'US', 24204 "zip":document.getElementById('form-zip_code').value 24205 }; 24206 24207 stripe_response.address_country = 'US'; 24208 stripe_response.address_state = document.getElementById('form-state').value 24209 } else { 24210 var address = { 24211 "address1":document.getElementById('form-address').value, 24212 "city":document.getElementById('form-city').value, 24213 "country":document.getElementById('form-country').value, 24214 "postcode":document.getElementById('form-zip_code').value 24215 }; 24216 24217 stripe_response.address_country = document.getElementById('form-country').value; 24218 } 24219 24220 if ($('#form-email').val() == '') { 24221 var email = document.getElementById('default_email').value; 24222 } else { 24223 var email = document.getElementById('form-email').value; 24224 } 24225 24226 var wepay_response = { 24227 "client_id":client_id, 24228 "user_name":user_name, 24229 "email":email, 24230 "cc_number":cc_number, 24231 "cvv":cvv, 24232 "expiration_month":expiration_month, 24233 "expiration_year":expiration_year, 24234 "address":address, 24235 "auto_update": true 24236 }; 24237 24238 24239 24240 //console.log(wepay_response); 24241 24242 24243 //if (typeof(WePay) != 'undefined') { 24244// var response = WePay.credit_card.create( wepay_response, function(data) { 24245// if (data.error) { 24246// // handle error response 24247// 24248// Noty.closeAll(); 24249// 24250// 24251// new Noty({
24252// theme: 'metroui', 24253// type: 'error', 24254// closeWith: ['button'], 24255// text: '<span class="noty_content">' + data.error_description + '<br/>' + an_javascript_translation.your_card_has_not_been_charged_please_try_again_or + ' <a href="/contact" target="_blank">' + an_javascript_translation.contact_us + '</a> ' + an_javascript_translation.if_it_keeps_happening + '.' + '</span>', 24256// }).show(); 24257// 24258// // early error handling 24259// if ((/Invalid credit card number/).test(data.error_description)) { 24260// $('#form-card_number').addClass('error_input_cc js-error_input_cc'); 24261// } else if ((/That credit card expiration date has already passed./).test(data.error_description)) { 24262// $('#form-month').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 24263// $('#form-year').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 24264// } 24265// 24266// $donate_submit_button.attr('disabled',false).removeClass('disabled').val(donation_submit_val); 24267// 24268// return false; 24269// } else { 24270// var input = $("<input>").attr("type", "hidden").attr("name","credit_card_id" ).val(data.credit_card_id); 24271// $('.js-donate_form').append($(input)); 24272// var input = $("<input>").attr("type", "hidden").attr("name","credit_card_last_digits" ).val(document.getElementById('form-card_number').value.substring(document.getElementById('form-card_number').value.length - 4, document.getElementById('form-card_number').value.length)); 24273// $('.js-donate_form').append($(input)); 24274 24275 24276 //form.submit(); 24277 var input = $("<input>").attr("type", "hidden").attr("name","credit_card_last_digits" ).val(document.getElementById('form-card_number').value.substring(document.getElementById('form-card_number').value.length - 4, document.getElementById('form-card_number').value.length)); 24278 $('.js-donate_form').append($(input)); 24279 stripe_tokenize(stripe_response, form, donation_submit_val, $donate_submit_button); 24280 // } 24281 // }); 24282 24283 //console.log(response); 24284 24285// if (response.error) { 24286// //console.log(response); 24287// 24288// Noty.closAll(); 24289// // handle error response 24290// 24291// new Noty({ 24292// theme: 'metroui', 24293// type: 'error', 24294// closeWith: ['button'], 24295// text: '<span class="noty_content">' + data.error_description + '<br/>' + an_javascript_translation.your_card_has_not_been_charged_please_try_again_or + ' <a href="/contact" target="_blank">' + an_javascript_translation.contact_us + '</a> ' + an_javascript_translation.if_it_keeps_happening + '.' + '</span>', 24296// }).show(); 24297// 24298// // early error handling 24299// if ((/Invalid credit card number/).test(data.error_description)) { 24300// $('#form-card_number').addClass('error_input_cc js-error_input_cc'); 24301// } else if ((/That credit card expiration date has already passed./).test(data.error_description)) { 24302// $('#form-month').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 24303// $('#form-year').addClass('error_input_cc js-error_input_cc').siblings('span.customSelect').addClass('error_input_cc js-error_input_cc'); 24304// } 24305// 24306// $donate_submit_button.attr('disabled',false).removeClass('disabled').val(donation_submit_val); 24307// 24308// return false; 24309// 24310// } 24311// } else { 24312// Noty.closeAll(); 24313// 24314// new Noty({ 24315// theme: 'metroui', 24316// type: 'error', 24317// closeWith: ['button'], 24318// text: an_javascript_translation.there_was_an_error_contacting_our_payment_processor + '<br/>' + an_javascript_translation.please_ensure_you_are_not_blocking_our_javascript_and_try_again_or + ' <a href="/contact" target="_blank">' + an_javascript_translation.contact_us + '</a> ' + an_javascript_translation.if_it_keeps_happening + '.', 24319// }).show(); 24320// 24321// $donate_submit_button.attr('disabled',false).removeClass('disabled').val(donation_submit_val); 24322// 24323// return false;
24324// } 24325 24326 24327 } else { 24328 affirmative_opt_in_submit(); 24329 if (!donation_return_flag) { form.submit(); } 24330 } 24331 } else { 24332 affirmative_opt_in_submit(); 24333 if (!donation_return_flag) { form.submit(); } 24334 } 24335 } else { 24336 affirmative_opt_in_submit(); 24337 if (!donation_return_flag && $(form).hasClass('js-edit_donation')) { form.submit(); } 24338 } 24339 24340 if (typeof(submitClicked) && $('#' + submitClicked).hasClass('js-email-save')) { 24341 if ($('.js-no_target_warning_checkbox:visible').length && !$('.js-no_target_warning_checkbox:checked').length) { 24342 if ($('.js-random_limit_input').val() == '') { 24343 $.smoothScroll($('.js-no_target_warning').offset().top - 40, {afterScroll: $('.js-no_target_warning').addClass('error_input') }); 24344 $.fancybox.close(); 24345 return false; 24346 } else { 24347 $('.js-no_target_warning').hide(); 24348 $('.js-no_target_warning').removeClass('error_input'); 24349 $('.js-no_target_warning_checkbox').attr('checked', false); 24350 } 24351 24352 } 24353 if ($('#' + submitClicked).hasClass('disabled')) { 24354 $.fancybox.close(); 24355 return false; 24356 } else { 24357 $('.js-email-save').addClass('disabled'); 24358 24359 setTimeout(function(){ $('.js-email-save').removeClass('disabled'); }, 3000); 24360 } 24361 } 24362 } 24363 } 24364 24365 }); 24366 24367 }); 24368 24369 // handle split 24370 $('form').submit(function() { 24371 if (!$('.js-create_donate_form').length) { 24372 donation_split_errors(); 24373 } 24374 24375 }); 24376 24377 if ($(".js-phone-parens").length) { 24378 $(".js-phone-parens").rules("add", { 24379 phone_parens: true 24380 }); 24381 } 24382 24383 if ($(".js-pipe_url").length) { 24384 $(".js-pipe_url").each(function() { 24385 $(this).rules("add", { 24386 pipe_url: true 24387 }); 24388 }); 24389 } 24390 24391 if ($(".js-pipe_url_https").length) { 24392 $(".js-pipe_url_https").each(function() { 24393 $(this).rules("add", { 24394 pipe_url_https: true 24395 }); 24396 }); 24397 } 24398 24399 if ($('.js-form_builder_output').length || $('.js-custom_fields').length) { 24400 $('[data-regex]').not('.redactor_clip_link').each(function() { 24401 $(this).rules("add", { regex: $(this).data('regex') }); 24402 }); 24403 } 24404 24405 24406 }; 24407 24408 redactorInit = function(redactor) { 24409 //console.log('init'); 24410 24411 $('.js-redactor').parents('form').not('.js-ladder_modal_action_form').areYouSure({'addRemoveFieldsMarksDirty':true} ); 24412 setTimeout(function() { 24413 //if () 24414 redactor.$box.find('div.redactor-editor').floatlabel(); 24415 24416 }, 200); 24417 24418 $(document).on('tabMove', function(event_campaign, element) { 24419 if ($(element).find('.redactor-toolbar').length) { 24420 $(element).find('.floatlabel-redactor').css('margin-top', ($(element).find('.redactor-toolbar').outerHeight() - 5)); 24421 } 24422 }); 24423 24424 $('.js-action_select').change(function() { 24425 if ($(this).val() == "email") { 24426 $(this).parents('.js-ladder_modal_create').find('.floatlabel-redactor').css('margin-top', ($(this).parents('.js-ladder_modal_create').find('.redactor-toolbar').outerHeight() - 5)); 24427 //setTimeout(function() { 24428 //console.log($(this).parents('.js-ladder_modal-action').find('div.redactor-editor')); 24429 $(this).parents('.js-ladder_modal-action').find('div.redactor-editor').trigger('change'); 24430 //}, 10000); 24431 } 24432 }); 24433/* 24434 $('.redactor_toolbar a.re-html').click(function() { 24435 if ($(this).hasClass('redactor_act')) { 24436 $("textarea.js-redactor").height( $("textarea.js-redactor")[0].scrollHeight ); 24437 } 24438 }); 24439*/ 24440 24441 if ($('.js-redactor').length) { 24442 24443 $('form').submit(function (e) { 24444 //console.log(redactor.$box.find('.js-redactor').hasClass('required')); 24445 if (!(/cancel/).test($('#' + submitClicked).attr('class')) && redactor.$box.find('.js-redactor').hasClass('required')) { 24446 //console.log(submitClicked); 24447 //console.log((/cancel/).test($('#petition-save_draft').attr('class'))); 24448 //console.log(redactor); 24449 if (redactor.code.get() == "" || (/redactor_placeholder/).test(redactor.code.get())) { 24450 redactor.$box.attr("class", "redactor-box error_input"); 24451 } else { 24452 redactor.$box.removeClass("error_input"); 24453 } 24454 24455 } 24456 24457 }); 24458 24459 $(document).on('click', '.js-save_action, .js-email_send_test', function (e) { 24460 //console.log(redactor.$box.find('.js-redactor').hasClass('required')); 24461 if (redactor.$box.find('.js-redactor').hasClass('required')) { 24462 //console.log(submitClicked); 24463 //console.log((/cancel/).test($('#petition-save_draft').attr('class'))); 24464 //console.log(redactor); 24465 if (redactor.code.get() == "" || (/redactor_placeholder/).test(redactor.code.get())) { 24466 redactor.$box.attr("class", "redactor-box error_input"); 24467 } else { 24468 redactor.$box.removeClass("error_input"); 24469 } 24470 24471 } 24472 24473 }); 24474 24475 24476 24477 $('.redactor_box, .redactor-box').keyup(function () { 24478 //console.log('Handler for .keyup() called.'); 24479 if (typeof(form_id) !== 'undefined') { 24480 if (redactor.$box.find('.js-redactor').hasClass('required')) { 24481 if (redactor.code.get() == "" || (/redactor_placeholder/).test(redactor.code.get())) { 24482 //console.log('if'); 24483 redactor.$box.attr("class", "redactor-box error_input"); 24484 //} 24485 } else { 24486 //console.log('no if'); 24487 redactor.$box.removeClass("error_input"); 24488 // } 24489 } 24490 } 24491 } 24492 }); 24493 24494 $('.redactor_box, .redactor-box').focusout(function () { 24495 //console.log('Handler for .focusout() called.'); 24496 if (typeof(form_id) !== 'undefined') { 24497 if (redactor.$box.find('.js-redactor').hasClass('required')) { 24498 if (redactor.code.get() == "" || (/redactor_placeholder/).test(redactor.code.get())) { 24499 //console.log('if'); 24500 redactor.$box.attr("class", "redactor-box error_input"); 24501 } else { 24502 //console.log('no if'); 24503 redactor.$box.removeClass("error_input"); 24504 } 24505 } 24506 } 24507 }); 24508 24509 canValidate(redactor); 24510 24511 $(".redactor_create_action-editable, .js-redactor.js-create_action-editable").focusin(function() { 24512 //$(this).parent().parent().find(".tooltip span").animate({opacity:".95"}, { duration: 300, queue: false }).addClass("ie_tool"); 24513 //$(this).parent().parent().find(".tooltip span").animate({bottom:"40px"}, { duration: 300, queue: false }).addClass("ie_tool"); 24514 //console.log($(this)); 24515 tooltipFunction($(this).parent().parent().parent().find(".js-tooltip:not(.js-tooltip_redactor_ignore)")); 24516 }).focusout(function () { 24517 //$(this).parent().parent().find(".tooltip span").animate({opacity:"0"}, { duration: 300, queue: false }).removeClass("ie_tool"); 24518 //$(this).parent().parent().find(".tooltip span").animate({bottom:"60px"}, { duration: 300, queue: false }).removeClass("ie_tool"); 24519 remove_tooltip(); 24520 }); 24521 24522 24523 var context = {}; 24524 var scope = {}; 24525 24526 $('.redactor_clip').each(function() { 24527 //console.log($(this).data('dropkiq-context')); 24528 //console.log($(this).data('dropkiq-scope')); 24529 $.extend(context, $(this).data('dropkiq-context')); 24530 $.extend(scope, $(this).data('dropkiq-scope')); 24531 }); 24532 //console.log(context); 24533 //console.log(scope); 24534 24535 24536 var textArea = redactor.$editor[0]; 24537 var options = {}; 24538 if (typeof(window.DropkiqUI) != "undefined") { 24539 var dropkiqUI = new window.DropkiqUI(textArea, {}, context, scope, "4fee6b50-29d5-0138-0a6d-4a36325215e0", options); 24540 dropkiqUI.registerFilter('no_profanity', function(){ 24541 return $('.js-dropkiq-no_profanity').data('dropkiq-no_profanity') 24542 }, "no_profanity", [], an_javascript_translation.output_blank_if_text_matches_profanity_list); 24543 dropkiqUI.registerFilter('title_case', function(){ 24544 return $('.js-dropkiq-titlecase').data('dropkiq-titlecase') 24545 }, "title_case", [], an_javascript_translation.output_string_with_first_letters_capitalized); 24546 dropkiqUI.registerFilter('us_state_full', function(){ 24547 return $('.js-dropkiq-us_state_full').data('dropkiq-us_state_full') 24548 }, "us_state_full", [], an_javascript_translation.only_output_a_state_full_name_if_the_value); 24549 } 24550 24551 24552 }/* 24553 else { 24554 redactorErrorFlag = false;
24555 } 24556*/ 24557 24558 if (typeof(event_in_past_flag) === 'undefined') { 24559 event_in_past_flag = false; 24560 } 24561 24562 if (getURLParameter('validate') == 'true') { 24563 // $('.js-suggested_modal_link_wrap').addClass('hide'); 24564 // $('.js-event_location_custom_link').addClass('hide'); 24565 // $('.js-event_location_suggested_link').removeClass('hide'); 24566 // $('.js-event_location').removeClass('hide'); 24567 24568 if (event_in_past_flag == true) { 24569 $('.js-event-start-date').val(''); 24570 } 24571 24572 canValidate(redactor); 24573 $('form').not('.js-create_email_campaign_form').valid(); 24574 if (!$('.js-form-submit').length) { 24575 $('.js-create_action_toolbox').append('<input type="submit" class="form-submit js-form-submit" style="display: none;" id="hidden-submit" />'); 24576 submitClicked = $('.js-form-submit').attr('id'); 24577 } 24578 24579 $('.js-form-submit').click(); 24580 24581 } 24582 } 24583 24584 24585 //redactorErrorFlag = false; 24586 24587 /* Setup the textareas */ 24588 24589 redactorLoad = function($element, container_width, with_clips, donate_form, focus) { 24590 //console.log('load'); 24591 if (container_width <= 960 || !with_clips) { 24592 var toolbarFixed_var = false; 24593 } else if ($('.js-ladder').length) { 24594 var toolbarFixed_var = true, 24595 toolbarFixedTopOffset_var = 0, 24596 toolbarFixedBox_var = false; 24597 } else { 24598 var toolbarFixed_var = true, 24599 toolbarFixedTopOffset_var = 0, 24600 toolbarFixedBox_var = false; 24601 } 24602 24603 if (with_clips) { 24604 var plugins_var = ['emoji','clearformatting','toolbartitles','clips','snippets','link_fix','edit_image_email','table','codemirror','align','general_fixes','button_social']; 24605 var buttons_var = ['html', '|', 'format', 'bold', 'italic', 'deleted', 'lists', 'image', 'table', 'link', 'alignment', 'horizontalrule']; 24606 var height = 300; 24607 } else { 24608 var plugins_var = ['link_fix','edit_image','video','table','codemirror','general_fixes','align']; 24609 if ($element.parents('.js-create_group_form').length) { 24610 var buttons_var = ['html', 'format', 'bold', 'italic', 'deleted', 'lists', 'image', 'video', 'file', 'table', 'alignment', 'horizontalrule']; 24611 } else { 24612 var buttons_var = ['html', 'format', 'bold', 'italic', 'deleted', 'lists', 'image', 'video', 'file', 'table', 'link', 'alignment', 'horizontalrule']; 24613 } 24614 var height = 150; 24615 } 24616 24617 if (donate_form) { 24618 var deniedTags_var = ['html', 'head', 'body', 'meta', 'applet', 'script', 'style', 'link']; 24619 var plugins_var = ['link_fix','edit_image_email','table','codemirror','general_fixes','align']; // use email image editor version here so as to work with no styles tags available 24620 } else { 24621 var deniedTags_var = ['html', 'head', 'body', 'meta', 'applet']; 24622 } 24623 24624 if (!focus) { 24625 var focus_var = false; 24626 } else { 24627 var focus_var = focus; 24628 } 24629 24630 //stupid IE scroll on enter bug 24631 //console.log($('body').attr('class')); 24632 if ($('body').hasClass('trident_6') || $('body').hasClass('trident_7')) { 24633 24634 var max_height = false; 24635 } else { 24636 var max_height = false; 24637 } 24638 24639 $element.redactor({ //turns on redactor WYSIWYG 24640 buttons: buttons_var, 24641 plugins: plugins_var, 24642 formatting: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','sup'], 24643 toolbarFixed: toolbarFixed_var, 24644 toolbarFixedTopOffset: toolbarFixedTopOffset_var, 24645 toolbarFixedBox: toolbarFixedBox_var, 24646 focus: focus_var, 24647 imageUpload: '/uploads/', 24648 imageUploadFields: '.js-redactor_image_upload_group_id', 24649 convertDivs: false, 24650 //dragUpload: false, 24651 //fileUpload: '/uploads/', 24652 deniedTags: deniedTags_var, 24653 cleanFontTag: false, 24654 linkSize: false, 24655 linkify: false, 24656 linkProtocol: 'templated', 24657 paragraphy: false, 24658 tidyHtml: true, 24659 minHeight: height, 24660 maxHeight: max_height, 24661 paragraphize: false, 24662 removeComments: false, 24663 //pasteLinks: false, 24664 pasteBlockTags: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'table', 'tbody', 'thead', 'tfoot', 'th', 'tr', 'td', 'ul', 'ol', 'li', 'blockquote', 'pre', 'p', 'div','img'], 24665 pasteInlineTags: ['strong', 'b', 'u', 'em', 'i', 'code', 'del', 'ins', 'samp', 'kbd', 'sup', 'sub', 'mark', 'var', 'cite', 'small', 'span', 'font', 'br'], 24666 codemirror: { 24667 lineNumbers: true, 24668 mode: 'htmlmixedliquid', 24669 indentUnit: 4, 24670 lineWrapping: true, 24671 viewportMargin: Infinity 24672 }, 24673 callbacks: { 24674 init: function() 24675 { 24676 //console.log('init'); 24677 redactorInit(this); 24678 24679 }, 24680 change: function() 24681 { 24682 //console.log('change'); 24683 //this is problematic on IE10 24684 //if (navigator.appVersion.indexOf("MSIE 10") == -1) { 24685 $element.parents('form').not('.js-ladder_modal_action_form').trigger('checkform.areYouSure'); 24686 24687 //} 24688 }, 24689 focus: function(e) { 24690 //console.log(this.$box); 24691 //if (!$('.js-tooltip_window').length) { 24692 remove_tooltip(); 24693 tooltipFunction(this.$box.parent().parent().find(".tooltip:not(.js-tooltip_redactor_ignore)"), '.js-content'); 24694 //} 24695 24696 //console.log('focus'); 24697/* 24698 if ($('.js-redactor').length > 1) { 24699 $('.js-redactor').not($(e.target).next()).each(function() { 24700 if ($(this).prev().hasClass('redactor_redactor')) { 24701 $(this).redactor('destroy'); 24702 } 24703 }); 24704 } 24705*/ 24706 }, 24707 blur: function(e) { 24708 remove_tooltip(); 24709 } 24710 } 24711 24712 }); 24713 24714 if ($('.js-email_bodies_wrap .js-redactor').length) { 24715 if ($('.js-prefer_html').val() == 'true') { 24716 //console.log('html mode detected'); 24717 setTimeout(function() {
24718 $element.redactor('codemirror.show'); 24719 //$('.CodeMirror')[0].CodeMirror.refresh() 24720 //$element.redactor('codemirror.refresh'); 24721 }, 1000); 24722 } 24723 24724 $element.parents('.redactor-box').find('.re-html').click(function() { 24725 prefer_html = "false"; 24726 if ($('.CodeMirror-wrap:visible').length) { 24727 prefer_html = "true"; 24728 } 24729 //console.log('after click: ' + localStorage.getItem('html_mode_' + encodeURIComponent(window.location.pathname))); 24730 24731 $.ajax({ 24732 url: `set_prefer_html`, 24733 method: 'POST', 24734 data: { 24735 id: $('.js-first_permalink_hook').data('first-permalink'), 24736 prefer_html: prefer_html 24737 } 24738 }).done(function(data) { 24739 $('.js-prefer_html').val(prefer_html); 24740 }); 24741 }); 24742 } 24743 } 24744 24745 redactor_init_function = function() { 24746 if ($('.js-redactor').length) { 24747 24748 var with_clips, donate_form; 24749 24750 $('.js-redactor').each(function() { 24751 if ($(this).hasClass('withclips')) { 24752 with_clips = true; 24753 } else { 24754 with_clips = false; 24755 } 24756 24757 if ($('.js-create_donate_form').length) { 24758 donate_form = true; 24759 } else { 24760 donate_form = false; 24761 } 24762 //console.log($(this)); 24763 redactorLoad($(this), $('.js-content > .js-container').width(), with_clips, donate_form); 24764 }); 24765 24766 24767 } 24768 24769 if (!$('.js-redactor').length) { 24770 canValidate(); 24771 24772 if (getURLParameter('validate') == 'true') { 24773 //console.log('valid'); 24774 24775 $('form').not('.js-create_email_campaign_form').valid(); 24776 if ($('.js-syndicate_group_list_wrap').length) { 24777 $('.js-form-submit').click(); 24778 } 24779 24780 } 24781 } 24782 } 24783 redactor_init_function(); 24784 24785 24786 24787 24788 24789 24790 // fundraising rule additions 24791 $('.js-donation_info_split input, .js-ticketed_event_ticket_number').each(function(i) { 24792 $(this).rules('add', { 24793 require_from_group: [1, '.js-required_group'] 24794 }); 24795 }); 24796 24797 $('.js-donate_recurring_type, .js-donate_recurring_period').on('change', function() { 24798 if ($('.js-donate_add_dollar_amount').length) { 24799 donate_recurring_type_required(); 24800 } 24801 }); 24802 24803 /* open modals */ 24804 24805 var modal_open = getURLParameter('modal'); 24806 if (modal_open && $('.' + modal_open).length && $('.' + modal_open).hasClass('js-machine_clickable')) { 24807 $('.' + modal_open).trigger('click'); 24808 } 24809 24810 data_processing_init = function() { 24811 var show_hide_data_processing_section = function($checkbox) { 24812 if( $checkbox.is(':checked')) { 24813 $checkbox.parent().parent().siblings(".js-data_processing_text_wrap").show().find('.js-data_processing_text').addClass('required'); 24814 } else { 24815 $checkbox.parent().parent().siblings(".js-data_processing_text_wrap").hide().find('.js-data_processing_text').removeClass('required'); 24816 } 24817 } 24818 24819 //show/hide group additional data processing text box, delayed so the height calculation for the floatlabel placement can be done while it's not hidden 24820 setTimeout(function() { 24821 show_hide_data_processing_section($('.js-data_processing_text_checkbox')); 24822 $('.js-data_processing_text_checkbox').click(function() { 24823 show_hide_data_processing_section($('.js-data_processing_text_checkbox')); 24824 }); 24825 },500); 24826 24827 //affirmative opt in required class/value manipulations 24828 if ($('.js-affirmative_optin_control_group').length) { 24829 $('.js-affirmative_optin_control_group .js-affirmative_optin_radio').addClass('required'); 24830 $('.js-affirmative_optin_control_group .js-affirmative_optin_radio_no').val('invalid'); 24831 } 24832 } 24833 data_processing_init(); 24834 24835 24836 /* homepage stuff ***************************************************/ 24837 24838 $(document).on('can-form-area-learn-more-about-partnerships_submitted', function() { 24839 $('.js-learn_more_form').hide(); 24840 $('.js-learn_more_form-thankyou').fadeIn(); 24841 }); 24842 24843 $(document).on('can-form-area-want-to-learn-more-sign-up-here_submitted', function() { 24844 $('.js-learn_more_form').hide(); 24845 $('.js-learn_more_form-thankyou').fadeIn(); 24846 }); 24847 24848 $(document).on('can-form-area-demo-mobile-messaging-on-action-network_submitted', function() { 24849 $('.js-learn_more_form').hide(); 24850 $('.js-learn_more_form-thankyou').fadeIn(); 24851 }); 24852 24853 24854 24855 var home_quote_1_height = $('.js-home_quote_1 blockquote').outerHeight(); 24856 var home_quote_2_height = $('.js-home_quote_2 blockquote').outerHeight(); 24857 24858 if (home_quote_1_height > home_quote_2_height) {
24859 $('.js-home_quote_2 blockquote').css('height', home_quote_1_height); 24860 } 24861 24862 if (home_quote_2_height > home_quote_1_height) { 24863 $('.js-home_quote_1 blockquote').css('height', home_quote_2_height); 24864 } 24865 /* developers page stuff ***************************************************/ 24866 $(document).on('can-form-area-request-developer-access_submitted', function() { 24867 $('.js-developers_form').hide(); 24868 $('.js-developers_form-thankyou').fadeIn(); 24869 $('.js-developers_section').removeClass( "developers_section" ).addClass("developers_section-submitted"); 24870 $('.js-integration-testimonials').removeClass( "integration-testimonials" ).addClass("integration-testimonials-submitted"); 24871 $('.js-integration-attribution').removeClass( "integration-attribution" ).addClass("integration-attribution-submitted"); 24872 $('.js-developers_form_section').addClass("developers_form_section-submitted"); 24873 $('html, body').animate({scrollTop:$('.developers_form_section-submitted').offset().top - 200}, 100); 24874 }); 24875 24876 24877 24878 /*********************** pricing calculator ************************/ 24879 /* Pricing Calculator Toggle */ 24880 $('.js-pricing_calculator_toggle .js-switch-toggle').click(function(e) { 24881 //e.preventDefault(); 24882 24883 if ($(this).hasClass('js-switch-enabled')) { 24884 24885 $(this).removeClass('switch-enabled js-switch-enabled').addClass('switch-disabled js-switch-disabled'); 24886 24887 $('.js-switch-option-movement').addClass('active js-active'); 24888 $('.js-switch-option-network').removeClass('active js-active'); 24889 $('.js-switch_text .network, .js-email-network-explain, .js-mobile-network-explain').addClass('hide'); 24890 $('.js-switch_text .movement, .js-email-movement-explain, .js-mobile-movement-explain').removeClass('hide'); 24891 $('.js-calculator_quote_email').attr('href', '#partner_modal'); 24892 $('.js-calculator_quote_mobile').attr('href', '#mobile_partner_modal'); 24893 $range.each(function() { 24894 calculatePrice($(this)); 24895 }); 24896 24897 } else { 24898 24899 $(this).removeClass('switch-disabled js-switch-disabled').addClass('switch-enabled js-switch-enabled'); 24900 24901 $('.js-switch-option-movement').removeClass('active js-active'); 24902 $('.js-switch-option-network').addClass('active js-active'); 24903 $('.js-switch_text .network, .js-email-network-explain, .js-mobile-network-explain').removeClass('hide'); 24904 $('.js-switch_text .movement, .js-email-movement-explain, .js-mobile-movement-explain').addClass('hide'); 24905 $('.js-calculator_quote_email').attr('href', '#partner_network_modal'); 24906 $('.js-calculator_quote_mobile').attr('href', '#mobile_partner_network_modal'); 24907 $range.each(function() { 24908 calculatePrice($(this)); 24909 }); 24910 } 24911 24912 }); 24913 24914 24915 // pricing calculations and range bubbles 24916 // set up all pricing variables for easy access 24917 const $range = $('.js-calc-slider'); 24918 24919 // AN pricing 24920 var movement_email_cpm = 1; 24921 var network_email_cpm = 2; 24922 var movement_mobile_cpm = 10; 24923 var network_mobile_cpm = 20; 24924 var movement_email_minimum = 10; 24925 var network_email_minimum = 100; 24926 var movement_mobile_minimum = 50; 24927 var network_mobile_minimum = 100; 24928 24929 // number options and twilio prices 24930 var toll_free = "Toll Free"; 24931 // var toll_free_25mps = "Toll Free 25mps"; 24932 // var toll_free_50mps = "Toll Free 50mps"; 24933 // var toll_free_75mps = "Toll Free 75mps"; 24934 var shortcode = "SHORTCODE"; 24935 24936 // breakpoints for when the next number type is recommended, max messages in one send to get approx 2 hours time to complete the send 24937 var toll_free_breakpoint = 540000; 24938 //var toll_free_25mps_breakpoint = 180000; 24939 //var toll_free_50mps_breakpoint = 360000; 24940 //var toll_free_75mps_breakpoint = 540000; 24941 24942 var toll_free_cost = 0; // it's actually $0.40 but it's too small to factor into our calculator 24943 //var toll_free_25mps_cost = 150; 24944 //var toll_free_50mps_cost = 300; 24945 //var toll_free_75mps_cost = 750; 24946 var shortcode_cost = 1000; 24947 24948 var toll_free_sms = 0.00676; 24949 var shortcode_sms = 0.00628; 24950 var toll_free_carrier_fees = 0.00108; 24951 var shortcode_carrier_fees = 0.00313; 24952 24953 var contact_us_breakpoint = 999; // point at which we show the contact us option vs giving a quote 24954 24955 var risk_fee_percentage = 0.03; 24956 var card_fee_percentage = 0.037; 24957 var speed_fee_percentage = 0.155; 24958 24959 24960 $range.each(function() { 24961 console.log(this); 24962 const $bubble = $(this).next('.js-calc-bubble'); 24963 24964 $(this).on('input', function() { 24965 setBubble($(this), $bubble); 24966 calculatePrice($(this)); 24967 }); 24968 24969 setBubble($(this), $bubble); 24970 calculatePrice($(this)); 24971 }); 24972 24973 function setBubble($range, $bubble) { 24974 const val = $range.val(); 24975 const min = $range.attr('min') ? $range.attr('min') : 0; 24976 const max = $range.attr('max') ? $range.attr('max') : 100; 24977 const newVal = Number(((val - min) * 100) / (max - min)); 24978 24979 $bubble.text(val); 24980 // from css-tricks - magic number based on size of native UI thumb 24981 $bubble.css({ visibility: "visible" }); 24982 $bubble.css({ left: `calc(${newVal}% + (${8 - newVal * 0.15}px))` }); 24983 } 24984 24985 function calculatePrice($range) { 24986 // email pricing calc here 24987 if ($range.hasClass('js-calc-slider-email_volume')) { 24988 if ($('.js-switch-option-movement.js-active').length) { 24989 price = ($('.js-calc-slider-email_volume').val() / 1000) * movement_email_cpm 24990 if (price < movement_email_minimum) { 24991 price = movement_email_minimum 24992 } 24993 } else { 24994 price = ($('.js-calc-slider-email_volume').val() / 1000) * network_email_cpm 24995 if (price < network_email_minimum) { 24996 price = network_email_minimum 24997 } 24998 } 24999 25000 $('.js-calculator_price_wrap_email_large').hide().removeClass('d-flex'); 25001 $('.js-calculator_price_wrap_email_small').show().addClass('d-flex'); 25002 25003 if (price > contact_us_breakpoint) { 25004 $('.js-calculator_price_wrap_email_large').show().addClass('d-flex'); 25005 $('.js-calculator_price_wrap_email_small').hide().removeClass('d-flex'); 25006 } else { 25007 $('.js-calculator_price_wrap_email_large').hide().removeClass('d-flex'); 25008 $('.js-calculator_price_wrap_email_small').show().addClass('d-flex'); 25009 } 25010
25011 $('.js-price-email').text(price); 25012 25013 } 25014 25015 if ($range.hasClass('js-calc-slider-mobile_send') || $range.hasClass('js-calc-slider-mobile_volume')) { 25016 var one_time_send = $('.js-calc-slider-mobile_send').val(); 25017 var primary = toll_free; 25018 var secondary = shortcode; 25019 25020 if (one_time_send <= toll_free_breakpoint) { 25021 primary = toll_free; 25022 secondary = shortcode; 25023 $('.js-plan_option_link_secondary_wrap').removeClass('hide'); 25024 $('.js-plan_option_link_primary').removeClass('nomr'); 25025 // } else if (one_time_send > toll_free_3mps_breakpoint && one_time_send <= toll_free_25mps_breakpoint) { 25026 // primary = toll_free_25mps; 25027 // secondary = toll_free_50mps; 25028 // } else if (one_time_send > toll_free_25mps_breakpoint && one_time_send <= toll_free_50mps_breakpoint) { 25029 // primary = toll_free_50mps; 25030 // secondary = toll_free_75mps; 25031 // } else if (one_time_send > toll_free_50mps_breakpoint && one_time_send <= toll_free_75mps_breakpoint) { 25032 // primary = toll_free_75mps; 25033 // secondary = shortcode; 25034 // $('.js-plan_option_link_secondary_wrap').removeClass('hide'); 25035 // $('.js-plan_option_link_primary').removeClass('nomr'); 25036 } else if (one_time_send > toll_free_breakpoint) { 25037 primary = shortcode; 25038 secondary = " "; 25039 $('.js-plan_option_link_secondary_wrap').addClass('hide'); 25040 $('.js-plan_option_link_primary').addClass('nomr'); 25041 } 25042 25043 $('.js-plan_option_link_primary').html(primary); 25044 $('.js-plan_option_link_secondary').html(secondary); 25045 25046 25047 if ($('.js-switch-option-movement.js-active').length) { 25048 price = ($('.js-calc-slider-mobile_volume').val() / 1000) * movement_mobile_cpm 25049 if (price < movement_mobile_minimum) { 25050 price = movement_mobile_minimum 25051 } 25052 } else { 25053 price = ($('.js-calc-slider-mobile_volume').val() / 1000) * network_mobile_cpm 25054 if (price < network_mobile_minimum) { 25055 price = network_mobile_minimum 25056 } 25057 } 25058 25059 $('.js-calculator_price_wrap_mobile_large').hide().removeClass('d-flex'); 25060 $('.js-calculator_price_wrap_mobile_small').show().addClass('d-flex'); 25061 25062 if (price > contact_us_breakpoint) { 25063 $('.js-calculator_price_wrap_mobile_large').show().addClass('d-flex'); 25064 $('.js-calculator_price_wrap_mobile_small').hide().removeClass('d-flex'); 25065 } else { 25066 $('.js-calculator_price_wrap_mobile_large').hide().removeClass('d-flex'); 25067 $('.js-calculator_price_wrap_mobile_small').show().addClass('d-flex'); 25068 } 25069 25070 price = addTelecomFees(price, primary); 25071 25072 $('.js-price-mobile').text(price); 25073 25074 } 25075 } 25076 25077 function addTelecomFees(price, primary) { 25078 var line_cost = 0; 25079 var sms_cost = 0; 25080 var carrier_fees = 0; 25081 var subtotal = 0; 25082 var risk_fee = 0; 25083 var card_fee = 0; 25084 var total = 0; 25085 25086 if (primary == toll_free) { 25087 line_cost = toll_free_cost; 25088 sms_cost = $('.js-calc-slider-mobile_volume').val() * toll_free_sms; // note: does not include any MMS 25089 carrier_fees = $('.js-calc-slider-mobile_volume').val() * toll_free_carrier_fees; 25090 } 25091 25092 // if (primary == toll_free_25mps) { 25093 // line_cost = toll_free_25mps_cost; 25094 // sms_cost = $('.js-calc-slider-mobile_volume').val() * toll_free_sms; // note: does not include any MMS 25095 // carrier_fees = $('.js-calc-slider-mobile_volume').val() * toll_free_carrier_fees; 25096 // } 25097 // 25098 // if (primary == toll_free_50mps) { 25099 // line_cost = toll_free_50mps_cost; 25100 // sms_cost = $('.js-calc-slider-mobile_volume').val() * toll_free_sms; // note: does not include any MMS 25101 // carrier_fees = $('.js-calc-slider-mobile_volume').val() * toll_free_carrier_fees; 25102 // } 25103 // 25104 // if (primary == toll_free_75mps) { 25105 // line_cost = toll_free_75mps_cost; 25106 // sms_cost = $('.js-calc-slider-mobile_volume').val() * toll_free_sms; // note: does not include any MMS 25107 // carrier_fees = $('.js-calc-slider-mobile_volume').val() * toll_free_carrier_fees; 25108 // } 25109 25110 if (primary == shortcode) { 25111 line_cost = shortcode_cost; 25112 sms_cost = $('.js-calc-slider-mobile_volume').val() * shortcode_sms; // note: does not include any MMS 25113 carrier_fees = $('.js-calc-slider-mobile_volume').val() * shortcode_carrier_fees; 25114 } 25115 25116 subtotal = price + sms_cost + carrier_fees + line_cost; 25117 risk_fee = subtotal * risk_fee_percentage; 25118 card_fee = subtotal * card_fee_percentage; 25119 speed_fee = subtotal * speed_fee_percentage; 25120 total = subtotal + risk_fee + card_fee + speed_fee; 25121 return total.toFixed(0); 25122 } 25123 25124 //click to get quote handling 25125 $('.js-calculator_quote_email').click(function() { 25126 var email_volume = $('.js-calc-slider-email_volume').val(); 25127 25128 if (email_volume < 200000) { 25129 var email_volume_thousands = Math.ceil((email_volume / 1000) / 10) * 10; 25130 } else { 25131 var email_volume_thousands = Math.ceil((email_volume / 1000) / 50) * 50; 25132 } 25133 25134 $('#fancybox-content #Emails-per-month').val(email_volume); 25135 try { jq_can('#fancybox-content select#Email-Volume-Drop-Down').select2('val', email_volume_thousands); } catch(err) { }; 25136 try { $('#fancybox-content select#Email-Volume-Drop-Down').select2('val', email_volume_thousands); } catch(err) { }; 25137 }); 25138 25139 $('.js-calculator_quote_mobile').click(function() { 25140 var message_volume = $('.js-calc-slider-mobile_volume').val(); 25141 var message_total = $('.js-calc-slider-mobile_send').val(); 25142 var message_per_second = "3mps"; 25143 25144 if (message_volume <= 5000) { 25145 var message_volume_thousands = 50; 25146 } else if (message_volume <= 10000) { 25147 var message_volume_thousands = 100; 25148 } else if (message_volume <= 50000 && message_volume > 10000) { 25149 var message_volume_thousands = Math.ceil((message_volume / 1000) / 10) * 100; 25150 } else if (message_volume <= 75000 && message_volume > 50000) { 25151 var message_volume_thousands = 750; 25152 } else if (message_volume <= 100000 && message_volume > 75000) { 25153 var message_volume_thousands = 1000; 25154 } else if (message_volume <= 150000 && message_volume > 100000) { // note, from here on out these are not visible because we show contact us, so haven't been tested 25155 var message_volume_thousands = 1500; 25156 } else if (message_volume < 1000000 && message_volume > 150000) { 25157 var message_volume_thousands = Math.ceil((message_volume / 1000) / 100) * 100; 25158 } 25159 25160 if (message_total <= 20000) { 25161 message_per_second = '3mps'; 25162 } else if (message_total <= 180000 && message_total > 20000) { 25163 message_per_second = '25mps'; 25164 } else if (message_total <= 360000 && message_total > 180000) { 25165 message_per_second = '50mps'; 25166 } else if (message_total <= 540000 && message_total > 360000) { 25167 message_per_second = '75mps'; 25168 } else if (message_total > 540000) { 25169 message_per_second = '>100mps'; 25170 } 25171 25172 jq_can('#fancybox-content input[name="largest send"]').each(function() { 25173 if ($(this).val() == message_per_second) { 25174 $(this).attr('checked','checked'); 25175 } else {
25176 $(this).attr('checked',false); 25177 } 25178 }); 25179 $('#fancybox-content input[name="largest send"]:checked').trigger('change'); 25180 try { $('#fancybox-content select#Mobile-Volume-Drop-Down').select2('val', message_volume_thousands); } catch(err) { }; 25181 jq_can('#fancybox-content input[name="largest send"]:checked').trigger('change'); 25182 try { jq_can('#fancybox-content select#Mobile-Volume-Drop-Down').select2('val', message_volume_thousands); } catch(err) { }; 25183 25184 }); 25185 25186 25187 /************************* start shared editing warning modal **********************/ 25188 25189 if ($('.js-shared_editing_modal').length) { 25190 var set_editing_key = function() { 25191 $.ajax({ 25192 url: '/write_protections/write_protection_' + encodeURIComponent(location.pathname), 25193 type: 'PUT' 25194 }).done(function(data) { 25195 if (data.response_code == "conflict") { 25196 $('.js-shared_editing_modal').trigger('click'); 25197 } 25198 }); 25199 } 25200 25201 var delete_editing_key = function() { 25202 navigator.sendBeacon( '/write_protections/write_protection_' + encodeURIComponent(location.pathname) + '/expire'); 25203 } 25204 25205 set_editing_key(); 25206 25207 25208 $(window).on('beforeunload unload pagehide', function() { 25209 delete_editing_key(); 25210 }); 25211 } 25212 25213 /************************* end shared editing warning modal **********************/ 25214 25215 25216 25217 /* ======================= start lists.js ======================= */ 25218 /* note: must be after all the list items js is instantiated, like the click to remove from events in event campaigns, as this plugin removes the items from the DOM */ 25219 25220 if (typeof(List) !== 'undefined' && typeof(ListPagination) !== 'undefined' ) { 25221 25222 // Dashboard - Groups 25223 var listjs_options1 = { 25224 valueNames: [ 'listjs_name', 'button', 'group_ac_draft' ], 25225 page: 5, 25226 plugins: [ ListPagination({}) ] 25227 }; 25228 25229 if ($('.js-dashboard_groups ul li').length && !$('.js-dashboard_groups ul li.js-nothing_yet').length) { 25230 var userList1 = new List('dashboard_groups', listjs_options1); 25231 } 25232 25233 // Dashboard - All Actions 25234 var listjs_options2 = { 25235 item: '<li class="action_list_line js-action_list_line"></li>', 25236 valueNames: [ 'action_title', 'action_type_badge', 'group_ac_draft' ], 25237 page: 25, 25238 plugins: [ ListPagination({}) ] 25239 }; 25240 25241 if ($('.js-action_list_wrap li.js-action_list_line').length) { 25242 var userList2 = new List('action_list_wrap', listjs_options2); 25243 } 25244 25245 group_admin_list_init = function() { 25246 // Group Manage - Admin List 25247 var listjs_options3 = { 25248 valueNames: [ 'listjs_name' ], 25249 page: 50, 25250 plugins: [ ListPagination({}) ] 25251 }; 25252 25253 if ($('#tab_members-admins ul li').length) { 25254 var userList3 = new List('tab_members-admins', listjs_options3); 25255 } 25256 25257 // Group Manage - Member List 25258 var listjs_options3b = { 25259 valueNames: [ 'listjs_name' ], 25260 page: 50, 25261 plugins: [ ListPagination({}) ] 25262 }; 25263 25264 if ($('#tab_members-members ul li').length) { 25265 var userList3b = new List('tab_members-members', listjs_options3b); 25266 } 25267 25268 // Group Manage - Pending Member List 25269 var listjs_options4 = { 25270 valueNames: [ 'listjs_name' ], 25271 page: 50, 25272 plugins: [ ListPagination({}) ] 25273 }; 25274 25275 if ($('#tab_pending_members ul li').length) { 25276 var userList4 = new List('tab_pending_members', listjs_options4); 25277 } 25278 25279 // Group Manage - Pending Invites List 25280 var listjs_options4a = { 25281 valueNames: [ 'listjs_name' ], 25282 page: 50, 25283 plugins: [ ListPagination({}) ] 25284 }; 25285 25286 if ($('#tab_pending_invites ul li').length) { 25287 var userList4a = new List('tab_pending_invites', listjs_options4); 25288 } 25289 25290 if ($.isFunction($.fn.smoothScroll) ) { 25291 $('.js-scroll_to_invitations_wrap').click(function() { 25292 $.smoothScroll($('.js-invitations_wrap').offset().top - 40); 25293 }); 25294 } 25295 25296 // Toggle "Select multiple" mode 25297 $('.js-select_multiple_button').click(function() { 25298 $(this).hide(); 25299 $(this).parent().find('.js-cancel_select_multiple').show(); 25300 $(this).parent().find('.js-select_all_none').show(); 25301 $(this).parents('.js-nested_tab').find('.js-list_search_wrap').addClass('disabled').attr('disabled','disabled'); 25302 const tab = $(this).closest('[id^="tab_"]'); 25303 25304 tab.find('.js-show_on_multiselect').show(); 25305 tab.find('.js-hide_on_multiselect').hide(); 25306 }); 25307 $('.js-cancel_select_multiple').click(function () { 25308 $(this).hide(); 25309 $(this).parent().find('.js-select_multiple_button').show(); 25310 $(this).parent().find('.js-select_all_none').hide(); 25311 $(this).parents('.js-nested_tab').find('.js-list_search_wrap').removeClass('disabled').attr('disabled',false); 25312 const tab = $(this).closest('[id^="tab_"]'); 25313 25314 tab.find('.js-show_on_multiselect').hide(); 25315 tab.find('.js-hide_on_multiselect').show(); 25316 }) 25317 25318 // Handle select all/none 25319 $('.js-select_all_none input').change(function () { 25320 const tab = $(this).closest('[id^="tab_"]'); 25321 const isChecked = $(this).is(':checked'); 25322 tab.find('.js-select_user_checkbox').prop('checked', isChecked); 25323 if (isChecked) { 25324 tab.find('.js-enable_on_selection').removeClass('disabled'); 25325 } else { 25326 tab.find('.js-enable_on_selection').addClass('disabled'); 25327 } 25328 }); 25329 25330 // Handle checkbox selections and enable/disable action buttons
25331 $('.js-select_user_checkbox').change(function () { 25332 const tab = $(this).closest('[id^="tab_"]'); 25333 const numChecked = tab.find('.js-select_user_checkbox:checked').length; 25334 if (numChecked > 0) { 25335 tab.find('.js-enable_on_selection').removeClass('disabled'); 25336 } else { 25337 tab.find('.js-enable_on_selection').addClass('disabled'); 25338 } 25339 }) 25340 } 25341 group_admin_list_init(); 25342 25343 // Ladders Manage - Ladder 25344 25345 var listjs_options50 = { 25346 page: 25, 25347 plugins: [ ListPagination({}) ], 25348 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25349 }; 25350 25351 if ($('.js-ladders_all_tab').length && group_ladder_list_array.length) { 25352 //console.log('new all tab'); 25353 //console.log(group_ladder_list_array.length); 25354 var userList50 = new List('all_tab', listjs_options50, group_ladder_list_array); 25355 } 25356 25357 var listjs_options51 = { 25358 page: 25, 25359 plugins: [ ListPagination({}) ], 25360 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25361 }; 25362 25363 if ($('.js-ladders_draft_tab').length && draft_ladder_list_array.length) { 25364 //console.log('new draft tab'); 25365 var userList51 = new List('draft_tab', listjs_options51, draft_ladder_list_array); 25366 } 25367 25368 var listjs_options52 = { 25369 page: 25, 25370 plugins: [ ListPagination({}) ], 25371 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25372 }; 25373 25374 if ($('.js-ladders_active_tab').length && active_ladder_list_array.length) { 25375 var userList52 = new List('active_tab', listjs_options52, active_ladder_list_array); 25376 } 25377 25378 var listjs_options53 = { 25379 page: 25, 25380 plugins: [ ListPagination({}) ], 25381 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25382 }; 25383 25384 if ($('.js-ladders_pause_tab').length && pause_ladder_list_array.length) { 25385 var userList53 = new List('pause_tab', listjs_options53, pause_ladder_list_array); 25386 } 25387 25388 var listjs_options54 = { 25389 page: 25, 25390 plugins: [ ListPagination({}) ], 25391 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25392 }; 25393 25394 if ($('.js-ladders_closed_tab').length && closed_ladder_list_array.length) { 25395 var userList54= new List('closed_tab', listjs_options54, closed_ladder_list_array); 25396 } 25397 25398 var listjs_options55 = { 25399 page: 25, 25400 plugins: [ ListPagination({}) ], 25401 item: '<li class="ladder_list_line js-ladder_list_line list-item"><div class="li_wrapper list-item__wrapper-shim"></div></li>' 25402 }; 25403 25404 if ($('.js-ladders_stopped_tab').length && stopped_ladder_list_array.length) { 25405 var userList55= new List('stopped_tab', listjs_options55, stopped_ladder_list_array); 25406 } 25407 25408 25409 25410 // all actions 25411 25412 25413 25414 group_manage_actions_list_js_init = function() { 25415 var listjs_options6 = { 25416 valueNames: [ 'listjs_name', 'action_type_badge', 'group_ac_draft', 'group_ac_stats' ], 25417 page: 25, 25418 plugins: [ ListPagination({}) ], 25419 item: '<li class="no_icon list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25420 }; 25421 25422 if ($('.js-tab_actions').length) { 25423 if ($('.js-group_our_actions ul').length) { 25424 group_action_list_array = []; 25425 $.each(JSON.parse($('.js-group_action_list_array').val()), function(i, e) { 25426 group_action_list_array.push({ li_wrapper: e }); 25427 }); 25428 25429 if (group_action_list_array.length) { 25430 var userList6 = new List('group_our_actions', listjs_options6, group_action_list_array); 25431 var group_actions_fancy_function = function() { 25432 // console.log('start'); 25433 $(".js-group_our_actions ul .js-fancylink").each(function() { 25434 if (!$(this).data('fancybox')) { 25435 $(this).fancybox({ 25436 onComplete: function() { 25437 $('body').addClass('body_has_modal'); 25438 }, 25439 onClosed: function() { 25440 $('.js-file_delete_link').css('display','inline'); 25441 $('.js-edit_confirm_delete').css('display','none'); 25442 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
25443 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 25444 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 25445 $('body').removeClass('form_builder_edit'); 25446 }, 25447 margin: 15, 25448 hideOnOverlayClick: false 25449 }); 25450 } 25451 }); 25452 } 25453 25454 userList6.on('paged', group_actions_fancy_function); 25455 userList6.on('searchComplete', group_actions_fancy_function); 25456 group_actions_fancy_function(); 25457 } 25458 } 25459 25460 /* fill search box in groups list */ 25461 var url_parameter_search = getURLParameter('search'); 25462 var url_parameter_tab = getURLParameter('tab'); 25463 25464 if (url_parameter_tab) { 25465 setTimeout(function() { 25466 var tab = "#" + url_parameter_tab; 25467 window.location.hash = tab; 25468 if ($('.js-group_our_actions ul').length) { 25469 if (url_parameter_search) { 25470 $(tab).find('.js-list_search_wrap input').val(url_parameter_search); 25471 $(tab).find('.js-list_search_link').trigger('click'); 25472 userList6.search(url_parameter_search); 25473 } 25474 } 25475 25476 }, 0); 25477 25478 } 25479 } 25480 } 25481 25482 25483 group_manage_actions_list_js_init(); 25484 25485 // Group Manage - Emails 25486 var email_stats_loading_object = {}; 25487 25488 $("body").on('click', '.js-manage_email_expand', function() { 25489 if ($(this).closest(".js-email_list_line").find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").is(':visible')) { 25490 $(this).closest(".js-email_list_line").find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideUp(100); 25491 } else { 25492 var $el = $(this); 25493 25494 $el.closest(".js-email_list_line").find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideDown(100); 25495 25496 if (!$el.closest('.js-email_list_line').find('.email_draft').length && !$('.js-tab_syn_emails').length) { 25497 25498 var permalink = $(this).data('email-permalink'); 25499 var endpoint = "emails"; 25500 25501 if ($(this).hasClass('js-manage_email_expand_email_campaigns')) { 25502 endpoint = "email_campaigns"; 25503 } 25504 25505 email_stats_loading_object[permalink] = self.setInterval(function() { 25506 //console.log('fire'); 25507 $el.closest('.js-email_list_line').find('.stat_line span').fadeTo(100, 0.1).fadeTo(200, 1.0); 25508 }, 1000); 25509 25510 $.getJSON('/' + endpoint + '/' + permalink + '/stats_row', function(data) { 25511 25512 $el.closest('.js-email_list_line').find('.js-email_list_stats, .js-sms_list_stats').replaceWith(data.html); 25513 $el.closest('.js-email_list_line').find('.js-email_list_stats, .js-sms_list_stats').css('display','block'); 25514 25515 window.clearInterval(email_stats_loading_object[permalink]); 25516 }) 25517 .error(function() { 25518 //console.log('error'); 25519 window.clearInterval(email_stats_loading_object[permalink]); 25520 }); 25521 } 25522 25523 } 25524 }); 25525 25526 var email_mobile_list_date_heading_append = function(that) { 25527 //console.log(that); //that may not work for initial load but works thereafter? 25528 if (that) { 25529 //console.log(that); 25530 $(that.list).find('li').each(function() { 25531 var date = $(this).find('.js-date_line').data('date'); 25532 var prev_date = $(this).prev().find('.js-date_line').data('date'); 25533 //console.log(date); 25534 //console.log(prev_date); 25535 if (date != '' && typeof(date) != 'undefined') { 25536 if (prev_date == '' || typeof(prev_date) == 'undefined' || prev_date != date) { 25537 $(this).before('<li id="schedule-heading" class="email_list_line heading no_icon"><strong>' + date + '</strong></li>'); 25538 } 25539 } 25540 }); 25541 } 25542 } 25543 25544 group_manage_emails_list_js_init = function() { 25545 var listjs_options7 = { 25546 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25547 page: 25, 25548 plugins: [ ListPagination({}) ], 25549 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25550 }; 25551 25552 if ($('.js-emails_all_tab').length) { 25553 group_email_list_array = []; 25554 $.each(JSON.parse($('.js-group_email_list_array').val()).reverse(), function(i, e) { 25555 group_email_list_array.push({ li_wrapper: e, index: i }); 25556 }); 25557 25558 if (group_email_list_array.length) { 25559 var userList7 = new List('email_list_wrap_emails', listjs_options7, group_email_list_array); 25560 toggleSort($('.js-emails_all_tab .js-list_sort_link'), userList7, "index", false); 25561 25562 $('.js-emails_all_tab .js-list_sort_link').click(function() { 25563 toggleSort(this, userList7, "index", true); 25564 }); 25565 } 25566 } 25567 25568 var listjs_options56 = { 25569 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25570 page: 25, 25571 plugins: [ ListPagination({}) ], 25572 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25573 }; 25574 25575 if ($('.js-emails_draft_tab').length) { 25576 25577 group_email_list_array_draft = []; 25578 25579 $.each(JSON.parse($('.js-group_email_list_array_draft').val()), function(i, e) { 25580 group_email_list_array_draft.push({ li_wrapper: e }); 25581 }); 25582 25583 if (group_email_list_array_draft.length) { 25584 var userList56 = new List('email_list_wrap_emails_draft', listjs_options56, group_email_list_array_draft); 25585 } 25586 } 25587 25588 25589 25590 var listjs_options57 = { 25591 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25592 page: 25, 25593 plugins: [ ListPagination({}) ], 25594 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25595 }; 25596 25597 if ($('.js-emails_scheduled_tab').length){ 25598 25599 group_email_list_array_scheduled = []; 25600 25601 $.each(JSON.parse($('.js-group_email_list_array_scheduled').val()), function(i, e) { 25602 group_email_list_array_scheduled.push({ li_wrapper: e }); 25603 }); 25604 25605 if (group_email_list_array_scheduled.length) { 25606 var userList57 = new List('email_list_wrap_emails_scheduled', listjs_options57, group_email_list_array_scheduled); 25607 25608 userList57.on('paged', email_mobile_list_date_heading_append); 25609 userList57.on('searchComplete', email_mobile_list_date_heading_append); 25610 email_mobile_list_date_heading_append(userList57); 25611 } 25612 } 25613 25614 var listjs_options58 = { 25615 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25616 page: 25, 25617 plugins: [ ListPagination({}) ], 25618 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25619 }; 25620 25621 if ($('.js-emails_sent_tab').length) { 25622 25623 group_email_list_array_sent = []; 25624 25625 $.each(JSON.parse($('.js-group_email_list_array_sent').val()), function(i, e) { 25626 group_email_list_array_sent.push({ li_wrapper: e }); 25627 }); 25628 25629 if (group_email_list_array_sent.length) { 25630 var userList58 = new List('email_list_wrap_emails_sent', listjs_options58, group_email_list_array_sent); 25631 25632 userList58.on('paged', email_mobile_list_date_heading_append); 25633 userList58.on('searchComplete', email_mobile_list_date_heading_append); 25634 email_mobile_list_date_heading_append(userList58); 25635 } 25636 } 25637 25638 var listjs_options59 = { 25639 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25640 page: 25, 25641 plugins: [ ListPagination({}) ], 25642 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25643 }; 25644 25645 if ($('.js-emails_qad_tab').length) { 25646 25647 group_email_list_array_qad = []; 25648 25649 $.each(JSON.parse($('.js-group_email_list_array_qad').val()), function(i, e) { 25650 group_email_list_array_qad.push({ li_wrapper: e }); 25651 }); 25652 25653 if (group_email_list_array_qad.length) { 25654 var userList59 = new List('email_list_wrap_emails_qad', listjs_options59, group_email_list_array_qad); 25655 } 25656 } 25657 25658 // all actions 25659 var listjs_options7b = { 25660 page: 100, 25661 plugins: [ ListPagination({}) ], 25662 item: '<li class="list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25663 }; 25664 25665 if ($('.js-all_list_wrap .js-all_list').length) { 25666 var userList7b = new List('email_list_wrap_emails', listjs_options7b, all_action_list_array); 25667 } 25668 25669 25670 // Group Manage - Email campaigns 25671 var listjs_options7a = { 25672 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25673 page: 25, 25674 plugins: [ ListPagination({}) ], 25675 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25676 }; 25677 25678 if ($('.js-group_admin_page .js-email_list_wrap_email_campaigns .js-lined').length) { 25679 var userList7a = new List('email_list_wrap_email_campaigns', listjs_options7a); 25680 } 25681 25682 25683 var listjs_options7ind = { 25684 item: '<div class="email_list_line js-email_list_line list-item"></div>', 25685 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25686 page: 25, 25687 plugins: [ ListPagination({}) ] 25688 }; 25689 25690 if ($('.js-email_list_wrap_emails div.js-email_list_line').length) { 25691 var userList7ind = new List('email_list_wrap_emails', listjs_options7ind); 25692 } 25693 25694 // Group Manage - Emails 25695 var listjs_options7aa = { 25696 item: '<li class="email_list_line js-email_list_line list-item"></li>', 25697 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25698 page: 25, 25699 plugins: [ ListPagination({}) ] 25700 }; 25701 25702 if ($('.js-email_list_wrap_emails li.js-email_list_line').not('.js-email_list_wrap_group_manage.js-email_list_wrap_emails li.js-email_list_line') .length && !$('.js-tab_syn_emails').length) { 25703 var userList7aa = new List('email_list_wrap_emails', listjs_options7a); 25704 } 25705 25706 pinned_items_init(); 25707 25708 25709 } 25710
25711 group_manage_emails_list_js_init(); 25712 25713 var listjs_options7emailcampaign = { 25714 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>', 25715 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25716 page: 25, 25717 plugins: [ ListPagination({}) ] 25718 }; 25719 25720 if ($('.js-tab_campaign_emails .js-email_list_wrap_emails ul').length && email_campaigns_email_array.length) { 25721 var listjs_emailcampaign = new List('email_list_wrap_emails', listjs_options7emailcampaign, email_campaigns_email_array); 25722 25723 var email_campaigns_fancy_function = function() { 25724 $(".js-tab_campaign_emails .js-fancylink").each(function() { 25725 if (!$(this).data('fancybox')) { 25726 $(this).fancybox({ 25727 onComplete: function() { 25728 $('body').addClass('body_has_modal'); 25729 }, 25730 onClosed: function() { 25731 $('.js-file_delete_link').css('display','inline'); 25732 $('.js-edit_confirm_delete').css('display','none'); 25733 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 25734 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 25735 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 25736 $('body').removeClass('form_builder_edit'); 25737 }, 25738 margin: 15, 25739 hideOnOverlayClick: false 25740 }); 25741 } 25742 }); 25743 25744 /* email campaign stat tabs */ 25745 $('.js-email_campaign_single_overall_stats-link').click(function(){ 25746 $(this).toggleClass('active'); 25747 $(this).parent().siblings('li').find('.js-email_campaign_single_test_results-link').removeClass('active'); 25748 $(this).parents('.list-item').find('.js-email_campaign_stat_tab_wrap').find('#email_campaign_single_test_results').hide(); 25749 $(this).parents('.list-item').find('.js-email_campaign_stat_tab_wrap').find('#email_campaign_single_overall_stats').toggle(); 25750 }); 25751 $('.js-email_campaign_single_test_results-link').click(function(){ 25752 $(this).toggleClass('active'); 25753 $(this).parent().siblings('li').find('.js-email_campaign_single_overall_stats-link').removeClass('active'); 25754 $(this).parents('.list-item').find('.js-email_campaign_stat_tab_wrap').find('#email_campaign_single_overall_stats').hide(); 25755 $(this).parents('.list-item').find('.js-email_campaign_stat_tab_wrap').find('#email_campaign_single_test_results').toggle(); 25756 }); 25757 25758 } 25759 25760 listjs_emailcampaign.on('paged', email_campaigns_fancy_function); 25761 listjs_emailcampaign.on('searchComplete', email_campaigns_fancy_function); 25762 email_campaigns_fancy_function(); 25763 } 25764 25765 25766 25767 25768 25769 25770 25771 // Group Manage - Mobile 25772 group_manage_mobile_list_js_init = function() { 25773 var listjs_options7mob = { 25774 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25775 page: 25, 25776 plugins: [ ListPagination({}) ], 25777 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25778 }; 25779 25780 if ($('.js-group_admin_page .js-email_list_wrap_sms .js-lined').length) { 25781 if ($('.js-group_mobile_message_list_array').val()) { 25782 group_mobile_message_list_array = []; 25783 $.each(JSON.parse($('.js-group_mobile_message_list_array').val()).reverse(), function(i, e) { 25784 group_mobile_message_list_array.push({ li_wrapper: e, index: i }); 25785 }); 25786 25787 if (group_mobile_message_list_array.length) { 25788 var userList7mob = new List('email_list_wrap_sms', listjs_options7mob, group_mobile_message_list_array); 25789 toggleSort($('.js-group_admin_page .js-email_list_wrap_sms .js-list_sort_link'), userList7mob, "index", false); 25790 25791 $('.js-group_admin_page .js-email_list_wrap_sms .js-list_sort_link').click(function() { 25792 toggleSort(this, userList7mob, "index", true); 25793 }); 25794 } 25795 25796 25797 25798 } 25799 } 25800 25801 var listjs_options58 = { 25802 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25803 page: 25, 25804 plugins: [ ListPagination({}) ], 25805 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25806 }; 25807 25808 if ($('.js-mobile_draft_tab').length) { 25809 if ($('.js-group_mobile_message_list_array_draft').val()) { 25810 group_mobile_message_list_array_draft = []; 25811 $.each(JSON.parse($('.js-group_mobile_message_list_array_draft').val()), function(i, e) { 25812 group_mobile_message_list_array_draft.push({ li_wrapper: e }); 25813 }); 25814 if (group_mobile_message_list_array_draft.length) { 25815 var userList58 = new List('email_list_wrap_sms_draft', listjs_options58, group_mobile_message_list_array_draft); 25816 } 25817 } 25818 } 25819 25820 var listjs_options59 = { 25821 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25822 page: 25, 25823 plugins: [ ListPagination({}) ], 25824 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25825 }; 25826 25827 if ($('.js-mobile_scheduled_tab').length) { 25828 if ($('.js-group_mobile_message_list_array_scheduled').val()) { 25829 group_mobile_message_list_array_scheduled = []; 25830 $.each(JSON.parse($('.js-group_mobile_message_list_array_scheduled').val()), function(i, e) { 25831 group_mobile_message_list_array_scheduled.push({ li_wrapper: e }); 25832 }); 25833 25834 if (group_mobile_message_list_array_scheduled.length) { 25835 var userList59 = new List('email_list_wrap_sms_scheduled', listjs_options59, group_mobile_message_list_array_scheduled); 25836 25837 userList59.on('paged', email_mobile_list_date_heading_append); 25838 userList59.on('searchComplete', email_mobile_list_date_heading_append); 25839 email_mobile_list_date_heading_append(userList59); 25840 } 25841 } 25842 } 25843 25844 var listjs_options60 = { 25845 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date', 'small-line' ], 25846 page: 25, 25847 plugins: [ ListPagination({}) ], 25848 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25849 }; 25850 25851 if ($('.js-mobile_sent_tab').length) { 25852 if ($('.js-group_mobile_message_list_array_sent').val()) { 25853 group_mobile_message_list_array_sent = []; 25854 $.each(JSON.parse($('.js-group_mobile_message_list_array_sent').val()), function(i, e) { 25855 group_mobile_message_list_array_sent.push({ li_wrapper: e }); 25856 }); 25857 25858 if (group_mobile_message_list_array_sent.length) { 25859 var userList60 = new List('email_list_wrap_sms_sent', listjs_options60, group_mobile_message_list_array_sent); 25860 25861 userList60.on('paged', email_mobile_list_date_heading_append); 25862 userList60.on('searchComplete', email_mobile_list_date_heading_append); 25863 email_mobile_list_date_heading_append(userList60); 25864 } 25865 } 25866 } 25867 25868 pinned_items_init(); 25869 } 25870
25871 group_manage_mobile_list_js_init(); 25872 25873 25874 25875 var mobile_stats_loading_object = {}; 25876 25877 $("body").on('click', '.js-manage_mobile_expand', function() { 25878 if ($(this).parent().parent().parent().find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").is(':visible')) { 25879 $(this).parent().parent().parent().find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideUp(100); 25880 } else { 25881 var $el = $(this); 25882 25883 $el.parent().parent().parent().find(".js-email_list_stats, .js-action_list_stats, .js-sms_list_stats").slideDown(100); 25884 25885 if (!$el.parents('.js-email_list_line').find('.email_draft').length && !$('.js-tab_syn_emails').length) { 25886 25887 var permalink = $(this).data('email-permalink'); 25888 25889 25890 mobile_stats_loading_object[permalink] = self.setInterval(function() { 25891 //console.log('fire'); 25892 $el.parents('.js-email_list_line').find('.stat_line span').fadeTo(100, 0.1).fadeTo(200, 1.0); 25893 }, 1000); 25894 25895 $.getJSON('/mobile_messages/' + permalink + '/stats_row', function(data) { 25896 //console.log(data); 25897 //console.log($el.parents('.js-email_list_line').find('.js-email_list_stats')); 25898 25899 $el.parents('.js-email_list_line').find('.js-email_list_stats, .js-sms_list_stats').replaceWith(data.html); 25900 $el.parents('.js-email_list_line').find('.js-email_list_stats, .js-sms_list_stats').css('display','block'); 25901 25902 window.clearInterval(mobile_stats_loading_object[permalink]); 25903 }) 25904 .error(function() { 25905 //console.log('error'); 25906 window.clearInterval(mobile_stats_loading_object[permalink]); 25907 }); 25908 } 25909 25910 } 25911 }); 25912 25913 25914 25915 // Group Manage - Reports
25916 group_manage_report_list_js_init = function() { 25917 var listjs_options8a = { 25918 item: '<li class="email_list_line js-email_list_line list-item"></li>', 25919 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date' ], 25920 page: 25, 25921 plugins: [ ListPagination({}) ] 25922 }; 25923 25924 if ($('.js-manage_reports_list li.js-email_list_line').length) { 25925 var userList8a = new List('manage_reports_list', listjs_options8a); 25926 } 25927 25928 // Group Manage - Reports 25929 var listjs_options8 = { 25930 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date' ], 25931 page: 25, 25932 plugins: [ ListPagination({}) ], 25933 item: '<li class="email_list_line js-email_list_line list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 25934 }; 25935 25936 if ($('.js-group_admin_page .js-manage_reports_list .js-lined').length) { 25937 group_report_list_array = []; 25938 $.each(JSON.parse($('.js-reports').val()), function(i, e) { 25939 group_report_list_array.push({ li_wrapper: e }); 25940 }); 25941 var userList8 = new List('manage_reports_list', listjs_options8, group_report_list_array); 25942 } 25943 25944 // Pinned Reports 25945 pinned_items_init(); 25946 } 25947
25948 group_manage_report_list_js_init(); 25949 25950 // Group Manage - Reports Individual 25951 var listjs_options8a = { 25952 item: '<div class="email_list_line js-email_list_line"></div>', 25953 valueNames: [ 'email_id', 'email_title', 'email_draft', 'manage_email_date' ], 25954 page: 25, 25955 plugins: [ ListPagination({}) ] 25956 }; 25957 25958 if ($('.js-manage_reports_list div.js-email_list_line').length) { 25959 var userList8a = new List('manage_reports_list', listjs_options8a); 25960 } 25961 25962 // Event Campaigns Manage - Manage Events 25963 var listjs_options9 = { 25964 valueNames: [ 'listjs_name','listjs_location','listjs_host','group_ac_draft', 'event_campaign_draft', 'event_campaign_private', 'event_campaign_status' ], 25965 page: 10, 25966 plugins: [ ListPagination({}) ] 25967 }; 25968 25969 if ($('.js-manage_campaign_events_list ul li').length) { 25970 var userList9 = new List('manage_campaign_events_list', listjs_options9); 25971 } 25972 25973 var listjs_options9pending = { 25974 valueNames: [ 'listjs_name','listjs_location','listjs_host','group_ac_draft', 'event_campaign_draft', 'event_campaign_private', 'event_campaign_status' ], 25975 page: 10, 25976 plugins: [ ListPagination({}) ] 25977 }; 25978 25979 if ($('#manage_campaign_events_list_pending ul li').length) { 25980 var userList9pending = new List('manage_campaign_events_list_pending', listjs_options9pending); 25981 } 25982 25983 var listjs_options9draft = { 25984 valueNames: [ 'listjs_name','listjs_location','listjs_host','group_ac_draft', 'event_campaign_draft', 'event_campaign_private', 'event_campaign_status' ], 25985 page: 10, 25986 plugins: [ ListPagination({}) ] 25987 }; 25988 25989 if ($('#manage_campaign_events_list_draft ul li').length) { 25990 var userList9draft = new List('manage_campaign_events_list_draft', listjs_options9draft); 25991 } 25992 25993 // Event Campaigns Show/List 25994 var listjs_options9a = { 25995 valueNames: [ 'listjs_name','listjs_location','listjs_host','group_ac_draft', 'event_campaign_draft', 'event_campaign_private', 'event_campaign_status' ], 25996 page: 10, 25997 plugins: [ ListPagination({}) ] 25998 }; 25999 26000 if ($('.js-event_campaign_list_wrap ul li').length) { 26001 var userList9a = new List('event_campaign_list_wrap', listjs_options9a); 26002 } 26003 26004 // Event Campaigns Breadcrumb Dropdowns 26005 $(document).on('click', '.js-step_toggle_dropdown', function() { 26006 var $stepMenu = $(this).find('.js-step_tab_menu'); 26007 26008 $stepMenu.toggle(); 26009 }); 26010 26011 $(document).on('mouseup', function(event) { 26012 var $target = $(event.target); 26013 26014 $('.js-step_tab_menu').not($target.closest('.js-step_tab_menu')).hide(); 26015 }); 26016 26017 $(document).on('keydown', function(event) { 26018 if (event.key === 'Escape') { 26019 $('.js-step_tab_menu').hide(); 26020 } 26021 }); 26022 26023 // Event Campaigns Toggle Sidebar/Fullwidth 26024 // @jason/backend, curious if this could be achieved with more ruby ifs on the view itself? 26025 function toggleSidebar() { 26026 var progressIndicator = $('.action_status_tracker').length > 0; 26027 var hostEvent = $('.host_event_link_wrap').length > 0; 26028 var customHtml = $('#custom_html').length > 0; 26029 26030 if (!progressIndicator && !hostEvent && !customHtml) { 26031 // make main col 100% 26032 $('.js-main_col').addClass('hundred'); 26033 // remove sidebar from page 26034 $('.js-sidebar').remove(); 26035 } 26036 } 26037 26038 if ($('body').hasClass('event_campaign_page')) { 26039 toggleSidebar(); 26040 } 26041 26042 26043 26044 // Website Tracking 26045 var listjs_options10 = { 26046 valueNames: [ 'listjs_name', ], 26047 page: 10, 26048 plugins: [ ListPagination({}) ], 26049 item: '<li class=""><div class="li_wrapper"></div></li>' 26050 }; 26051 26052 if ($('.js-website_tracking ul').length) { 26053 var userList10 = new List('website_tracking', listjs_options10, statistics_website_array); 26054 } 26055 26056 // Referral Tracking 26057 var listjs_options11 = { 26058 valueNames: [ 'listjs_name', ], 26059 page: 10, 26060 plugins: [ ListPagination({}) ], 26061 item: '<li class=""><div class="li_wrapper"></div></li>' 26062 }; 26063 26064 if ($('.js-referral_tracking ul').length) { 26065 var userList11 = new List('referral_tracking', listjs_options11, statistics_referrer_array); 26066 } 26067 26068 // Source Tracking 26069 var listjs_options12 = { 26070 valueNames: [ 'listjs_name', ], 26071 page: 10, 26072 plugins: [ ListPagination({}) ], 26073 item: '<li class=""><div class="li_wrapper"></div></li>' 26074 }; 26075 26076 if ($('.js-source_tracking ul').length) { 26077 var userList12 = new List('source_tracking', listjs_options12, statistics_source_array); 26078 } 26079 26080 // Recipient Tracking 26081 var listjs_options12b = { 26082 valueNames: [ 'listjs_name', ], 26083 page: 10, 26084 plugins: [ ListPagination({}) ] 26085 }; 26086 26087 if ($('.js-recipient_tracking ul li').length) { 26088 var userList12b = new List('recipient_tracking', listjs_options12b); 26089 } 26090 26091 // Groups - Our Campaigns 26092 var listjs_options13 = { 26093 valueNames: [ 'listjs_name', ], 26094 page: 4, 26095 plugins: [ ListPagination({}) ] 26096 }; 26097 26098 if ($('.js-our_campaigns ul li').length && !$('#create_action_page').length) { 26099 var userList13 = new List('our_campaigns', listjs_options13); 26100 } 26101 26102 var listjs_options13a = { 26103 valueNames: [ 'listjs_name', ], 26104 page: 4, 26105 plugins: [ ListPagination({}) ] 26106 }; 26107 26108 if ($('.js-group_our_campaigns ul li').length && !$('#create_action_page').length) { 26109 var userList13a = new List('group_our_campaigns', listjs_options13a); 26110 } 26111 26112 // Groups - Our Actions 26113 var listjs_options14 = { 26114 valueNames: [ 'listjs_name', ], 26115 page: 4, 26116 plugins: [ ListPagination({}) ], 26117 item: '<li class="our_single_action_campaign js-our_single_action_campaign"><div class="li_wrapper"></div></li>' 26118 }; 26119 26120 if ($('.js-our_actions ul.js-group_show_actions_list').length) { 26121 var userList14 = new List('our_actions', listjs_options14, group_public_action_list_array); 26122 } 26123 26124 // Groups - Our Actions Create 26125 var listjs_options14create = { 26126 valueNames: [ 'listjs_name', ], 26127 page: 4, 26128 plugins: [ ListPagination({}) ], 26129 item: '<li class="our_single_action_campaign js-our_single_action_campaign col3of12"><div class="li_wrapper"></div></li>' 26130 }; 26131 26132 if ($('.js-our_actions ul.js-group_create_actions_list').length) { 26133 var userList14 = new List('our_actions', listjs_options14create, group_public_action_list_array_create); 26134 } 26135 26136 // Control Panel - New User Accounts 26137 var listjs_options15 = { 26138 valueNames: [ 'listjs_name', ], 26139 page: 25, 26140 plugins: [ ListPagination({}) ] 26141 }; 26142 26143 if ($('.js-user_accounts_list ul li').length) { 26144 var userList15 = new List('user_accounts_list', listjs_options15); 26145 } 26146 26147 // Control Panel - Top 50 Users 26148 var listjs_options16 = { 26149 valueNames: [ 'listjs_name', ], 26150 page: 25, 26151 plugins: [ ListPagination({}) ] 26152 }; 26153 26154 if ($('.js-user_accounts_top_list ul li').length) { 26155 var userList16 = new List('user_accounts_top_list', listjs_options16); 26156 } 26157 26158 // Control Panel - Latest 50 Users to Email 26159 var listjs_options17 = { 26160 valueNames: [ 'listjs_name', ], 26161 page: 25, 26162 plugins: [ ListPagination({}) ] 26163 }; 26164 26165 if ($('.js-user_accounts_email_list ul li').length) { 26166 var userList17 = new List('user_accounts_email_list', listjs_options17); 26167 } 26168 26169 // Control Panel - Groups List 26170 var listjs_options18 = { 26171 valueNames: [ 'listjs_name', ], 26172 page: 25, 26173 plugins: [ ListPagination({}) ] 26174 }; 26175 26176 if ($('.js-groups_list ul li').length) { 26177 var userList18 = new List('groups_list', listjs_options18); 26178 } 26179 26180 // Control Panel - Top Groups List 26181 var listjs_options19 = { 26182 valueNames: [ 'listjs_name', ], 26183 page: 25, 26184 plugins: [ ListPagination({}) ] 26185 }; 26186 26187 if ($('.js-groups_top_list ul li').length) { 26188 var userList19 = new List('groups_top_list', listjs_options19); 26189 } 26190 26191 // Control Panel - Latest Email Groups List 26192 var listjs_options20 = { 26193 valueNames: [ 'listjs_name', ], 26194 page: 25, 26195 plugins: [ ListPagination({}) ] 26196 }; 26197 26198 if ($('.js-groups_email_list ul li').length) { 26199 var userList20 = new List('groups_email_list', listjs_options20); 26200 } 26201 26202 // Control Panel - Actions List 26203 var listjs_options21 = { 26204 valueNames: [ 'listjs_name', ], 26205 page: 25, 26206 plugins: [ ListPagination({}) ] 26207 }; 26208 26209 if ($('.js-actions_list ul li').length) { 26210 var userList21 = new List('actions_list', listjs_options21); 26211 } 26212 26213 // Control Panel - Top 50 Actions 26214 var listjs_options22 = { 26215 valueNames: [ 'listjs_name', ], 26216 page: 25, 26217 plugins: [ ListPagination({}) ] 26218 }; 26219 26220 if ($('.js-actions_top_list ul li').length) { 26221 var userList22 = new List('actions_top_list', listjs_options22); 26222 } 26223 26224 // Control Panel - Latest 50 Actions With More Than 100 Action Takers 26225 var listjs_options23 = { 26226 valueNames: [ 'listjs_name', ], 26227 page: 25, 26228 plugins: [ ListPagination({}) ] 26229 }; 26230 26231 if ($('.js-actions_100_list ul li').length) { 26232 var userList23 = new List('actions_100_list', listjs_options23); 26233 } 26234 26235 // Network - custom field questions 26236 var listjs_options24 = { 26237 valueNames: [ 'network_field_type', 'listjs_name', 'send_child_button' ], 26238 page: 25, 26239 plugins: [ ListPagination({}) ] 26240 }; 26241 26242 if ($('.js-network_custom_fields ul li').length) { 26243 var userList24 = new List('network_custom_fields', listjs_options24); 26244 var questions_function = function() { 26245 //console.log('start'); 26246 $('.js-custom_field_autocomplete').devbridgeAutocomplete('dispose'); 26247 $('.js-custom_field_autocomplete').devbridgeAutocomplete({ 26248 serviceUrl: '/groups/' + $('.js-group_id').data('group_id') + '/field_search' 26249 }); 26250 } 26251 userList24.on('paged', questions_function); 26252 userList24.on('searchComplete', questions_function); 26253 questions_function(); 26254 } 26255 26256 // Letter Target Reports 26257 var listjs_options25 = { 26258 valueNames: [ 'listjs_name', 'generic_badge' ], 26259 page: 25, 26260 plugins: [ ListPagination({}) ], 26261 item: '<li class="clearfix list-item"><div class="li_wrapper list-item__wrapper"></div></li>' 26262 }; 26263 26264 if ($('.js-letter_target_delivery_list').length) { 26265 // console.log(letter_target_delivery_array); 26266 var userList25 = new List('target_report', listjs_options25, letter_target_delivery_array); 26267 } 26268 26269 // User Search 26270 var listjs_options26 = { 26271 valueNames: [ 'listjs_name', 'listjs_email', 'listjs_zip', 'listjs_zip' ], 26272 page: 10, 26273 plugins: [ ListPagination({}) ] 26274 }; 26275 26276 if ($('.js-user_search_results .js-single_user_result').length) { 26277 var userList26 = new List('user_search_results', listjs_options26); 26278 } 26279 26280 // Canned Responses 26281 var listjs_options_canned_responses = { 26282 valueNames: [ 'listjs_name'], 26283 page: 10, 26284 plugins: [ ListPagination({}) ] 26285 }; 26286 26287 if ($('.js-manage_saved_response_wrap').length) { 26288 var userListCannedResponses = new List('manage_tags_wrap', listjs_options_canned_responses); 26289 } 26290 26291 26292 26293 // User Mobile Message Convo/History - toggle active convo 26294 $('.js-toggle_active_convo').click(function(e) { 26295 var $history = $('.js-tab_sms-history'); 26296 var $convo = $('.js-tab_sms-convo'); 26297 26298 e.preventDefault(); 26299 26300 $history.toggleClass('not-active'); 26301 $convo.toggleClass('active'); 26302 26303 if ($history.hasClass('not-active')) { 26304 $(this).text(an_javascript_translation.back_to_message_history); 26305 $(this).prepend('<i class="far fa-arrow-left"></i> '); 26306 } else { 26307 $(this).text(an_javascript_translation.view_active_conversation); 26308 $(this).prepend('<i class="far fa-comments"></i> '); 26309 } 26310 }); 26311 26312 26313 26314 26315 26316 // User Notes 26317 var listjs_options30 = { 26318 valueNames: [ 'listjs_content', 'commentmetadata' ], 26319 page: 5, 26320 plugins: [ ListPagination({}) ] 26321 }; 26322 26323 if ($('.js-user_view_notes ul li').length) { 26324 var userList30 = new List('user_view_notes', listjs_options30); 26325 } 26326 26327 26328 26329 26330 26331 var listjs_options33 = { 26332 valueNames: [ 'listjs_name' ], 26333 page: 5, 26334 plugins: [ ListPagination({}) ] 26335 }; 26336 26337 if ($('.js-user_view_subscriptions ul li').length) { 26338 var userList33 = new List('user_view_subscriptions', listjs_options33); 26339 } 26340 26341 var listjs_options33a = { 26342 valueNames: [ 'listjs_name' ], 26343 page: 5, 26344 plugins: [ ListPagination({}) ] 26345 }; 26346 26347 if ($('.js-user_view_sms_subscriptions ul li').length) { 26348 var userList33a = new List('user_view_sms_subscriptions', listjs_options33a); 26349 } 26350 26351 var listjs_options34_collections = { 26352 valueNames: [ 'listjs_name' ], 26353 page: 25, 26354 plugins: [ ListPagination({}) ], 26355 }; 26356 26357 if ($('.js-manage_collections_wrap ul li').length) { 26358 var userList34 = new List('manage_collections_wrap', listjs_options34_collections); 26359 } 26360 26361 // Manage shortlinks 26362 if ($('.js-manage_shortlinks_wrap ul li').length) { 26363 var userList34 = new List('manage_wrappers_wrap', listjs_options34_collections); 26364 } 26365 26366 var listjs_options34 = { 26367 valueNames: [ 'li_wrapper' ], 26368 page: 25, 26369 plugins: [ ListPagination({}) ], 26370 item: `<li class="tag list-item"><div class="li_wrapper list-item__wrapper"></div></li>` 26371 }; 26372 26373 if (typeof(tags_array) != 'undefined') { 26374 var userList34 = new List('manage_tags_wrap', listjs_options34, tags_array); 26375 var tags_fancy_function = function() { 26376 $(".js-manage_tags_wrap ul .js-fancylink").each(function() { 26377 if (!$(this).data('fancybox')) { 26378 $(this).fancybox({ 26379 onComplete: function() { 26380 $('body').addClass('body_has_modal'); 26381 }, 26382 onClosed: function() { 26383 $('.js-file_delete_link').css('display','inline'); 26384 $('.js-edit_confirm_delete').css('display','none'); 26385 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
26386 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 26387 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 26388 $('body').removeClass('form_builder_edit'); 26389 }, 26390 margin: 15, 26391 hideOnOverlayClick: false 26392 }); 26393 } 26394 }); 26395 canValidate(); 26396 } 26397 26398 userList34.on('paged', tags_fancy_function); 26399 userList34.on('searchComplete', tags_fancy_function); 26400 tags_fancy_function(); 26401 26402 $('.js-field_list_massops_sort_toggle').click(function() { 26403 toggleSort(this, userList34, $('.js-field_list_massops_sort_dropdown').val(), true); 26404 }); 26405 26406 $('.js-field_list_massops_sort_dropdown').change(function() { 26407 toggleSort($('.js-field_list_massops_sort_toggle'), userList34, $(this).val(), false); 26408 }); 26409 } 26410 26411 var listjs_options35 = { 26412 valueNames: [ 'listjs_name' ], 26413 page: 25, 26414 plugins: [ ListPagination({}) ] 26415 }; 26416 26417 if ($('.js-manage_wrappers_wrap ul li').length && !$('.js-ladders-manage-headline').length) { 26418 var userList35 = new List('manage_wrappers_wrap', listjs_options35); 26419 } 26420 26421 var listjs_options35_layout = { 26422 valueNames: [ 'listjs_name' ], 26423 page: 25, 26424 plugins: [ ListPagination({}) ] 26425 }; 26426 26427 if ($('.js-manage_email_layout ul li').length) { 26428 var userList35_layout = new List('manage_email_layout', listjs_options35_layout); 26429 } 26430 26431 var listjs_options35_wrappers = { 26432 valueNames: [ 'listjs_name' ], 26433 page: 25, 26434 plugins: [ ListPagination({}) ] 26435 }; 26436 26437 if ($('.js-manage_email_wrappers ul li').length) { 26438 var userList35_wrappers = new List('manage_email_wrappers', listjs_options35_wrappers); 26439 } 26440 26441 var listjs_options35uploads = { 26442 valueNames: [ 'listjs_name' ], 26443 page: 25, 26444 plugins: [ ListPagination({}) ], 26445 item: `<li class="upload_list_item"><div class="li_wrapper"></div></li>` 26446 }; 26447 26448 if ($('.js-manage_uploads_wrap ul').not('.js-list_uploads_empty, .js-list_search_wrap ul').length) { 26449 var userList35uploads = new List('manage_uploads_wrap', listjs_options35uploads, uploads_index_array); 26450 var upload_fancy_function = function() { 26451 $(".js-manage_uploads_wrap ul .js-fancylink").each(function() { 26452 if (!$(this).data('fancybox')) { 26453 $(this).fancybox({ 26454 onComplete: function() { 26455 $('body').addClass('body_has_modal'); 26456 }, 26457 onClosed: function() { 26458 $('.js-file_delete_link').css('display','inline'); 26459 $('.js-edit_confirm_delete').css('display','none'); 26460 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide(); 26461 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 26462 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 26463 $('body').removeClass('form_builder_edit'); 26464 }, 26465 margin: 15, 26466 hideOnOverlayClick: false 26467 }); 26468 } 26469 }); 26470 } 26471 26472 userList35uploads.on('paged', upload_fancy_function); 26473 userList35uploads.on('searchComplete', upload_fancy_function); 26474 upload_fancy_function(); 26475 } 26476 26477 // live updating upload counts (only works on the first page of uploads, but I think that's fine) 26478 if ($('.js-upload_browser_wrap div.js-upload_active-true').length) { 26479 //var interval = {}; 26480 var interval = window.setInterval(function() { 26481 if ($('.js-upload_browser_wrap div.js-upload_active-true').length) { 26482 var list = $('select.js-file-file_repository_switcher').val() 26483 $.getJSON(list + '/poll', function(data) { 26484 $('.js-upload_browser_wrap div.js-upload_active-true').removeClass('upload_active-true js-upload_active-true').addClass('upload_active-false js-upload_active-false'); 26485 $(data).each(function() { 26486 $this = $('div[data-list-id="' + this.id + '"]'); 26487 26488 if ($this.hasClass('js-upload_unsub')) { 26489 $this.find('.js-file_users').html(this.count + ' ' + an_javascript_translation.unsubs); 26490 } else { 26491 $this.find('.js-file_users').html(this.count + ' ' + an_javascript_translation.activists); 26492 $this.find('.js-file_new_act').html(this.new_count + ' ' + an_javascript_translation.new_activists); 26493 } 26494 26495 $this.removeClass('upload_active-false js-upload_active-false').addClass('upload_active-true js-upload_active-true'); 26496 }); 26497 }); 26498 } else { 26499 window.clearInterval(interval); 26500 } 26501 26502 }, 10000); 26503 } 26504 26505 var listjs_options_upload_letter_target_wrap = { 26506 valueNames: [ 'listjs_name' ], 26507 page: 25, 26508 plugins: [ ListPagination({}) ] 26509 }; 26510 26511 if ($('.js-upload_letter_target_wrap ul li').length) { 26512 var userList35 = new List('upload_letter_target_wrap', listjs_options_upload_letter_target_wrap); 26513 } 26514 26515 var listjs_options_keywords = { 26516 valueNames: [ 'listjs_name' ], 26517 page: 25, 26518 plugins: [ ListPagination({}) ] 26519 }; 26520 26521 if ($('.js-group-keywords-wrap ul li').length) { 26522 var userList35_keywords = new List('group-keywords-wrap', listjs_options_keywords); 26523 } 26524 26525 var listjs_options_keywords_shared = { 26526 valueNames: [ 'listjs_name' ], 26527 page: 25, 26528 plugins: [ ListPagination({}) ] 26529 }; 26530 26531 if ($('.js-shared-keywords-wrap ul li').length) { 26532 var userList35_keywords_shared = new List('shared-keywords-wrap', listjs_options_keywords_shared); 26533 } 26534 26535 $(".js-shared-keywords").on('click', function(){ 26536 $(".shared-keywords-wrap").css('display', 'block') 26537 $(".group-keywords-wrap").css('display', 'none') 26538 }); 26539 26540 $(".js-group-keywords").on('click', function(){ 26541 $(".group-keywords-wrap").css('display', 'block') 26542 $(".shared-keywords-wrap").css('display', 'none') 26543 }); 26544 26545 var listjs_options_datasets = { 26546 valueNames: [ 'listjs_name' ], 26547 page: 25, 26548 plugins: [ ListPagination({}) ] 26549 }; 26550 26551 if ($('.js-manage_datasets_wrap ul li').length) { 26552 var userListDataset = new List('manage_uploads_wrap', listjs_options_datasets); 26553 var datasets_fancy_function = function() { 26554 $(".js-manage_datasets_wrap ul .js-fancylink").each(function() { 26555 if (!$(this).data('fancybox')) { 26556 $(this).fancybox({ 26557 onComplete: function() { 26558 $('body').addClass('body_has_modal'); 26559 }, 26560 onClosed: function() { 26561 $('.js-file_delete_link').css('display','inline'); 26562 $('.js-edit_confirm_delete').css('display','none'); 26563 $('.js-add_tags_fly, .js-add_custom_fields_fly').hide();
26564 $('.js-has_add_tags_fly_button, .js-has_add_custom_fields_fly_button').show(); 26565 $('.js-tags_fly_value, .js-custom_fields_fly_value').val(''); 26566 $('body').removeClass('form_builder_edit'); 26567 }, 26568 margin: 15, 26569 hideOnOverlayClick: false 26570 }); 26571 } 26572 }); 26573 } 26574 26575 userListDataset.on('paged', datasets_fancy_function); 26576 userListDataset.on('searchComplete', datasets_fancy_function); 26577 datasets_fancy_function(); 26578 } 26579 26580 var listjs_options36 = { 26581 valueNames: [ 'listjs_name' ], 26582 page: 5, 26583 plugins: [ ListPagination({}) ] 26584 }; 26585 26586 if ($('#hidden_groups ul li').length) { 26587 var userList36 = new List('hidden_groups', listjs_options36); 26588 } 26589 26590 var listjs_options37 = { 26591 valueNames: [ 'listjs_name' ], 26592 page: 5, 26593 plugins: [ ListPagination({}) ] 26594 }; 26595 26596 if ($('#hidden_emails ul li').length) { 26597 var userList37 = new List('hidden_emails', listjs_options37); 26598 } 26599 26600 var listjs_options38 = { 26601 valueNames: [ 'listjs_name' ], 26602 page: 5, 26603 plugins: [ ListPagination({}) ] 26604 }; 26605 26606 if ($('#hidden_actions ul li').length) { 26607 var userList38 = new List('hidden_actions', listjs_options38); 26608 } 26609 26610 var listjs_options39 = { 26611 valueNames: [ 'listjs_name' ], 26612 page: 5, 26613 plugins: [ ListPagination({}) ] 26614 }; 26615 26616 if ($('#hidden_reports ul li').length) { 26617 var userList39 = new List('hidden_reports', listjs_options39); 26618 } 26619 26620 var listjs_options40 = { 26621 valueNames: [ 'listjs_name' ], 26622 page: 5, 26623 plugins: [ ListPagination({}) ] 26624 }; 26625 26626 if ($('.js-hidden_uploads ul li').length) { 26627 var userList40 = new List('hidden_uploads', listjs_options40); 26628 } 26629 26630 var listjs_options40_custom = { 26631 valueNames: [ 'listjs_name' ], 26632 page: 5, 26633 plugins: [ ListPagination({}) ] 26634 }; 26635 26636 if ($('.js-hidden_custom_fields ul li').length) { 26637 var userList40custom = new List('hidden_custom_fields', listjs_options40_custom); 26638 } 26639 26640 var listjs_options40_tags = { 26641 valueNames: [ 'listjs_name' ], 26642 page: 5, 26643 plugins: [ ListPagination({}) ] 26644 }; 26645 26646 if ($('.js-hidden_tags ul li').length) { 26647 var userList40tags = new List('hidden_tags', listjs_options40_tags); 26648 } 26649 26650 var listjs_options40_questions = { 26651 valueNames: [ 'listjs_name' ], 26652 page: 5, 26653 plugins: [ ListPagination({}) ] 26654 }; 26655 26656 if ($('.js-hidden_questions ul li').length) { 26657 var userList40questions = new List('hidden_questions', listjs_options40_questions); 26658 } 26659 26660 var listjs_options40_ladders = { 26661 valueNames: [ 'listjs_name' ], 26662 page: 5, 26663 plugins: [ ListPagination({}) ] 26664 }; 26665 26666 if ($('.js-hidden_ladders ul li').length) { 26667 var listjs_options40_ladders = new List('hidden_ladders', listjs_options40_ladders); 26668 } 26669 26670 var listjs_options40_mobile_messages = { 26671 valueNames: [ 'listjs_name' ], 26672 page: 5, 26673 plugins: [ ListPagination({}) ] 26674 }; 26675 26676 if ($('.js-hidden_mobile_messages ul li').length) { 26677 var listjs_options40_mobile_messages = new List('hidden_mobile_messages', listjs_options40_mobile_messages); 26678 } 26679 26680 var listjs_options40_email_campaigns = { 26681 valueNames: [ 'listjs_name' ], 26682 page: 5, 26683 plugins: [ ListPagination({}) ] 26684 }; 26685 26686 if ($('.js-hidden_email_campaigns ul li').length) { 26687 var listjs_options40_email_campaigns = new List('hidden_email_campaigns', listjs_options40_email_campaigns); 26688 } 26689 26690 var listjs_options40_email_wrappers = { 26691 valueNames: [ 'listjs_name' ], 26692 page: 5, 26693 plugins: [ ListPagination({}) ] 26694 }; 26695 26696 if ($('.js-hidden_email_wrappers ul li').length) { 26697 var listjs_options40_email_wrappers = new List('hidden_email_wrappers', listjs_options40_email_wrappers); 26698 } 26699 26700 var listjs_options40_email_snippets = { 26701 valueNames: [ 'listjs_name' ], 26702 page: 5, 26703 plugins: [ ListPagination({}) ] 26704 }; 26705 26706 if ($('.js-hidden_email_snippets ul li').length) { 26707 var listjs_options40_email_snippets = new List('hidden_email_snippets', listjs_options40_email_snippets); 26708 } 26709 26710 var listjs_options40_mobile_snippets = { 26711 valueNames: [ 'listjs_name' ], 26712 page: 5, 26713 plugins: [ ListPagination({}) ] 26714 }; 26715 26716 if ($('.js-hidden_mobile_snippets ul li').length) { 26717 var listjs_options40_mobile_snippets = new List('hidden_mobile_snippets', listjs_options40_mobile_snippets); 26718 } 26719 26720 var listjs_options40_email_layouts = { 26721 valueNames: [ 'listjs_name' ], 26722 page: 5, 26723 plugins: [ ListPagination({}) ] 26724 }; 26725 26726 if ($('.js-hidden_email_layouts ul li').length) { 26727 var listjs_options40_email_layouts = new List('hidden_email_layouts', listjs_options40_email_layouts); 26728 } 26729 26730 var listjs_options40_page_wrappers = { 26731 valueNames: [ 'listjs_name' ], 26732 page: 5, 26733 plugins: [ ListPagination({}) ] 26734 }; 26735 26736 if ($('.js-hidden_page_wrappers ul li').length) { 26737 var listjs_options40_page_wrappers = new List('hidden_page_wrappers', listjs_options40_page_wrappers); 26738 } 26739 26740 26741 26742 // Syndication 26743/* 26744 var listjs_options42 = { 26745 valueNames: [ 'listjs_name' ], 26746 page: 10, 26747 plugins: [ ListPagination({}) ] 26748 }; 26749 26750 if ($('#syndicate_group_list_wrap ul li').length) { 26751 var userList42 = new List('syndicate_group_list_wrap', listjs_options42); 26752 } 26753*/ 26754 26755 var listjs_options43 = { 26756 valueNames: [ 'listjs_name' ], 26757 page: 10, 26758 plugins: [ ListPagination({}) ] 26759 }; 26760 26761 if ($('.js-tab_syn_emails ul li').length) { 26762 var userList43 = new List('tab_syn_emails', listjs_options43); 26763 } 26764 26765 var listjs_options44 = { 26766 valueNames: [ 'listjs_name' ], 26767 page: 10, 26768 plugins: [ ListPagination({}) ] 26769 }; 26770 26771 if ($('.js-tab_syn_actions ul li').length) { 26772 var userList44 = new List('tab_syn_actions', listjs_options44); 26773 } 26774/* 26775 26776 // Manage Network 26777 var listjs_options45 = { 26778 valueNames: [ 'listjs_name' ], 26779 page: 10, 26780 plugins: [ ListPagination({}) ] 26781 }; 26782 26783 if ($('#network_tree').length) { 26784 var userList45 = new List('network_tree', listjs_options45); 26785 } 26786*/ 26787 26788 26789 26790 // Network - Business Rules 26791 var listjs_options47 = { 26792 valueNames: [ 'listjs_name' ], 26793 page: 25, 26794 plugins: [ ListPagination({}) ] 26795 }; 26796 26797 if ($('.js-manage_rules ul li').length) { 26798 var userList47 = new List('manage_rules', listjs_options47); 26799 } 26800 26801 26802 26803 // Sponsors Search 26804 var listjs_options49 = { 26805 valueNames: [ 'listjs_name', 'listjs_amount', 'listjs_period', 'listjs_created', 'listjs_last', 'listjs_status' ], 26806 page: 10, 26807 plugins: [ ListPagination({}) ] 26808 }; 26809
26810 if ($('.js-sponsors_tab_list ul li').length) { 26811 var userList49 = new List('sponsors_tab_list', listjs_options49); 26812 } 26813 26814 26815 var listjs_options_manage_email_snippets_wrap = { 26816 valueNames: [ 'listjs_name' ], 26817 page: 25, 26818 plugins: [ ListPagination({}) ] 26819 }; 26820 26821 if ($('.js-manage_email_snippets_wrap ul li').length) { 26822 var userList_listjs_options_manage_email_snippets_wrap = new List('manage_email_snippets_wrap', listjs_options_manage_email_snippets_wrap); 26823 } 26824 26825 var listjs_options_manage_mobile_snippets_wrap = { 26826 valueNames: [ 'listjs_name' ], 26827 page: 25, 26828 plugins: [ ListPagination({}) ] 26829 }; 26830 26831 if ($('.js-manage_mobile_snippets_wrap ul li').length) { 26832 var userList_listjs_options_manage_mobile_snippets_wrap = new List('manage_mobile_snippets_wrap', listjs_options_manage_mobile_snippets_wrap); 26833 } 26834 26835 var listjs_options_mass_operations_history_wrap = { 26836 valueNames: [ 'listjs_name' ], 26837 page: 25, 26838 plugins: [ ListPagination({}) ] 26839 }; 26840 26841 if ($('.js-mass_ops_history_outer_wrap ul li').length) { 26842 var userList_listjs_options_mass_operations_history_wrap = new List('mass_ops_history_outer_wrap', listjs_options_mass_operations_history_wrap); 26843 } 26844 26845 var listjs_options_unique_ids_wrap = { 26846 valueNames: [ 'listjs_name' ], 26847 page: 25, 26848 plugins: [ ListPagination({}) ] 26849 }; 26850 26851 if ($('.js-unique_ids_wrap ul li').length) { 26852 var userList_listjs_options_unique_ids_wrap = new List('manage_uploads_wrap', listjs_options_unique_ids_wrap); 26853 } 26854 26855 var listjs_options_upcoming_shifts_wrap = { 26856 valueNames: [ 'listjs_name' ], 26857 page: 25, 26858 plugins: [ ListPagination({}) ] 26859 }; 26860 26861 if ($('.js-tab_upcoming_shifts ul li').length) { 26862 var userList_listjs_options_upcoming_shifts_wrap = new List('tab_upcoming_shifts', listjs_options_upcoming_shifts_wrap); 26863 } 26864 26865 var listjs_options_past_shifts_wrap = { 26866 valueNames: [ 'listjs_name' ], 26867 page: 25, 26868 plugins: [ ListPagination({}) ] 26869 }; 26870 26871 if ($('.js-tab_past_shifts ul li').length) { 26872 var userList_listjs_options_past_shifts_wrap = new List('tab_past_shifts', listjs_options_past_shifts_wrap); 26873 } 26874 26875 26876 26877 } 26878 26879 /* ======================= end lists.js ======================= */ 26880 26881 /* ======================= show/hide for depends if/then fields ======================= */ 26882 if 26883 (($('input[data-depends-name][data-depends-value]').length || $('textarea[data-depends-name][data-depends-value]').length || $('select[data-depends-name][data-depends-value]').length || $('div[data-depends-name][data-depends-value]').length ) 26884 && !$('.js-visual_form_target').length 26885 ) { 26886 26887 var required_remove_function = function($object) { 26888 if ($object.hasClass('required') || $object.hasClass('required_checkboxes')) { 26889 $object.data('required', "true").removeClass('required required_checkboxes error_input') 26890 $object.parents('.error_checkbox').removeClass('error_checkbox'); 26891 $object.parents('.error_input-select_wrap').removeClass('error_input-select_wrap js-error_input-select_wrap'); 26892 } 26893 } 26894 26895 var required_add_function = function($object) { 26896 //console.log($object); 26897 //console.log($object.data('required')); 26898 if ($object.data('required') == "true") { 26899 //console.log('if'); 26900 if ($object.attr('type') == "checkbox") { 26901 $object.data('required', "false").addClass('required_checkboxes'); 26902 } else { 26903 //console.log('not check'); 26904 $object.data('required', "false").addClass('required'); 26905 } 26906 } 26907 } 26908 26909 var depends_function = function(object, hide) { 26910 //console.log('fire'); 26911 var input_name = $(object).attr('name'); 26912 var input_value = $.trim($(object).val()); 26913 26914 //if the object that changed is a radio or checkbox, only set a value if the box is checked, otherwise set it to nothing 26915 if (($(object).attr('type') == "radio" || $(object).attr('type') == "checkbox") && !$(object).is(':checked')) { 26916 input_value = ""; 26917 } 26918 var target_input = $('input[type="text"][data-depends-name="' + input_name + '"][data-depends-value]'); 26919 var target_checkboxes = $('input[type="checkbox"][data-depends-name="' + input_name + '"][data-depends-value]'); 26920 var target_radios = $('input[type="radio"][data-depends-name="' + input_name + '"][data-depends-value]'); 26921 var target_textarea = $('textarea[data-depends-name="' + input_name + '"][data-depends-value]'); 26922 var target_select = $('select[data-depends-name="' + input_name + '"][data-depends-value]'); 26923 var target_div = $('div[data-depends-name="' + input_name + '"][data-depends-value]'); 26924 //console.log(input_value); 26925 //console.log($(object).is(':checked')); 26926 target_input.each(function() { 26927 var $that = $(this); 26928 //console.log($that.val()); 26929 if (input_value == $.trim($that.data('depends-value')) 26930 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 26931 ) { 26932 //how the field if found and matched dependency 26933 $that.parents('.control-group').show(); 26934 required_add_function($that); 26935 } else { 26936 //otherwise, clear the value, trigger a change (in case cascading dependencies), and hide 26937 if ($that.val() != "") { 26938 //console.log($that); 26939 //console.log('change'); 26940 $that.val('').trigger('change'); 26941 } 26942 if (hide) { 26943 $that.parents('.control-group').hide(); 26944 required_remove_function($that); 26945 } 26946 26947 } 26948 }); 26949 //console.log(target_checkboxes); 26950 target_checkboxes.each(function() { 26951 var $that = $(this); 26952 if (input_value == $.trim($that.data('depends-value')) 26953 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 26954 ) { 26955 //console.log($that); 26956 //how the field if found and matched dependency 26957 $that.parents('.control-group').show(); 26958 required_add_function($that); 26959 } else { 26960 //otherwise, clear the checks, trigger a change (in case cascading dependencies), and hide 26961 if ($that.is(':checked')) { 26962 //console.log($that); 26963 //console.log('change'); 26964 $that.attr('checked', false).trigger('change'); 26965 } 26966 if (hide) { 26967 $that.parents('.control-group').hide(); 26968 required_remove_function($that); 26969 } 26970 26971 } 26972 }); 26973 26974 target_radios.each(function() { 26975 var $that = $(this); 26976 if (input_value == $.trim($that.data('depends-value')) 26977 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 26978 ) { 26979 //how the field if found and matched dependency 26980 $that.parents('.control-group').show(); 26981 required_add_function($that); 26982 } else { 26983 //otherwise, clear the checks, trigger a change (in case cascading dependencies), and hide 26984 if ($that.is(':checked')) { 26985 //console.log($that); 26986 //console.log('change'); 26987 $that.attr('checked', false).trigger('change'); 26988 } 26989 if (hide) { 26990 $that.parents('.control-group').hide(); 26991 required_remove_function($that); 26992 } 26993 } 26994 }); 26995 26996 target_textarea.each(function() { 26997 26998 var $that = $(this); 26999 //console.log($that.val()); 27000 if (input_value == $.trim($that.data('depends-value')) 27001 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 27002 ) { 27003 $that.parents('.control-group').show(); 27004 required_add_function($that); 27005 } else { 27006 if ($that.val() != "") { 27007 //console.log($that); 27008 //console.log('change'); 27009 $that.val('').trigger('change'); 27010 } 27011 if (hide) { 27012 $that.parents('.control-group').hide(); 27013 required_remove_function($that); 27014 } 27015 } 27016 }); 27017 27018 target_select.each(function() { 27019 27020 var $that = $(this); 27021 //console.log($that.val()); 27022 if (input_value == $.trim($that.data('depends-value')) 27023 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 27024 ) { 27025 $that.parents('.control-group').prev('.control-label').show(); 27026 $that.parents('.control-group').prev('.js-form_builder_output').find('.control-label').show(); 27027 $that.parents('.control-group').show(); 27028 required_add_function($that); 27029 } else { 27030 if ($that.val() != "") { 27031 //console.log($that); 27032 //console.log('change'); 27033 $that.val($(this).find('option').first().val()).trigger('change') 27034 } 27035 if (hide) { 27036 $that.parents('.control-group').prev('.control-label').hide(); 27037 $that.parents('.control-group').prev('.js-form_builder_output').find('.control-label').hide(); 27038 $that.parents('.control-group').hide(); 27039 required_remove_function($that); 27040 } 27041 } 27042 }); 27043 27044 target_div.each(function() { 27045 27046 var $that = $(this); 27047 //console.log($that.val()); 27048 if (input_value == $.trim($that.data('depends-value')) 27049 || (input_value != "" && $.trim($that.data('depends-value')) == "%") 27050 ) { 27051 //how the field if found and matched dependency 27052 $that.parents('.control-group').show(); 27053 } else { 27054 if (hide) { 27055 $that.parents('.control-group').hide(); 27056 } 27057 27058 } 27059 }); 27060 } 27061 27062 //first, hide all fields with dependencies 27063 $('input[data-depends-name][data-depends-value]').each(function() { 27064 $(this).parents('.control-group').hide(); 27065 required_remove_function($(this)); 27066 }); 27067 $('textarea[data-depends-name][data-depends-value]').each(function() { 27068 $(this).parents('.control-group').hide(); 27069 required_remove_function($(this)); 27070 }); 27071 $('select[data-depends-name][data-depends-value]').each(function() { 27072 $(this).parents('.control-group').prev('.control-label').hide(); 27073 $(this).parents('.control-group').prev('.js-form_builder_output').find('.control-label').hide(); 27074 $(this).parents('.control-group').hide(); 27075 required_remove_function($(this)); 27076 }); 27077 27078 $('div[data-depends-name][data-depends-value]').each(function() { 27079 $(this).parents('.control-group').hide(); 27080 }); 27081 27082 27083 if ($('.js-hide_fields_dependency').length) { 27084 //show dependent fields that have recognized user values
27085 $('.js-hide_fields_dependency').each(function() { 27086 var input_name = $(this).val(); 27087 //console.log(input_name); 27088 $('input[name="' + input_name + '"][data-depends-name][data-depends-value]').each(function() { 27089 var $that = $(this); 27090 //console.log($that); 27091 $('input[name="' + $that.data('depends-name') + '"], textarea[name="' + $that.data('depends-name') + '"], select[name="' + $that.data('depends-name') + '"]').each(function() { 27092 if ($(this).data('always') != true) { 27093 $that.parents('.control-group').show(); 27094 required_add_function($that); 27095 } 27096 }); 27097 }); 27098 27099 $('textarea[name="' + input_name + '"][data-depends-name][data-depends-value]').each(function() { 27100 var $that = $(this); 27101 $('input[name="' + $that.data('depends-name') + '"], textarea[name="' + $that.data('depends-name') + '"], select[name="' + $that.data('depends-name') + '"]').each(function() { 27102 if ($(this).data('always') != true) { 27103 $that.parents('.control-group').show(); 27104 required_add_function($that); 27105 } 27106 }); 27107 }); 27108 27109 $('select[name="' + input_name + '"][data-depends-name][data-depends-value]').each(function() { 27110 var $that = $(this); 27111 $('input[name="' + $that.data('depends-name') + '"], textarea[name="' + $that.data('depends-name') + '"], select[name="' + $that.data('depends-name') + '"]').each(function() { 27112 if ($(this).data('always') != true) { 27113 $that.parents('.control-group').prev('.control-label').show(); 27114 $that.parents('.control-group').prev('.js-form_builder_output').find('.control-label').show(); 27115 $that.parents('.control-group').show(); 27116 required_add_function($that); 27117 } 27118 }); 27119 }); 27120 27121 }); 27122 } 27123 27124 if ($('.js-hide_fields_dependency_html').length) { 27125 //show dependent html fields that have recognized user values 27126 $('.js-hide_fields_dependency_html').each(function() { 27127 var dependency_array = $(this).val().split(","); 27128 var dependency_name = dependency_array[0]; 27129 var dependency_value = dependency_array[1]; 27130 //console.log(input_name); 27131 $('div[data-depends-name="' + dependency_name + '"][data-depends-value="' + dependency_value + '"]').each(function() { 27132 $(this).parents('.control-group').show(); 27133 }); 27134 }); 27135 } 27136 27137 //deal with onload 27138 $('.control-group input[type="text"], .control-group input[type="checkbox"], .control-group input[type="radio"], .control-group textarea, .control-group select').each(function() { 27139 //console.log(this); 27140 //console.log($(this).val()); 27141 if ($(this).val() != '') { 27142 depends_function(this, false); 27143 } 27144 }); 27145 27146 var select_other_display = function(object) { 27147 $object = $(object); 27148 if ($object.hasClass('js-form_select2')) { 27149 if ($object.parents('.control-group').find('.js-form_builder_other_input').length 27150 && $object.find('option:selected').hasClass('js-other_option')) { 27151 $object.parents('.control-group').find('.js-form_builder_other_input_wrap').show(); 27152 } else { 27153 $object.parents('.control-group').find('.js-form_builder_other_input_wrap').hide(); 27154 } 27155 } 27156 27157 }; 27158 27159 //deal with onchange 27160 $('body').on('change keyup', '.control-group input[type="text"], .control-group input[type="checkbox"], .control-group input[type="radio"], .control-group textarea, .control-group select', function() { 27161 //console.log(this); 27162 depends_function(this, true); 27163 }); 27164 27165 } 27166 27167 var select_other_display = function(object) { 27168 $object = $(object); 27169 if ($object.hasClass('js-form_select2')) { 27170 if ($object.parents('.control-group').find('.js-form_builder_other_input').length 27171 && $object.find('option:selected').hasClass('js-other_option')) { 27172 $object.parents('.control-group').find('.js-form_builder_other_input_wrap').show(); 27173 } else { 27174 $object.parents('.control-group').find('.js-form_builder_other_input_wrap').hide(); 27175 } 27176 } 27177 27178 }; 27179 27180 //deal with onchange 27181 $('body').on('change keyup', '.control-group input[type="text"], .control-group input[type="checkbox"], .control-group input[type="radio"], .control-group textarea, .control-group select', function() { 27182 //console.log(this); 27183 select_other_display(this); 27184 }); 27185 27186 $('.js-hide_fields_dependency, .js-hide_fields_dependency_html').remove(); 27187 /* ======================= end show/hide for depends if/then fields ======================= */ 27188 27189 /* ======================= show/hide recognized custom fields ======================= */ 27190 if ($('.js-hide_fields').length) {
27191 $('.js-hide_fields').each(function() { 27192 var input_name = $(this).val(); 27193 $('input[name="' + input_name + '"][data-always="false"]').parents('.control-group').remove(); 27194 $('textarea[name="' + input_name + '"][data-always="false"]').parents('.control-group').remove(); 27195 $('select[name="' + input_name + '"][data-always="false"]').parents('.control-group').prev('.control-label').remove(); 27196 $('select[name="' + input_name + '"][data-always="false"]').parents('.control-group').prev('.js-form_builder_output').find('.control-label').remove(); 27197 $('select[name="' + input_name + '"][data-always="false"]').parents('.control-group').remove(); 27198 $(this).remove(); 27199 }); 27200 } 27201 /* ======================= end show/hide recognized custom fields ======================= */ 27202 27203 /* ======================= list sorting ======================= */ 27204 /** 27205 * Sorts an instance of list.js 27206 * 27207 * @icon the DOM element of the icon that should toggle its class. Starting icon should typically be fa-sort-amount-down 27208 * @list instance of list.js to sort 27209 * @index what list property to sort on. Needs to be passed in to list.js when the list is created 27210 * @toggle whether to toggle the class or not on sort. Useful for when you've changed what index you are sorting by (via dropdown, for example) but have not changed the sort order 27211 */ 27212 function toggleSort(icon, list, index, toggle) { 27213 var $sortIcon = $(icon).find('i'); 27214 27215 if (toggle) { 27216 $sortIcon.toggleClass('fa-sort-amount-down'); 27217 $sortIcon.toggleClass('fa-sort-amount-up'); 27218 } 27219 27220 if ($sortIcon.hasClass('fa-sort-amount-down')) { 27221 var order = 'desc'; 27222 27223 // the name index sorts alphabetically, and we want "A" at the top, which is the opposite sort order from other sorts like dates, where we want the closest date at the top (reverse chronological) 27224 if (index == 'name') { 27225 order = 'asc'; 27226 } 27227 list.sort(index, { order: order }); 27228 } else { 27229 var order = 'asc'; 27230 if (index == 'name') { 27231 order = 'desc'; 27232 } 27233 list.sort(index, { order: order }); 27234 } 27235 } 27236 27237 /* ======================= advanced search options ======================= */ 27238 27239 $('body').on('click', '.js-search_content', function() { searchContent($(this)); }); 27240 $('body').on('click', '.js-hide_advanced_search', hideAdvancedSearch); 27241 $('body').on('click', '.js-clear_advanced_search', clearAdvancedSearch); 27242 27243 function searchContent($this) { 27244 var $form = $($this.parents('form')); 27245 var url = $form.attr('action'); 27246 var query = $form.serializeArray(); 27247 $form.closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced, .js-email_list_advanced_search_results, .js-email_list_advanced_search_results_error').addClass('disabled'); 27248 $.ajax({ 27249 url: url, 27250 type: 'POST', 27251 data: query 27252 }).done(function(data) { 27253 $form.closest('.js-list_search_simple_or_advanced').find('.js-email_list_advanced_search_results, .js-email_list_advanced_search_results_error').hide(); 27254 $form.closest('.js-list_search_simple_or_advanced').find(".js-advanced-search-results").html(data).show(); 27255 $form.closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced, .js-email_list_advanced_search_results, .js-email_list_advanced_search_results_error').removeClass('disabled'); 27256 }).fail(function() { 27257 $form.closest('.js-list_search_simple_or_advanced').find('.js-email_list_advanced_search_results, .js-advanced-search-results').hide(); 27258 $form.closest('.js-list_search_simple_or_advanced').find('.js-email_list_advanced_search_results_error').show(); 27259 $form.closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced, .js-email_list_advanced_search_results, .js-email_list_advanced_search_results_error').removeClass('disabled'); 27260 }); 27261 } 27262 27263 function hideAdvancedSearch() { 27264 // Hide advanced search 27265 $(this).closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced, .js-advanced_search_empty, .js-advanced_search_error').hide(); 27266 $(this).closest('.js-list_search_simple_or_advanced').find('.js-advanced-search-results').html(''); 27267 // Clear advanced search inputs 27268 $(this).closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced .floatlabel-input').val('').change(); 27269 // Show simple search 27270 $(this).closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap, .js-simple_search_results').show(); 27271 } 27272 27273 function clearAdvancedSearch() { 27274 $(this).closest('.js-list_search_simple_or_advanced').find('.js-advanced-search-results').html(''); 27275 // Clear advanced search inputs 27276 $(this).closest('.js-list_search_simple_or_advanced').find('.js-list_search_wrap_advanced .floatlabel-input').val('').change(); 27277 } 27278 27279}); 27280 27281 27282 27283/*! 27284 * jQuery Plugin: Are-You-Sure (Dirty Form Detection) 27285 * https://github.com/codedance/jquery.AreYouSure/ 27286 * 27287 * Copyright (c) 2012-2014, Chris Dance and PaperCut Software http://www.papercut.com/ 27288 * Dual licensed under the MIT or GPL Version 2 licenses. 27289 * http://jquery.org/license 27290 * 27291 * Author: [email protected] 27292 * Version: 1.6.0 27293 * Date: 7th Feb 2014 27294 */ 27295(function($) { 27296 27297 $.fn.areYouSure = function(options) { 27298 27299 var settings = $.extend( 27300 { 27301 'message' : 'You have unsaved changes!', 27302 'dirtyClass' : 'dirty', 27303 'change' : null, 27304 'silent' : false, 27305 'addRemoveFieldsMarksDirty' : false, 27306 'fieldSelector': "select,textarea,input[type='text'],input[type='password'],input[type='checkbox'],input[type='radio'],input[type='hidden'],input[type='color'],input[type='date'],input[type='datetime'],input[type='datetime-local'],input[type='email'],input[type='month'],input[type='number'],input[type='range'],input[type='search'],input[type='tel'],input[type='time'],input[type='url'],input[type='week']" 27307 }, options); 27308 27309 var getValue = function($field) { 27310 if ($field.hasClass('ays-ignore') 27311 || $field.hasClass('aysIgnore') 27312 || $field.attr('data-ays-ignore') 27313 || $field.attr('name') === undefined) { 27314 return null; 27315 } 27316 27317 if ($field.is(':disabled')) { 27318 return 'ays-disabled'; 27319 } 27320 27321 var val; 27322 var type = $field.attr('type'); 27323 if ($field.is('select')) { 27324 type = 'select'; 27325 } 27326 27327 switch (type) { 27328 case 'checkbox': 27329 case 'radio': 27330 val = $field.is(':checked'); 27331 break; 27332 case 'select': 27333 val = ''; 27334 $field.find('option').each(function(o) { 27335 var $option = $(this); 27336 if ($option.is(':selected')) { 27337 val += $option.val(); 27338 } 27339 }); 27340 break; 27341 default: 27342 val = $field.val(); 27343 } 27344 27345 return val; 27346 }; 27347 27348 var storeOrigValue = function($field) { 27349 $field.data('ays-orig', getValue($field)); 27350 }; 27351 27352 var checkForm = function(evt) { 27353 27354 var isFieldDirty = function($field) { 27355 var origValue = $field.data('ays-orig'); 27356 if (undefined === origValue) { 27357 return false;
27358 } 27359 return (getValue($field) != origValue); 27360 }; 27361 27362 var $form = ($(this).is('form')) 27363 ? $(this) 27364 : $(this).parents('form'); 27365 27366 // Test on the target first as it's the most likely to be dirty 27367 if (isFieldDirty($(evt.target))) { 27368 setDirtyStatus($form, true); 27369 return; 27370 } 27371 27372 $fields = $form.find(settings.fieldSelector); 27373 27374 if (settings.addRemoveFieldsMarksDirty) { 27375 // Check if field count has changed 27376 var origCount = $form.data("ays-orig-field-count"); 27377 if (origCount != $fields.length) { 27378 setDirtyStatus($form, true); 27379 return; 27380 } 27381 } 27382 27383 // Brute force - check each field 27384 var isDirty = false; 27385 $fields.each(function() { 27386 $field = $(this); 27387 if (isFieldDirty($field)) { 27388 isDirty = true; 27389 return false; // break 27390 } 27391 }); 27392 27393 setDirtyStatus($form, isDirty); 27394 }; 27395 27396 var initForm = function($form) { 27397 var fields = $form.find(settings.fieldSelector); 27398 $(fields).each(function() { storeOrigValue($(this)); }); 27399 $(fields).unbind('change keyup', checkForm); 27400 $(fields).bind('change keyup', checkForm); 27401 $form.data("ays-orig-field-count", $(fields).length); 27402 setDirtyStatus($form, false); 27403 }; 27404 27405 var setDirtyStatus = function($form, isDirty) { 27406 var changed = isDirty != $form.hasClass(settings.dirtyClass); 27407 $form.toggleClass(settings.dirtyClass, isDirty); 27408 27409 // Fire change event if required 27410 if (changed) { 27411 if (settings.change) settings.change.call($form, $form); 27412 27413 if (isDirty) $form.trigger('dirty.areYouSure', [$form]); 27414 if (!isDirty) $form.trigger('clean.areYouSure', [$form]); 27415 $form.trigger('change.areYouSure', [$form]); 27416 } 27417 }; 27418 27419 var rescan = function() { 27420 var $form = $(this); 27421 var fields = $form.find(settings.fieldSelector); 27422 $(fields).each(function() { 27423 var $field = $(this); 27424 if (!$field.data('ays-orig')) { 27425 storeOrigValue($field); 27426 $field.bind('change keyup', checkForm); 27427 } 27428 }); 27429 // Check for changes while we're here 27430 $form.trigger('checkform.areYouSure'); 27431 }; 27432 27433 var reinitialize = function() { 27434 initForm($(this)); 27435 } 27436 27437 if (!settings.silent) { 27438 $(window).on('beforeunload.areYouSure pagehide.areYouSure', function(event) { 27439 $dirtyForms = $("form").filter('.' + settings.dirtyClass); 27440 if ($dirtyForms.length > 0) { 27441 // $dirtyForms.removeClass(settings.dirtyClass); // Prevent multiple calls? 27442 return settings.message; 27443 } 27444 }); 27445 27446 //remove||re-assign onbeforeunload on hover 27447 if (navigator.appVersion.indexOf("MSIE 10") !== -1) { 27448 $('a[href^="javascript:"]').mouseenter(function(){ 27449 //console.log('hover'); 27450 $(window).unbind('beforeunload.areYouSure pagehide.areYouSure'); 27451 }); 27452 27453 $('a[href^="javascript:"]').mouseleave(function(){ 27454 //console.log('up'); 27455 $(window).on('beforeunload.areYouSure pagehide.areYouSure', function(event) { 27456 $dirtyForms = $("form").filter('.' + settings.dirtyClass); 27457 if ($dirtyForms.length > 0) { 27458 // $dirtyForms.removeClass(settings.dirtyClass); // Prevent multiple calls? 27459 return settings.message; 27460 } 27461 }); 27462 }); 27463 } 27464 } 27465 27466 return this.each(function(elem) { 27467 27468 if (!$(this).is('form')) { 27469 return; 27470 } 27471 var $form = $(this); 27472 27473 $form.submit(function() { 27474 $form.removeClass(settings.dirtyClass); 27475 }); 27476 $form.bind('reset', function() { setDirtyStatus($form, false); }); 27477 // Add a custom events 27478 $form.bind('rescan.areYouSure', rescan); 27479 $form.bind('reinitialize.areYouSure', reinitialize); 27480 $form.bind('checkform.areYouSure', checkForm); 27481 initForm($form); 27482 27483 }); 27484 }; 27485})(jQuery); 27486 27487/* 27488 * Character Count Plugin - jQuery plugin 27489 * Dynamic character count for text areas and input fields 27490 * written by Alen Grakalic 27491 * http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas 27492 * 27493 * Copyright (c) 2009 Alen Grakalic (http://cssglobe.com) 27494 * Dual licensed under the MIT (MIT-LICENSE.txt) 27495 * and GPL (GPL-LICENSE.txt) licenses. 27496 * 27497 * Built for jQuery library 27498 * http://jquery.com 27499 * 27500 */ 27501 27502(function($) { 27503 27504 $.fn.charCount = function(options){ 27505 27506 // default configuration properties 27507 var defaults = { 27508 allowed: 140, 27509 warning: 25, 27510 css: 'counter', 27511 counterElement: 'span', 27512 cssWarning: 'warning', 27513 cssExceeded: 'exceeded', 27514 counterText: '', 27515 hostname: 'actn.et',
27516 detectEmoji: false, 27517 regex: "url", 27518 twitter: false, 27519 link_shortening: true 27520 }; 27521 27522 var options = $.extend(defaults, options); 27523 27524 if (options.twitter) { 27525 var linkShorteningLength = 23; 27526 } else { 27527 var linkShorteningLength = "https://".length + options.hostname.length + "/12345i0".length; // compose shortlink url format with custom hostname 27528 } 27529 27530 27531 27532 27533 27534 function calculate(obj, text_to_count){ 27535 //console.log(text_to_count); 27536 //console.log(options.linkShorteningLength); 27537 //make all links count for only 23 characters to take into account twitter's auto-shortening 27538 var url_regex = /(https?:\/\/)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&;//=]*)/; 27539 var url_strict_regex = /https?:\/\/?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&;//=]*)/; 27540 var regex = url_regex; 27541 if (options.regex = "url_strict") { 27542 var regex = url_strict_regex; 27543 } 27544 if ((regex).test(text_to_count) && options.link_shortening) { 27545 //if ((/https/).test($(obj).val().match(url_regex)[0])) { 27546 //console.log($(obj).val().length); 27547 //console.log($(obj).val().match(url_regex)[0].length); 27548 //console.log(linkShorteningLength); 27549 27550 var count = text_to_count.length - text_to_count.match(url_regex)[0].length + linkShorteningLength; 27551 //console.log(count); 27552 //} else { 27553 // var count = $(obj).val().length - $(obj).val().match(url_regex)[0].length + linkShorteningLength; 27554 //} 27555 } else { 27556 var count = text_to_count.length; 27557 } 27558 var available = options.allowed - count; 27559 if(available <= options.warning && available >= 0){ 27560 $(obj).parents(options.wrapperSelector).find('.js-twitter_count, .js-character_count').addClass(options.cssWarning); 27561 } else { 27562 $(obj).parents(options.wrapperSelector).find('.js-twitter_count, .js-character_count').removeClass(options.cssWarning); 27563 } 27564 if(available < 0){ 27565 $(obj).parents(options.wrapperSelector).find('.js-twitter_count, .js-character_count').addClass(options.cssExceeded); 27566 } else { 27567 $(obj).parents(options.wrapperSelector).find('.js-twitter_count, .js-character_count').removeClass(options.cssExceeded); 27568 } 27569 //console.log(available + options.counterText); 27570 $(obj).parents(options.wrapperSelector).find('.js-twitter_count strong small, .js-character_count strong small').html(available + options.counterText); 27571 }; 27572 27573 //this.each(function() { 27574 //console.log(this); 27575 //console.log($(this).parent().find('.js-twitter_count strong small')); 27576 $(this).parents(options.wrapperSelector).find('.js-twitter_count strong small, .js-character_count strong small').html('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>'); 27577 27578 if ($(this).is("textarea") || $(this).is("input")) { 27579 var text_to_count = $(this).val(); 27580 } else { 27581 var text_to_count = $(this).text().trim(); 27582 } 27583 calculate(this, text_to_count); 27584 $(this).on('keyup change', function(){ 27585 if ($(this).is("textarea") || $(this).is("input")) { 27586 var text_to_count = $(this).val(); 27587 } else { 27588 var text_to_count = $(this).text().trim(); 27589 } 27590 calculate(this, text_to_count); 27591 }); 27592 //}); 27593 27594 }; 27595 27596})(jQuery); 27597 27598$.fn.priorityOn = function (type, selector, data, fn) { 27599 this.each(function () { 27600 var $this = $(this); 27601 27602 var types = type.split(" "); 27603 27604 for (var t in types) { 27605 $this.on(types[t], selector, data, fn); 27606 27607 var currentBindings = $._data(this, 'events')[types[t]]; 27608 if ($.isArray(currentBindings)) { 27609 currentBindings.unshift(currentBindings.pop()); 27610 } 27611 } 27612 27613 27614 }); 27615 return this; 27616}; 27617 27618 27619//jQuery mutate plugin to detect dynamic changes in target's height 27620mutate_event_stack = [ 27621 { 27622 name: 'width', 27623 handler: function (elem){ 27624 n = {el:elem} 27625 if(!$(n.el).data('mutate-width'))$(n.el).data('mutate-width', $(n.el).width()); 27626 if ($(n.el).data('mutate-width')&&$(n.el).width() != $(n.el).data('mutate-width') ) { 27627 $(n.el).data('mutate-width', $(n.el).width()); 27628 return true; 27629 } 27630 return false; 27631 } 27632 }, 27633 { 27634 name:'height', 27635 handler: function (n){ 27636 element = n; 27637 if(!$(element).data('mutate-height'))$(element).data('mutate-height', $(element).height()); 27638 if ($(element).data('mutate-height')&&$(element).height() != $(element).data('mutate-height') ) { 27639 $(element).data('mutate-height', $(element).height()); 27640 return true; 27641 } 27642 } 27643 }, 27644 { 27645 name : 'top', 27646 handler : function (n){ 27647 if(!$(n).data('mutate-top'))$(n).data('mutate-top', $(n).css('top')); 27648 if ($(n).data('mutate-top')&&$(n).css('top') != $(n).data('mutate-top') ) { 27649 $(n).data('mutate-top', $(n).css('top')); 27650 return true; 27651 } 27652 } 27653 }, 27654 { 27655 name : 'bottom', 27656 handler : function (n){ 27657 if(!$(n).data('mutate-bottom'))$(n).data('mutate-bottom', $(n).css('bottom')); 27658 if ($(n).data('mutate-bottom')&&$(n).css('bottom') != $(n).data('mutate-bottom') ) { 27659 $(n).data('mutate-bottom', $(n).css('bottom')); 27660 return true; 27661 } 27662 } 27663 }, 27664 { 27665 name : 'right', 27666 handler : function (n){ 27667 if(!$(n).data('mutate-right'))$(n).data('mutate-right', $(n).css('right')); 27668 if ($(n).data('mutate-right')&&$(n).css('right') != $(n).data('mutate-right') ) { 27669 $(n).data('mutate-right', $(n).css('right')); 27670 return true; 27671 } 27672 } 27673 }, 27674 { 27675 name : 'left', 27676 handler : function (n){ 27677 if(!$(n).data('mutate-left'))$(n).data('mutate-left', $(n).css('left')); 27678 if ($(n).data('mutate-left')&&$(n).css('left') != $(n).data('mutate-left') ) { 27679 $(n).data('mutate-left', $(n).css('left')); 27680 return true; 27681 } 27682 } 27683 }, 27684 { 27685 name : 'hide', 27686 handler : function (n){ if ($(n).is(':hidden')) return true; } 27687 }, 27688 { 27689 name : 'show', 27690 handler : function (n){ if ($(n).is(':visible')) return true; } 27691 }, 27692 { 27693 name : 'scrollHeight', 27694 handler : function (n){ 27695 if(!$(n).data('prev-scrollHeight'))$(n).data('prev-scrollHeight', $(n)[0].scrollHeight); 27696 if ($(n).data('prev-scrollHeight')&&$(n)[0].scrollHeight != $(n).data('prev-scrollHeight') ) { 27697 $(n).data('prev-scrollHeight', $(n)[0].scrollHeight); 27698 return true; 27699 } 27700 } 27701 }, 27702 { 27703 name : 'scrollWidth', 27704 handler : function (n){ 27705 if(!$(n).data('prev-scrollWidth'))$(n).data('prev-scrollWidth', $(n)[0].scrollWidth); 27706 if ($(n).data('prev-scrollWidth')&&$(n)[0].scrollWidth != $(n).data('prev-scrollWidth') ) { 27707 $(n).data('prev-scrollWidth', $(n)[0].scrollWidth); 27708 return true; 27709 } 27710 } 27711 }, 27712 { 27713 name : 'scrollTop', 27714 handler : function (n){ 27715 if(!$(n).data('prev-scrollTop'))$(n).data('prev-scrollTop', $(n)[0].scrollTop()); 27716 if ($(n).data('prev-scrollTop')&&$(n)[0].scrollTop() != $(n).data('prev-scrollTop') ) { 27717 $(n).data('prev-scrollTop', $(n)[0].scrollTop()); 27718 return true; 27719 } 27720 } 27721 }, 27722 { 27723 name : 'scrollLeft', 27724 handler : function (n){ 27725 if(!$(n).data('prev-scrollLeft'))$(n).data('prev-scrollLeft', $(n)[0].scrollLeft()); 27726 if ($(n).data('prev-scrollLeft')&&$(n)[0].scrollLeft() != $(n).data('prev-scrollLeft') ) { 27727 $(n).data('prev-scrollLeft', $(n)[0].scrollLeft()); 27728 return true; 27729 } 27730 } 27731 } 27732]; 27733 27734//RAY TODO: This causes major slowdowns on the app. Changed speed from 1ms to 16ms to
27734slow down to 60FPS instead of 1000. 27735(function($){mutate={speed:16,event_stack:mutate_event_stack,stack:[],events:{},add_event:function(evt){mutate.events[evt.name]=evt.handler;},add:function(event_name,selector,callback,false_callback){mutate.stack[mutate.stack.length]={event_name:event_name,selector:selector,callback:callback,false_callback:false_callback}}};function reset(){var parent=mutate;if(parent.event_stack!='undefined'&&parent.event_stack.length){$.each(parent.event_stack,function(j,k){mutate.add_event(k);});} 27736parent.event_stack=[];$.each(parent.stack,function(i,n){$(n.selector).each(function(a,b){if(parent.events[n.event_name](b)===true){if(n['callback'])n.callback(b,n);}else{if(n['false_callback'])n.false_callback(b,n)}})}) 27737setTimeout(reset,mutate.speed);} 27738reset();$.fn.extend({mutate:function(){var event_name=false,callback=arguments[1],selector=this,false_callback=arguments[2]?arguments[2]:function(){};if(arguments[0].toLowerCase()=='extend'){mutate.add_event(callback);return this;} 27739$.each($.trim(arguments[0]).split(' '),function(i,n){event_name=n;mutate.add(event_name,selector,callback,false_callback);});return this;}});})(jQuery); 27740 27741// This runs way faster, but untested 27742// (function($) { 27743// // Cache selectors and their elements 27744// const selectorCache = new Map(); 27745// const CACHE_DURATION = 100; // Cache for 100ms 27746// let lastCacheTime = 0; 27747 27748// mutate = { 27749// speed: 16, // ~60fps instead of 1000fps 27750// event_stack: mutate_event_stack, 27751// stack: [], 27752// events: {}, 27753 27754// add_event: function(evt) { 27755// mutate.events[evt.name] = evt.handler; 27756// }, 27757 27758// add: function(event_name, selector, callback, false_callback) { 27759// mutate.stack.push({ 27760// event_name: event_name, 27761// selector: selector, 27762// callback: callback, 27763// false_callback: false_callback 27764// }); 27765// } 27766// }; 27767 27768// function getCachedElements(selector) { 27769// const now = Date.now(); 27770 27771// // Clear cache if expired 27772// if (now - lastCacheTime > CACHE_DURATION) { 27773// selectorCache.clear(); 27774// lastCacheTime = now; 27775// } 27776 27777// if (!selectorCache.has(selector)) { 27778// selectorCache.set(selector, $(selector).toArray()); 27779// } 27780 27781// return selectorCache.get(selector); 27782// } 27783 27784// function reset() { 27785// const parent = mutate; 27786 27787// // Process event stack 27788// if (parent.event_stack && parent.event_stack.length) { 27789// parent.event_stack.forEach(k => mutate.add_event(k)); 27790// parent.event_stack = []; 27791// } 27792 27793// // Use requestAnimationFrame for better performance 27794// const processRules = () => { 27795// parent.stack.forEach(rule => { 27796// const handler = parent.events[rule.event_name]; 27797// if (!handler) return; 27798 27799// const elements = getCachedElements(rule.selector); 27800// elements.forEach(element => { 27801// try { 27802// if (handler(element) === true) { 27803// rule.callback?.(element, rule); 27804// } else { 27805// rule.false_callback?.(element, rule); 27806// } 27807// } catch (e) { 27808// console.warn('Mutate handler error:', e); 27809// } 27810// }); 27811// }); 27812 27813// setTimeout(reset, mutate.speed); 27814// }; 27815 27816// requestAnimationFrame(processRules); 27817// } 27818 27819// reset(); 27820 27821// $.fn.extend({ 27822// mutate: function() { 27823// const event_name = arguments[0]; 27824// const callback = arguments[1]; 27825// const selector = this; 27826// const false_callback = arguments[2] || function() {}; 27827 27828// if (event_name && event_name.toLowerCase() === 'extend') { 27829// mutate.add_event(callback); 27830// return this; 27831// } 27832 27833// if (event_name) { 27834// event_name.trim().split(/\s+/).forEach(name => { 27835// mutate.add(name, selector, callback, false_callback); 27836// }); 27837// } 27838 27839// return this; 27840// } 27841// }); 27842// })(jQuery); 27843
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.