PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.0.2
Ever Compare – Products Compare Plugin for WooCommerce v1.0.2
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / assets / js / frontend.js

frontend.js in Ever Compare – Products Compare Plugin for WooCommerce 1.0.2, at assets/js/frontend.js

103 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ;(function($){
2 "use strict";
3
4 var $body = $('body'),
5 $popup = $('.htcompare-popup');
6
7 // Add product in compare table
8 $body.on('click', 'a.htcompare-btn', function (e) {
9 var $this = $(this),
10 id = $this.data('product_id'),
11 addedText = $this.data('added-text');
12
13 if( evercompare.popup === 'yes' ){
14 e.preventDefault();
15 if ( $this.hasClass('added') ) {
16 $body.find('.htcompare-popup').addClass('open');
17 return true;
18 }
19 }else{
20 if ( $this.hasClass('added') ) return true;
21 }
22
23 e.preventDefault();
24
25 $this.addClass('loading');
26
27 $.ajax({
28 url: evercompare.ajaxurl,
29 data: {
30 action: 'ever_compare_add_to_compare',
31 id: id,
32 },
33 dataType: 'json',
34 method: 'GET',
35 success: function ( response ) {
36 if ( response.table ) {
37 updateCompareData( response );
38 $popup.addClass('open');
39 } else {
40 console.log( 'Something wrong loading compare data' );
41 }
42 },
43 error: function ( data ) {
44 console.log('Something wrong with AJAX response.');
45 },
46 complete: function () {
47 $this.removeClass('loading').addClass('added');
48 $this.html('<span class="htcompare-btn-text">'+addedText+'</span>');
49 },
50 });
51
52 });
53
54 // Remove data from compare table
55 $body.on('click', 'a.htcompare-remove', function (e) {
56 var $table = $('.htcompare-table');
57
58 e.preventDefault();
59 var $this = $(this),
60 id = $this.data('product_id');
61
62 $table.addClass('loading');
63 $this.addClass('loading');
64
65 jQuery.ajax({
66 url: evercompare.ajaxurl,
67 data: {
68 action: 'ever_compare_remove_from_compare',
69 id: id,
70 },
71 dataType: 'json',
72 method: 'GET',
73 success: function (response) {
74 if (response.table) {
75 updateCompareData(response);
76 } else {
77 console.log( 'Something wrong loading compare data' );
78 }
79 },
80 error: function (data) {
81 console.log('Something wrong with AJAX response.');
82 },
83 complete: function () {
84 $table.removeClass('loading');
85 $this.addClass('loading');
86 },
87 });
88
89 });
90
91 // Update table HTML
92 function updateCompareData( data ) {
93 if ( $('.htcompare-table').length > 0 ) {
94 $('.htcompare-table').replaceWith( data.table );
95 }
96 }
97
98 // Close popup
99 $body.on('click','.htcompare-popup-close', function(e){
100 $popup.removeClass('open');
101 });
102
103 })(jQuery);