PageSourceSearch

https://minsterpeptides.co.uk/wp-content/plugins/fable-extra//inc/…/js/fable-extra-woocompare.js?ver=1.1.1

js minsterpeptides.co.uk collected 2026-10-09 02:57:40 UTC 5,985 bytes, 246 lines download raw bytes

1( function( $ ) {
2
3	'use strict';
4
5	$( document ).ready( function() {
6
7		var fableExtraWooLoadingClass = 'loading',
8			fableExtraWooAddedClass   = 'added in_compare',
9			btnSelector       = '.compare-btn';
10
11		$( document ).on( 'fable_extra_compare_update_fragments', updateFragments )
12
13		function productButtonsInit() {
14
15			$( btnSelector ).each( function() {
16
17				var button = $( this );
18
19				button.on( 'click', function ( event ) {
20
21					event.preventDefault();
22
23					var url  = fableExtraWoocompare.ajaxurl,
24						data = {
25							action: 'fable_extra_woocompare_add_to_list',
26							pid:    button.data( 'id' ),
27							nonce:  button.data( 'nonce' ),
28							single: button.hasClass( 'compare-btn-single' )
29						};
30
31					button
32						.removeClass( fableExtraWooAddedClass )
33						.addClass( fableExtraWooLoadingClass );
34
35					$.post(
36						url,
37						data,
38						function( response ) {
39
40							button.removeClass( fableExtraWooLoadingClass );
41
42							if( response.success ) {
43
44								switch ( response.data.action ) {
45
46									case 'add':
47
48										$( btnSelector + '[data-id=' + data.pid + ']' )
49											.addClass( fableExtraWooAddedClass )
50											.find( '.text' )
51											.html( fableExtraWoocompare.removeText );
52
53										if( response.data.comparePageBtn ) {
54
55											button.after( response.data.comparePageBtn );
56										}
57										break;
58
59									case 'remove':
60
61										$( btnSelector + '[data-id=' + data.pid + ']' )
62											.removeClass( fableExtraWooAddedClass )
63											.find( '.text' )
64											.text( fableExtraWoocompare.compareText );
65
66										$( '.fable-extra-woocompare-page-button' ).remove();
67
68										break;
69
70									default:
71
72										break;
73								}
74								data = {
75									action: 'fable_extra_woocompare_update'
76								};
77								fableExtraWoocompareAjax( null, data );
78							}
79
80							if ( undefined !== response.data.counts ) {
81								$( document ).trigger( 'fable_extra_compare_update_fragments', { response: response.data.counts } );
82							}
83
84						}
85					);
86				} );
87			} );
88		}
89
90		function fableExtraWoocompareAjax( event, data ) {
91
92			if( event ) {
93
94				event.preventDefault();
95			}
96
97			var url           = fableExtraWoocompare.ajaxurl,
98				widgetWrapper = $( 'div.fable-extra-woocompare-widget-wrapper' ),
99				compareList   = $( 'div.fable-extra-woocompare-list' );
100
101			data.isComparePage = !!compareList.length;
102			data.isWidget      = !!widgetWrapper.length;
103
104			if ( 'fable_extra_woocompare_update' === data.action && !data.isComparePage && !data.isWidget ) {
105
106				return;
107			}
108			compareList.addClass( fableExtraWooLoadingClass );
109			widgetWrapper.addClass( fableExtraWooLoadingClass );
110
111			$.post(
112				url,
113				data,
114				function( response ) {
115
116					compareList.removeClass( fableExtraWooLoadingClass );
117					widgetWrapper.removeClass( fableExtraWooLoadingClass );
118
119					if( response.success ) {
120
121						if( data.isComparePage ) {
122
123							$( 'div.fable-extra-woocompare-wrapper' ).html( response.data.compareList );
124							$( document ).trigger( 'enhance.tablesaw' );
125						}
126						if( data.isWidget ) {
127
128							widgetWrapper.html( response.data.widget );
129						}
130						if ( 'fable_extra_woocompare_empty' === data.action ) {
131
132							$( btnSelector )
133								.removeClass( fableExtraWooAddedClass )
134								.find( '.text' )
135								.text( fableExtraWoocompare.compareText );
136
137							$( '.fable-extra-woocompare-page-button' ).remove();
138						}
139						if ( 'fable_extra_woocompare_remove' === data.action ) {
140
141							$( btnSelector + '[data-id=' + data.pid + ']' )
142								.removeClass( fableExtraWooAddedClass )
143								.find( '.text' )
144								.text( fableExtraWoocompare.compareText );
145
146							$( '.fable-extra-woocompare-page-button' ).remove();
147						}
148					}
149
150					if ( undefined !== response.data.counts ) {
151						$( document ).trigger( 'fable_extra_compare_update_fragments', { response: response.data.counts } );
152					}
153
154					widgetButtonsInit();
155				}
156			);
157		}
158
159		function fableExtraWoocompareRemove( event ) {
160
161			var button = $( event.currentTarget ),
162				data   = {
163					action: 'fable_extra_woocompare_remove',
164					pid:    button.data( 'id' ),
165					nonce:  button.data( 'nonce' )
166				};
167
168			fableExtraWoocompareAjax( event, data );
169		}
170
171		function fableExtraWoocompareEmpty( event ) {
172
173			var data = {
174				action: 'fable_extra_woocompare_empty'
175			};
176
177			fableExtraWoocompareAjax( event, data );
178		}
179
180		function widgetButtonsInit() {
181
182			$( '.fable-extra-woocompare-remove' )
183				.off( 'click' )
184				.on( 'click', function ( event ) {
185					fableExtraWoocompareRemove( event );
186				} );
187
188			$( '.fable-extra-woocompare-empty' )
189				.off( 'click' )
190				.on( 'click', function( event ) {
191					fableExtraWoocompareEmpty( event );
192				} );
193		}
194
195		function getRefreshedFragments() {
196
197			$.ajax({
198				url: fableExtraWoocompare.ajaxurl,
199				type: 'get',
200				dataType: 'json',
201				data: {
202					action: 'fable_extra_compare_get_fragments'
203				}
204			}).done( function( response ) {
205
206				$( document ).trigger( 'fable_extra_compare_update_fragments', { response: response.data } );
207
208			});
209
210		}
211
212		function updateFragments( event, data ) {
213
214			if ( ! $.isEmptyObject( data.response.defaultFragments ) ) {
215				$.each( data.response.defaultFragments, function( key, val ) {
216					var $item  = $( key ),
217						$count = $( '.compare-count', $item );
218					if ( 0 === $count.length ) {
219						$item.append( fableExtraWoocompare.countFormat.replace( '%count%', val ) );
220					} else {
221						$item.find( '.compare-count' ).html( val );
222					}
223				} );
224			}
225
226			if ( ! $.isEmptyObject( data.response.customFragments ) ) {
227				$.each( data.response.customFragments, function( key, val ) {
228					var $item = $( key );
229					if ( $item.length ) {
230						$item.html( val );
231					}
232				} );
233			}
234
235		}
236
237		widgetButtonsInit();
238		productButtonsInit();
239		getRefreshedFragments();
240
241		$( document ).on( 'fable_extra_wc_products_changed', function() {
242			widgetButtonsInit();
243			productButtonsInit();
244		} );
245	} );
246}( 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.