PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / assets / targeting.js

targeting.js in GetResponse Forms by Optin Cat 2.0.2, at assets/targeting.js

310 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* jshint asi: true */
2 jQuery(document).ready( function($) {
3
4 //CHECK FOR ANY 'ACTIVE' OPTINS ( BARS AND SLIDE INS ) THAT SHOULD ALREADY BE SHOWING
5 function check_for_active_popups() {
6 var activeOptins = JSON.parse( get_cookie( 'fca_eoi_active_optins' ) )
7 if ( activeOptins.length > 0 ) {
8 for ( var id in activeOptins ) {
9 show_banner( activeOptins[id], true )
10 }
11 }
12 }
13
14 if ( typeof(fcaEoiTargetingData) !== 'undefined' ) {
15 for ( var id in fcaEoiTargetingData.popups ) {
16
17 //TEST COOKIES (SUCCESS, FREQUENCY, PAGECOUNT
18 var successOK = test_success( id, fcaEoiTargetingData.popups[id] )
19 var frequencyOK = test_frequency( id, fcaEoiTargetingData.popups[id].show_every )
20 var pageviewsOK = test_pageviews( fcaEoiTargetingData.popups[id] )
21
22 if ( frequencyOK && pageviewsOK && successOK ) {
23 var waitTime = parse_time( fcaEoiTargetingData.popups[id] )
24 var scrollPercent = parse_scroll( fcaEoiTargetingData.popups[id] )
25 var exitIntervention = parse_exit_intervention( fcaEoiTargetingData.popups[id] )
26
27 popup_handler( id, waitTime, scrollPercent, exitIntervention )
28
29 }
30 }
31 }
32
33 if ( typeof(fcaEoiBannerTargetingData) !== 'undefined' ) {
34 for ( var id in fcaEoiBannerTargetingData.banners ) {
35
36 //TEST COOKIES (SUCCESS, FREQUENCY, PAGECOUNT
37 var successOK = test_success( id, fcaEoiBannerTargetingData.banners[id] )
38 var frequencyOK = test_frequency( id, fcaEoiBannerTargetingData.banners[id].show_every )
39 var pageviewsOK = test_pageviews( fcaEoiBannerTargetingData.banners[id] )
40
41 if ( frequencyOK && pageviewsOK && successOK ) {
42 var waitTime = parse_time( fcaEoiBannerTargetingData.banners[id] )
43 var scrollPercent = parse_scroll( fcaEoiBannerTargetingData.banners[id] )
44 var exitIntervention = parse_exit_intervention( fcaEoiBannerTargetingData.banners[id] )
45
46 banner_handler( id, waitTime, scrollPercent, exitIntervention )
47
48 }
49 }
50 }
51
52 function banner_handler( id, waitTime, scrollPercent, exitIntervention ) {
53 window.setTimeout( function(){
54 $( window ).scroll( function() {
55 if ( scrollPercent <= scrolled_percent() ) {
56 if ( exitIntervention ) {
57 $(document).on('mouseleave', function(e) {
58 if( e.clientY < 0 ) {
59 show_banner( id, false )
60 }
61 })
62 } else {
63 show_banner( id, false )
64 }
65 }
66 }).scroll()
67 }, waitTime * 1000 )
68 }
69
70 function popup_handler( id, waitTime, scrollPercent, exitIntervention ) {
71 window.setTimeout( function(){
72 $( window ).scroll( function() {
73 if ( scrollPercent <= scrolled_percent() ) {
74 if ( exitIntervention ) {
75 $(document).on('mouseleave', function(e) {
76 if( e.clientY < 0 ) {
77 show_lightbox( id )
78 }
79 })
80 } else {
81 show_lightbox( id )
82 }
83 }
84 }).scroll()
85 }, waitTime * 1000 )
86 }
87
88 function test_success( id, popup ) {
89 if ( popup.hasOwnProperty( 'success_duration' ) ) {
90 if ( get_cookie( 'fca_eoi_success_' + id ) ) {
91 return false
92 }
93 }
94 return true
95 }
96
97 function test_pageviews( popup ) {
98 var condition = popup.conditions.filter( function( value ){
99 return value.parameter === 'pageviews'
100 })
101
102 if ( condition.length === 0 ){
103 return true
104 } else {
105 var sessionViews = parseInt( get_cookie( 'fca_eoi_pagecount' ) )
106
107 return sessionViews >= condition[0].value
108 }
109
110 }
111
112 function test_frequency( id, frequency ) {
113
114 var lastShown = get_cookie( 'fca_eoi_frequency_' + id )
115
116 if ( !lastShown ) {
117 return true
118 }
119
120 var difference = Math.floor(Date.now() / 1000) - lastShown
121
122 switch( frequency ) {
123 case 'always':
124 return true
125
126 case 'session':
127 return false
128
129 case 'day':
130 return difference >= 86400
131
132 case 'once':
133 return false
134
135 case 'month':
136 return difference >= 2592000
137
138 default:
139 return true
140 }
141
142 }
143
144 var fca_eoi_popups_shown = []
145 function show_lightbox( id ) {
146 if ( fca_eoi_popups_shown.indexOf( id ) === -1 && id > 0 ) {
147 fca_eoi_popups_shown.push( id )
148 add_impression( id, fcaEoiTargetingData )
149 var $lightbox = $( '#fca_eoi_lightbox_' + id )
150 $.featherlight( $lightbox, { variant: 'fca_eoi_featherlight', closeOnClick: false, afterOpen: function(){
151 var $instance = this.$instance
152
153 //BACKWARDS COMPATIBILITY CODE - REMOVE OLD HACK CLOSE BUTTON
154 $instance.find('.fca_eoi_layout_popup_close').hide()
155
156 var cookieDuration = fcaEoiTargetingData.popups[id].show_every === 'session' ? 0 : 365
157 set_cookie( 'fca_eoi_frequency_' + id, Math.floor(Date.now() / 1000), cookieDuration )
158 if ( $lightbox.find('.fca_eoi_layout_popup').hasClass('animated') ) {
159 setTimeout( function(){
160 $instance.find('span.featherlight-close-icon.featherlight-close').show()
161 $instance.find('.fca_eoi_form_input_element:visible').first().focus()
162 }, 1000)
163 } else {
164 $instance.find('span.featherlight-close-icon.featherlight-close').show()
165 $instance.find('.fca_eoi_form_input_element:visible').first().focus()
166 }
167 }})
168 }
169 }
170
171 var fca_eoi_banners_shown = []
172 function show_banner( id, disableAnim ) {
173 if ( fca_eoi_banners_shown.indexOf( id ) === -1 && typeof fcaEoiBannerTargetingData !== 'undefined' ) {
174
175 if ( typeof fcaEoiBannerTargetingData.banners[id] !== 'undefined' ) {
176 fca_eoi_banners_shown.push( id )
177 add_impression( id, fcaEoiBannerTargetingData )
178 if ( disableAnim ) {
179 $( '#fca_eoi_banner_' + id ).find('form').removeClass('animated')
180 }
181 $( '#fca_eoi_banner_' + id ).show().load( maybe_push_page( id ) )
182
183 $( '#fca_eoi_banner_' + id ).find('.fca_eoi_form_input_element:visible').first().focus()
184 var cookieDuration = fcaEoiBannerTargetingData.banners[id].show_every === 'session' ? 0 : 365
185 set_active_optins ( id )
186 set_cookie( 'fca_eoi_frequency_' + id, Math.floor(Date.now() / 1000), cookieDuration )
187 }
188 }
189 }
190
191 function maybe_push_page ( id ) {
192 var pushPage = $( '#fca_eoi_banner_' + id ).find('form').data('fca_eoi_push_page')
193
194 if ( pushPage === 'down' ) {
195 $('body').css('margin-top', $( '#fca_eoi_banner_' + id ).find('form').outerHeight() )
196 }
197
198 if ( pushPage === 'up' ) {
199 $('body').css('margin-bottom', $( '#fca_eoi_banner_' + id ).find('form').outerHeight() )
200 }
201 }
202
203 //MAKE THE CLOSE BUTTONS FOR BANNERS & SCROLLBOXES REMOVE THE COOKIE FOR IT
204 $('.fca_eoi_banner_close_btn, .fca_eoi_scrollbox_close_btn').click(function(){
205
206 var thisFormId = $(this).siblings( '#fca_eoi_form_id' ).val()
207 var activeOptins = JSON.parse( get_cookie( 'fca_eoi_active_optins' ) )
208
209 if ( !Array.isArray( activeOptins ) ) {
210 activeOptins = []
211 }
212 var index = activeOptins.indexOf( thisFormId )
213
214 if ( index !== -1 ) {
215 activeOptins.splice( index, 1 )
216 }
217 set_cookie ( 'fca_eoi_active_optins', JSON.stringify ( activeOptins ) )
218
219 })
220
221 function set_active_optins( id ) {
222 var activeOptins = JSON.parse( get_cookie( 'fca_eoi_active_optins' ) )
223
224 if ( !Array.isArray( activeOptins ) ) {
225 activeOptins = []
226 }
227
228 var index = activeOptins.indexOf( id )
229
230 if ( index === -1 ) {
231 activeOptins.push( id )
232 set_cookie ( 'fca_eoi_active_optins', JSON.stringify ( activeOptins ) )
233 }
234
235 }
236
237 function add_impression( id, adminData ) {
238 $.ajax({
239 url: adminData.ajax_url,
240 type: 'POST',
241 data: {
242 nonce: adminData.nonce,
243 form_id: id,
244 action: 'fca_eoi_activity'
245 }
246 })
247 }
248
249 function scrolled_percent() {
250 return 100 * $( window ).scrollTop() / ( $( document ).height() - $( window ).height() )
251 }
252
253 function parse_exit_intervention( popup ) {
254 return popup.conditions.filter( function( value ){
255 return value.parameter === 'exit_intervention'
256 }).length === 1
257 }
258
259
260 function parse_scroll( popup ) {
261 var condition = popup.conditions.filter( function( value ){
262 return value.parameter === 'scrolled_percent'
263 })
264
265 if ( condition.length === 0 ){
266 return 0
267 } else {
268 return condition[0].value
269 }
270
271 }
272
273 function parse_time( popup ) {
274
275 var condition = popup.conditions.filter( function( value ){
276 return value.parameter === 'time_on_page'
277 })
278
279 if ( condition.length === 0 ){
280 return 0
281 } else {
282 return condition[0].value
283 }
284
285 }
286
287 function set_cookie( name, value, exdays ) {
288 if ( exdays === 0 ) {
289 document.cookie = name + "=" + value + "" + ";" + "path=/;"
290 } else {
291 var d = new Date()
292 d.setTime( d.getTime() + ( exdays*24*60*60*1000 ) )
293 document.cookie = name + "=" + value + "" + ";" + "path=/;" + "expires=" + d.toUTCString()
294 }
295 }
296
297 function get_cookie( name ) {
298 var value = "; " + document.cookie
299 var parts = value.split( "; " + name + "=" )
300
301 if ( parts.length === 2 ) {
302 return parts.pop().split(";").shift()
303 } else {
304 return false
305 }
306 }
307
308 check_for_active_popups()
309
310 })