| 1 |
// Imagify tabs ==================================================================================== |
| 2 |
(function ($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names |
| 3 |
$('.imagify-badge').addClass('imagify-badge-checked'); |
| 4 |
$('.imagify-toggle-label').eq(0).css('color', '#c8ced5'); |
| 5 |
$('.imagify-toggle-label').eq(1).css('color', '#3b3f4a'); |
| 6 |
// Plan switcher. |
| 7 |
$('#imagify-toggle-plan').on('change', function() { |
| 8 |
var isChecked = $(this).is(':checked'); |
| 9 |
$('.imagify-toggle-label').eq(0).css('color', isChecked ? '#c8ced5' : '#3b3f4a'); |
| 10 |
$('.imagify-toggle-label').eq(1).css('color', isChecked ? '#3b3f4a' : '#c8ced5'); |
| 11 |
$('.imagify-badge').toggleClass('imagify-badge-checked', isChecked); |
| 12 |
$('#imagify_all_plan_view').toggleClass('imagify-year-selected', isChecked).toggleClass('imagify-month-selected', ! isChecked); |
| 13 |
$('.imagify-arrow-container img').eq(0).toggle(! isChecked); |
| 14 |
$('.imagify-arrow-container img').eq(1).toggle(isChecked); |
| 15 |
}); |
| 16 |
|
| 17 |
})(jQuery, document, window); |
| 18 |
|
| 19 |
|
| 20 |
// Imagify payment modal =========================================================================== |
| 21 |
(function ($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names |
| 22 |
|
| 23 |
var imagifyModal = {}; |
| 24 |
|
| 25 |
if (! $('#imagify-pricing-modal').length) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
imagifyModal = { |
| 30 |
$modal: $('#imagify-pricing-modal'), |
| 31 |
// Plans selection view & payment process view hidden by default. |
| 32 |
$plansView: $('#imagify-plans-selection-view'), |
| 33 |
$paymentView: $('#imagify-payment-process-view').hide(), |
| 34 |
$successView: $('#imagify-success-view').hide(), |
| 35 |
speedFadeIn: 300, |
| 36 |
|
| 37 |
getHtmlPrice: function (content, period) { |
| 38 |
var monthly, yearly, m, y, output; |
| 39 |
|
| 40 |
if (! period) { |
| 41 |
period = null; |
| 42 |
} |
| 43 |
|
| 44 |
if (typeof content !== 'object') { |
| 45 |
content += ''; // Be sure content is a string. |
| 46 |
content = content.split('.'); |
| 47 |
content[1] = content[1].length === 1 ? content[1] + '0' : ('' + content[1]).substring(0, 2); |
| 48 |
|
| 49 |
output = '<span class="imagify-price-big">' + content[0] + '</span> '; |
| 50 |
output += '<span class="imagify-price-mini">.' + content[1] + '</span>'; |
| 51 |
|
| 52 |
return output; |
| 53 |
} |
| 54 |
|
| 55 |
monthly = content.monthly + ''; |
| 56 |
yearly = content.yearly + ''; |
| 57 |
m = '0' === monthly ? ['0', '00'] : monthly.split('.'); |
| 58 |
y = '0' === yearly ? ['0', '00'] : yearly.split('.'); |
| 59 |
output = '<span class="imagify-switch-my">'; |
| 60 |
/* eslint-disable indent */ |
| 61 |
output += '<span aria-hidden="' + (period === 'monthly' ? 'false' : 'true') + '" class="imagify-monthly">'; |
| 62 |
output += '<span class="imagify-price-big">' + m[0] + '</span> '; |
| 63 |
output += '<span class="imagify-price-mini">.' + (m[1].length === 1 ? m[1] + '0' : ('' + m[1]).substring(0, 2)) + '</span>'; |
| 64 |
output += '</span> '; |
| 65 |
output += '<span aria-hidden="' + (period === 'yearly' ? 'false' : 'true') + '" class="imagify-yearly">'; |
| 66 |
output += '<span class="imagify-price-big">' + y[0] + '</span> '; |
| 67 |
output += '<span class="imagify-price-mini">.' + (y[1].length === 1 ? y[1] + '0' : ('' + y[1]).substring(0, 2)) + '</span>'; |
| 68 |
output += '</span>'; |
| 69 |
/* eslint-enable indent */ |
| 70 |
output += '</span>'; |
| 71 |
|
| 72 |
return output; |
| 73 |
}, |
| 74 |
|
| 75 |
getHtmlDiscountPrice: function (content, period) { |
| 76 |
var monthly, yearly, |
| 77 |
output = ''; |
| 78 |
|
| 79 |
if (! period) { |
| 80 |
period = null; |
| 81 |
} |
| 82 |
|
| 83 |
if (typeof content === 'object') { |
| 84 |
monthly = content.monthly + ''; |
| 85 |
yearly = content.yearly + ''; |
| 86 |
|
| 87 |
output += '<span class="imagify-price-discount">'; |
| 88 |
/* eslint-disable indent */ |
| 89 |
output += '<span class="imagify-price-discount-dollar">$</span>'; |
| 90 |
output += '<span class="imagify-switch-my">'; |
| 91 |
output += '<span aria-hidden="' + (period === 'monthly' ? 'false' : 'true') + '" class="imagify-monthly">'; |
| 92 |
output += '<span class="imagify-price-discount-number">' + monthly + '</span>'; |
| 93 |
output += '</span>'; |
| 94 |
output += '<span aria-hidden="' + (period === 'yearly' ? 'false' : 'true') + '" class="imagify-yearly">'; |
| 95 |
output += '<span class="imagify-price-discount-number">' + yearly + '</span>'; |
| 96 |
output += '</span>'; |
| 97 |
output += '</span>'; |
| 98 |
/* eslint-enable indent */ |
| 99 |
output += '</span>'; |
| 100 |
} else { |
| 101 |
content += ''; // Be sure content is a string. |
| 102 |
output += '<span class="imagify-price-discount">'; |
| 103 |
/* eslint-disable indent */ |
| 104 |
output += '<span class="imagify-price-discount-dollar">$</span>'; |
| 105 |
output += '<span class="imagify-price-discount-number">' + content + '</span>'; |
| 106 |
/* eslint-enable indent */ |
| 107 |
output += '</span>'; |
| 108 |
} |
| 109 |
|
| 110 |
return output; |
| 111 |
}, |
| 112 |
|
| 113 |
/** |
| 114 |
* @uses imagifyModal.getHtmlPrice() |
| 115 |
* @uses imagifyModal.getHtmlDiscountPrice() |
| 116 |
*/ |
| 117 |
populateOffer: function ($offer, datas, type, classes) { |
| 118 |
var promo = w.imagify_discount_datas, |
| 119 |
add = datas.additional_gb, // 4 (monthly) |
| 120 |
ann = datas.annual_cost, // 49.9 (monthly) |
| 121 |
id = datas.id, // 3 (monthly/onetime) |
| 122 |
lab = datas.label, // 'lite' (monthly/onetime) |
| 123 |
mon = datas.monthly_cost, // 4.99 (monthly) |
| 124 |
quo = datas.quota, // 1000 (MB) - 5000 images (monthly/onetime) |
| 125 |
cos = datas.cost, // 3.49 (onetime) |
| 126 |
label = datas.label.replace(/_.*$/, ''), |
| 127 |
name = -1 === quo ? 'Unlimited' : (quo >= 1000 ? quo / 1000 + ' GB' : quo + ' MB'), |
| 128 |
pcs = 'monthly' === type ? {monthly: mon, yearly: Math.round(ann / 12 * 100) / 100} : cos, |
| 129 |
pcsd = pcs, // Used if discount is active. |
| 130 |
percent, $datas_c, datas_content, applies_to = [], |
| 131 |
offer_by = '', |
| 132 |
additional_data = ''; |
| 133 |
|
| 134 |
applies_to = imagifyModal.getPromoAppliesTo(promo); |
| 135 |
|
| 136 |
|
| 137 |
// Change pricing value only if discount in percentage is active and if offer is a monthly and not a onetime. |
| 138 |
if ( |
| 139 |
promo.is_active |
| 140 |
&& 'percentage' === promo.coupon_type |
| 141 |
&& 'monthly' === type |
| 142 |
&& (0 < mon) |
| 143 |
&& (applies_to.includes(lab) || 'all' === applies_to[0]) |
| 144 |
) { |
| 145 |
percent = (100 - promo.coupon_value) / 100; |
| 146 |
pcs = 'monthly' === type ? { |
| 147 |
monthly: mon * percent, |
| 148 |
yearly: Math.round((ann * percent) / 12 * 100) / 100 |
| 149 |
} : cos * percent; |
| 150 |
} |
| 151 |
|
| 152 |
if (typeof classes !== 'undefined') { |
| 153 |
$offer.addClass('imagify-' + type + '-' + lab + classes); |
| 154 |
$offer.addClass('imagify-' + type + '-' + lab + classes); |
| 155 |
} |
| 156 |
|
| 157 |
// Label. |
| 158 |
$offer.find('.imagify-label-plans').text(label); |
| 159 |
|
| 160 |
// Name. |
| 161 |
$offer.find('.imagify-offer-size').text(name); |
| 162 |
|
| 163 |
// Main prices (pcs can be an object or a string). |
| 164 |
$offer.find('.imagify-number-block').html(imagifyModal.getHtmlPrice(pcs, 'monthly')); |
| 165 |
|
| 166 |
if ('Unlimited' === name) { |
| 167 |
offer_by = 'quota'; |
| 168 |
$offer.addClass('imagify-best-value'); |
| 169 |
additional_data = 'No additional cost'; |
| 170 |
} else { |
| 171 |
offer_by = '/month'; |
| 172 |
additional_data = '$' + add + ' per additional Gb'; |
| 173 |
} |
| 174 |
|
| 175 |
$offer.find('.imagify-offer-by').text(offer_by); |
| 176 |
|
| 177 |
// discount prices |
| 178 |
$offer.find('.imagify-price-block').prev('.imagify-price-discount').remove(); |
| 179 |
if ( |
| 180 |
promo.is_active |
| 181 |
&& 'percentage' === promo.coupon_type |
| 182 |
&& 'monthly' === type |
| 183 |
&& (0 < mon) |
| 184 |
&& (applies_to.includes(lab) || 'all' === applies_to[0]) |
| 185 |
) { |
| 186 |
$offer.find('.imagify-price-block').before(imagifyModal.getHtmlDiscountPrice(pcsd, 'monthly')); |
| 187 |
} |
| 188 |
// Nb images. |
| 189 |
$offer.find('.imagify-approx-nb').text(quo * 5); |
| 190 |
|
| 191 |
if ('monthly' === type) { |
| 192 |
// Additional price. |
| 193 |
$offer.find('.imagify-price-add-data').text(additional_data); |
| 194 |
} |
| 195 |
|
| 196 |
// Button data-offer attr. |
| 197 |
$datas_c = $offer.find('.imagify-payment-btn-select-plan').length ? $offer.find('.imagify-payment-btn-select-plan') : $offer; |
| 198 |
|
| 199 |
if ('monthly' === type) { |
| 200 |
datas_content = '{"' + lab + '":{"id":' + id + ',"name":"' + name + '","label":"' + lab + '","data":' + quo + ',"dataf":"' + name + '","imgs":' + (quo * 5) + ',"prices":{"monthly":' + pcs.monthly + ',"yearly":' + pcs.yearly + ',"add":' + add + '}}}'; |
| 201 |
} else { |
| 202 |
datas_content = '{"ot' + lab + '":{"id":' + id + ',"name":"' + name + '","label":"' + lab + '","data":' + quo + ',"dataf":"' + name + '","imgs":' + (quo * 5) + ',"price":' + pcs + '}}'; |
| 203 |
} |
| 204 |
|
| 205 |
$datas_c.attr('data-offer', datas_content); |
| 206 |
|
| 207 |
return $offer; |
| 208 |
}, |
| 209 |
|
| 210 |
/** |
| 211 |
* @uses imagifyModal.populateOffer() |
| 212 |
*/ |
| 213 |
getPricing: function ($button) { |
| 214 |
var nonce = $button.data('nonce'), |
| 215 |
prices_rq_datas = { |
| 216 |
action: 'imagify_get_prices', |
| 217 |
imagifynonce: nonce |
| 218 |
}, |
| 219 |
prices_rq_discount = { |
| 220 |
action: 'imagify_get_discount', |
| 221 |
imagifynonce: nonce |
| 222 |
}; |
| 223 |
|
| 224 |
imagifyModal.$modal.find('.imagify-modal-loader').hide().show(); |
| 225 |
imagifyModal.$modal.addClass('imagify-modal-loading'); |
| 226 |
|
| 227 |
/** |
| 228 |
* TODO: change the way to waterfall requests. |
| 229 |
* Use setInterval + counter instead. |
| 230 |
*/ |
| 231 |
|
| 232 |
// Get the true prices. |
| 233 |
$.post(ajaxurl, prices_rq_datas, function (prices_response) { |
| 234 |
|
| 235 |
if (! prices_response.success) { |
| 236 |
// TODO: replace modal content by any information. |
| 237 |
// An error occurred. |
| 238 |
|
| 239 |
return; |
| 240 |
} |
| 241 |
|
| 242 |
// Get the discount informations. |
| 243 |
$.post(ajaxurl, prices_rq_discount, function (discount_response) { |
| 244 |
var prices_datas, promo_datas, |
| 245 |
offers, |
| 246 |
mo_html = '', |
| 247 |
$mo_tpl, |
| 248 |
mo_clone, |
| 249 |
$estim_block, $offers_block, |
| 250 |
$banners, date_end, plan_names, promo, discount; |
| 251 |
|
| 252 |
if (! discount_response.success) { |
| 253 |
// TODO: replace modal content by any information. |
| 254 |
// An error occurred. |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
prices_datas = prices_response.data; |
| 259 |
promo_datas = discount_response.data; |
| 260 |
offers = { |
| 261 |
mo: [] |
| 262 |
}; |
| 263 |
$mo_tpl = $('#imagify-offer-monthly-template'); |
| 264 |
mo_clone = $mo_tpl.html(); |
| 265 |
$estim_block = $('.imagify-estimation-block'); |
| 266 |
|
| 267 |
// Remove inactive offers. |
| 268 |
$.each(prices_datas.monthlies, function (index, value) { |
| 269 |
if ('undefined' === typeof value.active |
| 270 |
|| |
| 271 |
('undefined' !== typeof value.active && true === value.active) |
| 272 |
) { |
| 273 |
if ('starter' === value.label) { |
| 274 |
return; |
| 275 |
} |
| 276 |
offers.mo.push(value); |
| 277 |
} |
| 278 |
}); |
| 279 |
|
| 280 |
// Refresh Analyzing block. |
| 281 |
$estim_block.removeClass('imagify-analyzing'); |
| 282 |
|
| 283 |
// Reset offer selection. |
| 284 |
$('.imagify-offer-selected').removeClass('imagify-offer-selected').find('.imagify-checkbox').prop('checked', false); |
| 285 |
|
| 286 |
// Don't create prices table if something went wrong during request. |
| 287 |
if (null === offers.mo) { |
| 288 |
$offers_block = $('.imagify-pre-checkout-offers'); |
| 289 |
|
| 290 |
// Hide main content. |
| 291 |
$offers_block.hide().attr('aria-hidden', true); |
| 292 |
|
| 293 |
// Show error message. |
| 294 |
$offers_block.closest('.imagify-modal-views').find('.imagify-popin-message').remove(); |
| 295 |
$offers_block.after('<div class="imagify-popin-message imagify-error"><p>' + imagifyPricingModal.labels.errorPriceAPI + '</p></div>'); |
| 296 |
|
| 297 |
// Show the modal content. |
| 298 |
imagifyModal.$modal.find('.imagify-modal-loader').fadeOut(300); |
| 299 |
imagifyModal.$modal.removeClass('imagify-modal-loading'); |
| 300 |
return; |
| 301 |
} |
| 302 |
|
| 303 |
// Autofill coupon code & Show banner if discount is active. |
| 304 |
w.imagify_discount_datas = promo_datas; |
| 305 |
|
| 306 |
if (promo_datas.is_active) { |
| 307 |
if (promo_datas.applies_to instanceof Array) { |
| 308 |
plan_names = []; |
| 309 |
var plan_list = []; |
| 310 |
|
| 311 |
for (var plan_infos = 0; plan_infos < promo_datas.applies_to.length; plan_infos++) { |
| 312 |
plan_list.push(promo_datas.applies_to[plan_infos].plan_name); |
| 313 |
} |
| 314 |
|
| 315 |
plan_list.forEach(function (item) { |
| 316 |
if (! plan_names.includes(item)) { |
| 317 |
plan_names.push(item); |
| 318 |
} |
| 319 |
}); |
| 320 |
|
| 321 |
plan_names = plan_names.join(', '); |
| 322 |
} else { |
| 323 |
plan_names = promo_datas.applies_to; |
| 324 |
} |
| 325 |
|
| 326 |
$banners = $('.imagify-modal-promotion'); |
| 327 |
date_end = promo_datas.date_end.split('T')[0]; |
| 328 |
promo = promo_datas.coupon_value; |
| 329 |
discount = 'percentage' === promo_datas.coupon_type ? promo + '%' : '$' + promo; |
| 330 |
|
| 331 |
|
| 332 |
// Show banners. |
| 333 |
$banners.addClass('active').attr('aria-hidden', 'false'); |
| 334 |
|
| 335 |
// Populate banners. |
| 336 |
$banners.find('.imagify-promotion-number').text(discount); |
| 337 |
$banners.find('.imagify-promotion-plan-name').text(plan_names); |
| 338 |
$banners.find('.imagify-promotion-date').text(date_end); |
| 339 |
|
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* Below lines will build Plan and Onetime offers lists. |
| 344 |
* It will also pre-select a Plan and/or Onetime in both of views: pre-checkout and pricing tables. |
| 345 |
*/ |
| 346 |
if (0 === offers.mo.length) { |
| 347 |
$('.imagify-pre-checkout-offers .imagify-offer-monthly').remove(); |
| 348 |
$('.imagify-tabs').remove(); |
| 349 |
$('.imagify-pricing-tab-monthly').remove(); |
| 350 |
} else { |
| 351 |
// Now, do the MONTHLIES Markup. |
| 352 |
offers.mo = offers.mo.reverse(); |
| 353 |
$.each(offers.mo, function (index, value) { |
| 354 |
var $tpl, |
| 355 |
classes = ''; |
| 356 |
|
| 357 |
// Populate each offer. |
| 358 |
$tpl = $(mo_clone).clone(); |
| 359 |
$tpl = imagifyModal.populateOffer($tpl, value, 'monthly', classes); |
| 360 |
|
| 361 |
// Complete Monthlies HTML. |
| 362 |
mo_html += $tpl[0].outerHTML; |
| 363 |
}); |
| 364 |
|
| 365 |
// Wait for element to be ready after ajax callback before adding ribbon. |
| 366 |
setTimeout(function() { |
| 367 |
// Add best value ribbon to unlimited plan. |
| 368 |
$('.imagify-best-value').prepend('<div class="imagify-ribbon"><span>Best Value!</span></div>'); |
| 369 |
}, 100); |
| 370 |
} |
| 371 |
|
| 372 |
// Fill pricing tables. |
| 373 |
if ($mo_tpl.parent().find('.imagify-offer-line')) { |
| 374 |
$mo_tpl.parent().find('.imagify-offer-line').remove(); |
| 375 |
} |
| 376 |
|
| 377 |
$mo_tpl.before(mo_html); |
| 378 |
|
| 379 |
|
| 380 |
// Show the content. |
| 381 |
imagifyModal.$modal.find('.imagify-modal-loader').fadeOut(300); |
| 382 |
imagifyModal.$modal.removeClass('imagify-modal-loading'); |
| 383 |
|
| 384 |
}); // Third AJAX request to get discount information. |
| 385 |
|
| 386 |
}); // End $.post. |
| 387 |
}, |
| 388 |
|
| 389 |
/** |
| 390 |
* 1) Modal Payment change/select plan |
| 391 |
* 2) Checkout selection(s) |
| 392 |
* 3) Payment process |
| 393 |
*/ |
| 394 |
|
| 395 |
getPeriod: function () { |
| 396 |
return $('#imagify_all_plan_view').hasClass('imagify-month-selected') ? 'monthly' : 'yearly'; |
| 397 |
}, |
| 398 |
|
| 399 |
switchToView: function ($view, data) { |
| 400 |
|
| 401 |
var viewId = $view.attr('id'), |
| 402 |
$modalContent = imagifyModal.$modal.children('.imagify-modal-content'); |
| 403 |
|
| 404 |
$view.siblings('.imagify-modal-views').hide().attr('aria-hidden', 'true'); |
| 405 |
|
| 406 |
// Plans view has tabs: display the right one. |
| 407 |
if (data && data.tab) { |
| 408 |
$view.find('a[href="#' + data.tab + '"]').trigger('click.imagify'); |
| 409 |
} |
| 410 |
|
| 411 |
// Payment view: it's an iframe. |
| 412 |
if ('imagify-payment-process-view' === viewId) { |
| 413 |
$modalContent.addClass('imagify-iframe-viewing'); |
| 414 |
} else { |
| 415 |
$modalContent.removeClass('imagify-iframe-viewing'); |
| 416 |
} |
| 417 |
|
| 418 |
// Success view: some tweaks. |
| 419 |
if ('imagify-success-view' === viewId) { |
| 420 |
$modalContent.addClass('imagify-success-viewing'); |
| 421 |
imagifyModal.$modal.attr('aria-labelledby', 'imagify-success-view'); |
| 422 |
} else { |
| 423 |
$modalContent.removeClass('imagify-success-viewing'); |
| 424 |
imagifyModal.$modal.removeAttr('aria-labelledby'); |
| 425 |
} |
| 426 |
|
| 427 |
$view.fadeIn(imagifyModal.speedFadeIn).attr('aria-hidden', 'false'); |
| 428 |
}, |
| 429 |
|
| 430 |
iframeSetSrc: function (params) { |
| 431 |
/** |
| 432 |
* params = { |
| 433 |
* 'plan_id': 0, |
| 434 |
* 'period': 'monthly'|'yearly' |
| 435 |
* } |
| 436 |
*/ |
| 437 |
|
| 438 |
var $iframe = $('#imagify-payment-iframe'), |
| 439 |
iframe_src = $iframe.attr('src'), |
| 440 |
pay_src = $iframe.data('src'), |
| 441 |
// Stop it ESLint, you're drunk. |
| 442 |
key, amount, // eslint-disable-line no-unused-vars |
| 443 |
rt_yearly, rt_monthly, $iframeClone, tofind; |
| 444 |
|
| 445 |
// If we only change monthly/yearly payment mode. |
| 446 |
if (typeof params === 'string' && '' !== iframe_src) { |
| 447 |
tofind = 'monthly' === params ? 'yearly' : 'monthly'; |
| 448 |
iframe_src = iframe_src.replace(tofind, params); |
| 449 |
$iframe.attr('src', iframe_src); |
| 450 |
return; |
| 451 |
} |
| 452 |
|
| 453 |
// If we get new informations about products. |
| 454 |
if (typeof params !== 'object') { |
| 455 |
return; |
| 456 |
} |
| 457 |
|
| 458 |
if (! params.period) { |
| 459 |
w.imagify.info('No period defined'); |
| 460 |
return; |
| 461 |
} |
| 462 |
|
| 463 |
rt_yearly = 'yearly' === params.period ? params.plan_id : 0; |
| 464 |
rt_monthly = 'monthly' === params.period ? params.plan_id : 0; |
| 465 |
|
| 466 |
// Compose route. |
| 467 |
// pay_src + /:monthlyplan(0)/:yearlyplan(0)/ |
| 468 |
pay_src = pay_src + 0 + '/' + rt_monthly + '/' + rt_yearly + '/none/'; |
| 469 |
|
| 470 |
console.log(pay_src); |
| 471 |
// iFrame sort of cache fix. |
| 472 |
$iframeClone = $iframe.remove().attr('src', pay_src); |
| 473 |
|
| 474 |
imagifyModal.$paymentView.html($iframeClone); |
| 475 |
}, |
| 476 |
|
| 477 |
/** |
| 478 |
* Public function triggered by payement iframe. |
| 479 |
*/ |
| 480 |
paymentClose: function () { |
| 481 |
$('.imagify-iframe-viewing .close-btn').trigger('click.imagify'); |
| 482 |
$('.imagify-iframe-viewing').removeClass('imagify-iframe-viewing'); |
| 483 |
}, |
| 484 |
|
| 485 |
/** |
| 486 |
* @uses imagifyModal.switchToView() |
| 487 |
*/ |
| 488 |
paymentBack: function () { |
| 489 |
imagifyModal.switchToView(imagifyModal.$plansView); |
| 490 |
}, |
| 491 |
|
| 492 |
/** |
| 493 |
* @uses imagifyModal.switchToView() |
| 494 |
*/ |
| 495 |
paymentSuccess: function () { |
| 496 |
imagifyModal.switchToView(imagifyModal.$successView); |
| 497 |
}, |
| 498 |
|
| 499 |
/** |
| 500 |
* @uses imagifyModal.paymentClose() |
| 501 |
* @uses imagifyModal.paymentBack() |
| 502 |
* @uses imagifyModal.paymentSuccess() |
| 503 |
*/ |
| 504 |
checkPluginMessage: function (e) { |
| 505 |
var origin = e.origin || e.originalEvent.origin; // eslint-disable-line no-shadow |
| 506 |
|
| 507 |
if ( imagifyPricingModal.imagify_app_domain !== origin ) { |
| 508 |
return; |
| 509 |
} |
| 510 |
|
| 511 |
switch (e.data) { |
| 512 |
case 'cancel': |
| 513 |
imagifyModal.paymentClose(); |
| 514 |
break; |
| 515 |
case 'back': |
| 516 |
imagifyModal.paymentBack(); |
| 517 |
break; |
| 518 |
case 'success': |
| 519 |
imagifyModal.paymentSuccess(); |
| 520 |
break; |
| 521 |
} |
| 522 |
}, |
| 523 |
getPromoAppliesTo: function(promo){ |
| 524 |
var applies_to = []; |
| 525 |
if (promo.applies_to instanceof Array) { |
| 526 |
var plan_list = []; |
| 527 |
|
| 528 |
for (var plan_infos = 0; plan_infos < promo.applies_to.length; plan_infos++) { |
| 529 |
plan_list.push(promo.applies_to[plan_infos].plan_name); |
| 530 |
} |
| 531 |
|
| 532 |
plan_list.forEach(function (item) { |
| 533 |
if (! applies_to.includes(item)) { |
| 534 |
applies_to.push(item); |
| 535 |
} |
| 536 |
}); |
| 537 |
} else { |
| 538 |
applies_to = [promo.applies_to]; |
| 539 |
} |
| 540 |
return applies_to; |
| 541 |
} |
| 542 |
}; |
| 543 |
|
| 544 |
/** |
| 545 |
* INIT. |
| 546 |
*/ |
| 547 |
|
| 548 |
/** |
| 549 |
* Get pricings on modal opening. |
| 550 |
* Build the pricing tables inside modal. |
| 551 |
*/ |
| 552 |
$('.imagify-get-pricing-modal').on('click.imagify-ajax', function () { |
| 553 |
imagifyModal.getPricing($(this)); |
| 554 |
}); |
| 555 |
|
| 556 |
/** |
| 557 |
* Get pricing on modal opening for admin bar menu, the button is added dynamically |
| 558 |
* Build the pricing tables inside modal. |
| 559 |
*/ |
| 560 |
$(document).on('click', '.imagify-admin-bar-upgrade-plan', function () { |
| 561 |
imagifyModal.getPricing($(this)); |
| 562 |
}); |
| 563 |
|
| 564 |
/** |
| 565 |
* Reset the modal on close. |
| 566 |
*/ |
| 567 |
$(d).on('modalClosed.imagify', '.imagify-payment-modal', function () { |
| 568 |
$(this).find('.imagify-modal-content').removeClass('imagify-success-viewing imagify-iframe-viewing'); |
| 569 |
|
| 570 |
// Reset first view after fadeout ~= 300 ms. |
| 571 |
setTimeout(function () { |
| 572 |
$('.imagify-modal-views').hide(); |
| 573 |
$('#imagify-plans-selection-view').show(); |
| 574 |
}, 300); |
| 575 |
|
| 576 |
//delay scrolltop top to avoid flickering |
| 577 |
setTimeout(function () { |
| 578 |
$('.imagify-payment-modal').find('.imagify-modal-content').scrollTop(0); |
| 579 |
}, 400); |
| 580 |
}); |
| 581 |
|
| 582 |
/** |
| 583 |
* View game, step by step. |
| 584 |
*/ |
| 585 |
|
| 586 |
/** |
| 587 |
* 2) when you checkout. |
| 588 |
* |
| 589 |
* @uses imagifyModal.switchToView() |
| 590 |
* @uses imagifyModal.getPeriod() |
| 591 |
* @uses imagifyModal.iframeSetSrc() |
| 592 |
*/ |
| 593 |
imagifyModal.$modal.on('click.imagify', '.imagify-payment-btn-select-plan', function (e) { |
| 594 |
var checkout_datas; |
| 595 |
|
| 596 |
e.preventDefault(); |
| 597 |
|
| 598 |
checkout_datas = {}; |
| 599 |
|
| 600 |
// Clear user account cache. |
| 601 |
if (imagifyPricingModal.userDataCache) { |
| 602 |
$.post(ajaxurl, { |
| 603 |
action: imagifyPricingModal.userDataCache.deleteAction, |
| 604 |
_wpnonce: imagifyPricingModal.userDataCache.deleteNonce |
| 605 |
}); |
| 606 |
} |
| 607 |
|
| 608 |
// Change views to go to checkout/payment view. |
| 609 |
imagifyModal.switchToView(imagifyModal.$paymentView); |
| 610 |
|
| 611 |
checkout_datas.plan_id = Object.values(JSON.parse($(this).attr('data-offer')))[0].id; |
| 612 |
checkout_datas.period = imagifyModal.getPeriod(); |
| 613 |
|
| 614 |
imagifyModal.iframeSetSrc(checkout_datas); |
| 615 |
}); |
| 616 |
|
| 617 |
// Message/communication API. |
| 618 |
w.addEventListener('message', imagifyModal.checkPluginMessage, true); |
| 619 |
|
| 620 |
})(jQuery, document, window); |
| 621 |
|