PageSourceSearch

https://myrightfood.com/wp-content/plugins/woozone-15.2/lib/frontend/js/frontend.js

js myrightfood.com collected 2026-10-02 16:03:17 UTC 40,362 bytes, 1,443 lines download raw bytes

1/*
2	Document   :  frontend
3	Created on :  August, 2013
4	Author     :  Andrei Dinca, AA-Team http://codecanyon.net/user/AA-Team
5*/
6
7// Initialization and events code for the app
8WooZone = (function ($) {
9	"use strict";
10	
11	var ajaxurl			= woozone_vars.ajax_url,
12		lang			= woozone_vars.lang;
13	var current_aff		= {};
14	
15	// init function, autoload
16	(function init() {
17		
18		// load the triggers
19		$(document).ready(function(){
20			//console.log( 'WooZone frontend script is loaded!' );
21
22			var $current_aff = $('#WooZone_current_aff');
23			if ( $current_aff.length > 0 ) {
24				current_aff = $current_aff.data('current_aff');
25			}
26
27			triggers();
28		});
29
30		// synchronization on frontend
31		var syncfront = syncfront_func();
32		syncfront.init();
33		
34	})();
35
36
37	//====================================================
38	//== :: TRIGGERS
39	function triggers() {
40
41		checkout_email();
42
43		load_amazon_reviews();
44
45		fix_images();
46	};
47
48
49	//====================================================
50	//== :: OTHERS
51
52	//:: LOAD AMAZON REVIEWS
53	function load_amazon_reviews() {
54		var wrapper = $('body #amzaff-amazon-review-tab');
55		wrapper.each(function(){
56			var data = {
57				action			: 'WooZone_frontend',
58				sub_action		: 'load_amazon_reviews',
59				prodid 			: wrapper.data('prodid')
60			};
61			//if (DEBUG) console.log( data );
62				
63			//loading( 'show', lang.saving );
64
65			$.post(ajaxurl, data, function(response) {
66				if ( misc.hasOwnProperty(response, 'status') ) {
67					if ( 'valid' == response.status ) {
68						wrapper.html( response.html );
69					}
70				}
71				//loading( 'close' );
72			}, 'json')
73			.fail(function() {})
74			.done(function() {})
75			.always(function() {});
76		});
77	}
78
79	//:: FIX IMAGES
80	function fix_images() {
81		// fix images on https/ssl
82		setInterval( function() {
83			var $imgFound = $("img[src*='ssl-images']");
84			
85			$imgFound.each(function(){
86				var that = $(this),
87					src = that.attr('src');
88				
89				if( src.indexOf('//') == 0 ){
90					if( src.indexOf("ssl-images") != false ){
91						that.attr('src', "https:" + src );
92						that.attr('srcset', "https:" + that.attr('srcset'));
93					}
94				}
95			});
96		}, 1000 );
97	}
98
99	//:: custom user email collecting before redirect to amazon
100	function checkout_email() {
101		if ( ! $('.cart_totals').length ) return false;
102
103		var woozone_email_wrapper 		= $('.woozone_email_wrapper'),
104			  woozone_checkout_email 		= $('#woozone_checkout_email'),
105			  woozone_email_mandatory 	= $('#woozone_checkout_email_required');
106
107		// checkout email is active
108  
109		if( woozone_checkout_email.length > 0 ) {
110			woozone_email_wrapper.insertBefore( $('.wc-proceed-to-checkout') );
111
112			var checkout_btn = $('.wc-proceed-to-checkout .checkout-button'),
113				  checkout_link = checkout_btn.attr('href');
114 
115			if( woozone_email_mandatory.length > 0 && woozone_email_mandatory.val() == '1' ) {
116				checkout_btn.addClass('disabled');
117				checkout_btn.attr('href', '#amz_checkout_email');
118				//console.log( checkout_btn );
119				//alert('E-mail field is mandatory!');
120			}
121
122			woozone_email_wrapper.on('keyup', woozone_checkout_email, function(e) {
123				var woozone_validate_email = /([A-Z0-9a-z_-][^@])+?@[^$#<>?]+?\.[\w]{2,4}/.test(woozone_checkout_email.val());
124						 
125				 if( woozone_validate_email ) {
126
127					if( woozone_email_mandatory.length > 0 && woozone_email_mandatory.val() == '1' ) {
128						checkout_btn.removeClass('disabled');
129						checkout_btn.attr('href', checkout_link);
130					 }
131
132					 woozone_checkout_email.css({'border': '1px solid #d1d1d1'});
133
134				 } else {
135
136					if( woozone_email_mandatory.length > 0 && woozone_email_mandatory.val() == '1' ) {
137						checkout_btn.addClass('disabled');
138						checkout_btn.attr('href', '#amz_checkout_email');
139					}
140
141					woozone_checkout_email.css({'border': '1px solid red'});
142
143				}
144			});
145		}
146
147		$('.wc-proceed-to-checkout').on('click', '.checkout-button', function(e) {
148			// checkout email is active
149			if ( woozone_checkout_email.length > 0 ) {
150				if( woozone_email_mandatory.length > 0 && woozone_email_mandatory.val() == '1' ) {
151					if ( $(this).hasClass('disabled') ) {
152						e.preventDefault();
153						return false;
154					}
155				}
156
157				if ( ! country_shop_checkout.allow_checkout() ) {
158					//console.log( 'checkout: You must check or cancel all amazon shops!' );
159					country_shop_checkout.set_msg_html( false, lang.amzcart_cancel_msg );
160					return false;
161				}
162				else {
163					//console.log( 'checkout: all good.' );
164					country_shop_checkout.set_msg_html( true, lang.amzcart_checkout_msg );
165				}
166				//return false; // uncomment to debug
167
168				if ( woozone_checkout_email.val() != '' ) {
169					jQuery.post(woozone_vars.ajax_url, 
170					{
171						'action': 'WooZone_before_user_checkout',
172						'_nonce': $('#woozone_checkout_email_nonce').val(),
173						'email': woozone_checkout_email.val()
174					}, function(data, textStatus) {
175						if ( (textStatus === 'success') || (textStatus === 'email_exists') ) {
176							//window.location.href = woozone_vars.checkout_url;
177							$(this).prop('href', woozone_vars.checkout_url); // to be sure it does the action!
178						} else {
179							alert( textStatus );
180						}
181					});
182				}
183			}
184			// checkout email is NOT active
185			else {
186				if ( ! country_shop_checkout.allow_checkout() ) {
187					//console.log( 'checkout: You must check or cancel all amazon shops!' );
188					country_shop_checkout.set_msg_html( false, lang.amzcart_cancel_msg );
189					return false;
190				}
191				else {
192					//console.log( 'checkout: all good.' );
193					country_shop_checkout.set_msg_html( true, lang.amzcart_checkout_msg );
194				}
195				//return false; // uncomment to debug
196				
197				// update feb 2017
198				// no need to do anything, as the current button action will go to checkout and do the reload itself
199				$(this).prop('href', woozone_vars.checkout_url); // to be sure it does the action!
200
201				// dageorge: i've commented this as I don't know why an ajax request is needed when email checkout is not active! (feedback from a client)
202				//jQuery.post(woozone_vars.ajax_url, 
203				//{
204				//	'action': 'WooZone_before_user_checkout',
205				//}, function(data, textStatus) {
206				//	if ( (textStatus === 'success') ) {
207				//		window.location.href = woozone_vars.checkout_url;
208				//	}
209				//});
210				
211			}
212		});
213	};
214	
215	//:: open popup
216	function popup(url, title, params) {
217		//url = 'http://www.amazon' + current_aff['user_country']['website'] + url;
218		window.open(url, title, params);
219	};
220
221
222	//====================================================
223	//== :: PRODUCT COUNTRY AVAILABILITY
224	var product_country_check = (function() {
225		
226		var DISABLED				= false; // disable this module!
227		var DEBUG					= false;
228		var maincontainer			= null,
229			mainloader				= null,
230			product_data			= {},
231			current_country			= {},
232			available_countries 	= [],
233			main_aff_id				= '',
234			aff_ids					= [],
235			cc_template 			= null,
236			us_li 					= null,
237			verify_interval			= 300, // verify requests: interval in miliseconds
238			verify_max_steps		= 15, // verify requests: maximum number of steps
239			updated_countries = false;
240			  
241
242		// Test!
243		function __() { console.log('__ method'); };
244		
245		// get public vars
246		function get_vars() {
247			return $.extend( {}, {
248			} );
249		};
250		
251		// init function, autoload
252		(function init() {
253			
254			if ( DISABLED ) return false;
255
256			// load the triggers
257			$(document).ready(function(){
258				maincontainer = $(".WooZone-country-check:first");
259				mainloader	  = maincontainer.find('.WooZone-country-loader');
260				//console.log( 'box country maincontainer', maincontainer );
261
262				// main box
263				build_main_box();
264
265				// small box on minicart
266				build_box_minicart();
267				
268				triggers();
269			});
270		})();
271		
272		// triggers
273		function triggers() {
274			maincontainer.on('click', 'li .WooZone-cc_checkbox input[type="radio"]', function (e) {
275				if (DEBUG) console.log( 'clicked', $(this) );
276				//save_countries();
277				save_product_country( $(this).parents('li:first').data('country') );
278			});
279		};
280		
281		function build_box_minicart() {
282			var newel 	  		= null,
283				  tpl				= $('#WooZone-cc-small-template'),
284				  minicart		= $('div.kd_small-cart .cart-details ul.kd_small_cart_items'),
285				  //minicart		= $('div.widget_shopping_cart_content .cart-details ul.kd_small_cart_items'),
286				  is_kingdom = minicart.length; // theme: kingdom
287
288			var cached = $('.WooZone-cc-small-cached').html();
289			//cached = JSON.stringify(cached);
290			cached = typeof cached != 'undefined'
291				? JSON && JSON.parse(cached) || $.parseJSON(cached) : cached;
292			if (DEBUG) console.log( 'cached', cached );
293
294			if ( ! tpl.length ) return false;
295			if ( ! is_kingdom || ! cached.length ) return false;
296 
297			$.each(cached, function(index, value) {
298				//console.log( index, value );
299				var current = minicart.find('li').filter(function(i) {
300					return value['cart_item_key'] == $(this).data('prodid');
301				});
302 
303				var __ = $( tpl.html() ).clone();
304				__.find(".WooZone-cc_domain").addClass( value.product_country.replace(".", "-") ).prop('title', value.country_name);
305				__.find(".WooZone-cc_status").addClass( value.country_status_css ).prop('title', value.country_status_text);
306
307				//console.log( current.find('.kd_cart_item-details'), __ ); 
308				current.find('.kd_cart_item-details').append( __ );
309			});
310		};
311
312		function build_main_box( pms ) {
313			var pms = pms || {};
314			var do_position = misc.hasOwnProperty(pms, 'do_position') ? pms.do_position : false;
315
316			if ( ! maincontainer.length ) {
317				if (DEBUG) console.log( '!!! ERROR: main box container not found!', maincontainer );
318				return false;
319			}
320
321			var _product_data = maincontainer.find('.WooZone-product-data').html();
322
323			console.log( _product_data );
324			//_product_data = JSON.stringify(_product_data);
325			_product_data = typeof _product_data != 'undefined'
326				? JSON && JSON.parse(_product_data) || $.parseJSON(_product_data) : _product_data;
327
328			// var product_pms = {
329			// 	'id'					: maincontainer.data('prodid'),
330			// 	'asin'				: maincontainer.data('asin'),
331			// 	'country'			: maincontainer.data('prodcountry'),
332			// 	'boxpos'			: maincontainer.data('boxpos'),
333			// 	'do_update'		: maincontainer.data('do_update')
334			// };
335			var product_pms = {
336				'id'					: _product_data.prodid,
337				'asin'				: _product_data.asin,
338				'country'			: _product_data.prodcountry,
339				'boxpos'			: _product_data.boxpos,
340				'do_update'		: _product_data.do_update
341			};
342			setTimeout( function() {
343				loading( 'show', lang.loading );
344				maincontainer.show();
345
346				if (do_position) {
347					position_box( product_pms );
348				}
349
350				var _update = function() {
351					if (updated_countries) {
352						if (DEBUG) console.log( 'countries: already updated!' );
353						return true;
354					}
355					if (product_data['do_update']) {
356						if (DEBUG) console.log( 'countries: updating...' );
357						//update_countries();
358						return true;
359					}
360					if (DEBUG) console.log( 'countries: no need to update!' );
361				}
362
363				set_product_data( product_pms );
364				build_countries_list();
365				if (DEBUG) console.log( product_data, available_countries );
366
367				load_template();
368				//make_requests();
369				build_countries_elements( _update );
370
371			}, 0);
372		}
373
374		// position product box
375		function position_box( pms ) {
376			var newel 	  		= null,
377				is_bravo = $('body.bravostore-body div.product#product-' + pms.id + ' form.cart').length, // theme: kingdom
378				is_kingdom = $('div.product#product-' + pms.id + ' > div.row:first .kd_description').length; // theme: kingdom
379
380			if ( 'before_add_to_cart' == pms.boxpos ) {
381				// theme: kingdom
382				if ( is_kingdom ) {
383					newel = $('div.product#product-' + pms.id + ' > div.row:first .kd_description .cart');
384				}
385				
386				if ( is_bravo ) {
387					newel = $('div.product#product-' + pms.id + ' form.cart');
388				}
389				
390				maincontainer.insertBefore( newel ).show();
391				
392			}
393			else if ( 'before_title_and_thumb' == pms.boxpos ) {
394				newel = $('div.product#product-' + pms.id);
395				if ( newel.length )
396					maincontainer.prependTo( newel ).show();
397				else {
398					// theme: kingdom
399					if ( is_kingdom ) {
400						newel = $('div.product#product-' + pms.id + ' > div.row:first');
401						maincontainer.insertBefore( newel ).show();
402					}
403				}
404			}
405			else if ( 'before_woocommerce_tabs' == pms.boxpos ) {
406				newel = $('div.product#product-' + pms.id + ' div.woocommerce-tabs.wc-tabs-wrapper');
407				if ( newel.length )
408					maincontainer.insertBefore( newel ).addClass('WooZone-boxpos-before_woocommerce_tabs').show();
409				else {
410					// theme: kingdom
411					if ( is_kingdom ) {
412						newel = $('div.product#product-' + pms.id + ' > div.row:first');
413						maincontainer.insertAfter( newel ).show();
414					}
415				}
416			}
417		};
418		
419		// add country to countries list
420		function add_country( new_country, where ) {
421			var where = where || 'available';
422			
423			if ( 'available' == where ) {
424				available_countries.push( new_country );
425			}
426		};
427	
428		// per country template - ul.li (to build the final box with all available countries)
429		function load_template() {
430
431			cc_template = maincontainer.find("#WooZone-cc-template").html();
432		};
433	
434		// set product data
435		function set_product_data( pms ) {
436
437			product_data = pms;
438		};
439
440		// build countries list
441		function build_countries_list() {
442			available_countries 	= [];
443
444			// aff ids json parse
445			var cached_aff_ids = maincontainer.find('.WooZone-country-affid').html();
446			//cached_aff_ids = JSON.stringify(cached_aff_ids);
447			cached_aff_ids = typeof cached_aff_ids != 'undefined'
448				? JSON && JSON.parse(cached_aff_ids) || $.parseJSON(cached_aff_ids) : cached_aff_ids;
449			//if (DEBUG) console.log( cached_aff_ids );
450			if ( cached_aff_ids && misc.hasOwnProperty(cached_aff_ids, 'main_aff_id') )
451				main_aff_id = cached_aff_ids.main_aff_id;
452			if ( cached_aff_ids && misc.hasOwnProperty(cached_aff_ids, 'aff_ids') )
453				aff_ids = cached_aff_ids.aff_ids;
454
455			// countries json parse
456			var cached_countries = maincontainer.find('.WooZone-country-cached').html();
457			//cached_countries = JSON.stringify(cached_countries);
458			cached_countries = typeof cached_countries != 'undefined'
459				? JSON && JSON.parse(cached_countries) || $.parseJSON(cached_countries) : cached_countries;
460			//if (DEBUG) console.log( cached_countries );
461			
462			$.each( cached_countries, function( index, value ){
463				var __ = {
464					'domain'		: value.domain,
465					'name'			: value.name
466				};
467				if ( misc.hasOwnProperty( value, 'available' ) ) {
468					__['available'] = value.available;
469				}
470				add_country( __ );
471			});
472			return false;
473		};
474
475		function build_countries_elements( callback ) {
476
477			var cc = 0;
478			$.each( available_countries, function( key, value ) {
479				//if ( cc >= 10 ) { return false; }
480				var __ = $(cc_template).clone();
481
482				__.data('country', value.domain);
483				__.find(".WooZone-cc_domain").addClass( value.domain.replace(".", "-") ).prop('title', value.name);
484				__.find(".WooZone-cc_name > a").text( value.name ).attr('href', build_product_link( value.domain, product_data['asin'], true ));
485				
486				var _countryflag_aslink = __.find(".WooZone-cc_domain > a");
487				if ( _countryflag_aslink.length ) { // add link to country flag
488					_countryflag_aslink.attr('href', build_product_link( value.domain, product_data['asin'], true ));
489				}
490				
491				// default country
492				if ( value.domain == product_data['country'] ) {
493					__.find('.WooZone-cc_checkbox input[type=radio]').prop('checked', true);
494					current_country['elm'] = __.find('.WooZone-cc_checkbox input[type=radio]');
495					current_country['country'] = value.domain;
496				}
497
498				maincontainer.append( __ );
499				//console.log( value ); return true;
500
501				// cached
502				if ( misc.hasOwnProperty( value, 'available' ) ) {
503					add_country_status_html( __, value.available );
504				}
505
506				cc++;
507
508			});
509			
510			setTimeout( function() {
511				loading( 'close' );
512				if ( $.isFunction( callback ) ) {
513					callback();
514				}
515			}, 0);
516		};
517
518		/*
519		function async_product_exist( data ) {
520			console.log( 'data', data );
521			console.log( 'data.NumRecords', data.NumRecords );
522			var __ = data.NumRecords == 0 ? 0 : 1;
523			add_country_status_html( us_li, __ );
524			add_country_status( 'com', __ );
525		}
526		
527		// product exists on amazon shops
528		function product_exist( elm, domain ) {
529
530			if ( domain === 'com' ) {
531				us_li = elm;
532
533				//console.log( product_data );
534
535				// search api url 
536				var search_api_url = 'https://ws-na.amazon-adsystem.com/widgets/q?TemplateId=PubStudio&ServiceVersion=20070822&MarketPlace=US&Operation=ItemSearch&InstanceId=5affe5b46c317&dataType=jsonp&Keywords=' + ( product_data['asin'] ) + '&SearchIndex=All&multipageStart=0&multipageCount=9&callback=check_product_asin&_=1526719917078';
537				console.log('search_api_url', search_api_url); return false;
538
539				$.ajax({
540				    url: search_api_url,
541				    jsonp: "check_product_asin",
542				    dataType: "jsonp"
543				})
544				.fail(function() {})
545				.done(function() {})
546				.always(function() {});
547			}
548			else {
549				var jqxhr = $.ajax({
550					crossDomain: true,
551					type:"GET",
552					processData: false,
553					contentType: "application/json; charset=utf-8",
554					async: true,
555					converters: {
556						"* text": window.String,
557						"text html": true,
558						"text json": true,
559						"text xml": jQuery.parseXML
560					},
561					url: build_product_link( domain, product_data['asin'] ),
562					data: {},
563					dataType: "jsonp",
564					jsonp: false,
565					complete: function (XMLHttpRequest, textStatus) {
566						if (DEBUG) console.log( 'product_exist function', XMLHttpRequest, textStatus );
567						if ( 404 == XMLHttpRequest.status ) {
568							add_country_status_html( elm, 0 );
569							add_country_status( domain, 0 );
570						} else {
571							add_country_status_html( elm, 1 );
572							add_country_status( domain, 1 );
573						}
574					}
575				})
576			}
577		};
578
579		// make requests to amazon shops
580		function make_requests() {
581			var pending = 0;
582
583			$.each( available_countries, function( key, value ) {
584				var __ = $(cc_template).clone();
585
586				__.data('country', value.domain);
587				__.find(".WooZone-cc_domain").addClass( value.domain.replace(".", "-") ).prop('title', value.name);
588				__.find(".WooZone-cc_name > a").text( value.name ).attr('href', build_product_link( value.domain, product_data['asin'], true ));
589				
590				var _countryflag_aslink = __.find(".WooZone-cc_domain > a");
591				if ( _countryflag_aslink.length ) { // add link to country flag
592					_countryflag_aslink.attr('href', build_product_link( value.domain, product_data['asin'], true ));
593				}
594				
595				// default country
596				if ( value.domain == product_data['country'] ) {
597					__.find('.WooZone-cc_checkbox input[type=radio]').prop('checked', true);
598					current_country['elm'] = __.find('.WooZone-cc_checkbox input[type=radio]');
599					current_country['country'] = value.domain;
600				}
601
602				maincontainer.append( __ );
603
604				//console.log( value ); return true;
605
606				// cached
607				if ( misc.hasOwnProperty( value, 'available' ) ) {
608					add_country_status_html( __, value.available );
609				}
610				else {
611					pending++;
612					product_exist( __, value.domain );					
613				}
614			} );
615
616			// verify all product amazon country verify requests are finished
617			if ( pending ) {
618				verify_requests();
619			}
620		};
621		
622		// verify status of requests to amazon shops
623		function verify_requests() {
624			var timer 		= null,
625				  contor		= 0;
626
627			function _verify() {
628				var pending = 0,
629					  is_done = contor >= verify_max_steps;
630
631				$.each( available_countries, function( key, value ) {
632					if ( ! misc.hasOwnProperty( value, 'available' ) )
633						pending++;
634				} );
635				//if (DEBUG) console.log( contor, pending );
636
637				if ( ! pending || is_done ) {
638					clearTimeout( timer );
639					timer = null;
640
641					if ( pending && is_done ) {
642						$.each( available_countries, function( key, value ) {
643							if ( ! misc.hasOwnProperty( value, 'available' ) ) {
644								var $current = maincontainer.find('li').filter(function(i) {
645									return $(this).data('country') == value.domain;
646								});
647
648								add_country_status_html( $current, 0 );
649								add_country_status( value.domain, 0 );
650							}
651						} );
652					}
653
654					save_countries();
655
656					return false;
657				}
658
659				contor++;
660				
661				timer = setTimeout( function() {
662					_verify();
663				}, verify_interval );
664			};
665
666			timer = setTimeout( function() {
667				_verify();
668			}, verify_interval );
669		};
670
671		// add country status: available or not
672		function add_country_status( country, status ) {
673			var index = get_available_country_index( country );
674			if ( index <= -1 ) return false;
675			available_countries[ index ]['available'] = status;
676			//console.log( country, index, status, available_countries );
677			return true;
678		};
679		
680		// get available country index from array of 'available_countries' based on country domain
681		function get_available_country_index( country ) {
682			var index = -1;
683			$.each( available_countries, function( key, value ) {
684				if ( country == value.domain ) {
685					index = key;
686					return false;
687				}
688			} );
689			return index;
690		};
691
692		// save countries per product
693		function save_countries() {
694			var countries = JSON.stringify( available_countries );
695			var data = {
696				action					: 'WooZone_frontend',
697				sub_action			: 'save_countries',
698				product_id			: product_data['id'],
699				product_country	: current_country['country'],
700				countries				: countries
701			};
702			if (DEBUG) console.log( data );
703			
704			loading( 'show', lang.saving );
705			$.post(ajaxurl, data, function(response) {
706
707				if ( misc.hasOwnProperty(response, 'status') ) {}
708				loading( 'close' );
709			}, 'json')
710			.fail(function() {})
711			.done(function() {})
712			.always(function() {});
713		};
714		*/
715
716		function update_countries() {
717			var countries = JSON.stringify( available_countries );
718			var data = {
719				action					: 'WooZone_frontend',
720				sub_action			: 'update_countries',
721				product_id			: product_data['id'],
722				asin 						: product_data['asin'],
723				product_country	: current_country['country'],
724			};
725			if (DEBUG) console.log( data );
726			
727			loading( 'show', lang.updating );
728			$.post(ajaxurl, data, function(response) {
729
730				if ( misc.hasOwnProperty(response, 'status') ) {}
731				if (DEBUG) console.log( 'countries: ajax update done!' );
732				//if (DEBUG) console.log( response.html );
733				loading( 'close' );
734				maincontainer.html( response.html );
735				mainloader = maincontainer.find('.WooZone-country-loader');
736				build_main_box({ do_position: false });
737
738			}, 'json')
739			.fail(function() {})
740			.done(function() {})
741			.always(function() { updated_countries = true; });
742		};
743
744		// save countries per product
745		function save_product_country( country ) {
746			var data = {
747				action					: 'WooZone_frontend',
748				sub_action			: 'save_product_country',
749				product_id				: product_data['id'],
750				product_country	: country || current_country['country']
751			};
752			if (DEBUG) console.log( data );
753			
754			loading( 'show', lang.saving );
755			$.post(ajaxurl, data, function(response) {
756
757				if ( misc.hasOwnProperty(response, 'status') ) {}
758				loading( 'close' );
759			}, 'json')
760			.fail(function() {})
761			.done(function() {})
762			.always(function() {});
763		};
764
765		function add_country_status_html( elm, status ) {
766			//console.log( elm, status );
767			if ( status ) {
768				if (DEBUG) console.log( elm.data('country') , "product valid" );
769				elm.find(".WooZone-cc-status").html( "<span class='WooZone-status-available'>" + lang.available_yes + "</span" );
770			} else {
771				if (DEBUG) console.log( elm.data('country') , "product not found" );
772				elm.find(".WooZone-cc-status").html( "<span class='WooZone-status-unavailable'>" + lang.available_no + "</span" );
773			}
774		};
775
776		// build product link for amazon country shop
777		function build_product_link( domain, asin, add_tag ) {
778			var addtag 	= add_tag || false,
779				  link 			=  "https://www.amazon." + ( domain ) + "/dp/" + asin;
780			
781			if ( addtag )
782				link += '/?tag=' + get_aff_id( domain );
783			//console.log( domain, asin, link );
784			return link;
785		};
786		
787		function get_aff_id( country ) {
788			var aff_id = main_aff_id;
789
790			$.each(aff_ids, function( index, value ) {
791				if ( value.country == country ) {
792					aff_id = value.aff_id;
793					return false;
794				}
795			});
796			return aff_id;
797		};
798		
799		// Loading
800		function loading( status, msg ) {
801			var msg = msg || '';
802
803			if ( '' == msg && 'show' == status )
804				msg = lang.loading;
805
806			if ( '' != msg )
807				mainloader.find('.WooZone-country-loader-text').html( msg );
808
809			if ( 'show' == status )
810				mainloader.fadeIn('fast');
811			else
812				mainloader.fadeOut('fast');
813		};
814
815		// external usage
816		return {
817			// attributes
818			'v'               : get_vars,
819			
820			// methods
821			'__'              : __
822			//,'add_country'			: add_country
823			//,'make_requests'		: make_requests
824			//,'set_product_data'	: set_product_data
825			//,'async_product_exist': async_product_exist
826		};
827	})();
828	
829	
830	//====================================================
831	//== :: AMAZON SHOPS CHECKOUT ON CART PAGE
832	var country_shop_checkout = (function() {
833		
834		var DISABLED				= false; // disable this module!
835		var DEBUG					= false;
836		var maincontainer			= null,
837			shops					= [],
838			shops_status			= {
839				'success'		: [],
840				'cancel'		: []
841			};
842			  
843
844		// Test!
845		function __() { console.log('__ method'); };
846		
847		// get public vars
848		function get_vars() {
849			return $.extend( {}, {
850			} );
851		};
852		
853		// init function, autoload
854		(function init() {
855			
856			if ( DISABLED ) return false;
857
858			// load the triggers
859			$(document).ready(function(){
860				maincontainer = $(".WooZone-cart-checkout");
861
862				// main box
863				if ( maincontainer.length ) {
864					maincontainer.find('ul li').each(function(index, value) {
865						var $this 		= $(this),
866							  country	= $this.data('domain');
867
868						shops.push( country );
869					});
870					if (DEBUG) console.log( shops ); 	
871				}
872
873				triggers();
874			});
875		})();
876		
877		// triggers
878		function triggers() {
879			// checkout form
880			maincontainer.on('submit', 'li .WooZone-cc_checkout form', function (e) {
881				e.preventDefault();
882				if (DEBUG) console.log( 'form to submit!' );
883				
884				var form 			= this,
885					  $form			= $(form),
886					  $li 				= $form.parents('li:first'),
887					  country 		= $li.data('domain');
888
889				//console.log( form, $form );
890				if ( $.inArray( country, shops_status.success) <= -1 && $.inArray( country, shops_status.cancel) <= -1 )
891					shops_status.success.push( country );
892				//console.log( shops_status );
893				set_status_html( $li, 1 );
894
895				form.submit();
896
897				return true;
898			});
899
900			// cancel
901			maincontainer.on('click', 'li .WooZone-cc_checkout input[type="button"].cancel', function (e) {
902				e.preventDefault();
903				if (DEBUG) console.log( 'form canceled!' );
904				
905				var $form 		= $(this).parents('form:first'),
906					  $li 				= $form.parents('li:first'),
907					  country 		= $li.data('domain');
908 
909				//console.log( $form );
910				if ( $.inArray( country, shops_status.success) <= -1 && $.inArray( country, shops_status.cancel) <= -1 )
911					shops_status.cancel.push( country );
912				//console.log( shops_status );
913				set_status_html( $li, 0 );
914
915				return true;
916			});
917		};
918		
919		function allow_checkout() {
920			var __ = [].concat( shops_status.success, shops_status.cancel );
921			if (DEBUG) console.log( __, __.length == shops.length );
922			return __.length == shops.length;
923		};
924		
925		function set_status_html( elm, status ) {
926			var text 			= status ? lang.amzcart_checkout : lang.amzcart_cancel,
927				  css_class 	= status ? 'success' : 'cancel';
928			elm.find('.WooZone-cc_status').removeClass('success cancel').addClass( css_class ).text( text );
929		};
930		
931		function set_msg_html( status, text ) {
932			var elm 			= maincontainer.find('.WooZone-cart-msg'),
933				  css_class 	= status ? 'success' : 'cancel';
934			//elm.prepend( $('<div />').removeClass('success cancel').addClass( css_class ).text( text ) );
935			var __ = $('<div />').removeClass('success cancel').addClass( css_class ).text( text );
936			elm.html( __ );
937		};
938		
939		// external usage
940		return {
941			// attributes
942			'v'                     			: get_vars,
943			
944			// methods
945			'__'                    			: __,
946			'allow_checkout'			: allow_checkout,
947			'set_msg_html'				: set_msg_html
948		};
949	})();
950
951
952	//====================================================
953	//== :: CROSS SELL BOX
954	var cross_sell_box = (function() {
955		
956		var DISABLED				= false; // disable this module!
957		var DEBUG					= false;
958		var maincontainer			= null,
959			mainloader				= null,
960			multiple_asins 			= [];
961			  
962
963		// Test!
964		function __() { console.log('__ method'); };
965		
966		// get public vars
967		function get_vars() {
968			return $.extend( {}, {
969			} );
970		};
971		
972		// init function, autoload
973		(function init() {
974			
975			if ( DISABLED ) return false;
976
977			// load the triggers
978			$(document).ready(function(){
979				maincontainer = $("body");
980				mainloader	  = maincontainer.find('.WooZone-cross-sell-loader');
981
982				triggers();
983
984				if ( maincontainer.find('.main-cross-sell').length ) {
985					load_box();
986				}
987			});
988		})();
989		
990		// load box
991		function load_box() {
992			var box 	= maincontainer.find('.main-cross-sell'),
993				  asin	= maincontainer.find('.main-cross-sell').data('asin'),
994				  boxd 	= maincontainer.find('#WooZone-cross-sell-debug');
995
996			var data = {
997				action					: 'WooZone_frontend',
998				sub_action			: 'load_cross_sell',
999				asin						: asin
1000			};
1001			if (DEBUG) console.log( data );
1002
1003			if ( boxd.length ) {
1004				boxd.html( 'Loading Ajax : make amazon request to retrieve products ...' ); boxd.show();
1005			}
1006
1007			loading( 'show', lang.load_cross_sell_box );
1008
1009			$.post(ajaxurl, data, function(response) {
1010
1011				if ( misc.hasOwnProperty(response, 'status') ) {
1012					box.html( response.html ).css({
1013						'min-height' : 'initial'
1014					});
1015					if ( boxd.length ) {
1016						boxd.html( response.debug ); boxd.show();
1017					}
1018				}
1019				loading( 'close' );
1020			}, 'json')
1021			.fail(function() {})
1022			.done(function() {})
1023			.always(function() {});
1024		};
1025		
1026		// empty cache
1027		function empty_cache( that ) {
1028			var box 	= maincontainer.find('.main-cross-sell'),
1029				  asin	= maincontainer.find('.main-cross-sell').data('asin'),
1030				  boxd 	= maincontainer.find('#WooZone-cross-sell-debug');
1031				  
1032			var data = {
1033				action				: 'WooZone_frontend',
1034				sub_action			: 'cross_sell_empty_cache',
1035				asin				: asin
1036			};
1037			if (DEBUG) console.log( data );
1038
1039			that.prop('disabled', true).after( lang.saving );
1040
1041			$.post(ajaxurl, data, function(response) {
1042
1043				if ( misc.hasOwnProperty(response, 'status') ) {
1044					window.location.reload();
1045				}
1046				loading( 'close' );
1047			}, 'json')
1048			.fail(function() {})
1049			.done(function() {})
1050			.always(function() {});
1051		};
1052		
1053		// triggers
1054		function triggers() {
1055
1056			// debug mode
1057			$("body").on("click", '#WooZone-cross-sell-debug button', function(e) {
1058				empty_cache( $(this) );
1059			});
1060
1061			// selection checkboxes
1062			$("body").on("change", '.cross-sell input', function(e) {
1063				var that				= $(this),
1064					row				= that.parents('li').eq(0),
1065					asin				= that.val(),
1066					the_thumb	= $('#cross-sell-thumb-' + asin).parents('li'),
1067					buy_block		= $('div.cross-sell-buy-btn');
1068
1069				var price_dec_sep = $('.cross-sell .cross-sell-price-sep').data('price_dec_sep');
1070
1071				buy_block.fadeOut('fast');
1072				if( that.is(':checked') ){
1073					row.attr('class', '');
1074					the_thumb.fadeIn('fast');
1075				}
1076				else{
1077					row.attr('class', '');
1078					row.addClass('cross-sale-uncheck');
1079
1080					the_thumb.fadeOut('fast');
1081				}
1082
1083				var _total_price 		= 0,
1084					  remaining_items	= 0;
1085
1086				$(".cross-sell ul.cross-sell-items li:not(.cross-sale-uncheck)").each(function(){
1087					var that    = $(this);
1088					var price   = that.find('.cross-sell-item-price').data('item_price'); //that.find('.cross-sell-item-price').text().replace(/[^-\d\.,]/g, '')
1089
1090					_total_price = _total_price + parseFloat(price);
1091
1092					remaining_items++;
1093				});
1094
1095				if ( _total_price > 0 ) {
1096					_total_price = _total_price.toFixed(2);
1097					if ( ',' == price_dec_sep ) {
1098						_total_price = numberFormat( _total_price );
1099					}
1100					$("#feq-products").show();
1101					var curr_price = $("#cross-sell-buying-price").text().match(/[\d.,]+/);
1102					$("#cross-sell-buying-price").text( $("#cross-sell-buying-price").text().replace(curr_price, _total_price) );
1103				}
1104				else{
1105					$("#feq-products").fadeOut('fast');
1106					var curr_price = $("#cross-sell-buying-price").text().match(/[\d.,]+/);
1107					$("#cross-sell-buying-price").text( $("#cross-sell-buying-price").text().replace(curr_price, _total_price) );
1108				}
1109
1110				buy_block.fadeIn('fast');
1111			});
1112
1113			// add to cart / checkout button
1114			$("body").on("click", '.cross-sell a#cross-sell-add-to-cart', function(e) {
1115				e.preventDefault();
1116
1117				var that = $(this);
1118
1119				// get all selected products
1120				var totals_checked  = $(".cross-sell ul.cross-sell-items li:not(.cross-sale-uncheck)").size();
1121				$(".cross-sell ul.cross-sell-items li:not(.cross-sale-uncheck)").each(function() {
1122					var that		= $(this),
1123						  q			= 1,
1124						  asin		= that.find('input').val();
1125
1126					multiple_asins.push(asin);
1127				});
1128
1129				if( totals_checked > 0 ){
1130					var newurl = that.attr('href') + '?amz_cross_sell=yes&asins=' + multiple_asins.join(',');
1131
1132					// window.location.href seems to have inconstant behavior in some browsers & also window.location directly not working in versions of IE
1133					// didn't work in my chrome/jimmy
1134					//window.location = newurl;
1135
1136					$(location).attr('href', newurl);
1137				}
1138			});
1139		};
1140		
1141		// Loading
1142		function loading( status, msg ) {
1143			var msg = msg || '';
1144
1145			if ( '' == msg && 'show' == status )
1146				msg = lang.loading;
1147
1148			if ( '' != msg )
1149				mainloader.find('.WooZone-cross-sell-loader-text').html( msg );
1150
1151			if ( 'show' == status )
1152				mainloader.fadeIn('fast');
1153			else
1154				mainloader.fadeOut('fast');
1155		};
1156
1157		function numberWithCommas(number) {
1158			var parts = number.toString().split(".");
1159			parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1160			return parts.join(".");
1161		};
1162
1163		function numberFormat(number) {
1164			var formatted_number = number.replace(',', '###');
1165				formatted_number = formatted_number.replace('.', ',');
1166				formatted_number = formatted_number.replace('###', '.');
1167				
1168			return formatted_number;
1169		};
1170
1171		// external usage
1172		return {
1173			// attributes
1174			'v'                     		: get_vars,
1175
1176			// methods
1177			'__'                    		: __
1178		};
1179	})();
1180
1181
1182	//====================================================
1183	//== :: SYNCHRONIZATION ON FRONTEND
1184	function syncfront_func() {
1185		
1186		var DISABLED				= false; // disable this module!
1187		var DEBUG					= true;
1188		var maincontainer			= null,
1189			mod_alias 				= 'syncfront/ ',
1190			sync_wrapper			= '#WooZone-syncfront-wrapper',
1191			sync_content 			= '#WooZone-syncfront-content',
1192			sync_debug 				= '#WooZone-syncfront-debug',
1193			is_page_product 		= false,
1194			sync_params 			= {},
1195			timer 					= null;
1196
1197		// init function, autoload
1198		function init() {
1199
1200			if ( DISABLED ) return false;
1201
1202			// load the triggers
1203			$(document).ready(function(){
1204				maincontainer = $("body");
1205
1206				// is this a product page?
1207				if ( $(sync_wrapper).length ) {
1208					is_page_product = true;
1209				}
1210
1211				// not a product page!
1212				if ( ! is_page_product ) {
1213					return false;
1214				}
1215
1216				sync_params = get_sync_params();
1217
1218				timer = dotimer();
1219
1220				triggers();
1221			});
1222		};
1223
1224		// triggers
1225		function triggers() {
1226			if (DEBUG) {
1227				//$(sync_wrapper).show();
1228				//$(sync_debug).show();
1229				console.log( mod_alias, 'is product page: ' + is_page_product );
1230			}
1231
1232			//:: yes, do refresh timer
1233			maincontainer.on('click', '#WooZone-syncfront-content .WooZone-syncfront-action-refresh-yes', function (e) {
1234				e.preventDefault();
1235
1236				timer.stop();
1237				window.location.reload();
1238			});
1239
1240			//:: no, don't refresh timer
1241			maincontainer.on('click', '#WooZone-syncfront-content .WooZone-syncfront-action-refresh-no', function (e) {
1242				e.preventDefault();
1243
1244				timer.stop();
1245				$(sync_wrapper).hide();
1246			});
1247
1248			//:: last sync status info
1249			//set_operation_product_info();
1250			set_operation_time();
1251
1252			//:: do ajax sync
1253			if ( 'yes' == sync_params.do_ajax ) {
1254				do_sync();
1255			}
1256			else {
1257				set_operation_msg( sync_params.do_msg );
1258			}
1259		};
1260
1261		function get_sync_params() {
1262			// get params
1263			var _params = $(sync_wrapper).find('.WooZone-syncfront-params').html();
1264			//_params = JSON.stringify(_params);
1265			_params = typeof _params != 'undefined'
1266				? JSON && JSON.parse(_params) || $.parseJSON(_params) : _params;
1267			if (DEBUG) console.log( mod_alias, 'params', _params );
1268
1269			return _params;
1270		};
1271
1272		// load box
1273		function do_sync() {
1274			var time_start 	= new Date().getTime(),
1275				time_end 	= null,
1276				duration 	= null;
1277
1278			set_operation_msg( 'STARTING AJAX TO SYNC PRODUCT...' );
1279
1280			var data = {
1281				'action'		: 'WooZone_frontend',
1282				'sub_action'	: 'do_sync',
1283				'asin' 			: sync_params.asin,
1284				'product_id'	: sync_params.product_id,
1285				'product_type' 	: sync_params.product_type,
1286				'nonce'			: woozone_vars.nonce
1287			};
1288			//if (DEBUG) console.log( data );
1289
1290			$.post(ajaxurl, data, function(response) {
1291
1292				if ( misc.hasOwnProperty(response, 'status') ) {
1293
1294					set_operation_msg( response.html );
1295
1296					// main wrapper
1297					if ( 'yes' == response.do_refresh ) {
1298					//if (1) { //DEBUG
1299						$(sync_wrapper).show();
1300						timer.start();
1301					}
1302
1303					set_operation_msg( 'FINISHED AJAX TO SYNC PRODUCT!' );
1304					if ( misc.hasOwnProperty(response, 'html_aftersync') ) {
1305						if ( $(sync_debug).length && '' != response.html_aftersync ) {
1306							$(sync_debug).find('table tbody').prepend( response.html_aftersync );
1307							set_operation_time();
1308						}
1309					}
1310
1311					time_end = new Date().getTime();
1312					duration = ( time_end - time_start ) / 1000;
1313					set_operation_msg( 'AJAX SYNC DURATION: {duration} seconds'.replace('{duration}', duration) );
1314				}
1315
1316			}, 'json')
1317			.fail(function() {})
1318			.done(function() {})
1319			.always(function() {});
1320		};
1321
1322		function dotimer() {
1323			var _timer 		= null,
1324				$remained 	= $(sync_content).find('h3 span'),
1325				remained 	= typeof $remained !== null && $remained.length ? $remained.text() : 15;
1326			//console.log( 'remained = ', remained, typeof $remained, $remained );
1327
1328			function start() {
1329				//console.log( $remained, remained  );
1330				
1331				function doit() {
1332					_timer = setTimeout( function() {
1333
1334						//console.log( _timer, remained  );
1335
1336						if ( remained ) {
1337							remained--;
1338							$remained.html( remained );
1339							doit();
1340						}
1341						else {
1342							stop();
1343							window.location.reload();
1344						}
1345
1346					}, 1000 );
1347				}
1348				doit();
1349			}
1350
1351			function stop() {
1352				clearTimeout( _timer );
1353				_timer = null;
1354			}
1355
1356			return {
1357				'start' : start,
1358				'stop' 	: stop
1359			}
1360		};
1361
1362		function set_operation_msg( msg, where ) {
1363			var where = where || 'prepend',
1364				opmsg = [];
1365
1366			if ( ! $(sync_debug).length ) {
1367				return false;
1368			}
1369
1370			opmsg.push( '<tr>' );
1371			opmsg.push( 	'<td>' + (new Date).toTimeString().slice(0,8) + '</td>' );
1372			opmsg.push(		'<td>' + msg + '</td>' );
1373			opmsg.push(	'</tr>' );
1374			opmsg = opmsg.join('');
1375
1376			if ( 'prepend' == where ) {
1377				$(sync_debug).find('table tbody').prepend( opmsg );
1378			}
1379			else {
1380				$(sync_debug).find('table tbody').append( opmsg );
1381			}
1382			$(sync_debug).show();
1383
1384			return opmsg;
1385		}
1386
1387		function set_operation_time() {
1388			if ( ! $(sync_debug).length ) {
1389				return false;
1390			}
1391
1392			var rows_upd = $(sync_debug).find('table tbody tr.wzsync-update-time');
1393			rows_upd.find('td:first').html( (new Date).toTimeString().slice(0,8) );
1394			rows_upd.removeClass('wzsync-update-time');
1395		}
1396
1397		function set_operation_product_info() {
1398			//var prodinfo = [];
1399			//prodinfo.push( 'product #ID: ' + sync_params.product_id );
1400			//prodinfo.push( 'product asin: ' + sync_params.asin );
1401			//prodinfo.push( 'product type: ' + sync_params.product_type );
1402			//set_operation_msg( prodinfo.join('<br />'), 'append' );
1403		}
1404		
1405		// external usage
1406		return {
1407			'init' : init
1408		};
1409	};
1410		
1411		
1412	//====================================================
1413	//== :: UTILS
1414
1415
1416
1417	//====================================================
1418	//== :: MISC
1419	var misc = {
1420	
1421		hasOwnProperty: function(obj, prop) {
1422			var proto = obj.__proto__ || obj.constructor.prototype;
1423			return (prop in obj) &&
1424			(!(prop in proto) || proto[prop] !== obj[prop]);
1425		}
1426	};
1427
1428	/*function async_product_exist( data )
1429	{
1430		product_country_check.async_product_exist( data );
1431	}*/
1432
1433	// external usage
1434	return {
1435		'popup'				: popup
1436		//'async_product_exist': async_product_exist
1437	}
1438})(jQuery);
1439
1440/*function check_product_asin( data )
1441{
1442	WooZone.async_product_exist( data );
1443}*/

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.