1( function( $ ) { 2 3 VamtamSubscribeForm = function( settings ) 4 { 5 this.settings = settings; 6 this.nodeClass = '.fl-node-' + settings.id; 7 this.form = $( this.nodeClass + ' .fl-subscribe-form' ); 8 this.button = this.form.find( 'a.vamtam-button' ); 9 this._init(); 10 }; 11 12 VamtamSubscribeForm.prototype = { 13 14 settings : {}, 15 nodeClass : '', 16 form : null, 17 button : null, 18 19 _init: function() 20 { 21 this.button.on( 'click', $.proxy( this._submitForm, this ) ); 22 }, 23 24 _submitForm: function( e ) 25 { 26 var postId = this.form.closest( '.fl-builder-content' ).data( 'post-id' ), 27 templateId = this.form.data( 'template-id' ), 28 templateNodeId = this.form.data( 'template-node-id' ), 29 nodeId = this.form.closest( '.fl-module' ).data( 'node' ), 30 buttonText = this.button.find( '.vamtam-button-text' ).text(), 31 waitText = this.button.closest( '.fl-form-button' ).data( 'wait-text' ), 32 name = this.form.find( 'input[name=fl-subscribe-form-name]' ), 33 email = this.form.find( '
33input[name=fl-subscribe-form-email]' ), 34 re = /\S+@\S+\.\S+/, 35 valid = true; 36 37 e.preventDefault(); 38 39 if ( this.button.hasClass( 'fl-form-button-disabled' ) ) { 40 return; // Already submitting 41 } 42 if ( name.length > 0 && name.val() == '' ) { 43 name.addClass( 'fl-form-error' ); 44 name.siblings( '.fl-form-error-message' ).show(); 45 valid = false; 46 } 47 if ( '' == email.val() || ! re.test( email.val() ) ) { 48 email.addClass( 'fl-form-error' ); 49 email.siblings( '.fl-form-error-message' ).show(); 50 valid = false; 51 } 52 53 if ( valid ) { 54 55 this.form.find( '> .fl-form-error-message' ).hide(); 56 this.button.find( '.vamtam-button-text' ).text( waitText ); 57 this.button.data( 'original-text', buttonText ); 58 this.button.addClass( 'fl-form-button-disabled' ); 59 60 $.post( FLBuilderLayoutConfig.paths.wpAjaxUrl, { 61 action : 'fl_builder_subscribe_form_submit', 62 name : name.val(), 63 email : email.val(), 64 post_id : postId, 65 template_id : templateId, 66 template_node_id : templateNodeId, 67 node_id : nodeId 68 }, $.proxy( this._submitFormComplete, this ) ); 69 } 70 }, 71 72 _submitFormComplete: function( response ) 73 { 74 var data = JSON.parse( response ), 75 buttonText = this.button.data( 'original-text' ); 76 77 if ( data.error ) { 78 79 if ( data.error ) { 80 this.form.find( '> .fl-form-error-message' ).text( data.error ); 81 } 82 83 this.form.find( '> .fl-form-error-message' ).show(); 84 this.button.removeClass( 'fl-form-button-disabled' ); 85 this.button.find( '.vamtam-button-text' ).text( buttonText ); 86 } else if ( 'message' == data.action ) { 87 this.form.find( '> *' ).hide(); 88 this.form.append( '<div class="fl-form-success-message">' + data.message + '</div>' ); 89 } else if ( 'redirect' == data.action ) { 90 window.location.href = data.url; 91 } 92 } 93 } 94 95 function initSubForms() { 96 const subForms = document.querySelectorAll( '.fl-module-vamtam-subscribe-form' ); 97 subForms.forEach( form => { 98 const id = form.dataset.node; 99 //We're essentially binding the form's button click to the appropriate handler. 100 new VamtamSubscribeForm( { 101 id: id, 102 } ) 103 }); 104 } 105 106 document.addEventListener( 'DOMContentLoaded', function() { 107 if ( window.FLBuilder ) { 108 FLBuilder.addHook( 'didCompleteAJAX', initSubForms ); 109 FLBuilder.addHook( 'didRenderLayoutComplete', initSubForms ); 110 } 111 initSubForms(); 112 } ); 113})( 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.