1function commentFiltering( $, element, order, rating, pageNumber ) { 2 3 var settings = { 4 allow_comment_reviews: element.data( 'allow-comment-reviews' ), 5 show_comment_count_title: element.data( 'show-comment-count-title' ), 6 comment_reply_type: element.data( 'comment-reply-type' ), 7 review_reply_type: element.data( 'review-reply-type' ), 8 avatar_size: { size: element.data( 'avatar-size' ) }, 9 show_verified_user_icon: element.data( 'show-verified-user-icon' ), 10 verified_user_icon_type: element.data( 'verified-user-icon-type' ), 11 verified_user_icon: { value: element.data( 'verified-user-icon' ) }, 12 verified_user_image: { url: element.data( 'verified-user-image' ) }, 13 comment_approval_label: element.data( 'comment-approval-label' ), 14 comment_list_rating_template: element.data( 'comment-list-rating-template' ), 15 allow_up_down_voting: element.data( 'allow-up-down-voting' ), 16 up_down_voting_template: element.data( 'up-down-voting-template' ), 17 reply_link_label: element.data( 'reply-link-label' ), 18 login_reply_link_label: element.data( 'login-reply-link-label' ), 19 comment_count_title_singular: element.data( 'comment-count-title-singular' ), 20 comment_count_title_plural: element.data( 'comment-count-title-plural' ), 21 no_comments_found_label: element.data( 'no-comments-found-label' ), 22 good_points_field_label: element.data( 'good-points-field-label' ), 23 bad_points_field_label: element.data( 'bad-points-field-label' ), 24 good_points_icon: element.data( 'good-points-icon' ), 25 bad_points_icon: element.data( 'bad-points-icon' ), 26 comment_permissions: element.data( 'comment-permissions' ), 27 comment_permission_roles: element.data( 'comment-permission-roles' ) 28 }; 29 30 $.ajax({ 31 type: 'GET', 32 data: { 33 action: 'comment_filtering', 34 postID: element.data( 'post-id' ), 35 userID: element.data( 'user-id' ), 36 settings: settings, 37 order: order, 38 rating: rating, 39 pageNumber: pageNumber, 40 nonce: element.data( 'nonce' ) 41 }, 42 dataType: 'html', 43 url: ghostpool_comment_params.ajax_url, 44 success: function( data, textStatus ) { 45 46 if ( 'success' === textStatus ) { 47 48 // Hide PHP comment pagination 49 $( '.gp-comment-list-wrapper .gp-pagination' ).hide(); 50 51 // Add loading class to comments list 52 $( '.gp-comment-list-wrapper' ).addClass( 'gp-loading' ); 53 54 setTimeout( function() { 55 56 // Add new comment list data 57 var filteredComments = $( data ); 58 $( '.gp-comment-list-inner' ).replaceWith( filteredComments ).removeClass( 'gp-loading' ).fadeIn(); 59 60 //$( '.gp-comments-count-title' ).html( $( data ).find( '.gp-comments-count-title' ) ); 61 62 // Reload ratings script 63 if ( filteredComments.find( '.rating' ).length ) { 64 filteredComments.find( '.rating' ).rating(); 65 } 66 67 $( '.gp-comment-list-wrapper' ).removeClass( 'gp-loading' ); 68 69 }, 800 ); 70 71 } 72 73 }, 74 error: function(e) { 75 //console.log(e); 76 } 77 78 }); 79 80} 81 82jQuery( document ).ready( function( $ ) { 83 84 'use strict'; 85 86 // Review title character limit message 87 $( document ).on( 'keyup', '#gp-review-title', function() { 88 var textLength = $( this ).attr( 'maxlength' ) - $( this ).val().length; 89 $( this ).next( '.gp-character-limit-message' ).find( '.gp-characters-remaining' ).text( textLength ); 90 }); 91 92 // Good points character limit message 93 $( document ).on( 'keyup', '#gp-good-points', function() { 94 var textLength = $( this ).attr( 'maxlength' ) - $( this ).val().length; 95 $( this ).next( '.gp-character-limit-message' ).find( '.gp-characters-remaining' ).text( textLength ); 96 }); 97 98 // Bad points character limit message 99 $( document ).on( 'keyup', '#gp-bad-points', function() { 100 var textLength = $( this ).attr( 'maxlength' ) - $( this ).val().length; 101 $( this ).next( '.gp-character-limit-message' ).find( '.gp-characters-remaining' ).text( textLength ); 102 }); 103 104 105 // Review text character limit message 106 $( document ).on( 'keyup', 'textarea#comment', function() { 107 var textLength = $( this ).attr( 'maxlength' ) - $( this ).val().length; 108 $( this ).next( '.gp-character-limit-message' ).find( '.gp-characters-remaining' ).text( textLength ); 109 }); 110 111 // Remove review title and rating fields from standard replies 112 var reviewTitleField = '', 113 ratingField = '', 114 goodBadPointsField = ''; 115 $( document ).on( 'click touchstart', '.gp-standard-reply a.comment-reply-link', function() { 116 var commentLi = $( this ).closest( 'li' ); 117 reviewTitleField = commentLi.find( '.gp-comment-form-review-title' ).children().detach(); 118 ratingField = commentLi.find( '.gp-form-rating' ).children().detach(); 119 goodBadPointsField = commentLi.find( '.gp-comment-form-good-bad-points' ).children().detach(); 120 }); 121 122 // Readd fields to main comment form when comment cancel link is clicked 123 $( document ).on( 'click touchstart', 'a#cancel-comment-reply-link', function() {
124 if ( '' !== reviewTitleField ) { 125 reviewTitleField.appendTo( '.gp-comment-form-review-title' ); 126 } 127 if ( '' !== ratingField ) { 128 ratingField.appendTo( '.gp-form-rating' ); 129 } 130 if ( '' !== goodBadPointsField ) { 131 goodBadPointsField.appendTo( '.gp-comment-form-good-bad-points' ); 132 } 133 }); 134 135 // Filter comment order 136 $( document ).on( 'change', 'select[name="gp-comment-filter-order-dropdown"]', function() { 137 var element = $( this ).closest( '.gp-comment-filters' ), 138 order = $( this ).val(), 139 rating = ''; 140 if ( $( 'select[name="gp-comment-filter-rating-dropdown"]' ).length ) { 141 rating = $( this ).parent().find( 'select[name="gp-comment-filter-rating-dropdown"]' ).val(); 142 } 143 $( this ).find( 'option[value="' + order + '"]' ).attr( 'selected', 'selected' ); 144 commentFiltering( $, element, order, rating, '' ); 145 return false; 146 }); 147 148 // Filter by comment rating 149 $( document ).on( 'change', 'select[name="gp-comment-filter-rating-dropdown"]', function() { 150 var element = $( this ).closest( '.gp-comment-filters' ), 151 rating = $( this ).val(), 152 order = ''; 153 if ( $( 'select[name="gp-comment-filter-order-dropdown"]' ).length ) { 154 order = $( this ).parent().find( 'select[name="gp-comment-filter-order-dropdown"]' ).val(); 155 } 156 $( this ).find( 'option[value="' + rating + '"]' ).attr( 'selected', 'selected' ); 157 commentFiltering( $, element, order, rating, 1 ); 158 return false; 159 }); 160 161 // Ajax comment pagination 162 $( document ).on( 'click', '.gp-comments-pagination .page-numbers a', function( e ) { 163 164 e.preventDefault(); 165 166 var element = $( this ).closest( '.gp-comment-list-wrapper' ).find( '.gp-comment-filters' ), 167 page_link = $( this ), 168 url = page_link.attr( 'href' ), 169 current_container = page_link.parent(), 170 order = '', 171 rating = ''; 172 173 var pageNumber = ''; 174 if ( page_link.hasClass( 'prev' ) ) { 175 pageNumber = url.split('/comment-page-')[1].split( '/' )[0]; 176 } else if ( page_link.hasClass( 'next' ) ) { 177 pageNumber = url.split('/comment-page-')[1].split( '/' )[0]; 178 } else { 179 pageNumber = page_link.text(); 180 } 181 182 if ( $( 'select[name="gp-comment-filter-order-dropdown"]' ).length ) { 183 order = element.find( 'select[name="gp-comment-filter-order-dropdown"]' ).val(); 184 } 185 186 if ( $( 'select[name="gp-comment-filter-rating-dropdown"]' ).length ) { 187 rating = element.find( 'select[name="gp-comment-filter-rating-dropdown"]' ).val(); 188 } 189 190 page_link.attr( 'href', '#' ); 191 192 commentFiltering( $, element, order, rating, pageNumber ); 193 194 return false; 195 196 }); 197 198 // Submitting comment form 199 $( 'body' ).on( 'submit', '.comments-area #commentform', function( e ) { 200 201 e.preventDefault(); 202 203 var commentForm = $( this ), 204 commentElement = $( this ).closest( '.gp-element-comments' ), 205 action = commentForm.attr( 'action' ), 206 formData = commentForm.serializeArray(), 207 nameField = commentForm.find( '#author' ), 208 emailField = commentForm.find( '#email' ), 209 reviewTitleField = commentForm.find( '#gp-review-title' ), 210 ratingField = commentForm.find( '.gp-element-add-rating' ), 211 goodPointsField = commentForm.find( '#gp-good-points' ), 212 badPointsField = commentForm.find( '#gp-bad-points' ), 213 gp_comment_element_params = commentForm.find( '.gp_comment_element_params' ).data( 'params' ), 214 ratingInputField = commentForm.find( '.gp-element-add-rating .rating' ), 215 commentField = commentForm.find( '#comment' ), 216 hasError = false; 217 218 // Hide success/error messages upon comment submission 219 commentForm.find( '.gp-comment-success-message' ).hide(); 220 commentElement.find( '.gp-comment-error-message' ).hide(); 221 nameField.removeClass( 'gp-required' ); 222 emailField.removeClass( 'gp-required' ); 223 reviewTitleField.removeClass( 'gp-required' ); 224 ratingField.removeClass( 'gp-required' ); 225 goodPointsField.removeClass( 'gp-required' ); 226 badPointsField.removeClass( 'gp-required' ); 227 commentField.removeClass( 'gp-required' ); 228 commentForm.addClass( 'gp-loading' ); 229 230 // Check if name field is empty 231 if ( nameField.length && ( nameField.val() === '' && ( 'true' === nameField.attr( 'aria-required' ) || nameField.attr( 'required' ) ) && ! commentform.closest( 'ol' ).hasClass( 'comment-list' ) ) ) { 232 nameField.addClass( 'gp-required' ); 233 hasError = true; 234 } 235 236 // Check if email field is empty 237 if ( emailField.length && ( emailField.val() === '' && ( 'true' === emailField.attr( 'aria-required' ) || emailField.attr( 'required' ) ) && ! commentform.closest( 'ol' ).hasClass( 'comment-list' ) ) ) { 238 emailField.addClass( 'gp-required' ); 239 hasError = true; 240 } 241 242 // Check if review title field is empty 243 if ( '' === reviewTitleField.val() && 'true' === reviewTitleField.attr( 'required' ) && ! commentForm.closest( 'ol' ).hasClass( 'comment-list' ) ) { 244 reviewTitleField.addClass( 'gp-required' ); 245 hasError = true; 246 } 247 248 // Check if good points field is empty 249 if ( '' === goodPointsField.val() && 'true' === goodPointsField.attr( 'required' ) && ! commentForm.closest( 'ol' ).hasClass( 'comment-list' ) ) { 250 goodPointsField.addClass( 'gp-required' ); 251 hasError = true; 252 } 253 254 // Check if bad points field is empty 255 if ( '' === badPointsField.val() && 'true' === badPointsField.attr( 'required' ) && ! commentForm.closest( 'ol' ).hasClass( 'comment-list' ) ) { 256 badPointsField.addClass( 'gp-required' ); 257 hasError = true; 258 } 259 260 // Check if rating field is empty 261 if ( ratingField.length && ratingField.closest( '.gp-form-rating' ).hasClass( 'gp-required' ) && ! commentForm.closest( 'ol' ).hasClass( 'comment-list' ) ) { 262 263 ratingInputField.each( function( index ) { 264
265 var ratingValue = parseFloat( $( this ).val() ); 266 267 // Set rating to zero if rating is empty 268 if ( '' === ratingValue || 0 === ratingValue ) { 269 hasError = true; 270 ratingField.addClass( 'gp-required' ); 271 return false; 272 } 273 274 // Prevent rating lower than minimum 275 if ( ratingValue < ratingField.data( 'min-rating' ) ) { 276 hasError = true; 277 ratingField.addClass( 'gp-required' ); 278 return false; 279 } 280 281 // Prevent rating higher than maximum 282 if ( ratingValue > ratingField.data( 'max-rating' ) ) { 283 hasError = true; 284 ratingField.addClass( 'gp-required' ); 285 return false; 286 } 287 288 // Final check to make sure a valid rating is being submitted 289 if ( ! $.isNumeric( ratingValue ) ) { 290 hasError = true; 291 ratingField.addClass( 'gp-required' ); 292 return false; 293 } 294 295 }); 296 297 } 298 299 // Check if comment field is empty 300 if ( commentField.val() === '' ) { 301 commentField.addClass( 'gp-required' ); 302 hasError = true; 303 } 304 305 // Show error messages if there is an error 306 if ( true === hasError ) { 307 308 // Show error messages 309 setTimeout( function() { 310 commentForm.removeClass( 'gp-loading' ); 311 commentElement.find( '.gp-comment-success-message' ).hide(); 312 commentElement.find( '.gp-comment-error-message' ).text( commentElement.data( 'error-message' ) ).css({ opacity: 0, display: 'block' }).animate({ opacity:1 }, 600 ); 313 }, 800 ); 314 315 } else { 316 317 // If there's no error, submit comment 318 $.ajax({ 319 type: 'post', 320 url: action, 321 clearForm: true, 322 data: formData, 323 beforeSend: function() {}, 324 success: function( data, textStatus ) { 325 326 if ( textStatus === 'success' ) { 327
328 // Submit comment rating 329 if ( commentElement.find( '.rating' ).length && $.isFunction( window.submitRating ) ) { 330 submitRating( $, ratingField ); 331 } 332 333 // Prevent another rating being sent 334 commentForm.find( 'input, textarea' ).attr( 'disabled', true ); 335 commentForm.find( '.rating' ).attr( 'data-readonly', '' ); 336 337 // Reload comment list from ajax data 338 commentElement.find( '.gp-comment-list' ).replaceWith( $( data ).find( '.comments-area .gp-comment-list' ) ); 339 340 console.log(data); 341 342 // Reload comment form from ajax data 343 if ( commentElement.find( '#wp-temp-form-div' ).length ) { 344 // If reply comment form 345 commentElement.find( '#wp-temp-form-div' ).replaceWith( $( data ).find( '.comments-area #respond' ) ); 346 } else { 347 // If main comment form 348 commentElement.find( '#respond' ).replaceWith( $( data ).find( '.comments-area #respond' ) ); 349 } 350 351 // Reload ratings script 352 if ( commentElement.find( '.rating' ).length ) { 353 commentElement.find( '.rating' ).rating(); 354 } 355 356 // Add loading class to comment form 357 commentElement.find( '#respond' ).addClass( 'gp-loading' ); 358 359 // Hide already voted messages from showing 360 commentElement.find( '.gp-already-voted' ).hide(); 361 362 // If it's a not a normal reply comment, proceed to update comment breakdown 363 if ( ! commentForm.closest( 'li' ).hasClass( 'gp-standard-reply' ) && $( '.gp-element-show-rating-breakdown' ).length ) { 364 365 var breakdownContainer = $( '.gp-element-show-rating-breakdown' ), 366 postID = breakdownContainer.data( 'post-id' ), 367 maxRating = parseFloat( breakdownContainer.data( 'max-rating' ) ), 368 fractions = parseFloat( breakdownContainer.data( 'fractions' ) ), 369 decimalPlaces = parseFloat( breakdownContainer.data( 'decimal-places' ) ) + 1, 370 ratingSum = parseFloat( breakdownContainer.data( 'rating-sum' ) ), 371 userVotes = parseFloat( breakdownContainer.data( 'user-votes' ) ), 372 userVotesSingularLabel = breakdownContainer.data( 'user-votes-singular-label' ), 373 userVotesPluralLabel = breakdownContainer.data( 'user-votes-plural-label' ), 374 breakdownAverageRating = breakdownContainer.find( '.gp-breakdown-average-rating' ); 375 376 if ( commentElement.find( '.gp-comment-list > li:last-child .rating' ).length ) { 377 var submittedAverageRating = parseFloat( commentElement.find( '.gp-comment-list > li:last-child .rating' ).val() ); 378 } else if ( commentElement.find( '.gp-comment-list > li:last-child .gp-actual-rating' ).length ) { 379 var submittedAverageRating = parseFloat( commentElement.find( '.gp-comment-list > li:last-child .gp-actual-rating' ).text() ); 380 } 381 // Add submitted user rating to current rating sum 382 var newRatingSum = ratingSum + submittedAverageRating; 383 384 // Add 1 to user votes and update user votes text 385 var newUserVotes = userVotes + 1; 386 387 // Get new average rating for post 388 var newPostAverageRatingRaw = newRatingSum / newUserVotes, 389 newPostAverageRating = parseFloat( newPostAverageRatingRaw ).toPrecision( decimalPlaces ); 390 391 // Dynamically update average rating values and user votes 392 breakdownAverageRating.find( '.gp-actual-rating' ).text( newPostAverageRating ); 393 if ( newUserVotes == 1 ) { 394 var userVotesText = ' ' + userVotesSingularLabel; 395 } else { 396 userVotesText = ' ' + userVotesPluralLabel; 397 } 398 breakdownAverageRating.find( '.gp-user-votes-text' ).text( newUserVotes + userVotesText ); 399 breakdownAverageRating.data( 'user-votes', newUserVotes ); 400 401 // Update average rating 402 if ( breakdownAverageRating.find( '.rating' ).length ) { 403 breakdownAverageRating.find( '.rating' ).rating( 'rate', newPostAverageRating ); 404 } 405 406 // Update each breakdown bar 407 $( '.gp-breakdown-entry' ).each( function( index ) { 408 409 var breakdownEntry = $( this ), 410 breakdownRating = parseFloat( breakdownEntry.find( '.gp-breakdown-rating' ).text() ); 411 412 // Dynamically update breakdown rating count 413 if ( submittedAverageRating === breakdownRating ) { 414 var currentRatingCount = parseFloat( breakdownEntry.attr( 'data-current-rating-count' ) ); 415 currentRatingCount = currentRatingCount + 1; 416 breakdownEntry.attr( 'data-current-rating-count', currentRatingCount ); 417 } else { 418 currentRatingCount = parseFloat( breakdownEntry.attr( 'data-current-rating-count' ) ); 419 } 420 421 // Dynamically update breakdown bar 422 var breakdownBarValue = ( currentRatingCount > 0 && newUserVotes > 0 ) ? ( currentRatingCount / newUserVotes ) * maxRating : 0; 423 if ( breakdownEntry.find( '.rating' ).length ) { 424 breakdownEntry.find( '.rating' ).rating( 'rate', breakdownBarValue ); 425 } 426 427 // Dynamically update breakdown percentage 428 if ( currentRatingCount > 0 && newUserVotes > 0 ) { 429 var percentage = Math.round( ( currentRatingCount / newUserVotes ) * 100 ); 430 } else { 431 percentage = 0; 432 } 433 breakdownEntry.find( '.gp-breakdown-percentage' ).text( percentage + '%' ); 434 435 }); 436 437 } 438 439 // Reload comments 440 setTimeout( function() { 441 442 // Hide comment form components 443 if ( 'yes' != commentElement.data( 'multiple-comments' ) ) { 444 commentElement.find( '#respond' ).hide(); 445 } else if ( 'yes' != commentElement.data( 'multiple-ratings' ) ) { 446 commentElement.find( '.gp-comment-form-review-title' ).hide(); 447 commentElement.find( '.gp-form-rating' ).hide(); 448 } 449 450 // Remove loading class from comment form 451 commentElement.find( '#respond' ).removeClass( 'gp-loading' ); 452 453 // Show success message 454 commentElement.find( '.gp-comment-success-message' ).css({ opacity: 0, display: 'block' }).animate({ opacity:1 }, 300 ); 455 456 }, 800 ); 457 458 } 459 460 }, 461 error: function( xhr, textStatus, errorThrown ) { 462 463 //console.log( xhr, textStatus, errorThrown ); 464 465 // Show error messages 466 setTimeout( function() { 467 commentForm.removeClass( 'gp-loading' ); 468 commentElement.find( '.gp-comment-success-message' ).hide(); 469 commentElement.find( '.gp-comment-error-message' ).text( commentElement.data( 'duplicate-comments-message' ) ).css({ opacity: 0, display: 'block' }).animate({ opacity: 1 }, 600 ); 470 }, 800 ); 471 472 } 473 }); 474 475 } 476 477 return false;
478 479 }); 480 481});
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.