PluginProbe
GetResponse Forms by Optin Cat / trunk
GetResponse Forms by Optin Cat vtrunk
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 / admin / fca-eoi-rules.js

fca-eoi-rules.js in GetResponse Forms by Optin Cat trunk, at assets/admin/fca-eoi-rules.js

147 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* jshint asi: true */
2
3 jQuery( document ).ready( function( $ ) {
4
5 $('#fca_eoi_add_rule').click(function(e){
6 e.preventDefault()
7 jQuery('#fca_eoi_primary_rules_table').append( fcaEoiRuleTableHtml.rowNew )
8
9 add_condition_select_handlers()
10 set_available_conditions()
11 add_delete_handlers()
12 $(this).blur()
13
14 if ( $('.fca_eoi_condition_select').length === 1 && fcaEoiDistro === 'free' || $('.fca_eoi_condition_select').length === 6 ) {
15 $(this).hide()
16 }
17 })
18
19 function load_rules() {
20 var optional_rules = []
21 //unset the conditions that always show
22 if ( $.isArray( fcaEoiRules ) ) {
23 optional_rules = fcaEoiRules.filter(function( el ){
24 return el.parameter !== 'devices' && el.parameter !== 'show_every' && el.parameter !== 'live'
25 })
26 } else {
27 //backward compatibility from 1.7.x & earlier to 1.8
28 for ( el in fcaEoiRules ) {
29 var obj = fcaEoiRules[el]
30 if ( obj.parameter !== 'devices' && obj.parameter !== 'show_every' && obj.parameter !== 'live' ) {
31 optional_rules.push( {
32 'parameter': obj.parameter,
33 'value': obj.value
34 } )
35 }
36 }
37 //set devices
38 if ( fcaEoiDistro === 'premium' ) {
39 $('[name="fca_eoi[publish_lightbox][devices]"]').val( 'all' )
40 } else {
41 $('[name="fca_eoi[publish_lightbox][devices]"]').val( 'desktop' )
42 }
43
44 if ( $('[name="fca_eoi[publish_lightbox][show_every]"]').val() === 'never' ) {
45 $('[name="fca_eoi[publish_lightbox][live]"]').prop( 'checked', false )
46 } else {
47 $('[name="fca_eoi[publish_lightbox][live]"]').prop( 'checked', true )
48 }
49 }
50 $.each( optional_rules, function ( key, obj ) {
51 $('#fca_eoi_add_rule').click()
52 $('.fca_eoi_condition_select').last().val( obj.parameter ).change()
53 if ( obj.parameter === 'exit_intervention' ) {
54 $('.fca_eoi_condition_select').last().closest('th').next().find('input, select').prop( 'checked', 'checked' ).change()
55 } else {
56 $('.fca_eoi_condition_select').last().closest('th').next().find('input, select').val( obj.value ).change()
57 }
58 })
59
60 }
61 //console.log ( fcaEoiRules )
62 load_rules()
63
64 })
65
66 function add_delete_handlers() {
67 var $ = jQuery
68
69 $('.fca_eoi_delete_condition').unbind('click')
70
71 $('.fca_eoi_delete_condition').click(function(){
72 $(this).closest('tr').remove()
73 $('#fca_eoi_add_rule').show()
74 set_available_conditions()
75 })
76
77 }
78
79 function set_available_conditions() {
80 var $ = jQuery
81
82 var activeConditions = []
83 $('.fca_eoi_condition_select').each(function(){
84 activeConditions.push( $(this).val() )
85 })
86 $('.fca_eoi_condition_select').children().show()
87
88 $.each( activeConditions, function ( index, conditionStr ) {
89 $('.fca_eoi_condition_select').children('[value="' + conditionStr + '"]').hide()
90 })
91 }
92
93 function add_condition_select_handlers() {
94
95 var $ = jQuery
96
97 $('.fca_eoi_condition_select').unbind('change')
98
99 $('.fca_eoi_condition_select').change(function(){
100
101 $targetTd = $(this).closest('th').next()
102 var newHtml = false
103
104 set_available_conditions()
105
106 $(this).siblings('.fca_eoi_at_least').hide()
107
108 switch ( $(this).val() ) {
109
110 case "scrolled_percent":
111 newHtml = fcaEoiRuleTableHtml.dataScroll
112 $(this).siblings('.fca_eoi_at_least').show()
113 break
114
115 case "pageviews":
116 newHtml = fcaEoiRuleTableHtml.dataPageviews
117 $(this).siblings('.fca_eoi_at_least').show()
118 break
119
120 case "time_on_page":
121 newHtml = fcaEoiRuleTableHtml.dataTime
122 $(this).siblings('.fca_eoi_at_least').show()
123 break
124
125 case "include":
126 newHtml = fcaEoiRuleTableHtml.dataInclude
127 break
128
129 case "exclude":
130 newHtml = fcaEoiRuleTableHtml.dataExclude
131 break
132
133 case "exit_intervention":
134 newHtml = fcaEoiRuleTableHtml.dataExit
135 break
136
137 default:
138
139 }
140
141 if ( newHtml ) {
142 $targetTd.html( newHtml )
143 $targetTd.find('.select2').select2()
144 }
145 })
146
147 }