PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | assets/js/admin.js +74 -744 1.5 → trunk View file →
@@ -1,762 +1,92 @@
1 -jQuery(function($){
1 +window.imagify = window.imagify || {};
2 2
3 - var concat = ajaxurl.indexOf("?") > 0 ? "&" : "?",
4 - imagify = {
5 - log: function ( content ) {
6 - if (console !== 'undefined') console.log( content );
7 - },
8 - info: function ( content ) {
9 - if (console !== 'undefined') console.info( content );
10 - }
11 - };
12 -
13 - /*
14 - * Create a new Imagify account
15 - */
16 - $('#imagify-signup').click( function(e){
17 - e.preventDefault();
18 -
19 - // Display the sign up form
20 - swal({
21 - title: imagifyAdmin.labels.signupTitle,
22 - text: imagifyAdmin.labels.signupText,
23 - confirmButtonText: imagifyAdmin.labels.signupConfirmButtonText,
24 - type: "input",
25 - closeOnConfirm: false,
26 - allowOutsideClick: true,
27 - showLoaderOnConfirm: true,
28 - customClass: "imagify-sweet-alert imagify-sweet-alert-signup"
29 - },
30 - function(inputValue){
31 - if ($.trim(inputValue) == "" || ! inputValue) {
32 - swal.showInputError(imagifyAdmin.labels.signupErrorEmptyEmail);
33 - return false;
34 - }
35 -
36 - $.get(ajaxurl + concat + "action=imagify_signup&email=" +inputValue + "&imagifysignupnonce="+ $('#imagifysignupnonce').val())
37 - .done(function(response){
38 - if( !response.success ) {
39 - swal.showInputError(response.data);
40 - } else {
41 - swal({
42 - title:imagifyAdmin.labels.signupSuccessTitle,
43 - text: imagifyAdmin.labels.signupSuccessText,
44 - type: "success",
45 - customClass: "imagify-sweet-alert"
46 - });
47 - }
48 - });
49 - });
50 - });
51 -
52 - /*
53 - * Check and save the Imagify API Key
54 - */
55 - $('#imagify-save-api-key').click( function(e){
56 - e.preventDefault();
57 -
58 - // Display the sign up form
59 - swal({
60 - title: imagifyAdmin.labels.saveApiKeyTitle,
61 - text: imagifyAdmin.labels.saveApiKeyText,
62 - confirmButtonText: imagifyAdmin.labels.saveApiKeyConfirmButtonText,
63 - type: "input",
64 - closeOnConfirm: false,
65 - allowOutsideClick: true,
66 - showLoaderOnConfirm: true,
67 - customClass: "imagify-sweet-alert imagify-sweet-alert-signup"
68 - },
69 - function(inputValue){
70 - if ($.trim(inputValue) == "" || ! inputValue) {
71 - swal.showInputError(imagifyAdmin.labels.signupErrorEmptyEmail);
72 - return false;
73 - }
74 -
75 - $.get(ajaxurl + concat + "action=imagify_check_api_key_validity&api_key=" +inputValue + "&imagifycheckapikeynonce="+ $('#imagifycheckapikeynonce').val())
76 - .done(function(response){
77 - if( !response.success ) {
78 - swal.showInputError( response.data );
79 - } else {
80 - swal({
81 - title: imagifyAdmin.labels.ApiKeyCheckSuccessTitle,
82 - text: imagifyAdmin.labels.ApiKeyCheckSuccessText,
83 - type: "success",
84 - customClass: "imagify-sweet-alert"
85 - });
86 - }
87 - });
88 - });
89 - });
90 -
91 - /*
92 - * Toggle an Imagify notice
93 - */
94 - $('.imagify-notice-dismiss').click( function( e ) {
95 - e.preventDefault();
96 -
97 - var obj = $(this),
98 - parent = obj.parents('.imagify-welcome, .imagify-notice'),
99 - href = obj.attr('href');
100 -
101 - // Hide the notice
102 - parent.fadeTo( 100 , 0, function() {
103 - $(this).slideUp( 100, function() {
104 - $(this).remove();
105 - });
106 - });
107 -
108 - // Save the dismiss notice
109 - $.get( href.replace( 'admin-post.php', 'admin-ajax.php' ) );
110 - });
111 -
112 -
113 - /*
114 - * Imagify Light modal
115 - */
116 - var imagify_open_modal = function( $the_link ){
117 -
118 - var the_target = $the_link.data('target') || $the_link.attr('href');
119 -
120 - $( the_target ).css('display', 'flex').hide().fadeIn(400).attr('aria-hidden', 'false').attr('tabindex', '0').focus().removeAttr('tabindex').addClass('modal-is-open');
121 - $('body').addClass('imagify-modal-is-open');
122 -
123 - };
124 -
125 - // accessibility
126 - $('.imagify-modal').attr('aria-hidden', 'true');
127 -
128 - // on click on modal trigger
129 - $('.imagify-modal-trigger').on('click.imagify', function(){
130 -
131 - imagify_open_modal( $(this) );
132 -
133 - return false;
134 - });
135 -
136 - // on click on close button
137 - $(document).on('click.imagify', '.imagify-modal .close-btn', function(){
138 - $(this).closest('.imagify-modal').fadeOut(400).attr('aria-hidden', 'true').removeClass('modal-is-open');
139 - $('body').removeClass('imagify-modal-is-open');
140 - })
141 - .on('blur.imagify', '.imagify-modal .close-btn', function(){
142 - var $modal = $(this).closest('.imagify-modal');
143 - if ( $modal.attr('aria-hidden') === 'false' ) {
144 - $modal.attr('tabindex', '0').focus().removeAttr('tabindex');
3 +jQuery.extend( window.imagify, {
4 + concat: ajaxurl.indexOf( '?' ) > 0 ? '&' : '?',
5 + log: function( content ) {
6 + if ( undefined !== console ) {
7 + console.log( content ); // eslint-disable-line no-console
145 8 }
146 - });
9 + },
10 + info: function( content ) {
11 + if ( undefined !== console ) {
12 + console.info( content ); // eslint-disable-line no-console
13 + }
14 + },
15 + openModal: function( $link ) {
16 + var target = $link.data( 'target' ) || $link.attr( 'href' ),
17 + $target = jQuery( target );
147 18
148 - // `Esc` key binding
149 - $(window).on('keydown', function(e){
150 - if ( e.keyCode == 27 && $('.imagify-modal.modal-is-open').length > 0 ) {
19 + $target.css( 'display', 'flex' ).hide().fadeIn( 400 ).attr( {
20 + 'aria-hidden': 'false',
21 + 'tabindex': '0'
22 + } ).trigger('focus').removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
151 23
152 - e.preventDefault();
153 -
154 - // trigger the event
155 - $('.imagify-modal.modal-is-open').find('.close-btn').trigger('click.imagify');
156 -
157 - return false;
24 + jQuery( 'body' ).addClass( 'imagify-modal-is-open' );
25 + },
26 + template: function( id ) {
27 + if ( undefined === _ ) {
28 + // No need to load underscore everywhere if we don't use it.
29 + return '';
158 30 }
159 - });
160 -
161 - var busy = false,
162 - xhr = false;
163 -
164 - $('#wp-admin-bar-imagify').hover( function() {
165 - if ( true === busy ) {
166 - return;
167 - }
168 -
169 - busy = true;
170 -
171 - var $adminBarProfile = $('#wp-admin-bar-imagify-profile-content');
172 -
173 - if( $adminBarProfile.is(':empty') ) {
174 - xhr = $.get(ajaxurl + concat + "action=imagify_get_admin_bar_profile&imagifygetadminbarprofilenonce="+ $('#imagifygetadminbarprofilenonce').val())
175 - .done(function(response){
176 - $adminBarProfile.html(response.data);
177 - $('#wp-admin-bar-imagify-profile-loading').remove();
178 - busy = false;
179 - });
180 - }
181 - });
182 31
183 - /**
184 - * Payment Modal
185 - *
186 - * @since 1.5
187 - * @author Geoffrey
188 - */
189 -
190 - if ( $('#imagify-pricing-modal').length ) {
191 - var $modal = $('#imagify-pricing-modal'),
192 - imagify_get_html_price = function( content, period ) {
193 - if ( ! period ) period = null;
194 - output = '';
32 + return _.memoize( function( data ) {
33 + var compiled,
34 + options = {
35 + evaluate: /<#([\s\S]+?)#>/g,
36 + interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
37 + escape: /\{\{([^}]+?)\}\}(?!\})/g,
38 + variable: 'data'
39 + };
195 40
196 - if ( typeof content === 'object' ) {
197 - var monthly = content.monthly + "",
198 - yearly = content.yearly + "",
199 - m = monthly.split('.'),
200 - y = yearly.split('.');
201 -
202 - output += '<span class="imagify-switch-my"><span aria-hidden="' + ( period === 'monthly' ? 'false' : 'true' ) + '" class="imagify-monthly"><span class="imagify-price-big">' + m[0] + '</span> <span class="imagify-price-mini">.' + ( m[1].length === 1 ? m[1] + '0' : m[1] ) + '</span></span> <span aria-hidden="' + ( period === 'yearly' ? 'false' : 'true' ) + '" class="imagify-yearly"><span class="imagify-price-big">' + y[0] + '</span> <span class="imagify-price-mini">.' + ( y[1].length === 1 ? y[1] + '0' : y[1] ) + '</span></span></span>';
203 - } else {
204 - var content = content + "", // be sure content is a string
205 - v = content.split('.');
206 -
207 - output += '<span class="imagify-price-big">' + v[0] + '</span> <span class="imagify-price-mini">.' + ( v[1].length === 1 ? v[1] + '0' : v[1] ) + '</span>';
208 - }
209 -
210 - return output;
211 - },
212 - imagify_get_pricing = function( $button ){
213 - var data = {
214 - action: 'imagify_get_prices',
215 - imagifynonce: $button.data('nonce')
216 - };
217 -
218 - $modal.find('.imagify-modal-loader').hide().show();
219 -
220 - $.post( ajaxurl, data, function( response ) {
221 - if ( response.success ) {
222 - var datas = response.data,
223 - monthlies = datas.monthlies,
224 - onetimes = datas.onetimes,
225 - mo_user_cons= 1000, // TODO: dynamic, in MB,
226 - ot_user_cons= 51000, // TODO: dynamic, in MB,
227 - $mo_tpl = $('#imagify-offer-monthly-template'),
228 - $ot_tpl = $('#imagify-offer-onetime-template'),
229 - ot_clone = $ot_tpl.html(),
230 - mo_clone = $mo_tpl.html(),
231 - ot_html = '',
232 - mo_html = '',
233 - ot_suggested= false,
234 - mo_suggested= false;
235 -
236 - // Do the MONTHLIES Markup
237 - // TODO: remove offers from monthlies depending on mo_user_cons
238 -
239 - $.each( monthlies, function( index, value ) {
240 - if ( value.label === 'free' ) {
241 - return true; // continue like (but $.each is not a loop… so)
242 - }
243 - var add = value.additional_gb, // 4
244 - ann = value.annual_cost, // 49.9
245 - id = value.id, // 3
246 - lab = value.label, // 'lite'
247 - mon = value.monthly_cost, // 4.99
248 - quo = value.quota, // 1000 (MB) - 5000 images
249 - name= ( quo >= 1000 ? quo/1000 + ' GB' : quo + ' MB' ),
250 - $tpl= $( mo_clone ).clone(),
251 - pcs = { monthly: mon, yearly: Math.round( ann / 12 * 100 ) / 100 };
252 -
253 - // parent classes
254 - classes = '';
255 - if ( ( mo_user_cons < quo && mo_suggested === false ) ) {
256 - classes = ' imagify-offer-selected';
257 - mo_suggested = true;
258 - }
259 - $tpl.addClass( 'imagify-monthly-' + lab + classes);
260 -
261 - // name
262 - $tpl.find('.imagify-offer-size').text( name );
263 -
264 - // nb images
265 - $tpl.find('.imagify-approx-nb').text( quo * 5 );
266 -
267 - // additionnal price
268 - $tpl.find('.imagify-price-add-data').text( '$' + add );
269 -
270 - // main prices
271 - $tpl.find('.imagify-number-block').html( imagify_get_html_price( pcs, 'monthly' ) );
272 -
273 - // button data-offer attr
274 - $tpl.find('.imagify-payment-btn-select-plan').attr('data-offer', '{"' + lab + '":{"id":' + id + ',"name":"' + name + '","data":' + quo + ',"dataf":"' + name + '","imgs":' + ( quo * 5 ) + ',"prices":{"monthly":' + pcs.monthly + ',"yearly":' + pcs.yearly + ',"add":' + add + '}}}');
275 -
276 - // complete Monthlies HTML
277 - mo_html += $tpl[0].outerHTML;
278 -
279 - });
280 -
281 - // Do the ONETIMES Markup
282 - // TODO: add custom estimation in onetimes table based on ot_user_cons
283 - $.each( onetimes, function( index, value ) {
284 - var id = value.id, // 1
285 - co = value.cost, // 3.49
286 - la = value.label, // "250MB"
287 - qu = value.quota, // 250
288 - name = ( qu >= 1000 ? qu / 1000 + ' GB' : qu + ' MB' ),
289 - $tpl = $( ot_clone ).clone();
290 -
291 - // parent classes
292 - classes = '';
293 - if ( ( ot_user_cons < qu && ot_suggested === false ) ) {
294 - classes = ' imagify-offer-selected';
295 - ot_suggested = true;
296 - }
297 - $tpl.addClass( 'imagify-onetime-' + la + classes);
298 -
299 - // name
300 - $tpl.find('.imagify-offer-size').text( name );
301 -
302 - // nb images
303 - $tpl.find('.imagify-approx-nb').text( qu * 5 );
304 -
305 - // main prices
306 - $tpl.find('.imagify-number-block').html( imagify_get_html_price( co, 'monthly' ) );
307 -
308 - // button data-offer attr
309 - $tpl.find('.imagify-payment-btn-select-plan').attr('data-offer', '{"ot' + la + '":{"id":' + id + ',"name":"' + name + '","data":' + qu + ',"dataf":"' + name + '","imgs":' + ( qu * 5 ) + ',"price":' + co + '}}');
310 -
311 - // complete Monthlies HTML
312 - ot_html += $tpl[0].outerHTML;
313 - });
314 -
315 - // Fill pricing tables
316 - if ( $mo_tpl.parent().find('.imagify-offer-line') ) {
317 - $mo_tpl.parent().find('.imagify-offer-line').remove();
318 - }
319 - $mo_tpl.before( mo_html );
320 -
321 - if ( $ot_tpl.parent().find('.imagify-offer-line') ) {
322 - $ot_tpl.parent().find('.imagify-offer-line').remove();
323 - }
324 - $ot_tpl.before( ot_html );
325 -
326 - // Fill the Pre-checkout view
327 - // (depending on user_cons)
328 -
329 - // Show the content
330 - $modal.find('.imagify-modal-loader').fadeOut(300);
331 -
332 -
333 - } else {
334 - // TODO: replace modal content by any information
335 - // an error occurred
336 - }
337 -
338 - }); // end $.post
339 - },
340 - imagify_check_check = function( $checkbox ) {
341 - var sel_class = 'imagify-offer-selected';
342 -
343 - $checkbox.each(function(){
344 - if ( $(this).is(':checked') ) {
345 - $(this).closest('.imagify-offer-line').addClass( sel_class );
346 - }
347 - else {
348 - $(this).closest('.imagify-offer-line').removeClass( sel_class );
349 - }
350 - });
351 - },
352 - imagify_check_radio = function( $radio ) {
353 - var year_class = 'imagify-year-selected',
354 - month_class = 'imagify-month-selected';
355 -
356 - $radio.each(function(){
357 - // to handle modal pricing & modal suggestion
358 - var $_this = $(this);
359 - var $parent = '';
360 -
361 - if ( $_this.parent('.imagify-cart-list-switcher').length ) {
362 - $parent = $_this.closest('.imagify-cart');
363 - } else if ( $_this.parent('.imagify-small-options').length ) {
364 - $parent = $_this.parent('.imagify-small-options').next('.imagify-pricing-table');
365 - } else {
366 - $parent = $_this.closest('.imagify-offer-line');
367 - }
368 -
369 - var $to_switch = $parent.find('.imagify-switch-my');
370 -
371 - if ( $_this.val() === 'yearly' ) {
372 - $parent.addClass( year_class ).removeClass( month_class );
373 - $to_switch.find('.imagify-monthly').attr('aria-hidden', 'true');
374 - $to_switch.find('.imagify-yearly').attr('aria-hidden', 'false');
375 - } else {
376 - $parent.addClass( month_class ).removeClass( year_class );
377 - $to_switch.find('.imagify-monthly').attr('aria-hidden', 'false');
378 - $to_switch.find('.imagify-yearly').attr('aria-hidden', 'true');
379 - }
380 - });
381 - return $radio;
382 - },
383 - $checkboxes = $('.imagify-offer-line').find('.imagify-checkbox'),
384 - $radios = $('.imagify-payment-modal').find('.imagify-radio-line').find('input');
385 -
386 - // check all boxes on load
387 - imagify_check_check( $checkboxes );
388 - imagify_check_radio( $radios.filter(':checked') );
389 -
390 - // check the changed box
391 - $checkboxes.on('change.imagify', function(){
392 - imagify_check_check( $(this) );
393 - });
394 -
395 - // check the radio box
396 - $radios.on('change.imagify', function(){
397 - imagify_check_radio( $(this) );
398 - });
399 -
400 - /**
401 - * Get pricings on modal opening
402 - * Build the pricing tables inside modal
403 - */
404 - $('#imagify-get-pricing-modal').on('click.imagify-ajax', function(){
405 - imagify_get_pricing( $(this) );
406 - });
407 -
408 - /**
409 - * 1) Modal Payment change/select plan
410 - * 2) Checkout selection(s)
411 - * 3) Payment process
412 - */
413 -
414 - // plans selection view & payment process view hidden by default
415 - var $plans_view = $('#imagify-plans-selection-view'),
416 - $payment_view = $('#imagify-payment-process-view'),
417 - $pre_view = $('#imagify-pre-checkout-view'),
418 - $success_view = $('#imagify-success-view'),
419 - speedFadeIn = 300,
420 - $another_btn = $('.imagify-choose-another-plan'),
421 - imagify_iframe_set_src = function( params ) {
422 - /*
423 - params = {
424 - 'monthly': {
425 - 'lite': {
426 - name: 'something',
427 - id: ''
428 - }
429 - },
430 - 'onetime': {
431 - 'recommended': {
432 - name: 'Recommend',
433 - id: ''
434 - }
435 - },
436 - 'period': 'monthly'|'yearly'
437 - }
438 - */
439 - var $iframe = $('#imagify-payment-iframe'),
440 - iframe_src = $iframe.attr('src'),
441 - monthly_id = 0,
442 - onetime_id = 0;
443 - if ( typeof params === 'object' ) {
444 - if ( params.monthly ) {
445 - monthly_id = params.monthly[ Object.keys( params.monthly )[0] ].id;
446 - }
447 - if ( params.onetime ) {
448 - onetime_id = params.onetime[ Object.keys( params.onetime )[0] ].id;
449 - // if onetime ID === 999 it's a custom plan, send datas instead
450 - onetime_id = ( onetime_id == 999 ? params.onetime[ Object.keys( params.onetime )[0] ].data : onetime_id );
451 - }
452 -
453 - if ( params.period ) {
454 - iframe_src = iframe_src.split('?')[0] + '?monthly=' + monthly_id + '&onetime=' + onetime_id + '&api=' + imagify_get_api_key() + '&period=' + params.period;
455 -
456 - $iframe.attr( 'src', iframe_src );
457 -
458 - } else {
459 - imagifyAdmin.labels.info('No period defined');
460 - }
461 - } else if ( typeof params === 'string' ) {
462 - iframe_src = iframe_src.split('&period=');
463 - $iframe.attr( 'src', iframe_src[0] + '&period=' + params );
464 - }
465 - },
466 - imagify_get_period = function() {
467 - return ( $('.imagify-cart').hasClass('imagify-month-selected') ? 'monthly' : 'yearly' );
468 - },
469 - imagify_get_api_key = function(){
470 - return $('#imagify-payment-iframe').data('imagify-api');
41 + return function() {
42 + compiled = compiled || _.template( jQuery( '#tmpl-' + id ).html(), null, options );
43 + data = data || {};
44 + return compiled( data );
471 45 };
46 + } );
47 + }
48 +} );
472 49
473 - // init views
474 - $plans_view.hide();
475 - $payment_view.hide();
476 - $success_view.hide();
477 - //$pre_view.hide();
478 50
479 - // 1) when you decide to choose another plan
480 -
481 - // 1.a) on click, display choices
482 - $another_btn.on('click.imagify', function(){
483 - var $_this = $(this),
484 - type = $_this.data('imagify-choose');
51 +// Imagify light modal =============================================================================
52 +(function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names
485 53
486 - // hide current
487 - $_this.closest('.imagify-modal-views').hide().attr('aria-hidden', 'true');
488 - // hide the checkout view (click could be a triggered action ;p)
489 - $payment_view.hide().attr('aria-hidden', 'true');
54 + // Accessibility.
55 + $( '.imagify-modal' ).attr( 'aria-hidden', 'true' );
490 56
491 - // show choices
492 - $plans_view.fadeIn(speedFadeIn).attr('aria-hidden', 'false');
493 -
494 - // trigger on tab
495 - var temp = setInterval(function(){
496 - var tab = type == 'plan' ? 'monthly' : 'onetime';
497 - $plans_view.find('a[href="#imagify-pricing-tab-' + tab + '"]').trigger('click.imagify');
498 - clearInterval( temp );
499 - temp = null;
500 - }, 60 );
57 + $( d )
58 + // On click on modal trigger, open modal.
59 + .on( 'click.imagify', '.imagify-modal-trigger', function( e ) {
60 + e.preventDefault();
61 + w.imagify.openModal( $( this ) );
62 + } )
63 + // On click on close button, close modal.
64 + .on( 'click.imagify', '.imagify-modal .close-btn', function() {
65 + var $modal = $( this ).closest( '.imagify-modal' );
501 66
502 - return false;
503 - });
67 + $modal.fadeOut( 400 ).attr( 'aria-hidden', 'true' ).removeClass( 'modal-is-open' ).trigger( 'modalClosed.imagify' );
504 68
505 - // 1.b) on click in a choice, return to pre-checkout step
506 - $modal.on('click.imagify', '.imagify-payment-btn-select-plan', function(){
69 + $( 'body' ).removeClass( 'imagify-modal-is-open' );
70 + } )
71 + // On close button blur, improve accessibility.
72 + .on( 'blur.imagify', '.imagify-modal .close-btn', function() {
73 + var $modal = $( this ).closest( '.imagify-modal' );
507 74
508 - var $_this = $(this),
509 - $offer_line = $_this.closest('.imagify-offer-line'),
510 - datas = $_this.data('offer'),
511 - datas_str = $_this.attr('data-offer'),
512 - is_onetime = ( $_this.closest('.imagify-tab-content').attr('id') === 'imagify-pricing-tab-monthly' ? false : true ),
513 - $target_line = ( is_onetime ? $pre_view.find('.imagify-offer-onetime') : $pre_view.find('.imagify-offer-monthly') ),
514 - period = ( is_onetime ? null : ( ( $_this.closest('.imagify-pricing-table').hasClass('imagify-month-selected') ) ? 'monthly' : 'yearly') ),
515 - price = ( is_onetime ? imagify_get_html_price( datas[ Object.keys( datas )[0] ].price ) : imagify_get_html_price ( datas[ Object.keys( datas )[0] ].prices, period ) ),
516 - imgs = $offer_line.find('.imagify-approx-nb').text(),
517 - offer_size = $offer_line.find('.imagify-offer-size').text(),
518 - monthly_txt = ( ! is_onetime ? '<span class="imagify-price-by">' + $offer_line.find('.imagify-price-by').text() + '</span>' : '' );
519 -
520 - // change views to go back pre-checkout
521 - $plans_view.hide().attr('aria-hidden', 'true');
522 - $pre_view.fadeIn(speedFadeIn).attr('aria-hidden', 'false');
523 -
524 - // change price (+ "/month" if found in monthly plans)
525 - $target_line.find('.imagify-number-block').html( price + monthly_txt )
526 -
527 - // change approx images nb
528 - $target_line.find('.imagify-approx-nb').text( imgs );
529 -
530 - // change offer size name
531 - $target_line.find('.imagify-offer-size').text( offer_size );
532 -
533 - // change datas (json)
534 - $target_line.attr('data-offer', datas_str );
535 -
536 - if ( ! is_onetime ) {
537 - $target_line.find('.imagify-price-add-data').text( $offer_line.find('.imagify-price-add-data').text() );
538 -
539 - // trigger period selected from offer selection view to pre-checkout view
540 - if ( period === 'monthly' ) {
541 - $target_line.find('#imagify-subscription-monthly').trigger('click.imagify');
542 - }
543 - else {
544 - $target_line.find('#imagify-subscription-yearly').trigger('click.imagify');
545 - }
546 - $target_line.find('.imagify-inline-options').find('input:radio:checked').trigger('change.imagify');
75 + if ( $modal.attr( 'aria-hidden' ) === 'false' ) {
76 + $modal.attr( 'tabindex', '0' ).trigger('focus').removeAttr( 'tabindex' );
547 77 }
548 -
549 - return false;
550 - });
551 -
552 -
553 - // 2) when you checkout
554 - $('#imagify-modal-checkout-btn').on('click.imagify', function(){
555 -
556 - var $monthly_offer = $('.imagify-offer-monthly'),
557 - $onetime_offer = $('.imagify-offer-onetime'),
558 - checkout_datas = {},
559 - period_choosen = ( $monthly_offer.hasClass('imagify-year-selected') ? 'year' : 'month' );
560 -
561 - // if user choose a monthly plan
562 - if ( $monthly_offer.hasClass('imagify-offer-selected') ) {
563 -
564 - checkout_datas.monthly = JSON.parse( $monthly_offer.attr('data-offer') );
565 - $('.imagify-cart-list-my-choice').show();
566 -
567 - // price calculation
568 - prices = checkout_datas.monthly[Object.keys(checkout_datas.monthly)[0]].prices;
569 - save_price = Math.round( ( ( prices.monthly - prices.yearly ) * 12 ) * 100 ) / 100;
570 - $('.imagify-nb-save-per-year').text( '$' + save_price );
571 -
572 - } else {
573 - $('.imagify-cart-list-my-choice').hide();
78 + } )
79 + // On click on dropped layer of modal, close modal.
80 + .on( 'click.imagify', '.imagify-modal', function( e ) {
81 + $( e.target ).filter( '.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
82 + } )
83 + // `Esc` key binding, close modal.
84 + .on( 'keydown.imagify', function( e ) {
85 + if ( 27 === e.keyCode && $( '.imagify-modal.modal-is-open' ).length > 0 ) {
86 + e.preventDefault();
87 + // Trigger the event.
88 + $( '.imagify-modal.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
574 89 }
90 + } );
575 91
576 - // if user choose a one time plan
577 - if ( $onetime_offer.hasClass('imagify-offer-selected') ) {
578 - checkout_datas.onetime = JSON.parse( $onetime_offer.attr('data-offer') );
579 - }
580 -
581 - // change views to go to checkout/payment view
582 - $pre_view.hide().attr('aria-hidden', 'true');
583 - $payment_view.fadeIn(speedFadeIn).attr('aria-hidden', 'false');
584 -
585 - // hide "Cancel you removing" blocks
586 - $('.imagify-cart-emptied-item').hide().attr('aria-hidden', 'true');
587 -
588 - // Step 2 active
589 - $('#imagify-pricing-step-2').addClass('active');
590 -
591 - // Car item emptyfied & hidden
592 - $payment_view.find('.imagify-cart-item').hide()
593 - .attr('data-offer', '');
594 -
595 - // Then completion of those items
596 - $.each( checkout_datas, function( index, value ) {
597 -
598 - var $line = $payment_view.find('.imagify-cart-item-' + index ),
599 - offer = value[Object.keys(value)[0]],
600 - $cart = $('.imagify-cart');
601 -
602 - $line.show();
603 -
604 - // product datas
605 - $line.attr('data-offer', JSON.stringify( value ) );
606 -
607 - // product name
608 - $line.find('.imagify-the-product-name').text( offer.name );
609 -
610 - // datas provide
611 - $line.find('.imagify-cart-offer-data').text( offer.dataf );
612 -
613 - // prices
614 - if ( index === 'onetime') {
615 - $line.find('.imagify-number-block').html( imagify_get_html_price( offer.price ) );
616 - } else {
617 - $line.find('.imagify-number-block').find('.imagify-switch-my').html( imagify_get_html_price( offer.prices, period_choosen + 'ly' ) );
618 - }
619 -
620 - // right class on Cart List depending on period selected
621 - $cart.removeClass( 'imagify-month-selected imagify-year-selected' )
622 - .addClass( 'imagify-' + period_choosen + '-selected' );
623 -
624 - // trigger period choosen
625 - if ( period_choosen === 'month' ) {
626 - $cart.find('#imagify-checkout-monthly').trigger('click.imagify');
627 - } else {
628 - $cart.find('#imagify-checkout-yearly').trigger('click.imagify');
629 - }
630 - $cart.find('.imagify-inline-options').find('input:radio:checked').trigger('change.imagify');
631 -
632 - });
633 -
634 - checkout_datas.period = imagify_get_period();
635 -
636 - imagify_iframe_set_src( checkout_datas );
637 - return false;
638 - });
639 -
640 -
641 - // Removing an item
642 - $('.imagify-remove-from-cart').on('click.imagify', function(){
643 - var $_this = $(this),
644 - $line = $_this.closest('.imagify-cart-item'),
645 - is_monthly = $line.hasClass('imagify-cart-item-monthly'),
646 - $other_line = ( is_monthly ? $('.imagify-cart-item-onetime') : $('.imagify-cart-item-monthly') ),
647 - is_empty = $other_line.hasClass('imagify-temporary-removed'),
648 - offer_datas = $line.attr('data-offer'), // string
649 - still_datas = ( is_empty ? null : $other_line.data('offer') ); // object
650 -
651 - $line.hide().attr('aria-hidden', 'true').attr('data-offer', '').addClass('imagify-temporary-removed');
652 - $line.next('.imagify-cart-emptied-item').fadeIn(300).attr('aria-hidden', 'false').attr('data-offer', offer_datas )
653 - .find('.imagify-removed-name').html( $line.find('.imagify-cart-product-name').html() );
654 -
655 - if ( typeof imagify_iframe_set_src === 'function' ) {
656 - if ( still_datas !== null ) {
657 - var datas_to_send = {};
658 - datas_to_send[ ( is_monthly ? 'onetime' : 'monthly' )] = still_datas;
659 - datas_to_send.period = imagify_get_period();
660 - imagify_iframe_set_src( datas_to_send );
661 - }
662 - else {
663 - imagifyAdmin.labels.info('No offers selected');
664 - }
665 - } else {
666 - imagifyAdmin.labels.info('imagify_iframe_set_src seems to be not declared');
667 - }
668 - return false;
669 - });
670 -
671 - // cancel action
672 - $('.imagify-cancel-removing').on('click.imagify', function(){
673 -
674 - var $_this = $(this),
675 - $msg_block = $_this.closest('.imagify-cart-emptied-item'),
676 - $line = $msg_block.prev('.imagify-cart-item'),
677 - is_monthly = $line.hasClass('imagify-cart-item-monthly'),
678 - $other_line = ( is_monthly ? $('.imagify-cart-item-onetime') : $('.imagify-cart-item-monthly') ),
679 - other_empty = $other_line.hasClass('imagify-temporary-removed'),
680 - offer_datas = $msg_block.attr('data-offer'), // string
681 - still_datas = ( other_empty ? null : $other_line.data('offer') ); // object
682 -
683 -
684 - $msg_block.hide().attr('aria-hidden', 'true').attr('data-offer', '')
685 - .prev('.imagify-cart-item').fadeIn(300).attr('aria-hidden', 'true').attr('data-offer', offer_datas ).removeClass('imagify-temporary-removed');
686 -
687 - // if new_datas === {} that is because both offers been cancelled
688 - var new_datas = {};
689 -
690 - new_datas.monthly = ( is_monthly ? JSON.parse( offer_datas ) : still_datas );
691 - new_datas.onetime = ( is_monthly ? still_datas : JSON.parse( offer_datas ) );
692 - new_datas.period = imagify_get_period();
693 -
694 -
695 - if ( typeof imagify_iframe_set_src === 'function' ) {
696 - imagify_iframe_set_src( new_datas );
697 - } else {
698 - imagifyAdmin.labels.info('imagify_iframe_set_src seems to be not declared…');
699 - }
700 -
701 - return false;
702 - });
703 -
704 - // on Yearly/Monthly payment change on checkout...
705 - $('.imagify-cart-list-my-choice').find('input[type="radio"]').on('change.imagify', function(){
706 - imagify_iframe_set_src( $(this).val() );
707 - });
708 -
709 - /**
710 - * Go back to previous step ("Choose Another Plan" links)
711 - */
712 - $('.imagify-back-to-plans').on('click.imagify', function(){
713 - var $_this = $(this),
714 - is_onetime = $_this.closest('.imagify-cart-item').hasClass('imagify-cart-item-onetime');
715 -
716 - if ( is_onetime ) {
717 - $('.imagify-offer-onetime').find('.imagify-choose-another-plan').trigger('click.imagify');
718 - } else {
719 - $('.imagify-offer-monthly').find('.imagify-choose-another-plan').trigger('click.imagify');
720 - }
721 -
722 - return false;
723 - });
724 -
725 - }
726 -
727 - /**
728 - * Tabs
729 - *
730 - * @Markup:
731 - * ul.imagify-tabs
732 - * li.imagify-tab.imagify-current
733 - * a[href="#target"]
734 - * div.imagify-tabs-contents
735 - * div.imagify-tab-content#target
736 - */
737 - if ( $('.imagify-tabs').length ) {
738 -
739 - var $tabs = $('.imagify-tab');
740 -
741 - $tabs.on('click.imagify', function(){
742 -
743 - var $_this = $(this);
744 -
745 - if ( ! $_this.hasClass('imagify-current') ) {
746 - var target = $_this.find('a').attr('href') || '#' + $_this.find('a').attr('aria-controls'),
747 - curr_class = 'imagify-current';
748 -
749 - // show right tab content
750 - $_this.closest('.imagify-tabs').next('.imagify-tabs-contents').find('.imagify-tab-content').hide().attr('aria-hidden', 'true');
751 - $( target ).fadeIn(275).attr('aria-hidden', 'false');
752 -
753 - // change active tabs
754 - $_this.closest('.imagify-tabs').find('.imagify-tab').removeClass( curr_class ).attr('aria-selected', 'false');
755 - $_this.addClass( curr_class ).attr('aria-selected', 'true');
756 - }
757 -
758 - return false;
759 - });
760 -
761 - }
762 -});
92 +} )(jQuery, document, window);