1jQuery.fn.bindFirst = function(name, fn) { 2 // bind as you normally would 3 // don't want to miss out on any jQuery magic 4 this.on(name, fn); 5 var events = this.data('events') || jQuery._data(this[0], 'events'); 6 var handlers = events[name]; 7 // take out the handler we just inserted from the end 8 var handler = handlers.splice(handlers.length - 1)[0]; 9 // move it at the beginning 10 handlers.splice(0, 0, handler); 11}; 12 13//Rainmaker 14var Rainmaker = function() {} 15 16Rainmaker.prototype = { 17 18 init : function(form){ 19 // var that = form; 20 21 if(jQuery(form).closest('.rainmaker_form').length < 1) return; 22 23 if(jQuery(form).closest('.rainmaker_form').hasClass('rm_init_done') ) return; 24 25 if(jQuery(form).find('.rm_required_field, .ig_form_required_field').length < 1){ 26 jQuery(form).append('<div style="position:absolute; left: -5000px"><input type="text" class="rm_required_field" value="" tabindex="-1"/></div>'); 27 } 28 29 jQuery(form).closest('.rainmaker_form').addClass(jQuery(form).closest('.rainmaker_form').data('type') || ''); 30 31 jQuery(form).bindFirst('submit', function(e){ 32 window.rainmaker.addLead(e, jQuery(e.target)); 33 }); // submit Event 34 35 jQuery(form).closest('.rainmaker_form').addClass('rm_init_done'); 36 }, 37 38 addLead : function(e, form, icg_msg){ 39 var form = form || undefined; 40 if(typeof(form) !== 'undefined'){ 41 42 if(jQuery(form).closest('.rainmaker_form').length < 1) return; 43 44 var icg_msg = icg_msg || undefined; 45 var fm_parent = form.closest('.rainmaker_form'); 46 47 jQuery(fm_parent).find('.rm-loader').show(); 48 jQuery(fm_parent).find('.rm_button').attr("disabled", true); 49 // TODO :: Quick fix - Allowing mailchimp 4 WP form submission even if the action is blank. 50 var mc4wpform = jQuery(form).find('input[name="_mc4wp_form_id"]') && jQuery(form).find('input[name="_mc4wp_form_id"]').length > 0; 51 if(!jQuery(fm_parent).hasClass('rm_custom') || (!jQuery(form).attr('action') && !mc4wpform) ){ 52 e.preventDefault(); 53 } 54 55 if(jQuery(form).find('.rm_required_field').val() || jQuery(form).find('.ig_form_required_field').val()){ 56 jQuery(fm_parent).find('.rm-loader').hide(); 57 form.slideUp("slow"); 58 jQuery(fm_parent).find('div.rm_form_message').show(); 59 return; 60 } 61 var formData = {}; 62 var formData = window.rainmaker.prepareFormData(e, form, icg_msg, formData); 63 action = rm_pre_data.ajax_url + '?action=rm_rainmaker_add_lead'; 64 jQuery(form).trigger( 'add_lead.rm', [formData] ); 65 66 jQuery.ajax({ 67 68 type: 'POST', 69 url: action, 70 data: formData, 71 dataType: 'json', 72 success: function(response){ 73 if(response && typeof response.error !== 'undefined' && response.error !== ""){ 74 jQuery(fm_parent).find('.rm-loader').hide(); 75 jQuery(fm_parent).find('div.rm_form_error_message').text(response.error).show(); 76 jQuery(window).trigger('error.rm', [form, response]); 77 } else if(response && typeof response.success !== 'undefined'){ 78 jQuery(form)[0].reset(); 79 jQuery(form).trigger('success.rm', [form, response]); 80 jQuery(fm_parent).find('.rm-loader').hide(); 81 //TODO :: Later Move this in success callback 82 form_message = jQuery(fm_parent).next('div.rm_form_message').html(); 83 if( typeof form_message !== 'undefined' && form_message.trim() !== ''){ 84 jQuery(fm_parent).slideUp("slow"); 85 jQuery(fm_parent).next('div.rm_form_message').show(); 86 // jQuery(fm_parent).next().next('div.rm_form_error_message').hide(); 87 } 88 //TODO :: Later Move this in success callback 89 var redirection_url = response.redirection_url || ''; 90 redirection_url = redirection_url.trim(); 91 if (typeof(redirection_url) === 'string' && redirection_url != '') { 92 if (!/^https?:\/\//i.test(redirection_url) ) { 93 redirection_url = "http://"+redirection_url; 94 } 95 setTimeout(function(){ 96 window.location.href = redirection_url; 97 }, 200); 98 } 99 100 }else{ 101 jQuery(fm_parent).find('.rm-loader').hide(); 102 } 103 }, 104 error: function(err){ 105 jQuery(fm_parent).find('.rm-loader').hide(); 106 console.log(err); 107 }, 108 }); 109 } 110 }, 111 112 prepareFormData: function (e, form, icg_msg, formData){ 113 jQuery.each((jQuery(form).serializeArray() || {}), function(i, field){ 114 formData['rmfpx_'+ field.name] = field.value; 115 }); 116 117 formData['rmfpx_added'] = true; 118 formData['rmfpx_rm_nonce_field'] = rm_pre_data.rm_nonce_field; 119 formData['rmfpx_rm_form-id'] = jQuery(form.closest('.rainmaker_form')).data('form-id'); 120 121 // Send Icegram Data To Rainmaker 122 if(typeof icegram !== 'undefined'){ 123 formData['rmfpx_ig_mode'] = icegram.mode; 124 formData['rmfpx_ig_remote_url'] = window.location.href; 125 if(typeof icg_msg === 'undefined'){ 126 var msg_id = (jQuery(form.closest('[id^=icegram_message_]') || {}).attr('id') || '').split('_').pop() || 0 ; 127 icg_msg = icegram.get_message_by_id(msg_id) || {}; 128 } 129 if(typeof icg_msg.data !== 'undefined'){ 130 formData['rmfpx_ig_message_id'] = icg_msg.data.id; 131 formData['rmfpx_ig_campaign_id'] = icg_msg.data.campaign_id; 132 } 133 } 134 return formData; 135 }, 136 137 138}; 139 140if(typeof window.rainmaker === 'undefined'){ 141 window.rainmaker = new Rainmaker(); 142} 143 144jQuery(document).ready(function(){ 145 jQuery('.rainmaker_form form').each(function(i, v){ 146 window.rainmaker.init(v); 147 }); 148}); 149
150// Start : For Icegram Compatibility 151jQuery( window ).on( "init.icegram", function(e, ig) { 152 // Find and init all RM forms within Icegram messages/divs 153 if(typeof ig !== 'undefined' && typeof ig.messages !== 'undefined' ){ 154 jQuery.each(ig.messages, function(i, msg){ 155 var forms = jQuery(msg.el).find('.rainmaker_form form'); 156 forms.each(function(i, form){ 157 if(!jQuery(form).hasClass('rm_init_done')){ 158 window.rainmaker.init(form); 159 jQuery(form).addClass('rm_init_done'); 160 } 161 }); 162 }); 163 } 164 165}); // init.icegram 166 167//Handle CTA function(s) after successful submission of form 168 jQuery( window ).off('success.rm'); 169 jQuery( window ).on('success.rm', function(e, form, response) { 170 if( typeof icegram !== 'undefined'){ 171 var msg_id = ((jQuery(e.target).closest('[id^=icegram_message_]') || {}).attr('id') || '').split('_').pop() || 0 ; 172 var msg = icegram.get_message_by_id(msg_id) || undefined; 173 if(typeof msg !== 'undefined'){ 174 //TODO:: test this for contact form. 175 // if(msg.data.cta === 'form_via_ajax' && msg.el.find('.rm_subscription').length > 0){ 176 if(msg.data.cta === 'form_via_ajax' && msg.el.find('.rm_subscription, .rm_contact').length > 0){ 177 // TODO::test this , causing duplicate messages 178 msg.el.trigger('form_success.ig_cta', [msg]); 179 } else if(msg.data.cta === 'form' || !msg.data.cta){ 180 if(msg.data.use_form == undefined){ 181 msg.data.response_text = ''; 182 } 183 response_text = '<div class="ig_form_response_text">'+ (msg.data.response_text || msg.el.find('.rm_form_message').html() || '') +'</div>'; 184 msg.el.find('.ig_form_container, .ig_message, .ig_headline').hide(); 185 var appendTo = msg.el.filter('.ig_container'); 186 if(jQuery.inArray(msg.data.type, ['interstitial', 'messenger']) !== -1){ 187 appendTo = msg.el.find('.ig_message'); 188 appendTo.show(); 189 msg.el.find('.ig_headline').text('').show(); 190 }else if(msg.data.type === 'tab'){ 191 //TODO :: hide is not working 192 appendTo = msg.el.find('.ig_data'); 193 msg.el.find('.ig_headline').show(); 194 } 195 try{ 196 appendTo.append(response_text); 197 }catch(err){ 198 console.log(err); 199 } 200 } 201 } 202 203 } 204}); //success.rm 205 206// addLead on IG-CTA form submit event 207jQuery(window).off('form_submit.ig_cta'); 208jQuery(window).on('form_submit.ig_cta', window.rainmaker.addLead);
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.