1/** 2 * ShareThis Reviews 3 * 4 * @package ShareThis_Reviews 5 */ 6 7document.addEventListener("DOMContentLoaded", function() { 8 const container = document.querySelector( '.review-section-wrap' ); 9 const impContainer = document.querySelector( '.impression-wrap' ); 10 11 if ( container ) { 12 const submitReview = container.querySelector( '#submit-user-review' ); 13 const submitRating = container.querySelector( '#submit-user-rating' ); 14 15 if ( submitReview ) { 16 submitReview.addEventListener( 'click', e => { 17 e.preventDefault(); 18 e.stopPropagation(); 19 20 const review = e.currentTarget.parentNode.querySelector( 'textarea' ).value, 21 title = e.currentTarget.parentNode.querySelector( '#title' ).value, 22 name = 0 !== document.querySelector( '#name' ).length ? e.currentTarget.parentNode.querySelector( '#name' ).value : '', 23 rating = 0 !== document.querySelector( 'input[name="st-review-rating"]' ).length + 1 ? document.querySelector( 'input[name="st-review-rating"]:checked' ).value : ''; 24 25 stAddReview( review, title, rating, name ); 26 } ); 27 } 28 29 if ( submitRating ) { 30 submitRating.addEventListener( 'click', e => { 31 var name = 0 !== document.querySelector( '#name' ).length ? e.currentTarget.siblings( '#name' ).val() : '', 32 rating = $( 'input[name="st-review-rating"]:checked' ).val(); 33 34 stAddRating( rating, name ); 35 } ); 36 } 37 38 if ( impContainer ) { 39 impContainer.querySelector( '.st-impression' ).on( 'click', e => { 40 const overallImpression = e.currentTarget.parentNode.querySelector( '.overall-impression' ); 41 const impression = e.currentTarget.getAttribute( 'data-imp' ), 42 count = parseInt( overallImpression.innerHTML ) + 1, 43 impressioned = document.getCookie( 'st-impression' ); 44 45 if ( '' === impressioned ) { 46 47 // Add one to count. 48 overallImpression.innerHTML = count; 49 50 stAddImpression( impression ); 51 } 52 } ); 53 } 54 55 const starsHearts = container.querySelectorAll( '.stars input[type="radio"], .hearts input[type="radio"]' ); 56 57 if ( starsHearts ) { 58 starsHearts.forEach( starsHeart => { 59 starsHeart.addEventListener( 'click', e => { 60 const number = parseInt( e.currentTarget.value ) + 1; 61 let i = 0; 62 63 document.querySelector( '.review-section-wrap .rating-wrap .rating-icon svg path' ).setAttribute( 'style', '' ); 64 65 for ( i = number; i <= 5; i++ ) { 66 document.querySelector( '#sharethis-rating-' + i ).parentNode.querySelector( 'label .symbol-icon-wrap svg path' ).style.fill = 'currentColor'; 67 } 68 } ); 69 } ); 70 } 71 72 // Open review form. 73 container.querySelector( '#open-review-form' ).addEventListener( 'click', e => { 74 e.currentTarget.style.display = 'none'; 75 76 setTimeout( function () { 77 document.querySelector( '.review-hidden-wrap' ).style.display = 'block'; 78 }, 500 ); 79 } ); 80 } 81 82 /** 83 * Add review to current post. 84 * 85 * @param review 86 * @param title 87 * @param rating 88 * @param name 89 */ 90 function stAddReview( review, title, rating, name ) { 91 const data = new FormData(); 92 93 data.append('rating', rating); 94 data.append('postid', window.postid); 95 data.append('review', review); 96 data.append('title', title); 97 data.append('name', name); 98 data.append('nonce', window.nonce); 99 data.append('action', 'add_review'); 100 101 window.fetch(window.ajaxurl, { 102 method: 'POST', 103 credentials: 'same-origin', 104 body: data 105 }).then(() => { 106 document.querySelector( 'input[name="st-review-rating"]' ).setAttribute( 'checked', false ); 107 document.querySelector( '.review-section-wrap textarea' ).value = ''; 108 document.querySelector( '.review-section-wrap input' ).value = ''; 109 window.location.reload(); 110 }); 111 } 112 113 /** 114 * Add rating to current post. 115 * 116 * @param rating 117 * @param name 118 */ 119 function stAddRating( rating, name ) { 120 const data = new FormData(); 121 122 data.append('rating', rating); 123 data.append('postid', window.postid); 124 data.append('name', name); 125 data.append('nonce', window.nonce); 126 data.append('action', 'add_rating'); 127 128 window.fetch(window.ajaxurl, { 129 method: 'POST', 130 credentials: 'same-origin', 131 body: data 132 }).then(() => { 133 document.querySelector( 'input[name="st-review-rating"]' ).setAttribute('checked', true); 134 document.querySelector( '.review-section-wrap input' ).value = ''; 135 window.location.reload(); 136 }); 137 } 138 139 /** 140 * Add impression to current post. 141 * 142 * @param impression 143 */ 144 function stAddImpression( impression ) { 145 const d = new Date(); 146 147 d.setTime(d.getTime() + (30*24*60*60*1000)); 148 const expires = "expires="+ d.toUTCString(); 149 const data = new FormData(); 150 151 data.append('impression', impression); 152 data.append('postid', window.postid); 153 data.append('nonce', window.nonce); 154 data.append('action', 'add_impression'); 155 156 window.fetch(window.ajaxurl, { 157 method: 'POST', 158 credentials: 'same-origin', 159 body: data 160 }).then(() => { 161 document.cookie = 'st-impression=true; ' + expires + '; path=/'; 162 }); 163 } 164} );
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.