PageSourceSearch

https://essentialsbyinjest.com/wp-content/themes/eat-clean-chicago…/frontend/js/meal-plans.js?ver=4.0.10.264

js essentialsbyinjest.com collected 2026-09-29 02:01:05 UTC 25,788 bytes, 853 lines download raw bytes

1/* CUSTOM FUNCTIONALITY */
2jQuery( function( $ ) {
3	const $html_body = $([document.documentElement, document.body]),
4		$window = $(window),
5		$body = $(document.body);
6
7	let	window_width = window.innerWidth,
8		window_height = window.innerHeight,
9		update_functions = [],
10		resize_timeout = '',
11		current_window_width = 0,
12		current_window_height = 0;
13		
14	const mediaQuery = window.matchMedia !== undefined ? window.matchMedia("(prefers-reduced-motion: reduce)") : false,
15		prefers_reduced_motion = !mediaQuery || mediaQuery.matches;
16		
17		
18	const methods = {
19		
20		// INIT
21		init : function(){
22			
23			// archive
24			methods.init_wc_archive();
25			
26			
27			// on window resize event
28			$window.on('resize', function(){
29				methods.screen_resize();
30			});
31		},
32		
33		
34		
35		// WC: Archive
36		init_wc_archive: function(){
37			
38			// Meal Plans archive page
39			const $wca_main = $('#wcl-plan-main'),
40				$wca_sidebar_cart = $('#wcl-mp-sidebar'),
41				$products = $('ul.products');
42				
43			if( $products[0] ){
44				$products.find('a.woocommerce-LoopProduct-link').attr('tabindex', '-1');
45				
46				// Body events
47				$body
48					// on Quick view modal open
49					.on( 'quick-view-displayed', function(){
50						$body.addClass( 'quick-view-displayed' );
51					} )
52					
53					// on Quick view modal close
54					.on( 'quick-view-closed', function(){
55						$body.removeClass( 'quick-view-displayed' );
56					} );
57			}
58			
59			if( $wca_main[0] && $wca_sidebar_cart[0] ){
60				methods.$wca_main = $wca_main;
61				methods.$wca_sidebar_cart = $wca_sidebar_cart;
62				
63				// Body events
64				$body
65			
66					// before add to cart
67					.on( 'adding_to_cart', methods.set_wca_sidebar_loading )
68					
69					// after add to cart
70					.on( 'added_to_cart', function( e, fragments, cart_hash, $thisbutton ){
71						methods.populate_wca_mini_cart( fragments );
72						methods.populate_wca_sidebar( fragments );
73						methods.clear_wca_sidebar_loading();
74					} )
75
76					// after remove from cart
77					.on( 'removed_from_cart', function( e, fragments, cart_hash, $thisbutton ){
78						methods.populate_wca_sidebar( fragments );
79					} )
80					
81					// add Meal Plan id to Quick view modal
82					.on( 'quick-view-displayed', function(){
83						const $qw = $('.quick-view'),
84							$qw_form = $qw.find('form'),
85							$wca_sidebar_form = $wca_sidebar_cart.find('form');
86						
87						const mpid = $wca_sidebar_form.data('mpid');
88						if( mpid ){
89							$qw_form.append( '<input type="hidden" name="mpid" value="' + mpid + '">' );
90						}
91						
92						const $autoship_frequency = $wca_sidebar_cart.find('.sidebar--autoship [name=wc_autoship_frequency]');
93						if( $autoship_frequency[0] ){
94							$qw_form.append( '<input type="hidden" name="wc_autoship_frequency" value="' + $autoship_frequency.val() + '">' );
95						}
96						$qw_form.find('.wc-autoship-container').remove();
97						
98						const portion = $wca_sidebar_form.data('portion');
99						if( portion ){
100							$qw.find( '.mp-addon-row:not(.mp-addon-' + portion + ')' ).hide();
101						}
102					} )
103					
104					// hide Quick View modal on "Continue shipping click"
105					.on( 'click', '.quick-view .woocommerce-message-btns .button-dark', function(){
106						$(this).closest('.pp_content').find('.pp_close_custom').trigger('click');
107						return false;
108					} );
109					
110					
111				// Main events
112				$wca_main
113					
114					// show Quick view modal on product link click
115					.on( 'click', 'li.product .woocommerce-loop-product__link, li.product .add_to_cart_button:not(.wpdev_ajax_add_to_cart)', function(){
116						const $qw_btn = $(this).closest('li.product').find('.quick-view-button');
117						if( $qw_btn[0] ){
118							$qw_btn.trigger('click');
119							return false;
120						}
121					} )
122					
123					.find( 'li.product' ).addClass( 'processed' );
124					
125				methods.update_wca_autoship_data();
126
127
128				// Step by step
129				const $wcl_step_by_step_progress = $wca_main.find('.wcl-step-by-step-progress');
130				if( $wcl_step_by_step_progress[0] ){
131					methods.$wcl_step_by_step_progress = $wcl_step_by_step_progress;
132					methods.$wcl_step_by_step_body = $wca_main.find('.wcl-step-by-step-body');
133
134					const $wcl_step_by_step_pagination = $wca_main.find('.wcl-step-by-step-pagination');
135					methods.$wcl_step_by_step_pagination = $wcl_step_by_step_pagination;
136
137					// progress click
138					$wcl_step_by_step_progress.on( 'click', '.wcl-step-by-step-progress__step-button', methods.wca_step_by_step_progress_click );
139
140					// pagination click
141					if( $wcl_step_by_step_pagination[0] ){
142						$wcl_step_by_step_pagination.on( 'click', '.wcl-step-by-step-pagination__button', methods.wca_step_by_step_pagination_click );
143					}
144				}
145					
146					
147				// Sidebar events
148				$wca_sidebar_cart
149				
150					// toggle mobile view
151					.on( 'click', '.sidebar--toggler', methods.wca_toggle_mobile_view )
152					
153					// show/hide options
154					.on( 'change', '.sidebar--autoship-controls-primary input', methods.wca_update_primary_options )
155				
156					// show/hide Update cart button
157					.on( 'change', '.quantity input, .sidebar--autoship select', methods.check_wca_update_cart )
158					
159					// remove cart item
160					.on( 'click', '.product-remove a', methods.remove_wca_cart_item )
161					
162					// form update
163					.on( 'click', '#mp-btn-update-cart', function(){
164						$wca_sidebar_cart.find( 'form' ).trigger( 'submit' );
165						return false;
166					} )
167
168                    // subscription check
169                    .on( 'click', '#mp-btn-next', methods.check_wca_subscriptions )
170					
171					// submit sidebar cart form
172					.on( 'submit', 'form', methods.submit_wca_cart );
173				
174				
175				// Diet
176				const $diet_toggle = $wca_main.find('#meal-plan-tags-toggle');
177				if( $diet_toggle[0] ){
178					methods.update_wca_diet( $diet_toggle );
179					update_functions.push([ methods.update_wca_diet, $diet_toggle ]);	
180				}
181			}
182		},
183
184		// - change step by step pagination click
185		wca_step_by_step_pagination_click: function(){
186			const $wcl_step_by_step_progress = methods.$wcl_step_by_step_progress,
187				$current_step = $wcl_step_by_step_progress.find('.wcl-step-by-step-progress__step--current');
188
189			const $button = $(this);
190			if( $button.hasClass('wcl-step-by-step-pagination__button--prev') ){
191				const $prev_step = $current_step.prev();
192
193				if( $prev_step[0] ){
194					methods.wca_step_by_step_switch_term( $prev_step.find('.wcl-step-by-step-progress__step-button').attr('data-term-id') );
195				}
196			}
197			else if( $button.hasClass('wcl-step-by-step-pagination__button--next') ){
198				const $next_step = $current_step.next();
199
200				if( $next_step[0] ){
201					methods.wca_step_by_step_switch_term( $next_step.find('.wcl-step-by-step-progress__step-button').attr('data-term-id') );
202				}
203			}
204
205			return false;
206		},
207
208		// - step by step progress click
209		wca_step_by_step_progress_click: function(){
210			if( !methods.$wca_main.hasClass('is-loading') ){
211				methods.wca_step_by_step_switch_term( $(this).attr('data-term-id') );
212			}
213
214			return false;
215		},
216
217		// - change step by step term
218		wca_step_by_step_switch_term: function( term_id ){
219			if( methods.$wca_main.hasClass('is-loading') ){
220				return false;
221			}
222
223			// remove current and completed classes
224			const $wcl_step_by_step_progress = methods.$wcl_step_by_step_progress;
225			$wcl_step_by_step_progress
226				.find('.wcl-step-by-step-progress__step')
227					.removeClass('wcl-step-by-step-progress__step--current wcl-step-by-step-progress__step--completed');
228
229			
230			// add current and completed classes
231			const $step_button = $wcl_step_by_step_progress.find('.wcl-step-by-step-progress__step-button[data-term-id="' + term_id + '"]');
232			$step_button
233				.parent()
234					.addClass('wcl-step-by-step-progress__step--current')
235					.prevAll()
236						.addClass('wcl-step-by-step-progress__step--completed');
237			
238			
239			// update pagination
240			const $wcl_step_by_step_pagination = methods.$wcl_step_by_step_pagination;
241			
242			const $prev_step = $step_button.parent().prev();
243			if( $prev_step[0] ){
244				$wcl_step_by_step_pagination.find('.wcl-step-by-step-pagination__button--prev')
245					.text($prev_step.find('.wcl-step-by-step-progress__step-label').text())
246					.show();
247			}
248			else{
249				$wcl_step_by_step_pagination.find('.wcl-step-by-step-pagination__button--prev')
250					.hide();
251			}
252			
253			const $next_step = $step_button.parent().next();
254			if( $next_step[0] ){
255				$wcl_step_by_step_pagination.find('.wcl-step-by-step-pagination__button--next')
256					.html($next_step.find('.wcl-step-by-step-progress__step-label').text())
257					.show();
258			}
259			else{
260				$wcl_step_by_step_pagination.find('.wcl-step-by-step-pagination__button--next')
261					.hide();
262			}
263			
264			
265			// hide all body terms
266			const $wcl_step_by_step_body = methods.$wcl_step_by_step_body;
267			$wcl_step_by_step_body.find('.wcl-step-by-step-term').hide();
268
269			
270			// check if we need to load items
271			let $wcl_step_by_step_term = $wcl_step_by_step_body.find('#wcl-step-by-step-term-' + term_id);
272			if( $wcl_step_by_step_term[0] ){
273				prefers_reduced_motion ? $wcl_step_by_step_term.show() : $wcl_step_by_step_term.fadeIn('fast');
274			}
275			else{
276				$wcl_step_by_step_term = $(`<div class="wcl-step-by-step-term" id="wcl-step-by-step-term-${term_id}" style="display: none;"><h3 class="wcl-step-by-step-content-title">${$step_button.find('.wcl-step-by-step-progress__step-label').text()}</h3><div class="wcl-step-by-step-content"></div></div>`);
277				$wcl_step_by_step_body.append($wcl_step_by_step_term);
278				prefers_reduced_motion ? $wcl_step_by_step_term.show() : $wcl_step_by_step_term.fadeIn('fast');
279				methods.wca_step_by_step_items_load( term_id );
280			}
281
282			
283			// change history state
284			methods.change_history_state( { wcl_step: term_id } );
285		},
286
287		// - load step by step items
288		wca_step_by_step_items_load: function( term_id ){
289			const $wca_main = methods.$wca_main;
290			if( $wca_main.hasClass('is-loading') ){
291				return false;
292			}
293
294			const $wcl_step_by_step_body = methods.$wcl_step_by_step_body,
295				$wcl_step_by_step_term = $wcl_step_by_step_body.find('#wcl-step-by-step-term-' + term_id);
296
297			if( term_id ){
298				$wca_main.addClass('is-loading');
299
300				$.ajax({
301					type: 'POST',
302					url: ajax_global.ajaxurl,
303					dataType: 'json',
304					data: {
305						action: 'wca_mp_get_sbs_products',
306						mpid: methods.$wca_main.data('mpid'),
307						term_id: term_id
308					}
309				})
310				.done(function(data){
311					if( data ){
312						if( data.success ){
313							if( data.data && data.data.body !== undefined ){
314								$wcl_step_by_step_term.find('.wcl-step-by-step-content')
315									.html( data.data.body )
316									.find('a.woocommerce-LoopProduct-link')
317										.attr('tabindex', '-1');
318							}
319						}
320						else{
321							if( data.data && data.data.msg !== undefined ){
322								methods.show_notification( 'error', data.data.msg );
323							}
324						}
325						if( data.data && data.data.notices !== undefined ){
326							for( let i = 0, iL = data.data.notices.length; i < iL; i++ ){
327								methods.show_notification( 'info', data.data.notices[i] );
328							}
329						}
330					}
331				})
332				.fail(function(){
333					methods.show_notification( 'error', 'Something went wrong. Please try again.' );
334				})
335				.always(function(){
336					$wca_main.removeClass('is-loading');
337				});
338			}
339		},
340
341		
342		// - update diet state
343		update_wca_diet: function( $diet_toggle ){
344			if( window_width > 767 ){
345				$diet_toggle.attr( 'aria-expanded', 'true' );
346			}
347			else{
348				const $tags = $diet_toggle.parent().find('#meal-plan-tags');
349				if( $tags[0] && $tags.hasClass('show') ){
350					$diet_toggle.attr( 'aria-expanded', 'true' );
351				}
352				else{
353					$diet_toggle.attr( 'aria-expanded', 'false' );
354				}
355			}
356		},
357		
358		// - add sidebar loading state
359		set_wca_sidebar_loading: function(){
360			methods.$wca_sidebar_cart
361				.addClass('is-loading')
362				.data( 'is-loading', true );
363		},
364		
365		// - clear sidebar loading state
366		clear_wca_sidebar_loading: function(){
367			methods.$wca_sidebar_cart
368				.removeClass('is-loading')
369				.data( 'is-loading', false );
370		},
371		
372		// - check sidebar loading state
373		check_wca_sidebar_loading: function(){
374			return methods.$wca_sidebar_cart.data('is-loading') == true ? true : false;
375		},
376		
377		// - toggle mobile view
378		wca_toggle_mobile_view: function(){
379			if( prefers_reduced_motion ){
380				$body.toggleClass('wcl-sidebar-active');
381			}
382			else{
383				const $wca_sidebar_cart = methods.$wca_sidebar_cart;
384				$wca_sidebar_cart
385					.stop()
386					.fadeOut( 0, function(){
387						$body.toggleClass('wcl-sidebar-active');
388						$wca_sidebar_cart.fadeIn('fast');
389					} );
390			}
391			
392			return false;
393		},
394		
395		// - update subscription/no subscription options
396		wca_update_primary_options: function(){
397			const $secondary = methods.$wca_sidebar_cart.find('.sidebar--autoship-controls-secondary'),
398				$actual = methods.$wca_sidebar_cart.find('.sidebar--autoship-controls-actual select');
399			
400			if( $(this).val() === 'autoship' ){
401				prefers_reduced_motion ? $secondary.show() : $secondary.slideDown('fast');
402				$actual
403					.val( $secondary.find('input[type=radio]:checked').val() )
404					.trigger( 'change' );
405			}
406			else{
407				prefers_reduced_motion ? $secondary.hide() : $secondary.slideUp('fast');
408				$actual
409					.val( $(this).val() )
410					.trigger( 'change' );
411			}
412		},
413		
414		// - check Update cart status
415		check_wca_update_cart: function(){
416			const $wca_sidebar_cart = methods.$wca_sidebar_cart,
417				$update_button = $wca_sidebar_cart.find('#mp-btn-update-cart'),
418				$next_button = $wca_sidebar_cart.find('#mp-btn-next');
419
420			let is_changed = false;
421			
422			
423			// check if any item quantity is changed
424			const $items = $wca_sidebar_cart.find('.sidebar-cart-item');
425			if( $items[0] ){
426				let $item = [];
427				for( let i = 0, iL = $items.length; i < iL; i++ ){
428					$item = $items.eq(i);
429					if( $item.data('quantity') != $item.find('.quantity input').val() ){
430						is_changed = true;
431						break;
432					}
433				}
434			}
435			
436			// check if autoship option is changed
437			const $autoship = $wca_sidebar_cart.find('.sidebar--autoship select');
438			if( $autoship[0] && $autoship.val() != $autoship.data('selected') ){
439				methods.update_wca_autoship_data( $autoship.val() );
440				is_changed = true;
441			}
442			
443			
444			if( is_changed ){
445				$update_button.show();
446				$next_button.hide();
447			}
448			else{
449				$update_button.hide();
450				$next_button.show();
451			}
452		},
453		
454		// - update autoship data
455		update_wca_autoship_data: function( autoship_frequency ){
456			if( autoship_frequency == undefined ){
457				const $autoship = methods.$wca_sidebar_cart.find('.sidebar--autoship select');
458				if( $autoship[0] ){
459					autoship_frequency = $autoship.val();
460				}
461			}
462			
463			if( autoship_frequency !== undefined ){
464				if( autoship_frequency !== 'no_autoship' ){
465					methods.$wca_main.find('.wpdev_ajax_add_to_cart')
466						.attr( 'data-wc_autoship_frequency', autoship_frequency )
467						.removeAttr( 'data-remove_wc_autoship_frequency' );
468				}
469				else{
470					methods.$wca_main.find('.wpdev_ajax_add_to_cart')
471						.attr( 'data-remove_wc_autoship_frequency', true )
472						.removeAttr( 'data-wc_autoship_frequency' );
473				}
474			}
475		},
476		
477		// - change cart qty defaults
478		update_wca_cart_qtys: function( $wca_sidebar_cart ){
479			if( $wca_sidebar_cart === undefined ){
480				$wca_sidebar_cart = methods.$wca_sidebar_cart;
481			}
482			const $inputs = $wca_sidebar_cart.find('.sidebar-cart-item .quantity .input-text');
483			
484			if( $inputs[0] ){
485				let $input = [];
486				
487				for( let i = 0, iL = $inputs.length; i < iL; i++ ){
488					$input = $inputs.eq(i);
489					$input.closest( '.sidebar-cart-item' ).data( 'quantity', $input.val() );
490				}
491			}
492			
493			$wca_sidebar_cart
494				.find('#mp-btn-update-cart')
495					.hide()
496				.end()
497				.find('#mp-btn-next')
498					.show();
499		},
500		
501		// - submit cart
502		submit_wca_cart: function(){
503			const $wca_sidebar_cart = methods.$wca_sidebar_cart,
504				$form = $(this);
505			
506			if( !methods.check_wca_sidebar_loading() ){
507				methods.set_wca_sidebar_loading();
508				
509				let extra_params = {};
510				
511				// add subscription options
512				const $subscription = $wca_sidebar_cart.find('.sidebar--autoship select[name=wc_autoship_frequency]');
513				if( $subscription[0] ){
514					if( $subscription.val() !== 'no_autoship' ){
515						extra_params['wc_autoship_frequency'] = $subscription.val();
516					}
517					else{
518						extra_params['remove_wc_autoship_frequency'] = true;
519					}
520				}
521				
522				// merge extra params with form data
523				let data = $form.serialize();
524				if( !$.isEmptyObject(extra_params) ){
525					data += '&' + $.param(extra_params);
526				}
527					
528				$.ajax({
529					type: 'POST',
530					url: ajax_global.ajaxurl,
531					dataType: 'json',
532					data: data
533				})
534				.done(function(data){
535					if( data ){
536						if( data.status === 'ok' ){
537							if( data.fragments !== undefined ){
538								methods.populate_wca_mini_cart( data.fragments );
539								methods.populate_wca_sidebar( data.fragments );
540							}
541							if( data.msg !== undefined ){
542								methods.show_notification( 'success', data.msg );
543							}
544							methods.update_wca_cart_qtys( $wca_sidebar_cart );
545						}
546						else{
547							if( data.msg !== undefined ){
548								methods.show_notification( 'error', data.msg );
549							}
550						}
551						if( data.notices !== undefined ){
552							for( let i = 0, iL = data.notices.length; i < iL; i++ ){
553								methods.show_notification( 'info', data.notices[i] );
554							}
555						}
556					}
557				})
558				.always(function(){
559					methods.clear_wca_sidebar_loading();
560				});
561			}
562			
563			return false;
564		},
565		
566		// - remove cart item
567		remove_wca_cart_item: function(){
568			const $wca_sidebar_cart = methods.$wca_sidebar_cart,
569				$link = $(this),
570				$form = $link.closest('form');
571			
572			if( !methods.check_wca_sidebar_loading() ){
573				methods.set_wca_sidebar_loading();
574				
575				const link_href_parts = $link.attr( 'href' ).split('?');
576				let ajax_data = methods.get_search_params( link_href_parts.length > 1 ? link_href_parts[1] : '' );
577				ajax_data['action'] = 'mp_delete_wca_cart_item';
578				ajax_data['mpid'] = $form.find('[name=mpid]').val();
579				
580				$.ajax({
581					type: 'POST',
582					url: ajax_global.ajaxurl,
583					dataType: 'json',
584					data: ajax_data
585				})
586				.done(function(data){
587					if( data ){
588						if( data.status === 'ok' ){
589							if( data.fragments !== undefined ){
590								methods.populate_wca_mini_cart( data.fragments );
591								methods.populate_wca_sidebar( data.fragments );
592							}
593							if( data.msg !== undefined ){
594								methods.show_notification( 'success', data.msg );
595							}
596							methods.update_wca_cart_qtys( $wca_sidebar_cart );
597						}
598						else{
599							if( data.msg !== undefined ){
600								methods.show_notification( 'error', data.msg );
601							}
602						}
603					}
604				})
605				.fail(function(){})
606				.always(function(){
607					methods.clear_wca_sidebar_loading();
608				});
609			}
610			
611			return false;
612		},
613		
614		// - populate mini cart amount
615		populate_wca_mini_cart: function( fragments ){
616			if( fragments !== undefined ){
617				if( fragments['menu-cart-counter'] !== undefined ){
618					$('#masthead .menu-cart-counter').replaceWith( fragments['menu-cart-counter'] );
619				}
620				if( fragments['a.cart-contents'] !== undefined ){
621					$('#masthead a.cart-contents').replaceWith( fragments['a.cart-contents'] );
622				}
623				if( fragments['#minicart-content-wrapper'] !== undefined ){
624					$('#minicart-content-wrapper').replaceWith( fragments['#minicart-content-wrapper'] );
625				}
626			}
627		},
628		
629		// - populate sidebar
630		populate_wca_sidebar: function( fragments ){
631			if( fragments !== undefined && fragments['meal_plans'] !== undefined ){
632				const meal_plans_data = fragments['meal_plans'],
633					$wca_sidebar_cart = methods.$wca_sidebar_cart;
634				
635				
636				// autoship
637				const $autoship = $wca_sidebar_cart.find('.sidebar--autoship select[name=wc_autoship_frequency]');
638				if( $autoship[0] ){
639					if( meal_plans_data['wc_autoship_frequency'] !== undefined ){
640						const frequency = meal_plans_data['wc_autoship_frequency'] ? meal_plans_data['wc_autoship_frequency'] : 'no_autoship';
641						$autoship
642							.val( frequency )
643							.data( 'selected', frequency );
644					}
645					else{
646						$autoship.data( 'selected', $autoship.val() );
647					}
648				}
649				
650				
651				// cart
652				if( meal_plans_data['cart'] !== undefined ){
653					$wca_sidebar_cart.find( '.wc-sidebar-cart' ).html( meal_plans_data['cart'] );	
654				}
655				
656				
657				// notification
658				let $notification = $wca_sidebar_cart.find( '.sidebar--notification' );
659				if( meal_plans_data['notification'] !== undefined ){
660					if( !$notification[0] ){
661						$notification = $('<div class="sidebar--notification"></div>');
662						$wca_sidebar_cart.find( '.sidebar--notifications' ).prepend( $notification );
663					}
664					
665					$notification.html( meal_plans_data['notification'] );	
666				}
667				else{
668					$notification.remove();
669				}
670				
671				
672				// progress
673				let $progress = $wca_sidebar_cart.find( '.sidebar--progress' );
674				if( meal_plans_data['total'] !== undefined && meal_plans_data['min'] !== undefined ){
675					if( !$progress[0] ){
676						$progress = $('<div class="sidebar--progress"><div class="sidebar--progress-scale"></div></div>');
677						$wca_sidebar_cart.find( '.sidebar--notifications' ).append( $progress );
678					}
679					
680					let $scale = $progress.find('.sidebar--progress-scale');
681					if( !$scale[0] ){
682						$scale = $('<div class="sidebar--progress-scale"></div>');
683						$progress.append( $scale );
684					}
685					
686					let total = parseInt( meal_plans_data['total'] ),
687						min = parseInt( meal_plans_data['min'] ),
688						max = parseInt( meal_plans_data['max'] );
689					
690					if( isNaN(total) ){
691						total = 0;
692					}
693					if( isNaN(min) ){
694						min = 0;
695					}
696					if( isNaN(max) ){
697						max = 99999;
698					}
699					
700					total >= min && total <= max ? $scale.addClass('sidebar--progress-scale-complete') : $scale.removeClass('sidebar--progress-scale-complete');
701					if( min > 0 ){
702						$scale.css( 'width', Math.min( 100, Math.max( 0, ( 100 / min * total ) ) ) + '%' );
703					}
704					else{
705						$scale.css( 'width', '0%' );
706					}
707				}
708				else{
709					$progress.remove();
710				}
711				
712				
713				// next button
714				const $next_button = $wca_sidebar_cart.find( '#mp-btn-next' );
715				if( $next_button[0] ){
716					
717					// subtotal
718					if( meal_plans_data['subtotal'] !== undefined ){
719						$next_button.find('.sidebar--next-subtotal').html( meal_plans_data['subtotal'] );
720					}
721					
722					// status
723					if( meal_plans_data['next_status'] !== undefined ){
724						switch( meal_plans_data['next_status'] ){
725							case 'ok': 
726								$next_button.removeAttr( 'aria-disabled' );
727								break;
728							case 'nope': 
729								$next_button.attr( 'aria-disabled', 'true' );
730								break;
731						}	
732					}
733				}
734			}
735			
736			methods.check_wca_update_cart();
737		},
738
739        // - check if we have a subscription
740        check_wca_subscriptions: function(){
741            if( window_width < 576 && !$body.hasClass('wcl-sidebar-active') ){
742                const $wca_sidebar_subs = methods.$wca_sidebar_cart.find('.sidebar--autos
742hip');
743
744                if( $wca_sidebar_subs[0] ){
745                    if( $wca_sidebar_subs.data('sidebar-title') ){
746                        methods.$wca_sidebar_cart.find('.sidebar--header-wrap .sidebar--title').attr( 'data-active-title', $wca_sidebar_subs.data('sidebar-title') );
747                    }
748
749                    $body.addClass('wcl-sidebar-active');
750                    return false;
751                }
752			}
753        },
754
755
756
757		// screen resize check
758		screen_resize: function(){
759			clearTimeout(resize_timeout);
760			resize_timeout = setTimeout(function(){
761				current_window_width = window.innerWidth;
762				current_window_height = window.innerHeight;
763
764				if( current_window_width != window_width || current_window_height != window_height ){
765					window_width = current_window_width;
766					window_height = current_window_height;
767					methods.update();
768				}
769			}, 300);
770		},
771		
772		// update on screen resize
773		update: function(){
774			for(let i = 0, iL = update_functions.length; i < iL; i++){
775				update_functions[i][0](update_functions[i][1]);
776			}
777		},
778		
779		// scroll to
780		scroll_to: function( $el, offset, speed ){
781			if( $el[0] ){
782				offset = offset ? offset : 0;
783				speed = speed ? speed : 500;
784				
785				$html_body.animate({
786					scrollTop: $el.offset().top - offset
787				}, speed);
788			}
789		},
790
791		// - change history state
792		change_history_state: function( data ){
793			if( window.history.replaceState !== undefined ){
794				let params = methods.get_search_params(),
795					url = window.location.href.split('?')[0];
796				
797				if( data && data.wcl_step !== undefined ){
798					params['wcl_step'] = data.wcl_step;
799				}
800				else if( params['wcl_step'] !== undefined ){
801					delete params['wcl_step'];
802				}
803				
804				window.history.replaceState({}, document.title, url + '?' + Object.keys(params).map(function(key){ return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); }).join('&') );			
805			}
806		},
807		
808		// parse search params from url
809		get_search_params : function(str){
810			if( !str ){
811				str = window.location.search;
812			}
813
814			const objURL = {};
815			try{
816				const searchParams = new URLSearchParams( str );
817				searchParams.forEach(function( value, key ){
818					objURL[ key ] = value;
819				});
820			}
821			catch( err ){
822				str.replace(
823					new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
824					function( $0, $1, $2, $3 ){
825						objURL[ decodeURIComponent( $1 ) ] = decodeURIComponent( $3 || '' );
826					}
827				);
828			}
829
830			return objURL;
831		},
832		
833		// show notification
834		show_notification: function( type, msg ){
835			const has_toastr = window.toastr !== undefined ? true : false;
836
837			switch( type ){
838				case 'success': 
839					has_toastr ? toastr.success(msg) : alert(msg);
840					break;
841				
842				case 'error': 
843					has_toastr ? toastr.error(msg) : alert(msg);
844					break;
845				
846				default: 
847					has_toastr ? toastr.info(msg) : alert(msg);
848			}
849		},
850	}
851	
852	methods.init();
853});

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.