PageSourceSearch

https://fairlightcycles.com/wp-content/themes/fairlight-cycles/assets/scripts/switcher-flags.js?ver=1.0.0

js fairlightcycles.com collected 2026-10-06 07:40:46 UTC 2,640 bytes, 92 lines download raw bytes

1( function( $ ) {
2	var switcher_flags = {
3		template: function( data ) {
4			if ( ! data.id ) {
5				return data.text;
6			}
7			var flag     = '';
8			var currency = $(data.element).data('currency');
9
10			if (typeof currency !== 'undefined' && currency ) {
11				if ('EUR' === currency) {
12					flag = 'eu';
13				} else if( 'X' !== currency.substring(0,1) ) {
14					flag = currency.toLowerCase().substring(0,2);
15				}
16			}
17
18			if ( ! flag ) {
19				flag = data.id.toLowerCase();
20			}
21			var $element = $( '<span><i class="fi" style="margin-right: 3px;"></i><span></span></span>' );
22			$element.find('i.fi').addClass('fi-'+flag);
23			$element.find('span').text(data.text);
24
25			return $element;
26		},
27
28		selectionTemplate: function( data ) {
29			var el = switcher_flags.template( data );
30			return el.html();
31		},
32
33		afterSelectionTemplate: function() {
34			$('.wc-price-based-country .select2-selection__rendered').each( function(){
35				var text = $(this).text();
36				if ( text.indexOf('span>') > 0 ) {
37					$(this).html( text );
38				}
39			});
40		},
41
42		init_select2: function() {
43			$('header select.wcpbc-currency-switcher, header select.wcpbc-country-switcher, footer select.wcpbc-currency-switcher, footer select.wcpbc-country-switcher').select2({
44				dropdownCssClass: 'f16 :all: wcpbc-switcher',
45				containerCssClass: 'f16',
46				templateResult: switcher_flags.template,
47				templateSelection:  switcher_flags.selectionTemplate,
48				minimumResultsForSearch: Infinity,
49				width: 'auto'
50			});
51
52			switcher_flags.afterSelectionTemplate();
53
54			$('header select.wcpbc-currency-switcher, header select.wcpbc-country-switcher, footer select.wcpbc-currency-switcher, footer select.wcpbc-country-switcher').on('change', function(){
55				switcher_flags.afterSelectionTemplate();
56			});
57		},
58
59		init: function() {
60
61			$(document).ready(switcher_flags.init_select2);
62
63			/*
64			 * After AJAX geolocation.
65			 */ 
66			$(document.body).on('wc_price_based_country_after_ajax_geolocation', switcher_flags.init_select2);
67		}
68	};
69	
70	switcher_flags.init();
71
72	$('select[form=wcpbc-widget-country-switcher-form]').on('change', function(e){
73		var country = $(this).val();
74		
75		$form = $('#wcpbc-widget-country-switcher-form');
76		$form.find('input[name="wcpbc-manual-country"]').val(country);
77		var href = new URL(window.location.href);
78
79		href.searchParams.delete('v');
80		var countryData = wcpbc_switcher_flags.countries.find(function(element, index){
81			return element.id === country;
82		});
83
84		if(countryData !== undefined && countryData !== null){
85			href.searchParams.set('v', countryData.hash);
86		}
87		
88		$form.attr('action', href);
89		$form.submit();
90  
91	  });
92})( jQuery );

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.