PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.6.2.6
Products Compare for WooCommerce v3.6.2.6
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / js / products_compare.js
products-compare-for-woocommerce / js Last commit date
admin.js 2 months ago jquery.cookie.js 2 months ago jquery.mousewheel.min.js 2 months ago products_compare.js 2 months ago
products_compare.js
339 lines
1 jQuery(window).on('popstate', function(event) {
2 console.log(event);
3 if ( event.originalEvent.state != null && event.originalEvent.state.BeRocket == 'Compare' ) {
4 location.reload();
5 }
6 });
7 (function ($){
8 $(document).ready( function () {
9 $(document).on( 'click', '.br_compare_button .fa', function ( event ) {
10 $button = $(this).parent();
11 event.preventDefault();
12 event.stopPropagation();
13 var id = $button.data('id');
14 toggle_products_compare(id);
15 load_selected_list();
16 });
17 $(document).on( 'click', '.br_compare_button', function ( event ) {
18 if ( add_products_compare($(this).data('id')) ) {
19 event.preventDefault();
20 load_selected_list();
21 } else {
22 if( $(this).is('.berocket_product_smart_compare') && $('.berocket_compare_box').length == 0 ) {
23 event.preventDefault();
24 load_smart_compare_table();
25 }
26 }
27 });
28 $(document).on( 'click', '.br_remove_compare_product', function ( event ) {
29 event.preventDefault();
30 var $parent = $(this).parents('.berocket_compare_widget');
31 remove_products_compare($(this).data('id'));
32 $('.br_widget_compare_product_'+$(this).data('id')).remove();
33 has_compared_products( $parent.find('ul li').length );
34 if( typeof(br_compare_page) != 'undefined' ) {
35 location.replace(br_compare_page);
36 }
37 });
38 function set_page_to_history() {
39 if( typeof(br_compare_page) != 'undefined' && typeof(history) != 'undefined' ) {
40 var stateParameters = {BeRocket: 'Compare'};
41 history.replaceState(stateParameters, "BeRocket Rules");
42 history.pushState(stateParameters, "BeRocket Rules", br_compare_page);
43 history.pathname = br_compare_page;
44 }
45 }
46 $(document).on( 'click', '.br_remove_compare_product_reload', function ( event ) {
47 event.preventDefault();
48 remove_products_compare($(this).data('id'));
49 if($(this).parents('#br_popup').length > 0) {
50 var $popup_object = $(this).parents('#br_popup').data('br_popup_main');
51 jQuery($popup_object).br_popup().hide_popup();
52 load_selected_list();
53 load_smart_compare_table($popup_object);
54 set_page_to_history();
55 } else {
56 location.replace(br_compare_page);
57 }
58 });
59 $(document).on('click', '.br_remove_all_compare', function(event) {
60 event.preventDefault();
61 $(this).parents('.br_new_compare_block').first().find('.br_remove_compare_product_reload').each(function() {
62 remove_products_compare($(this).data('id'));
63 });
64 if($(this).parents('#br_popup').length > 0) {
65 var $popup_object = $(this).parents('#br_popup').data('br_popup_main');
66 jQuery($popup_object).br_popup().hide_popup();
67 load_selected_list();
68 load_smart_compare_table($popup_object);
69 set_page_to_history();
70 } else {
71 location.replace(br_compare_page);
72 }
73 });
74 function load_selected_list() {
75 if ( $('.berocket_compare_widget').length > 0 ) {
76 compare_products_execute_func( the_compare_products_data.user_func.before_load );
77 jQuery(document).trigger('berocket_compare-before_load');
78 var data = {action: 'br_get_compare_products'};
79 $.post( the_compare_products_data.ajax_url, data, function ( data ) {
80 var $data = $(data).find('.berocket_compare_widget');
81 var $data_text = $(data).find('.berocket_compare_widget');
82 $data_text.find('img').remove();
83 $('.berocket_compare_widget').each( function ( i, o ) {
84 if ( $(o).data('type') == 'text' ) {
85 $(o).html($data_text.html());
86 } else {
87 $(o).html($data.html());
88 }
89 if( $(o).data('fast_compare') ) {
90 $(o).find('.berocket_open_compare').addClass('berocket_open_smart_compare');
91 }
92 });
93 has_compared_products( $data.find('ul li').length );
94 compare_products_execute_func( the_compare_products_data.user_func.after_load );
95 jQuery(document).trigger('berocket_compare-after_load');
96 });
97 }
98 }
99 function has_compared_products( count ) {
100 if ( count > 0 ) {
101 $('.berocket_show_compare_toolbar').show();
102 } else {
103 $('.berocket_compare_widget_toolbar').hide();
104 $('.berocket_show_compare_toolbar').hide();
105 $('.berocket_open_compare').remove();
106 }
107 BeRocket_hide_compare_empty_widget();
108 }
109 $(document).on( 'click', '.berocket_show_compare_toolbar', function ( event ) {
110 event.preventDefault();
111 $('.berocket_compare_widget_toolbar').show();
112 });
113 $(document).on( 'click', '.berocket_hide_compare_toolbar', function ( event ) {
114 event.preventDefault();
115 $('.berocket_compare_widget_toolbar').hide();
116 });
117 $(document).on( 'click', '.berocket_back_full_screen, .berocket_compare_box .berocket_normal_size', function ( event ) {
118 event.preventDefault();
119 $('.berocket_compare_box').removeClass('berocket_full_screen_box');
120 $('.berocket_back_full_screen').remove();
121 $('.berocket_compare_box .berocket_normal_size').remove();
122 setTimeout( berocket_load_compare_table, 100 );
123 });
124 $(document).on('click', '.berocket_open_smart_compare', function(event) {
125 event.preventDefault();
126 load_smart_compare_table();
127 });
128 $('body').append($('.berocket_compare_widget_toolbar_block'));
129 function BeRocket_hide_compare_empty_widget() {
130 $('.berocket_compare_widget_start').each(function() {
131 if( $(this).find('.berocket_compare_widget ul li').length ) {
132 $(this).show();
133 } else {
134 $(this).hide();
135 }
136 });
137 }
138 BeRocket_hide_compare_empty_widget();
139 //FROM COMPARE TABLE FILE
140 if( the_compare_products_data.hide_same_default ) {
141 jQuery(".br_same_attr").hide();
142 }
143 jQuery(document).on('click', '.br_show_compare_dif', function(event) {
144 event.preventDefault();
145 var $parent = $(this).parents('.br_new_compare_block').first();
146 if( $(this).is('.br_hidden_same') ) {
147 $parent.find('.br_same_attr').show();
148 $(this).removeClass('br_hidden_same').text(the_compare_products_data.hide_same);
149 } else {
150 $parent.find('.br_same_attr').hide();
151 $(this).addClass('br_hidden_same').text(the_compare_products_data.show_same);
152 }
153 });
154 $(window).scroll( function () {
155 $('.br_new_compare_block_wrap').each(function() {
156 if(! $(this).find('.br_new_compare_block').is('.br_full_size_popup') && $(this).find('.br_new_compare_block').length > 0 ) {
157 if( jQuery(window).width() > 767 ) {
158 var top = jQuery(window).scrollTop() - $(this).find('.br_new_compare_block .br_top_table').offset().top + parseInt(the_compare_products_data.toppadding);
159 if( jQuery('#wpadminbar').length ) {
160 top += jQuery('#wpadminbar').height();
161 }
162 var max_top = $(this).find('.br_new_compare_block').height() - $(this).find('.br_new_compare_block .br_main_top').height() - parseInt(the_compare_products_data.toppadding);
163 if ( top < 0 ) {
164 top = 0;
165 } else if ( top > max_top ) {
166 top = max_top;
167 }
168 } else {
169 var top = 0;
170 }
171 $(this).find('.br_new_compare_block .br_main_top').css('top', top );
172 }
173 });
174 });
175 berocket_popup_compare_scroll_fix();
176 });
177 })(jQuery);
178 var load_smart_compare_table_interval;
179 function load_smart_compare_table($popup_object) {
180 if( typeof($popup_object) == 'undefined' ) {
181 $popup_object = jQuery(the_compare_products_data.compare_selector);
182 }
183 jQuery('.br_compare_popup').remove();
184 jQuery.post(the_compare_products_data.ajax_url, {action:'br_get_compare_list'}, function(data) {
185 clearInterval(load_smart_compare_table_interval);
186 if( data && jQuery(data).find('.br_compare_popup_block').length ) {
187 jQuery('.br_compare_popup_block, '+the_compare_products_data.compare_selector).html(jQuery(data).find('.br_compare_popup_block').html());
188 if( the_compare_products_data.hide_same_default ) {
189 jQuery('.br_compare_popup_block, '+the_compare_products_data.compare_selector).find(".br_same_attr").hide();
190 }
191 load_smart_compare_table_interval = setInterval(function() {
192 if( ! $popup_object.data('br_popup_data') || ! $popup_object.data('br_popup_data').opened ) {
193 $popup_object.br_popup().open_popup();
194 clearInterval(load_smart_compare_table_interval);
195 }
196 }, 100);
197 } else {
198 jQuery('.br_compare_popup_block, '+the_compare_products_data.compare_selector).html("");
199 jQuery('.br_new_compare_block_wrap').hide();
200 }
201 });
202 }
203 function toggle_products_compare( product ) {
204 var products = set_get_products_compare_cookie();
205 if ( ! products || products.search( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)|(," + product + ",)") ) == -1 ) {
206 add_products_compare( product );
207 return true;
208 } else {
209 remove_products_compare( product );
210 return false;
211 }
212 }
213 function add_products_compare( product ) {
214 var products = set_get_products_compare_cookie();
215 jQuery('.br_product_' + product).addClass('br_compare_added');
216 jQuery('.br_product_' + product).find('span.br_compare_button_text').text(jQuery('.br_product_' + product).find('span.br_compare_button_text').data('added'));
217 if ( ! products || products.search( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)|(," + product + ",)") ) == -1 ) {
218 if ( products !== false && products ) {
219 products = products + ',' + product;
220 } else {
221 products = '' + product;
222 }
223 set_get_products_compare_cookie( products );
224 return true;
225 } else {
226 set_get_products_compare_cookie( products );
227 return false;
228 }
229 }
230 function remove_products_compare( product ) {
231 compare_products_execute_func( the_compare_products_data.user_func.before_remove );
232 jQuery(document).trigger('berocket_compare-before_remove');
233 var products = set_get_products_compare_cookie();
234 if ( products !== false && products ) {
235 products = products.replace( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)"), '' );
236 products = products.replace( new RegExp("," + product + ","), ',' );
237 }
238 jQuery('.br_product_' + product).removeClass('br_compare_added');
239 jQuery('.br_product_' + product).find('span.br_compare_button_text').text(jQuery('.br_product_' + product).find('span.br_compare_button_text').data('not_added'));
240 set_get_products_compare_cookie(products);
241 compare_products_execute_func( the_compare_products_data.user_func.after_remove );
242 jQuery(document).trigger('berocket_compare-after_remove');
243 return products;
244 }
245 function set_get_products_compare_cookie ( value ) {
246 if ( typeof value === "undefined" ) {
247 value = false;
248 }
249 if ( value === false ) {
250 if ( jQuery.cookie( 'br_products_compare' ) ) {
251 return jQuery.cookie( 'br_products_compare' );
252 } else {
253 return false;
254 }
255 } else {
256 /*var path = the_compare_products_data.home_url;
257 path = path.split(document.domain);
258 path = path[1];
259 if ( path == '' ) {
260 path == '/';
261 }*/
262 jQuery.cookie( 'br_products_compare', value, { path: '/', domain: document.domain } );
263 }
264 }
265 function compare_products_execute_func ( func ) {
266 if( the_compare_products_data.user_func != 'undefined'
267 && the_compare_products_data.user_func != null
268 && typeof func != 'undefined'
269 && func.length > 0 ) {
270 try{
271 eval( func );
272 } catch(err){
273 alert('You have some incorrect JavaScript code (Product Compare)');
274 }
275 }
276 }
277 function berocket_popup_compare_scroll_fix() {
278 jQuery('.br_popup_inner:not(.br_compare_scroll_ready), .br_new_compare_block:not(.br_compare_scroll_ready)').each(function() {
279 if( jQuery(this).is('.br_popup_inner') ) {
280 jQuery(this).scroll(function() {
281 var $parent = jQuery(this);
282 if( jQuery(window).width() > 767 ) {
283 var top = jQuery(this).position().top - $parent.find('.br_top_table').position().top;
284 if ( top < 0 ) {
285 top = 0;
286 }
287 } else {
288 var top = 0;
289 }
290 $parent.find('.br_main_top').css('top', top );
291 });
292 }
293 jQuery(this).find('.br_main_top').mousewheel( function( event ) {
294 var $parent = jQuery(this).parents('.br_popup_inner, .br_new_compare_block').first();
295 event.preventDefault();
296 event.stopPropagation();
297 var scroll = $parent.find('.br_main_top').scrollLeft() - ( ( event.deltaY + event.deltaX ) * event.deltaFactor );
298 $parent.find('.br_main_top').scrollLeft(scroll);
299 $parent.find('.br_main_top').scroll();
300 });
301 jQuery(this).find('.br_main_top, .br_right_table').scroll( function() {
302 var $parent = jQuery(this).parents('.br_popup_inner, .br_new_compare_block').first();
303 var table_hidden_scroll = $parent.find('.br_new_compare_block').data('table_hidden_scroll');
304 var table_scroll = $parent.find('.br_new_compare_block').data('table_scroll');
305 var left_initial = jQuery(this).scrollLeft();
306 var set_size = 0;
307 if( jQuery(this).is('.br_main_top') ) {
308 var check_scroll_table = table_hidden_scroll;
309 set_size = jQuery(this).parents('.br_new_compare_block').find('.br_right_table table').width();
310 } else {
311 var check_scroll_table = table_scroll;
312 set_size = jQuery(this).parents('.br_new_compare_block').find('.br_main_top table').width();
313 }
314 if( check_scroll_table != left_initial ) {
315 var this_size = jQuery(this).find('table').width();
316 left = set_size / this_size * left_initial;
317 if( left < 0 ) {
318 left = left - 0.5;
319 } else {
320 left = left + 0.5;
321 }
322 left = parseInt(left);
323 if( jQuery(this).is('.br_main_top') ) {
324 table_hidden_scroll = left_initial;
325 table_scroll = left;
326 jQuery(this).parents('.br_new_compare_block').find('.br_right_table').scrollLeft(left);
327 } else {
328 table_hidden_scroll = left;
329 table_scroll = left_initial;
330 jQuery(this).parents('.br_new_compare_block').find('.br_main_top').scrollLeft(left);
331 }
332 }
333 $parent.find('.br_new_compare_block').data('table_hidden_scroll', table_hidden_scroll);
334 $parent.find('.br_new_compare_block').data('table_scroll', table_scroll);
335 });
336 jQuery(this).addClass('br_compare_scroll_ready');
337 });
338 }
339