1 2var LWA_Ajaxify = { 3 ajaxifiables : {}, 4 is_ajaxifiable : function( $form ){ 5 // we can pass a jQuery object or a DOM element, but we ideally want DOM 6 let form = $form instanceof jQuery ? $form[0] : $form; 7 let type = false; 8 Object.keys(LWA_Ajaxify.ajaxifiables).forEach( function( selector ){ 9 if( form.matches( selector ) ){ 10 type = selector; 11 } 12 }); 13 return type; 14 }, 15 init : function() { 16 document.dispatchEvent( new CustomEvent( 'lwa_ajaxify_init' ) ); 17 jQuery( Object.keys( LWA_Ajaxify.ajaxifiables ).join(',') ).each( function( el ){ 18 let $form = jQuery(this); 19 $form.wrap('<div class="lwa-wrapper"></div>') 20 .wrap('<div class="lwa"></div>') 21 .addClass('lwa-form'); 22 let selector = LWA_Ajaxify.is_ajaxifiable( this ); 23 let ajaxify = LWA_Ajaxify.ajaxifiables[selector]; // we assume in this case it comes up positive since it's a matched selector already 24 if ( ajaxify.type === 'login' ) { 25 $form.append( jQuery('<input type="hidden" name="login-with-ajax" value="login">') ); 26 } else if ( ajaxify.type === 'register' ) { 27 $form.append( jQuery('<input type="hidden" name="login-with-ajax" value="register">') ); 28 } else if ( ajaxify.type === 'remember' ) { 29 $form.append( jQuery('<input type="hidden" name="login-with-ajax" value="remember">') ); 30 } 31 if( ajaxify && typeof ajaxify.init == 'function' ) { 32 ajaxify.init( this ); 33 } 34 }); 35 jQuery(document).on('lwa_addStatusElement', function(e, form, statusElement){ 36 let selector = LWA_Ajaxify.is_ajaxifiable( form ); 37 if( selector !== false ) { 38 let ajaxify = LWA_Ajaxify.ajaxifiables[selector]; 39 if( ajaxify && typeof ajaxify.addStatusElement == 'function' ) { 40 ajaxify.addStatusElement( form, statusElement ); 41 } 42 } 43 }); 44 jQuery(document).on('lwa_handleStatus', function(e, response, statusElement){ 45 if( statusElement.hasClass('lwa-ajaxify-status') ) { 46 let form = statusElement.closest('.lwa').find( Object.keys(LWA_Ajaxify.ajaxifiables).join(',') ); 47 if ( form.length > 0 ) { 48 statusElement.show(); 49 let selector = LWA_Ajaxify.is_ajaxifiable( form ); 50 let ajaxify = LWA_Ajaxify.ajaxifiables[selector]; 51 if( ajaxify && typeof ajaxify.handleStatus == 'function' ) { 52 ajaxify.handleStatus( response, statusElement, form ); 53 } 54 } 55 } 56 }); 57 jQuery(document).on('lwa_pre_ajax', function(e, response, form, statusElement){ 58 let selector = LWA_Ajaxify.is_ajaxifiable( form ); 59 if( selector !== false ) { 60 statusElement.hide(); 61 let ajaxify = LWA_Ajaxify.ajaxifiables[selector]; 62 if( ajaxify && typeof ajaxify.pre_ajax == 'function' ) { 63 ajaxify.pre_ajax( form ); 64 } 65 } 66 }); 67 jQuery(document).on('lwa_register lwa_remember', function(e, response, form, statusElement){ 68 let selector = LWA_Ajaxify.is_ajaxifiable( form ); 69 if ( selector ) { 70 let ajaxify = LWA_Ajaxify.ajaxifiables[selector]; // we assume in this case it comes up positive since it's a matched selector already 71 if (['register', 'remember'].includes(ajaxify.type)) { 72 if (response.result) { 73 form.hide(); 74 form.find('input').val(''); 75 } 76 if (ajaxify && typeof ajaxify[e.type] == 'function') { 77 ajaxify[e.type](form); 78 } 79 } 80 } 81 }); 82 document.dispatchEvent( new CustomEvent( 'lwa_ajaxify_loaded' ) ); 83 } 84}; 85jQuery(document).ready( LWA_Ajaxify.init );
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.