| 1 |
|
| 2 |
|
| 3 |
jQuery(function($) { |
| 4 |
|
| 5 |
'use strict'; |
| 6 |
$(document).ready(function ($) { |
| 7 |
|
| 8 |
function enable_disable_recapcha(){ |
| 9 |
if ($("input[name='wpfnl-recapcha-enable']").prop("checked")){ |
| 10 |
$("#wpfnl-recapcha").show() |
| 11 |
}else{ |
| 12 |
$("#wpfnl-recapcha").hide() |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")){ |
| 17 |
$("#wpfnl-utm").show() |
| 18 |
}else{ |
| 19 |
$("#wpfnl-utm").hide() |
| 20 |
} |
| 21 |
$('#utm-enable').on('click',function (){ |
| 22 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")){ |
| 23 |
$("#wpfnl-utm").show() |
| 24 |
}else { |
| 25 |
$("#wpfnl-utm").hide() |
| 26 |
} |
| 27 |
}) |
| 28 |
|
| 29 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")){ |
| 30 |
$("#wpfnl-gtm").show() |
| 31 |
}else{ |
| 32 |
$("#wpfnl-gtm").hide() |
| 33 |
} |
| 34 |
$('#gtm-enable').on('click',function (){ |
| 35 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")){ |
| 36 |
$("#wpfnl-gtm").show() |
| 37 |
}else { |
| 38 |
$("#wpfnl-gtm").hide() |
| 39 |
} |
| 40 |
}) |
| 41 |
|
| 42 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")){ |
| 43 |
$("#wpfnl-facebook-pixel").show() |
| 44 |
}else{ |
| 45 |
$("#wpfnl-facebook-pixel").hide() |
| 46 |
} |
| 47 |
$('#facebook-pixel-enable').on('click',function (){ |
| 48 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")){ |
| 49 |
$("#wpfnl-facebook-pixel").show() |
| 50 |
}else { |
| 51 |
$("#wpfnl-facebook-pixel").hide() |
| 52 |
} |
| 53 |
}) |
| 54 |
|
| 55 |
enable_disable_recapcha() |
| 56 |
|
| 57 |
$('#recapcha-pixel-enable').on('click',function (){ |
| 58 |
enable_disable_recapcha() |
| 59 |
}) |
| 60 |
|
| 61 |
$('.wpfnl-log-view').on('click',function (e){ |
| 62 |
e.preventDefault(); |
| 63 |
var thisElement = $(this); |
| 64 |
show_log(thisElement); |
| 65 |
}) |
| 66 |
|
| 67 |
$('.wpfnl-log-delete').on('click',function (e){ |
| 68 |
e.preventDefault(); |
| 69 |
var thisElement = $(this); |
| 70 |
delete_log(thisElement); |
| 71 |
}) |
| 72 |
|
| 73 |
/** |
| 74 |
* Show WPFunnels log |
| 75 |
*/ |
| 76 |
function show_log(thisElement) { |
| 77 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 78 |
|
| 79 |
var log_key = $( '#wpfnl-log option:selected' ).val(); |
| 80 |
var payload = { |
| 81 |
'logKey': log_key |
| 82 |
}; |
| 83 |
if ( !log_key ) { |
| 84 |
$( '#log-viewer pre' ).html( '' ); |
| 85 |
} else { |
| 86 |
wpAjaxHelperRequest( 'wpfnl-show-log', payload ) |
| 87 |
.success( function ( response ) { |
| 88 |
thisElement.find('.wpfnl-loader').hide(); |
| 89 |
|
| 90 |
if( response.success ){ |
| 91 |
$( '#log-viewer pre' ).html( response.content ); |
| 92 |
} |
| 93 |
} ) |
| 94 |
.error( function ( response ) { |
| 95 |
} ); |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Show WPFunnels log |
| 102 |
*/ |
| 103 |
function delete_log(thisElement) { |
| 104 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 105 |
localStorage.setItem("buttonClicked", true); |
| 106 |
|
| 107 |
var log_key = $( '#wpfnl-log option:selected' ).val(); |
| 108 |
var payload = { |
| 109 |
'logKey': log_key |
| 110 |
}; |
| 111 |
if ( !log_key ) { |
| 112 |
$( '#log-viewer' ).html( '' ); |
| 113 |
} else { |
| 114 |
wpAjaxHelperRequest( 'wpfnl-delete-log', payload ) |
| 115 |
.success( function ( response ) { |
| 116 |
if( response.success ){ |
| 117 |
$('#wpfnl-log option:selected').remove(); |
| 118 |
$('#log-viewer').empty(); |
| 119 |
} |
| 120 |
|
| 121 |
thisElement.find('.wpfnl-loader').hide(); |
| 122 |
|
| 123 |
} ) |
| 124 |
.error( function ( response ) { |
| 125 |
} ); |
| 126 |
} |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
var GeneralSettingsHandler = function () { |
| 131 |
$(document.body) |
| 132 |
.on('click', '#wpfnl-update-global-settings', this.updateGeneralSettings) |
| 133 |
.on('click', '#clear-template', this.clearTemplates) |
| 134 |
.on('click', '#clear-transients', this.clearTransients) |
| 135 |
|
| 136 |
/** |
| 137 |
* settings page Permalink Settings permalink |
| 138 |
* change on keyup |
| 139 |
* |
| 140 |
* @since 1.0.0 |
| 141 |
*/ |
| 142 |
$('code.stepbase').text( $('input[name="wpfnl-permalink-step-base"]').val() ); |
| 143 |
$('code.funnelbase').text( $('input[name="wpfnl-permalink-funnel-base"]').val() ); |
| 144 |
|
| 145 |
$('input[name="wpfnl-permalink-step-base"]').keyup(function () { |
| 146 |
if( $(this).val() != ''){ |
| 147 |
$('code.stepbase').text( $(this).val() ); |
| 148 |
}else{ |
| 149 |
$('code.stepbase').text( 'wpfunnels' ); |
| 150 |
} |
| 151 |
}); |
| 152 |
|
| 153 |
$('input[name="wpfnl-permalink-funnel-base"]').keyup(function () { |
| 154 |
if( $(this).val() != ''){ |
| 155 |
$('code.funnelbase').text( $(this).val() ); |
| 156 |
}else{ |
| 157 |
$('code.funnelbase').text( 'step' ); |
| 158 |
} |
| 159 |
}); |
| 160 |
|
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
/** |
| 165 |
* update general settings |
| 166 |
* |
| 167 |
* @param e |
| 168 |
* @since 1.0.0 |
| 169 |
*/ |
| 170 |
GeneralSettingsHandler.prototype.updateGeneralSettings = function (e) { |
| 171 |
e.preventDefault(); |
| 172 |
var userRole = {}; |
| 173 |
var permittedRole = {}; |
| 174 |
var gtmEvents = {}; |
| 175 |
var fbTrackEvent = {}; |
| 176 |
var advancedSettings= {}; |
| 177 |
$("input[name='analytics-role[]']").map(function(){ |
| 178 |
if($(this).prop("checked")){ |
| 179 |
userRole[$(this).data('role')] = 'true'; |
| 180 |
} |
| 181 |
return $(this).prop("checked") ? 1 : 0; |
| 182 |
}).get(); |
| 183 |
|
| 184 |
$("input[name='permission-role[]']").map(function(){ |
| 185 |
if($(this).prop("checked")){ |
| 186 |
permittedRole[$(this).data('role')] = 'true'; |
| 187 |
} |
| 188 |
return $(this).prop("checked") ? 1 : 0; |
| 189 |
}).get(); |
| 190 |
|
| 191 |
|
| 192 |
$("input[name='wpfnl-gtm-events[]']").map(function(){ |
| 193 |
if($(this).prop("checked")){ |
| 194 |
gtmEvents[$(this).data('role')] = 'true'; |
| 195 |
} |
| 196 |
return $(this).prop("checked") ? 1 : 0; |
| 197 |
}).get(); |
| 198 |
|
| 199 |
$("input[name='wpfnl-facebook_pixel_events[]']").map(function(){ |
| 200 |
if($(this).prop("checked")){ |
| 201 |
fbTrackEvent[$(this).data('role')] = 'true'; |
| 202 |
} |
| 203 |
return $(this).prop("checked") ? 1 : 0; |
| 204 |
}).get(); |
| 205 |
|
| 206 |
var payload = { |
| 207 |
'funnel_type' : $('#wpfunnels-funnel-type').val(), |
| 208 |
'builder' : $('#wpfunnels-page-builder').val(), |
| 209 |
'paypal_reference' : $('#wpfunnels-paypal-reference').is(':checked') ? 'on' : 'off', |
| 210 |
'analytics_roles' : userRole, |
| 211 |
'permission_role' : permittedRole, |
| 212 |
'order_bump' : $('#wpfunnels-order-bump').is(':checked') ? 'on' : 'off', |
| 213 |
'ab_testing' : $('#wpfunnels-ab-testing').is(':checked') ? 'on' : 'off', |
| 214 |
'permalink_settings' : $("input[name='wpfunnels-set-permalink']:checked").val(), |
| 215 |
'permalink_step_base' : $('#wpfunnels-permalink-step-base').val(), |
| 216 |
'permalink_funnel_base' : $('#wpfunnels-permalink-funnel-base').val(), |
| 217 |
'set_permalink' : $('input[name="wpfunnels-set-permalink"]:checked').val(), |
| 218 |
'offer_orders' : $('input[name="offer-orders"]:checked').val(), |
| 219 |
'skip_offer_step' : $('#wpfnl-skip-offer-step').is(':checked') ? 'on' : 'off', |
| 220 |
'skip_offer_step_for_free' : $('#wpfnl-skip-offer-step-for-free').is(':checked') ? 'on' : 'off', |
| 221 |
'skip_offer_for_recurring_buyer' : $('#wpfnl-skip-offer-for-recurring-buyer').is(':checked') ? 'on' : 'off', |
| 222 |
'skip_offer_for_recurring_buyer_within_year' : $('#wpfnl-skip-offer-for-recurring-buyer-within-year').is(':checked') ? 'on' : 'off', |
| 223 |
'show_supported_payment_gateway' : $('#wpfnl-show-supported-payment-gateway').is(':checked') ? 'on' : 'off', |
| 224 |
'gtm_enable' : $('input[name="wpfnl-gtm-enable"]:checked').val(), |
| 225 |
'gtm_container_id' : $('#wpfnl-gtm-container-id').val(), |
| 226 |
'gtm_events' : gtmEvents, |
| 227 |
'enable_fb_pixel' : $('input[name="wpfnl-facebook-pixel-enable"]:checked').val(), |
| 228 |
'fb_tracking_code' : $('#wpfnl-facebook-tracking-code').val(), |
| 229 |
'fb_tracking_events' : fbTrackEvent, |
| 230 |
'utm_enable' : $('input[name="wpfnl-utm-enable"]:checked').val(), |
| 231 |
'utm_source' : $('#wpfnl-utm-source').val(), |
| 232 |
'utm_medium' : $('#wpfnl-utm-medium').val(), |
| 233 |
'utm_campaign' : $('#wpfnl-utm-campaign').val(), |
| 234 |
'utm_content' : $('#wpfnl-utm-content').val(), |
| 235 |
'disable_theme_style' : $('#disable-theme-style').is(':checked') ? 'on' : 'off', |
| 236 |
'enable_log_status' : $('#enable-log-status').is(':checked') ? 'on' : 'off', |
| 237 |
'enable_recaptcha' : $('input[name="wpfnl-recapcha-enable"]:checked').val(), |
| 238 |
'recaptcha_site_key' : $('#wpfnl-recapcha-site-key').val(), |
| 239 |
'recaptcha_site_secret' : $('#wpfnl-recapcha-site-secret').val(), |
| 240 |
|
| 241 |
|
| 242 |
}; |
| 243 |
|
| 244 |
var thisLoader = $(this).find('.wpfnl-loader'); |
| 245 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 246 |
|
| 247 |
thisLoader.fadeIn(); //show loader |
| 248 |
|
| 249 |
wpAjaxHelperRequest("update-general-settings", payload) |
| 250 |
.success(function (response) { |
| 251 |
thisLoader.fadeOut(); |
| 252 |
thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn(); |
| 253 |
|
| 254 |
setTimeout(function () { |
| 255 |
thisAlert.fadeOut().text('').removeClass('box wpfnl-success'); |
| 256 |
}, 2000); |
| 257 |
|
| 258 |
}) |
| 259 |
.error(function (response) { |
| 260 |
thisLoader.fadeOut(); |
| 261 |
thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn(); |
| 262 |
setTimeout(function () { |
| 263 |
thisAlert.fadeOut().text('').removeClass('box wpfnl-error'); |
| 264 |
}, 2000); |
| 265 |
}); |
| 266 |
|
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
GeneralSettingsHandler.prototype.clearTemplates = function (e) { |
| 271 |
e.preventDefault(); |
| 272 |
var sync_icon = $(this).find('.sync-icon'); |
| 273 |
var check_icon = $(this).find('.check-icon'); |
| 274 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 275 |
|
| 276 |
sync_icon.show(); |
| 277 |
|
| 278 |
var payload = {}; |
| 279 |
wpAjaxHelperRequest("clear-templates", payload) |
| 280 |
.success(function (response) { |
| 281 |
sync_icon.hide(); |
| 282 |
check_icon.fadeIn(); |
| 283 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 284 |
|
| 285 |
setTimeout( function(){ |
| 286 |
check_icon.hide(); |
| 287 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 288 |
}, 4000); |
| 289 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 290 |
}) |
| 291 |
|
| 292 |
.error(function (response) { |
| 293 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 294 |
|
| 295 |
setTimeout( function(){ |
| 296 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 297 |
}, 2000); |
| 298 |
|
| 299 |
console.log('error'); |
| 300 |
}); |
| 301 |
}; |
| 302 |
|
| 303 |
|
| 304 |
/** |
| 305 |
* clear all transients related to wpfunnels |
| 306 |
* |
| 307 |
* @param e |
| 308 |
*/ |
| 309 |
GeneralSettingsHandler.prototype.clearTransients = function (e) { |
| 310 |
e.preventDefault(); |
| 311 |
if ( confirm('Are you sure you want to run this tool?') ) { |
| 312 |
|
| 313 |
var sync_icon = $(this).find('.sync-icon'); |
| 314 |
var check_icon = $(this).find('.check-icon'); |
| 315 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 316 |
|
| 317 |
sync_icon.show(); |
| 318 |
|
| 319 |
var payload = {}; |
| 320 |
wpAjaxHelperRequest("clear-transient", payload) |
| 321 |
.success(function (response) { |
| 322 |
sync_icon.hide(); |
| 323 |
check_icon.fadeIn(); |
| 324 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 325 |
|
| 326 |
setTimeout( function(){ |
| 327 |
check_icon.hide(); |
| 328 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 329 |
}, 4000); |
| 330 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 331 |
}) |
| 332 |
|
| 333 |
.error(function (response) { |
| 334 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 335 |
|
| 336 |
setTimeout( function(){ |
| 337 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 338 |
}, 2000); |
| 339 |
|
| 340 |
console.log('error'); |
| 341 |
}); |
| 342 |
} |
| 343 |
}; |
| 344 |
|
| 345 |
new GeneralSettingsHandler(); |
| 346 |
|
| 347 |
}); |
| 348 |
|
| 349 |
}); |
| 350 |
|