Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function ($){
- var form_json_data = false;
- var form_id;
- var flag = false;
- var title_field_name;
- var after_submit = true;
- /*
- * After Submit the form Abandoned setting false
- */
- jQuery(document).on( 'click' , '.wpcf7-submit' , function(){
- if(jQuery(document).find('.wpcf7-response-output').length > 0){
- after_submit = false;
- }
- });
- /*
- * All Field are Required
- */
- if( jQuery(document).find('.all-field').length > 0 ){
- jQuery(document).on( 'input' , '.esb-cf7-abandoned-form :input' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form select' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form input[type=radio]' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form input[type=checkbox]' , prepare_data );
- }
- /*
- * If Email or Phone Number is Provided
- */
- if( jQuery(document).find('.req-field').length > 0 ){
- jQuery(document).on( 'input' , '.esb-cf7-abandoned-form :input[type=email]' , check_email_val);
- jQuery(document).on( 'input' , '.esb-cf7-abandoned-form :input[type=number]' , check_email_val );
- /*
- * Check that Email or Phone exict or not
- */
- function check_email_val(){
- if( jQuery(this).val() ){
- jQuery(document).on( 'input' , '.esb-cf7-abandoned-form :input' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form select' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form input[type=radio]' , prepare_data );
- jQuery(document).on( 'change' , '.esb-cf7-abandoned-form input[type=checkbox]' , prepare_data );
- }
- }
- }
- /*
- * function to prepare json data
- */
- function prepare_data( event ){
- if( jQuery(document).find('.esb-cf7-abandoned-form').length > 0 ){
- var form = jQuery(event.target).closest('.esb-cf7-abandoned-form');
- form_id = jQuery(document).find('input:hidden[name=_wpcf7]').val();
- form_json_data = JSON.stringify( form.serializeArray() );
- }
- jQuery.each( form, function( i, form_val ) {
- jQuery.each( form_val, function( i, input_tag ) {
- if( input_tag.tagName.toLowerCase() != 'textarea' && i >= 5 ){
- title_field_name = jQuery( input_tag ).attr('name');
- return false;
- }
- });
- });
- }
- /*
- * Tab Chage Event
- */
- jQuery(document).on( 'mouseleave', mouse_leave_event );
- /*
- * click Of Link 'a' tag
- */
- jQuery(document).on( 'click', click_event );
- /*
- * Window Refresh Event
- */
- jQuery(window).unload(function() {
- send_data();
- });
- /*
- * Send Data In post via Ajax
- */
- function send_data( ){
- if( !after_submit ){
- return;
- }
- if ( !form_json_data || flag) {
- return;
- }
- flag = true;
- /*
- * Set flag false after 5 second
- */
- setTimeout( function() {
- flag = false;
- }, 5000 );
- jQuery.ajax({
- url : ESB_CF7_PUBLIC_ENTRIES_AJAX.ajaxurl,
- type: 'post',
- data: {
- action : 'esb_cf7_abandoned_entry',
- form_id : form_id,
- title_field_name : title_field_name,
- form_value : form_json_data
- }
- });
- form_json_data = false;
- }
- /*
- * If mouse leave from only topbar
- */
- function mouse_leave_event( event ){
- if ( event.offsetX < -1 || event.clientY > 20 ) {
- return;
- }
- send_data();
- }
- /*
- * Click of 'a' Tag ( Same Screen Or target=_blank )
- */
- function click_event( event ){
- var click_item = event.srcElement;
- if( click_item.tagName == 'undefined' || click_item.tagName.toLowerCase() !== 'a' || !click_item.href ){
- click_item = click_item.parentNode;
- }
- if( click_item && click_item.href){
- var link = click_item.href;
- if( ! link.match( /^javascript\:/i ) ){
- var target = ( click_item.target && !click_item.target.match( /^_(self|parent|top)$/i ) ) ? click_item.target : false;
- }
- if ( event.ctrlKey || event.shiftKey || event.metaKey ) {
- target = '_blank';
- }
- if ( target ) {
- /*
- * If target is = _blank , javascript: , self , parent , top than opens a new window and trigger send_data() function
- */
- send_data();
- }else {
- /*
- * If target is not defined Prevent standard click, track then open
- */
- if ( event.preventDefault ) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- }
- /*
- * Trigger send_data() function & Proceed to URL
- */
- send_data();
- window.location.href = link;
- }
- }
- }
- });//End Of Documnet Ready
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement