1/** 2 * Native reviews â storefront behavior. Fold into the store JS bundle. 3 * 4 * - ec_reviews_filter( product_id, rating ): click a distribution bar to show only that rating ( toggle ). 5 * - Review-request landing: open the reviews tab, scroll to the form, pre-select the star tapped in the email. 6 * 7 * Uses the same star elements the existing form binds ( .ec_details_review_input[data-review-score] ), so it 8 * triggers the theme's own click handler rather than duplicating its state logic. 9 */ 10function ec_reviews_filter( product_id, rating ) { 11 var lists = document.querySelectorAll( '.ec_details_customer_review_list[data-product-id="' + product_id + '"]' ); 12 if ( ! lists.length ) { return false; } 13 var summary = lists[0].closest( '.ec_details_customer_reviews_tab' ) || document; 14 var active = summary.querySelector( '.ec_review_dist_row.is-active' ); 15 var same = active && parseInt( active.getAttribute( 'data-rating' ), 10 ) === rating; 16 summary.querySelectorAll( '.ec_review_dist_row' ).forEach( function( r ) { r.classList.remove( 'is-active' ); } ); 17 lists.forEach( function( list ) { 18 list.querySelectorAll( 'li[data-rating]' ).forEach( function( li ) { 19 li.style.display = ( same || parseInt( li.getAttribute( 'data-rating' ), 10 ) === rating ) ? '' : 'none'; 20 } ); 21 } ); 22 if ( ! same ) { 23 var row = summary.querySelector( '.ec_review_dist_row[data-rating="' + rating + '"]' ); 24 if ( row ) { row.classList.add( 'is-active' ); } 25 } 26 return false; 27} 28 29( function() { 30 function ready( fn ) { if ( document.readyState !== 'loading' ) { fn(); } else { document.addEventListener( 'DOMContentLoaded', fn ); } } 31 ready( function() { 32 var banner = document.querySelector( '.ec_review_request_banner' ); 33 if ( ! banner ) { return; } 34 var pid = banner.getAttribute( 'data-product-id' ), rand = banner.getAttribute( 'data-rand-id' ), rating = parseInt( banner.getAttribute( 'data-prefill-rating' ), 10 ) || 0; 35 36 /* Open the reviews tab if the theme uses tabs ( the tab link carries the product id + rand in its class ) */ 37 var tab = document.querySelector( '.ec_details_customer_reviews_tab_' + pid + '_' + rand ); 38 var tabLink = document.querySelector( '[onclick*="ec_show_review_tab"], .ec_details_tab_review_' + pid + '_' + rand + ', .ec_details_tab_reviews' ); 39 if ( tab && tabLink && window.getComputedStyle( tab ).display === 'none' ) { tabLink.click(); } 40 41 /* Pre-select the star from the email */ 42 if ( rating >= 1 && rating <= 5 ) { 43 var star = document.getElementById( 'ec_details_review_star' + rating + '_' + pid + '_' + rand ); 44 if ( star ) { setTimeout( function() { star.click(); }, 50 ); } 45 } 46 47 /* Scroll to the form */ 48 var form = banner.closest( '.ec_details_customer_reviews_form' ); 49 if ( form ) { setTimeout( function() { form.scrollIntoView( { behavior: 'smooth', block: 'start' } ); }, 150 ); } 50 } ); 51} )(); 52 53/* 6.0.0: the distribution bars are plain links; wire them to ec_reviews_filter() ( delegated, so AJAX-refreshed lists keep working ). */ 54( function() { 55 document.addEventListener( 'click', function( e ) { 56 var row = e.target && e.target.closest ? e.target.closest( '.ec_review_dist_row' ) : null; 57 if ( ! row ) { return; } 58 e.preventDefault(); 59 var tab = row.closest( '.ec_details_customer_reviews_tab' ); 60 var list = ( tab || document ).querySelector( '.ec_details_customer_review_list' ); 61 if ( ! list ) { return; } 62 ec_reviews_filter( list.getAttribute( 'data-product-id' ), parseInt( row.getAttribute( 'data-rating' ), 10 ) ); 63 } ); 64} )();
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.