1let MER; 2jQuery(document).ready(function ($) { 3 4 /** 5 * @namespace MER 6 * @type {{ 7 * event_cart : object, 8 * form_input: object, 9 * form_data: object, 10 * response: object, 11 * display_debug: boolean, 12 * ticket_selector_iframe: boolean, 13 * }} 14 * @namespace eei18n 15 * @type {{ 16 * wp_debug: boolean, 17 * ajax_url: string, 18 * iframe_tickets_added: string, 19 * }} 20 * @namespace form_data 21 * @type {{ 22 * action: string, 23 * ticket: string, 24 * line_item: string, 25 * ee: string, 26 * cart_results: string, 27 * confirm_delete_state: string, 28 * }} 29 */ 30 31 32 MER = { 33 34 /** 35 * DOM element - main event cart container 36 */ 37 event_cart: {}, 38 39 /** 40 * DOM element - event cart text input field 41 */ 42 form_input: {}, 43 44 /** 45 * DOM element - AJAX notices container 46 */ 47 ajax_notices: {}, 48 49 /** 50 * array of form data 51 * @namespace form_data 52 * @type {{ 53 * action: string, 54 * ticket: string, 55 * line_item: string, 56 * ee: string, 57 * cart_results: string, 58 * }} 59 */ 60 form_data: {}, 61 62 /** 63 * AJAX response 64 * @namespace response 65 * @type {{ 66 * errors: string, 67 * attention: string, 68 * success: string, 69 * new_html: object, 70 * tickets_added: boolean, 71 * btn_id: string, 72 * btn_txt: string, 73 * form_html: string, 74 * mini_cart: string, 75 * cart_results: string, 76 * redirect_url: string, 77 * }} 78 */ 79 response: {}, 80 81 /** 82 * display debugging info in console? 83 * @namespace display_debug 84 * @type boolean 85 */ 86 display_debug: eei18n.wp_debug, 87 88 /** 89 * is ticket selector in an iframe ? 90 * @namespace ticket_selector_iframe 91 * @type boolean 92 */ 93 ticket_selector_iframe: typeof eei18n.ticket_selector_iframe !== 'undefined' 94 ? eei18n.ticket_selector_iframe 95 : false, 96 97 /** 98 * the last submit button to be clicked 99 * @namespace ticket_selector_submit_btn 100 * @type Object 101 */ 102 ticket_selector_submit_btn: null, 103 104 /********** INITIAL SETUP **********/ 105 106 /** 107 * @function initialize 108 */ 109 initialize: function () { 110 MER.ajax_notices = $('#espresso-ajax-notices'); 111 const event_cart = $('#event-cart'); 112 if (event_cart.length) { 113 MER.event_cart = event_cart; 114 MER.set_listener_for_add_ticket_button(); 115 MER.set_listener_for_remove_ticket_button(); 116 MER.set_listener_for_delete_ticket_button(); 117 MER.set_listener_for_update_event_cart_button(); 118 MER.set_listener_for_empty_event_cart_link(); 119 } else { 120 MER.set_listener_for_ticket_selector_submit_btn(); 121 } 122 }, 123 124 /** 125 * @function set_listener_for_add_ticket_button 126 */ 127 set_listener_for_add_ticket_button: function () { 128 MER.event_cart.on('click', 129 '.event-cart-add-ticket-button', 130 function (event) { 131 if (! $(this).hasClass('disabled-event-cart-btn') && 132 ! $(this).hasClass('js-disabled-event-cart-btn') 133 ) { 134 const urlParams = $(this).eeGetParams(); 135 MER.form_data = {}; 136 MER.form_data.action = 'espresso_add_ticket_to_event_cart'; 137 MER.form_data.ticket = typeof (urlParams.ticket) !== 'undefined' 138 ? urlParams.ticket 139 : ''; 140 MER.form_data.line_item 141 = typeof (urlParams.line_item) !== 'undefined'
142 ? urlParams.line_item 143 : ''; 144 MER.submit_ajax_request(); 145 } 146 event.preventDefault(); 147 event.stopPropagation(); 148 } 149 ); 150 }, 151 152 /** 153 * @function set_listener_for_remove_ticket_button 154 */ 155 set_listener_for_remove_ticket_button: function () { 156 MER.event_cart.on('click', 157 '.event-cart-remove-ticket-button', 158 function (event) { 159 event.preventDefault(); 160 event.stopPropagation(); 161 if (! $(this).hasClass('disabled-event-cart-btn') && 162 ! $(this).hasClass('js-disabled-event-cart-btn') 163 ) { 164 if (! MER.confirm_required_ticket_delete($(this))) { 165 return; 166 } 167 const urlParams = $(this).eeGetParams(); 168 MER.form_data = {}; 169 MER.form_data.action = 'espresso_remove_ticket_from_event_cart'; 170 MER.form_data.ticket = typeof (urlParams.ticket) !== 'undefined' 171 ? urlParams.ticket 172 : ''; 173 MER.form_data.line_item 174 = typeof (urlParams.line_item) !== 'undefined' 175 ? urlParams.line_item 176 : ''; 177 MER.submit_ajax_request(); 178 } 179 } 180 ); 181 }, 182 183 /** 184 * @function set_listener_for_delete_ticket_button 185 */ 186 set_listener_for_delete_ticket_button: function () { 187 MER.event_cart.on('click', 188 '.event-cart-delete-ticket-button', 189 function (event) { 190 event.preventDefault(); 191 event.stopPropagation(); 192 if (! $(this).hasClass('disabled-event-cart-btn') && 193 ! $(this).hasClass('js-disabled-event-cart-btn') 194 ) { 195 if (! MER.confirm_required_ticket_delete($(this), true)) { 196 return; 197 } 198 const urlParams = $(this).eeGetParams(); 199 MER.form_data = {}; 200 MER.form_data.action = 'espresso_delete_ticket_from_event_cart'; 201 MER.form_data.ticket = typeof (urlParams.ticket) !== 'undefined' 202 ? urlParams.ticket 203 : ''; 204 MER.form_data.line_item 205 = typeof (urlParams.line_item) !== 'undefined' 206 ? urlParams.line_item 207 : ''; 208 MER.submit_ajax_request(); 209 } 210 } 211 ); 212 }, 213 214 /** 215 * @function confirm_required_ticket_delete 216 */ 217 confirm_required_ticket_delete: function ($button, deleteAll) { 218 deleteAll = typeof deleteAll !== 'undefined' ? deleteAll : false; 219 if ($button.hasClass('required')) { 220 // not deleting all, so need to check ticket qty 221 if (deleteAll !== true) { 222 const $target = $('#' + $button.data('target')); 223 deleteAll = $target.length && parseInt($target.val()) === 1; 224 } 225 if (deleteAll === true) { 226 return confirm(eei18n.confirm_delete_state); 227 } 228 } 229 // proceed with deletion 230 return true; 231 }, 232 233 /** 234 * @function set_listener_for_update_event_cart_link 235 */ 236 set_listener_for_update_event_cart_button: function () { 237 MER.event_cart.on('click', 238 '.event-cart-update-cart-lnk', 239 function (event) { 240 if (! $(this).hasClass('disabled-event-cart-btn') && 241 ! $(this).hasClass('js-disabled-event-cart-btn') 242 ) { 243 MER.form_data = MER.get_form_data(MER.event_cart, true); 244 //console.log( MER.form_data ); 245 MER.form_data.action = 'espresso_update_event_cart'; 246 MER.submit_ajax_request(); 247 } 248 event.preventDefault(); 249 event.stopPropagation(); 250 } 251 ); 252 }, 253 254 /** 255 * @function set_listener_for_empty_event_cart_link 256 */ 257 set_listener_for_empty_event_cart_link: function () { 258 MER.event_cart.on('click', 259 '.event-cart-empty-cart-lnk', 260 function (event) { 261 if (! $(this).hasClass('disabled-event-cart-btn') && 262 ! $(this).hasClass('js-disabled-event-cart-btn') 263 ) { 264 MER.form_data = {}; 265 MER.form_data.action = 'espresso_empty_event_cart'; 266 MER.submit_ajax_request(); 267 } 268 event.preventDefault(); 269 event.stopPropagation(); 270 } 271 ); 272 }, 273 274 /** 275 * @function set_listener_for_ticket_selector_submit_btn 276 */ 277 set_listener_for_ticket_selector_submit_btn: function () { 278 $(document).on('click', '.ticket-selector-submit-ajax', 279 function (event) { 280 MER.ticket_selector_submit_btn = $(this); 281 MER.form_data = MER.get_form_data($(this), false); 282 283 // console.log(JSON.stringify('MER.form_data', null, 4)); 284 // console.log( MER.form_data ); 285 if (typeof MER.form_data.ee === 'undefined') { 286 // alert('206) MER.form_data.ee = ' + MER.form_data.ee); 287 MER.form_data.ee = 'view_event_cart'; 288 MER.form_data.event_cart = 'view'; 289 // console.log(JSON.stringify('MER.form_data', null, 4)); 290 // console.log(MER.form_data); 291 } 292 293 let ticket_count = 0; 294 if (typeof MER.form_data['tkt-slctr-event-id'] !== 'undefined' && 295 MER.form_data['tkt-slctr-event-id'] !== '' 296 ) { 297 let tkt_slctr_qty = 'tkt-slctr-qty-'; 298 tkt_slctr_qty += MER.form_data['tkt-slctr-event-id']; 299 tkt_slctr_qty += '[]'; 300 //console.log( tkt_slctr_qty ); 301 //console.log( MER.form_data[ tkt_slctr_qty ] ); 302 if (typeof MER.form_data[tkt_slctr_qty] !== 'undefined' && 303 MER.form_data[tkt_slctr_qty] !== '' 304 ) { 305 const ticket_quantities = MER.form_data[tkt_slctr_qty]; 306 //console.log( 'ticket_quantities' ); 307 //console.log( ticket_quantities ); 308 if (typeof ticket_quantities === 'object') { 309 $.each(ticket_quantities, function (index, ticket_quantity) { 310 //console.log( 'ticket_quantity' ); 311 //console.log( ticket_quantity ); 312 ticket_count = ticket_count + parseInt(ticket_quantity); 313 //alert( 'ticket_quantity = ' + parseInt( ticket_quantity ) ); 314 }); 315 } else { 316 ticket_count = parseInt(ticket_quantities); 317 } 318 } 319 } 320 ticket_count = parseInt(ticket_count); 321 //console.log( JSON.stringify( 'ticket_count: ' + ticket_count, null, 322 // 4 ) ); console.log( JSON.stringify( 'typeof ticket_count: ' + ( 323 // typeof ticket_count ), null, 4 ) ); console.log( JSON.stringify( 324 // 'MER.form_data.event_cart: ' + MER.form_data.event_cart, null, 4 ) 325 // ); var view_cart = MER.form_data.event_cart === 'view'; 326 const view_cart = typeof MER.form_data.event_cart !== 'undefined' && 327 MER.form_data.event_cart === 'view'; 328 //console.log( JSON.stringify( 'view_cart: ' + view_cart, null, 4 ) 329 // ); 330 //console.log( JSON.stringify( 'MER.ticket_selector_iframe: ' + 331 // MER.ticket_selector_iframe, null, 4 ) ); alert( 332 // 'MER.form_data.event_cart = ' + MER.form_data.event_cart + '\n' + 333 // 'ticket_count = ' + ticket_count + '\n' + 'view_cart = ' + 334 // view_cart ); alert('( ticket_count !== 0 ) = ' + ( ticket_count 335 // !== 0 ) + '\n' + '( ticket_count === 0 && ! view_cart ) = ' + ( 336 // ticket_count === 0 && !view_cart ) + '\n' + '! ( 337 // MER.ticket_selector_iframe && view_cart ) = ' + !( 338 // MER.ticket_selector_iframe && view_cart )); 339 if (! (MER.ticket_selector_iframe && view_cart)) { 340 MER.form_data.action = 'espresso_' + MER.form_data.ee; 341 MER.submit_ajax_request(); 342 event.preventDefault(); 343 event.stopPropagation(); 344 } 345 // console.log( JSON.stringify( 'ticket_count: ' + ticket_count, 346 // null, 4 ) ); console.log( JSON.stringify( 'view_cart: ' + 347 // view_cart, null, 4 ) ); 348 }); 349 }, 350 351 /** 352 * @function close_modal 353 * @param {Object} event 354 */ 355 close_modal: function (event) { 356 const cart_results_wrapper = $('#cart-results-modal-wrap-dv'); 357 if (cart_results_wrapper.length) { 358 cart_results_wrapper.eeRemoveOverlay().hide(); 359 event.preventDefault(); 360 event.stopPropagation(); 361 if (MER.ticket_selector_submit_btn !== null) { 362 MER.ticket_selector_submit_btn.focus(); 363 MER.ticket_selector_submit_btn = null; 364 } 365 } 366 }, 367 368 /** 369 * @function close_modal_after_click 370 */ 371 close_modal_after_click: function (event) { 372 MER.remove_listeners_for_modal(); 373 MER.close_modal(event); 374 }, 375 376 /** 377 * @function set_listener_for_close_modal_btn 378 */ 379 set_listener_for_close_modal_btn: function () { 380 $(document).on( 381 'click', 382 '.close-modal-js', 383 MER.close_modal_after_click 384 ); 385 }, 386 387 /** 388 * @function close_modal_after_click 389 */ 390 close_modal_after_keyup: function (event) { 391 if (event.keyCode === 27) { 392 MER.remove_listeners_for_modal(); 393 MER.close_modal(event); 394 } 395 }, 396 397 /** 398 * @function set_listener_for_escape_modal 399 */ 400 set_listener_for_escape_modal: function () { 401 $(document).on('keyup', MER.close_modal_after_keyup); 402 }, 403 404 /** 405 * @function set_listener_for_escape_modal 406 */ 407 remove_listeners_for_modal: function () { 408 $(document).unbind('click', MER.close_modal_after_keyup); 409 $(document).unbind('keyup', MER.close_modal_after_keyup); 410 }, 411 412 /** 413 * @function submit_promo_code 414 */ 415 submit_ajax_request: function () { 416 // console.log(JSON.stringify('MER.form_data', null, 4)); 417 // console.log(MER.form_data); 418 // no form_data ? 419 if (typeof MER.form_data.action === 'undefined' || MER.form_data.action === '') { 420 return; 421 } 422 MER.form_data.noheader = 1; 423 MER.form_data.ee_front_ajax = 1; 424 // send AJAX 425 $.ajax({ 426 427 type: 'POST', 428 url: eei18n.ajax_url, 429 data: MER.form_data, 430 dataType: 'json', 431 432 beforeSend: function () { 433 MER.do_before_sending_ajax(); 434 }, 435 436 success: function (response) { 437 MER.response = response; 438 MER.process_response(MER.response); 439 MER.do_after_ajax(); 440 }, 441 442 error: function (response) { 443 MER.response = response; 444 MER.response.error = eei18n.server_error; 445 MER.do_after_ajax(); 446 }, 447 448 }); 449 450 }, 451 452 /** 453 * @function do_before_sending_ajax 454 */ 455 do_before_sending_ajax: function () { 456 MER.disable_buttons(); 457 $('#espresso-ajax-long-loading').remove(); 458 $('#espresso-ajax-loading').show(); 459 }, 460 461 /** 462 * @function do_after_ajax 463 */ 464 do_after_ajax: function () { 465 MER.enable_buttons(); 466 $('#espresso-ajax-loading').fadeOut('fast'); 467 MER.display_messages(MER.response); 468 }, 469 470 /** 471 * @function process_response 472 */ 473 process_response: function () { 474 // console.log(MER.response); 475 if (typeof MER.response === 'object') { 476 if (typeof MER.response.redirect_url !== 'undefined' && MER.response.redirect_url !== '') { 477 // redirect browser 478 window.location.replace(MER.response.redirect_url); 479 return; 480 } 481 if (typeof MER.response.new_html !== 'undefined') { 482 MER.process_new_html(); 483 } 484 if (typeof MER.response.tickets_added !== 'undefined' && 485 MER.response.tickets_added === true 486 ) { 487 MER.process_tickets_added(); 488 } 489 if (typeof MER.response.mini_cart !== 'undefined' && 490 MER.response.mini_cart !== '' 491 ) { 492 MER.process_mini_cart(); 493 494 } 495 if (typeof MER.response.cart_results !== 'undefined' && 496 MER.response.cart_results !== '' 497 ) { 498 MER.process_cart_results(); 499 } 500 } 501 }, 502 503 /** 504 * @function process_new_html 505 */ 506 process_new_html: function () { 507 // loop thru tracked errors 508 $.each(MER.response.new_html, function (index, html) { 509 // console.log( JSON.stringify( 'index: ' + index, null, 4 ) ); 510 if (typeof index !== 'undefined' && typeof html !== 'undefined') { 511 const event_cart_element = $(MER.event_cart).find(index); 512 if (event_cart_element.length) { 513 event_cart_element.replaceWith(html); 514 $(MER.event_cart).parent().eeScrollTo(200); 515 // console.log( JSON.stringify( 'html: ' + html, null, 4 ) ); 516 } 517 } 518 }); 519 }, 520 521 /** 522 * @function process_tickets_added 523 */ 524 process_tickets_added: function () { 525 const btn_id = typeof MER.response.btn_id !== 'undefined' 526 ? MER.response.btn_id 527 : ''; 528 const btn_txt = typeof MER.response.btn_txt !== 'undefined' 529 ? MER.response.btn_txt 530 : ''; 531 const form_html = typeof MER.response.form_html !== 'undefined' 532 ? MER.response.form_html 533 : ''; 534 const submit_button = $(btn_id); 535 if (submit_button.length && btn_txt !== '') { 536 if (submit_button.val() !== btn_txt)
536{ 537 submit_button.val(btn_txt); 538 const ticket_form = submit_button.parents('form:first'); 539 if (ticket_form.length && form_html !== '') { 540 ticket_form.append(form_html); 541 //console.log( JSON.stringify( 'form_html: ' + form_html, null, 4 )); 542 } 543 } 544 } 545 $('.ticket-selector-tbl-qty-slct').each(function () { 546 //console.log( JSON.stringify( 'ticket-selector-tbl-qty-slct id: ' + $(this).attr('id'), null, 4 ) ); 547 if ($(this).find('option[value="0"]').length > 0) { 548 $(this).val(0); 549 } 550 $(this).prop('checked', false); 551 }); 552 }, 553 554 /** 555 * @function process_mini_cart 556 */ 557 process_mini_cart: function () { 558 const mini_cart = $('#ee-mini-cart-details'); 559 //console.log( mini_cart ); 560 if (mini_cart.length) { 561 mini_cart.html(MER.response.mini_cart); 562 $('#mini-cart-whats-next-buttons').fadeIn(); 563 } 564 }, 565 566 /** 567 * @function process_cart_results 568 */ 569 process_cart_results: function () { 570 const cart_results_wrapper = $('#cart-results-modal-wrap-dv'); 571 //console.log( mini_cart ); 572 if (cart_results_wrapper.length) { 573 cart_results_wrapper.html(MER.response.cart_results) 574 .eeCenter('fixed') 575 .eeAddOverlay(0.5) 576 .show(); 577 MER.add_modal_notices(); 578 // now that modal is open, set listeners for closing it 579 MER.set_listener_for_close_modal_btn(); 580 MER.set_listener_for_escape_modal(); 581 } else if (MER.ticket_selector_iframe) { 582 MER.show_event_cart_ajax_msg('success', 583 eei18n.iframe_tickets_added, 584 6000 585 ); 586 } 587 588 }, 589 590 /** 591 * @function add_modal_notices 592 */ 593 add_modal_notices: function () { 594 let notices = ''; 595 if (typeof MER.response.attention !== 'undefined' && MER.response.attention) { 596 notices += '<div class="espresso-ajax-modal-notices attention"><p>'; 597 notices += MER.response.attention + '</p></div>'; 598 } else if (typeof MER.response.errors !== 'undefined' && MER.response.errors) { 599 notices += '<div class="espresso-ajax-modal-notices errors"><p>'; 600 notices += MER.response.errors + '</p></div>'; 601 } else if (typeof MER.response.success !== 'undefined' && MER.response.success) { 602 notices += '<div class="espresso-ajax-modal-notices success"><p>'; 603 notices += MER.response.success + '</p></div>'; 604 } 605 if (notices !== '') { 606 notices = '<div id="espresso-ajax-modal-notices-dv"' + 607 ' style="display: block;">' + notices + '</div>'; 608 const cart_results = $('#cart-results-modal-dv'); 609 const notices_width = cart_results.innerWidth(); 610 cart_results.append(notices); 611 $('#espresso-ajax-modal-notices-dv') 612 .css({'width': notices_width}) 613 .show(); 614 } 615 }, 616 617 /** 618 * @function get_form_data 619 * @param {object} form_container 620 * @param {boolean} form_within - whether the form should be looked for 621 * above or within the indicated DOM element 622 */ 623 get_form_data: function (form_container, form_within) { 624 if (! form_container.length) { 625 return {}; 626 } 627 form_within = typeof form_within === 'boolean' ? form_within : false; 628 const serialized_form_data = form_within 629 ? form_container.find('form').serializeArray() 630 : form_container.parents('form:first').serializeArray(); 631 return MER.convert_to_JSON(serialized_form_data); 632 }, 633 634 /** 635 * @function disable_buttons 636 */ 637 disable_buttons: function () { 638 $('.event-cart-button').each(function () { 639 $(this).addClass('js-disabled-event-cart-btn'); 640 }); 641 }, 642 643 /** 644 * @function enable_buttons 645 */ 646 enable_buttons: function () { 647 $('.event-cart-button').each(function () { 648 $(this).removeClass('js-disabled-event-cart-btn'); 649 }); 650 }, 651 652 /** 653 * @function display messages 654 * @param {object} msg 655 */ 656 display_messages: function (msg) { 657 if (typeof msg.attention !== 'undefined' && msg.attention) { 658 MER.show_event_cart_ajax_msg('attention', msg.attention, 18000); 659 } else if (typeof msg.errors !== 'undefined' && msg.errors) { 660 MER.show_event_cart_ajax_msg('error', msg.errors, 12000); 661 } else if (typeof msg.success !== 'undefined' && msg.success) { 662 MER.show_event_cart_ajax_msg('success', msg.success, 6000); 663 } 664 }, 665 666 /** 667 * @function show event cart ajax msg 668 * @param {string} type 669 * @param {string} msg 670 * @param {number} fadeOut 671 */ 672 show_event_cart_ajax_msg: function (type, msg, fadeOut) { 673 // does an actual message exist ? 674 if (typeof msg !== 'undefined' && msg !== '') { 675 // ensure message type is set 676 /** @type {string} - whether an error or success */ 677 const msg_type = typeof type !== 'undefined' && type !== '' 678 ? type 679 : 'error'; 680 // make sure fade out time is not too short 681 fadeOut = typeof fadeOut === 'undefined' || fadeOut < 4000 682 ? 4000 683 : fadeOut; 684 // center notices on screen 685 MER.ajax_notices.eeCenter('fixed'); 686 /** @type {object} - target parent container */ 687 const espresso_ajax_msg = $('#espresso-ajax-notices-' + msg_type); 688 /** @type {object} - actual message container */ 689 espresso_ajax_msg.children('.espresso-notices-msg').html(msg); 690 // display message 691 espresso_ajax_msg.removeClass('hidden') 692 .show() 693 .delay(fadeOut) 694 .fadeOut(); 695 } 696 }, 697 698 /** 699 * @function convert_to_JSON 700 * @param {string} serialized_array 701 */ 702 convert_to_JSON: function (serialized_array) { 703 const json_object = {}; 704 $.each(serialized_array, function () { 705 if (json_object[this.name]) { 706 if (! json_object[this.name].push) { 707 json_object[this.name] = [json_object[this.name]]; 708 } 709 json_object[this.name].push(this.value || ''); 710 } else { 711 json_object[this.name] = this.value || ''; 712 } 713 }); 714 return json_object; 715 }, 716 717 718 }; 719 720 MER.initialize(); 721 722}
vendor: 4 bytes, lines 722-723
722); 723
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.