// Imagify tabs ==================================================================================== (function ($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names $('.imagify-badge').addClass('imagify-badge-checked'); $('.imagify-toggle-label').eq(0).css('color', '#c8ced5'); $('.imagify-toggle-label').eq(1).css('color', '#3b3f4a'); // Plan switcher. $('#imagify-toggle-plan').change(function() { var isChecked = $(this).is(':checked'); $('.imagify-toggle-label').eq(0).css('color', isChecked ? '#c8ced5' : '#3b3f4a'); $('.imagify-toggle-label').eq(1).css('color', isChecked ? '#3b3f4a' : '#c8ced5'); $('.imagify-badge').toggleClass('imagify-badge-checked', isChecked); $('#imagify_all_plan_view').toggleClass('imagify-year-selected', isChecked).toggleClass('imagify-month-selected', ! isChecked); $('.imagify-arrow-container img').eq(0).toggle(! isChecked); $('.imagify-arrow-container img').eq(1).toggle(isChecked); }); })(jQuery, document, window); // Imagify payment modal =========================================================================== (function ($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names var imagifyModal = {}; if (! $('#imagify-pricing-modal').length) { return; } imagifyModal = { $modal: $('#imagify-pricing-modal'), // Plans selection view & payment process view hidden by default. $plansView: $('#imagify-plans-selection-view'), $paymentView: $('#imagify-payment-process-view').hide(), $successView: $('#imagify-success-view').hide(), speedFadeIn: 300, getHtmlPrice: function (content, period) { var monthly, yearly, m, y, output; if (! period) { period = null; } if (typeof content !== 'object') { content += ''; // Be sure content is a string. content = content.split('.'); content[1] = content[1].length === 1 ? content[1] + '0' : ('' + content[1]).substring(0, 2); output = '' + content[0] + ' '; output += '.' + content[1] + ''; return output; } monthly = content.monthly + ''; yearly = content.yearly + ''; m = '0' === monthly ? ['0', '00'] : monthly.split('.'); y = '0' === yearly ? ['0', '00'] : yearly.split('.'); output = ''; /* eslint-disable indent */ output += ''; output += '' + m[0] + ' '; output += '.' + (m[1].length === 1 ? m[1] + '0' : ('' + m[1]).substring(0, 2)) + ''; output += ' '; output += ''; output += '' + y[0] + ' '; output += '.' + (y[1].length === 1 ? y[1] + '0' : ('' + y[1]).substring(0, 2)) + ''; output += ''; /* eslint-enable indent */ output += ''; return output; }, getHtmlDiscountPrice: function (content, period) { var monthly, yearly, output = ''; if (! period) { period = null; } if (typeof content === 'object') { monthly = content.monthly + ''; yearly = content.yearly + ''; output += ''; /* eslint-disable indent */ output += '$'; output += ''; output += ''; output += '' + monthly + ''; output += ''; output += ''; output += '' + yearly + ''; output += ''; output += ''; /* eslint-enable indent */ output += ''; } else { content += ''; // Be sure content is a string. output += ''; /* eslint-disable indent */ output += '$'; output += '' + content + ''; /* eslint-enable indent */ output += ''; } return output; }, /** * @uses imagifyModal.getHtmlPrice() * @uses imagifyModal.getHtmlDiscountPrice() */ populateOffer: function ($offer, datas, type, classes) { var promo = w.imagify_discount_datas, add = datas.additional_gb, // 4 (monthly) ann = datas.annual_cost, // 49.9 (monthly) id = datas.id, // 3 (monthly/onetime) lab = datas.label, // 'lite' (monthly/onetime) mon = datas.monthly_cost, // 4.99 (monthly) quo = datas.quota, // 1000 (MB) - 5000 images (monthly/onetime) cos = datas.cost, // 3.49 (onetime) label = datas.label.replace(/_.*$/, ''), name = -1 === quo ? 'Unlimited' : (quo >= 1000 ? quo / 1000 + ' GB' : quo + ' MB'), pcs = 'monthly' === type ? {monthly: mon, yearly: Math.round(ann / 12 * 100) / 100} : cos, pcsd = pcs, // Used if discount is active. percent, $datas_c, datas_content, applies_to = [], offer_by = '', additional_data = ''; applies_to = imagifyModal.getPromoAppliesTo(promo); // Change pricing value only if discount in percentage is active and if offer is a monthly and not a onetime. if ( promo.is_active && 'percentage' === promo.coupon_type && 'monthly' === type && (0 < mon) && (applies_to.includes(lab) || 'all' === applies_to[0]) ) { percent = (100 - promo.coupon_value) / 100; pcs = 'monthly' === type ? { monthly: mon * percent, yearly: Math.round((ann * percent) / 12 * 100) / 100 } : cos * percent; } if (typeof classes !== 'undefined') { $offer.addClass('imagify-' + type + '-' + lab + classes); $offer.addClass('imagify-' + type + '-' + lab + classes); } // Label. $offer.find('.imagify-label-plans').text(label); // Name. $offer.find('.imagify-offer-size').text(name); // Main prices (pcs can be an object or a string). $offer.find('.imagify-number-block').html(imagifyModal.getHtmlPrice(pcs, 'monthly')); if ('Unlimited' === name) { offer_by = 'quota'; $offer.addClass('imagify-best-value'); additional_data = 'No additional cost'; } else { offer_by = '/month'; additional_data = '$' + add + ' per additional Gb'; } $offer.find('.imagify-offer-by').text(offer_by); // discount prices $offer.find('.imagify-price-block').prev('.imagify-price-discount').remove(); if ( promo.is_active && 'percentage' === promo.coupon_type && 'monthly' === type && (0 < mon) && (applies_to.includes(lab) || 'all' === applies_to[0]) ) { $offer.find('.imagify-price-block').before(imagifyModal.getHtmlDiscountPrice(pcsd, 'monthly')); } // Nb images. $offer.find('.imagify-approx-nb').text(quo * 5); if ('monthly' === type) { // Additional price. $offer.find('.imagify-price-add-data').text(additional_data); } // Button data-offer attr. $datas_c = $offer.find('.imagify-payment-btn-select-plan').length ? $offer.find('.imagify-payment-btn-select-plan') : $offer; if ('monthly' === type) { 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 + '}}}'; } else { datas_content = '{"ot' + lab + '":{"id":' + id + ',"name":"' + name + '","label":"' + lab + '","data":' + quo + ',"dataf":"' + name + '","imgs":' + (quo * 5) + ',"price":' + pcs + '}}'; } $datas_c.attr('data-offer', datas_content); return $offer; }, /** * @uses imagifyModal.populateOffer() */ getPricing: function ($button) { var nonce = $button.data('nonce'), prices_rq_datas = { action: 'imagify_get_prices', imagifynonce: nonce }, prices_rq_discount = { action: 'imagify_get_discount', imagifynonce: nonce }; imagifyModal.$modal.find('.imagify-modal-loader').hide().show(); imagifyModal.$modal.addClass('imagify-modal-loading'); /** * TODO: change the way to waterfall requests. * Use setInterval + counter instead. */ // Get the true prices. $.post(ajaxurl, prices_rq_datas, function (prices_response) { if (! prices_response.success) { // TODO: replace modal content by any information. // An error occurred. return; } // Get the discount informations. $.post(ajaxurl, prices_rq_discount, function (discount_response) { var prices_datas, promo_datas, offers, mo_html = '', $mo_tpl, mo_clone, $estim_block, $offers_block, $banners, date_end, plan_names, promo, discount; if (! discount_response.success) { // TODO: replace modal content by any information. // An error occurred. return; } prices_datas = prices_response.data; promo_datas = discount_response.data; offers = { mo: [] }; $mo_tpl = $('#imagify-offer-monthly-template'); mo_clone = $mo_tpl.html(); $estim_block = $('.imagify-estimation-block'); // Remove inactive offers. $.each(prices_datas.monthlies, function (index, value) { if ('undefined' === typeof value.active || ('undefined' !== typeof value.active && true === value.active) ) { if ('starter' === value.label) { return; } offers.mo.push(value); } }); // Refresh Analyzing block. $estim_block.removeClass('imagify-analyzing'); // Reset offer selection. $('.imagify-offer-selected').removeClass('imagify-offer-selected').find('.imagify-checkbox').prop('checked', false); // Don't create prices table if something went wrong during request. if (null === offers.mo) { $offers_block = $('.imagify-pre-checkout-offers'); // Hide main content. $offers_block.hide().attr('aria-hidden', true); // Show error message. $offers_block.closest('.imagify-modal-views').find('.imagify-popin-message').remove(); $offers_block.after('
'); // Show the modal content. imagifyModal.$modal.find('.imagify-modal-loader').fadeOut(300); imagifyModal.$modal.removeClass('imagify-modal-loading'); return; } // Autofill coupon code & Show banner if discount is active. w.imagify_discount_datas = promo_datas; if (promo_datas.is_active) { if (promo_datas.applies_to instanceof Array) { plan_names = []; var plan_list = []; for (var plan_infos = 0; plan_infos < promo_datas.applies_to.length; plan_infos++) { plan_list.push(promo_datas.applies_to[plan_infos].plan_name); } plan_list.forEach(function (item) { if (! plan_names.includes(item)) { plan_names.push(item); } }); plan_names = plan_names.join(', '); } else { plan_names = promo_datas.applies_to; } $banners = $('.imagify-modal-promotion'); date_end = promo_datas.date_end.split('T')[0]; promo = promo_datas.coupon_value; discount = 'percentage' === promo_datas.coupon_type ? promo + '%' : '$' + promo; // Show banners. $banners.addClass('active').attr('aria-hidden', 'false'); // Populate banners. $banners.find('.imagify-promotion-number').text(discount); $banners.find('.imagify-promotion-plan-name').text(plan_names); $banners.find('.imagify-promotion-date').text(date_end); } /** * Below lines will build Plan and Onetime offers lists. * It will also pre-select a Plan and/or Onetime in both of views: pre-checkout and pricing tables. */ if (0 === offers.mo.length) { $('.imagify-pre-checkout-offers .imagify-offer-monthly').remove(); $('.imagify-tabs').remove(); $('.imagify-pricing-tab-monthly').remove(); } else { // Now, do the MONTHLIES Markup. offers.mo = offers.mo.reverse(); $.each(offers.mo, function (index, value) { var $tpl, classes = ''; // Populate each offer. $tpl = $(mo_clone).clone(); $tpl = imagifyModal.populateOffer($tpl, value, 'monthly', classes); // Complete Monthlies HTML. mo_html += $tpl[0].outerHTML; }); // Wait for element to be ready after ajax callback before adding ribbon. setTimeout(function() { // Add best value ribbon to unlimited plan. $('.imagify-best-value').prepend('