1( function ( $ ) { 2 "use strict"; 3 4 let latlApp = { 5 6 init: function () { 7 this.bind(); 8 this.dom(); 9 }, 10 dom: function () { 11 this.form; 12 this.formParent; 13 this.ajaxRunning = false; 14 }, 15 bind: function () { 16 document.addEventListener( 'submit', ( event ) => { 17 18 if ( event.target.closest( '.latl-form' ) ) { 19 event.preventDefault(); 20 latlApp.formSubmit.call( event.target, event ); 21 } 22 } ); 23 24 $( document ).on( 'click', '.latl-changer', function ( e ) { 25 e.preventDefault(); 26 const linkParent = $( this ).closest( '.tipi-logged-out-wrap' ); 27 linkParent.removeClass( 'latl-active-1 latl-active-2 latl-active-3' ).addClass( 'latl-active-' + $( this ).data( 'changer' ) ); 28 } ); 29 30 $( document ).on( 'click', '.latl-cancel', function ( e ) { 31 e.preventDefault(); 32 const linkParent = $( this ).closest( '.tipi-logged-out-wrap' ); 33 linkParent.find( '.latl-status' ).attr( 'class', 'latl-status' ).html( '' ); 34 linkParent.removeClass( 'latl-active-1 latl-active-2 latl-active-3' ).addClass( 'latl-active-1' ); 35 } ); 36 }, 37 formSubmit: function ( event ) { 38 39 event.preventDefault(); 40 41 latlApp.form = $( this ); 42 latlApp.formParent = latlApp.form.closest( '.tipi-logged-out' ); 43 44 let ajaxFlag = latlApp.form.find( '.latl-ajax' ); 45 46 if ( ajaxFlag.length === 0 ) { 47 ajaxFlag = $( '<input class="latl-ajax" name="lwa" type="hidden" value="1" />' ); 48 latlApp.form.prepend( ajaxFlag ); 49 } 50 51 if ( latlApp.ajaxRunning === true ) { 52 return; 53 } 54 55 $.ajax( { 56 type: 'POST', 57 url: latl.ajax_url, 58 data: new URLSearchParams( new FormData( this ) ).toString(), 59 dataType: 'json', 60 beforeSend: function () { 61 latlApp.loadingOn(); 62 }, 63 success: function ( data ) { 64 65 // Handle the message. 66 latlApp.messageHandler( data ); 67 68 // Disable the loading animation. 69 latlApp.loadingOff(); 70 71 // Check if the result isn't successful. 72 if ( data.status !== 'success' || data.action === 'reset' ) { 73 // If so, bail. 74 return; 75 } 76 77 // Refresh the page. 78 setTimeout( function () { 79 location.reload(); 80 }, 300 ); 81 82 // Trigger the event on the document. 83 $( document ).trigger( 'latl_' + data.action, [ data, latlApp.form ] ); 84 85 }, 86 error: function ( data ) { 87 88 // Handle the message. 89 latlApp.messageHandler( data ); 90 91 // Disable the loading animation. 92 latlApp.loadingOff(); 93 }, 94 95 } ); 96 97 }, 98 loadingOn: function () { 99 latlApp.formParent.addClass( 'loading' ).parent().addClass( 'tipi-spin' ); 100 latlApp.ajaxRunning = true; 101 }, 102 loadingOff: function () { 103 latlApp.formParent.removeClass( 'loading' ).parent().removeClass( 'tipi-spin' ); 104 setTimeout( function () { 105 latlApp.ajaxRunning = false; 106 }, 750 ); 107 }, 108 messageHandler: function ( data ) { 109 const statusElement = $( '.latl-status' ); 110 111 // Check if the message was successful. 112 if ( data.status === 'success' ) { 113 // If so, add the success class and message. 114 statusElement.attr( 'class', 'latl-status latl-status-confirm' ).html( data.message ); 115 } else { 116 const errorMsg = data.message ? data.message : latl.i18n.error; 117 statusElement.attr( 'class', 'latl-status latl-status-invalid' ).html( errorMsg ); 118 } 119 } 120 }; 121 latlApp.init(); 122} )( jQuery );
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.