1/* 2* Plugin Name: WP Review Pro 3* Plugin URI: http://mythemeshop.com/plugins/wp-review-pro/ 4* Description: Create reviews! Choose from Stars, Percentages, Circles or Points for review scores. Supports Retina Display, WPMU & Unlimited Color Schemes. 5* Author: MyThemesShop 6* Author URI: http://mythemeshop.com/ 7*/ 8( function( $, wpreview, Cookies ) { 9 "use strict"; 10 11 wpreview.initNotificationBar = function() { 12 // Add class to body. 13 if ( $( '#hello-bar' ).length ) { 14 $( 'body' ).addClass( 'has-hello-bar' ); 15 } 16 17 // Move notification bar to after open body tag if is not floating top. 18 $( '#hello-bar.hello-bar--top:not(.hello-bar--floating)' ).prependTo( 'body' ); 19 20 // Add padding top for body. 21 if ( $( '#hello-bar.hello-bar--top.hello-bar--floating' ).length ) { 22 $( 'body' ).css({ paddingTop: $( '#hello-bar' ).height() + 10 }); 23 } 24 }; 25 26 wpreview.getAnimateDuration = function( animation ) { 27 if ( ! animation ) { 28 return 0; 29 } 30 switch ( animation ) { 31 case 'flipOutX': 32 case 'flipOutY': 33 case 'bounceIn': 34 case 'bounceOut': 35 return 750; 36 37 case 'hinge': 38 return 2000; 39 } 40 41 return 1000; 42 }; 43 44 wpreview.openPopup = function( popup ) { 45 if ( ! popup ) { 46 popup = '#wp-review-popup'; 47 } 48 49 $.magnificPopup.open({ 50 items: { 51 src: popup, 52 type: 'inline' 53 }, 54 removalDelay: wpreview.getAnimateDuration( wpreview.popup.animation_out ), 55 callbacks: { 56 beforeOpen: function() { 57 this.st.mainClass = 'animated ' + wpreview.popup.animation_in; 58 }, 59 beforeClose: function() { 60 var $wrap = this.wrap, 61 $bg = $wrap.prev(), 62 $mfp = $wrap.add( $bg ); 63 64 $mfp.removeClass( wpreview.popup.animation_in ).addClass( wpreview.popup.animation_out ); 65 } 66 } 67 }); 68 }; 69 70 wpreview.initPopup = function() { 71 if ( ! $( '#wp-review-popup' ).length ) { 72 return; 73 } 74 75 var popupShown = false, 76 expiration = parseInt( wpreview.popup.expiration ), 77 cookieName = wpreview.popup.cookie_name || 'wpr-popup'; 78 79 function canShowPopup() { 80 if ( popupShown ) { 81 return false; 82 } 83 if ( expiration && Cookies.get( cookieName ) ) { 84 return false; 85 } 86 if ( wpreview.popup.screen_size_check && $( window ).width() <= parseInt( wpreview.popup.screen_width ) ) { 87 return false; 88 } 89 return true; 90 } 91 92 function showPopup() { 93 wpreview.openPopup( '#wp-review-popup' ); 94 95 popupShown = true; 96 97 if ( expiration ) { 98 Cookies.set( cookieName, 1, { 99 expires: expiration // Number of days. 100 }); 101 } 102 } 103 104 // Popup show on load. 105 if ( wpreview.popup.show_on_load ) { 106 var delay = parseInt( wpreview.popup.delay ) * 1000; 107 setTimeout( function() { 108 if ( ! canShowPopup() ) { 109 return; 110 } 111 showPopup(); 112 }, delay ); 113 } 114 115 // Popup show on reaching to bottom. 116 if ( wpreview.popup.show_on_reach_bottom && $( '#wp-review-content-bottom' ).length ) { 117 var offsetTop = $( '#wp-review-content-bottom' ).offset().top; 118 119 $( window ).on( 'scroll', function() { 120 if ( ! canShowPopup() ) { 121 return; 122 } 123 var scrollTop = $( window ).scrollTop(); 124 if ( scrollTop >= offsetTop ) { 125 showPopup(); 126 } 127 }); 128 } 129 130 // Exit intent popup. 131 if ( wpreview.popup.exit_intent ) { 132 $( document ).exitIntent( function() { 133 if ( ! canShowPopup() ) { 134 return; 135 } 136 showPopup(); 137 }); 138 } 139 }; 140 141 wpreview.loadReviews = function( $el, options ) { 142 $el.html( '<div class="loading"></div>' ); 143 function onSuccess( response ) { 144 $el.removeClass( 'js-reviews-placeholder loading' ).html( response ); 145 }; 146 147 function onError( response ) { 148 console.log( response ); 149 }; 150 151 wp.ajax.send( 'wp-review-load-reviews', { 152 success: onSuccess, 153 error: onError, 154 data: options 155 }); 156 }; 157 158 wpreview.ajaxReviewsLoading = function() { 159 $( '.js-reviews-placeholder' ).each( function() { 160 var options = $( this ).attr( 'data-options' ) ? JSON.parse( $( this ).attr( 'data-options' ) ) : {}; 161 wpreview.loadReviews( $( this ), options ); 162 }); 163 164 $( document ).on( 'click', '.reviews-pagination a', function( ev ) { 165 ev.preventDefault(); 166 var $pagination, $reviews, options, page; 167 $pagination = $( this ).closest( '.reviews-pagination' ); 168 $reviews = $pagination.closest( '.wp-reviews-list' ); 169 options = $reviews.attr( 'data-options' ) ? JSON.parse( $reviews.attr( 'data-options' ) ) : {};
170 page = $pagination.attr( 'data-page' ) ? parseInt( $pagination.attr( 'data-page' ) ) : 1; 171 options.page = $( this ).hasClass( 'previous' ) ? ( page - 1 ) : ( page + 1 ); 172 options.no_cache = true; 173 wpreview.loadReviews( $reviews, options ); 174 }); 175 }; 176 177 wpreview.featuresRating = function( $wrapper ) { 178 var data = $wrapper.data(); 179 if ( ! data.rating ) { 180 return; 181 } 182 data.action = 'wpr-visitor-features-rating'; 183 184 $.ajax ({ 185 beforeSend: function() { 186 $wrapper.addClass( 'wp-review-loading' ); 187 }, 188 data: data, 189 type: 'post', 190 url: wpreview.ajaxurl, 191 success: function( response ) { 192 $wrapper.removeClass( 'wp-review-loading' ); 193 if ( typeof response != 'object' ) { 194 response = JSON.parse( response ); 195 } 196 if ( 'ok' != response.status ) { 197 console.error( response ); 198 return; 199 } 200 response.html = response.html.replace( 'delay-animation', '' ); 201 $wrapper.closest( '#review' ).replaceWith( response.html ); 202 203 Cookies.set( 'wpr_visitor_has_reviewed_post_' + data.post_id, 1, { 204 expires: 315360000000 // 10 years. 205 }); 206 }, 207 error: function( response ) { 208 $wrapper.removeClass( 'wp-review-loading' ); 209 console.log( response ); 210 } 211 }); 212 }; 213 214 wpreview.initResponsiveTable = function() { 215 if ( 'function' !== typeof $.fn.stacktable ) { 216 return; 217 } 218 219 $( '.comparison-table' ).stacktable(); 220 }; 221 222 wpreview.addVerifiedPurchase = function() { 223 $( '.wp_review_comment.verified cite, .wp_review_comment.verified .fn' ).after( '<em> ' + wpreview.verifiedPurchase + '</em>' ); 224 }; 225 226 $( document ).ready( function() { 227 wpreview.initNotificationBar(); 228 wpreview.initPopup(); // Maybe need to run on window load. 229 wpreview.ajaxReviewsLoading(); 230 wpreview.initResponsiveTable(); 231 wpreview.addVerifiedPurchase(); 232 233 // $( '[data-ui-tabs]' ).tabs(); 234 235 $( '[data-wp-review-tabs] .tab-title:first-child' ).addClass( 'active' ); 236 $( '[data-wp-review-tabs] .tab-content:first-of-type' ).fadeIn(); 237 238 $( '[data-wp-review-tabs] .tab-title button' ).on( 'click', function( ev ) { 239 ev.preventDefault(); 240 var $btn, $tabs, href; 241 $btn = $( this ); 242 $tabs = $btn.closest( '[data-wp-review-tabs]' ); 243 href = $btn.attr( 'data-href' ); 244 $tabs.find( '.tab-title' ).removeClass( 'active' ); 245 $btn.closest( '.tab-title' ).addClass( 'active' ); 246 $tabs.find( '.tab-content' ).hide(); 247 $tabs.find( href ).fadeIn(); 248 }); 249 250 $( '#commentform' ).on( 'submit', function( ev ) { 251 $( this ).find( '.wpr-error' ).remove(); 252 if ( $( this ).hasClass( 'wpr-uncompleted-rating' ) ) { 253 $( this ).append( '<div class="wpr-error">' + wpreview.rateAllFeatures + '</div>' ); 254 ev.preventDefault(); 255 } 256 }); 257 }); 258})( jQuery, window.wpreview || {}, Cookies ); 259 260jQuery(document).ready(function($) { 261 262 $('.wp-review-comment-field.allowed-to-rate a').on('click', function() { 263 var $this = $(this), 264 $elem = $this.closest('.wp-review-comment-field'); 265 if ($elem.hasClass('allowed-to-rate')) { 266 $elem.removeClass('has-not-rated-yet'); 267 $elem.find('.review-result').css('width', parseInt($this.data('input-value'))*20+'%'); 268 $elem.find('.wp_review_comment_rating').val($this.data('input-value')); 269 } 270 }); 271 272 // animate 273 if ($('.review-wrapper').length) { 274 $('.review-wrapper').wpr_appear().on('wpr_appear', function(event) { 275 // this element is now inside browser viewport 276 var $this = $(this); 277 if ($this.hasClass('delay-animation')) { 278 $this.removeClass('delay-animation'); 279 if ($this.find('.wp-review-circle-rating').length) { 280 $this.find('.wp-review-circle-rating').each(function(index, el) { 281 if ($(el).closest('.wp-review-user-rating').length) 282 return true; // don't animate circle-input 283 284 var initial_value = $(el).data('initial_value'); 285 $({value: 0}).animate({value: initial_value}, { 286 duration: 2000, 287 easing:'swing', 288 step: function() 289 { 290 $(el).val(Math.floor(this.value)).trigger('change'); 291 }, 292 complete: function() { 293 $(el).val(initial_value).trigger('change'); 294 } 295 }); 296 }); 297 } 298 } 299 }).on('wpr_disappear', function(event) { 300 var $this = $(this); 301 //$this.addClass('delay-animation'); // rewind animation 302 }); 303 $(window).load(function() { 304 $.wpr_force_appear(); // if it's right there on window.load 305 }); 306 307 } 308 309 310 var $commentFeedback = $('.wp-review-feedback'); 311 $commentFeedback.on('click', 'a', function(e){ 312 var $this = $(this); 313 314 e.preventDefault(); 315 316 if ( $this.hasClass('voted') || $this.siblings().hasClass('voted') || $commentFeedback.hasClass('processing') ) return; 317 318 $.ajax({ 319 type: 'POST', 320 url: wpreview.ajaxurl, 321 beforeSend: function(){ 322 $commentFeedback.addClass('processing'); 323 }, 324 data: { action: 'mts_review_feedback', isHelpful: $this.data('value'), commentId: $this.data('comment-id') }, 325 success: function(data){ 326 $this.closest('.wp-review-feedback').find('a').removeClass('voted'); 327 $this.addClass('voted').find('.feedback-count').text('('+data+')'); 328 }, 329 error: function(jqXHR){ 330 alert(jqXHR.responseText); 331 },
332 complete: function() { 333 $commentFeedback.removeClass('processing'); 334 } 335 }); 336 }); 337 338 339 /* 340 Add class to comment form 341 */ 342 if ($('#wp-review-comment-title-field').length) { 343 $('#wp-review-comment-title-field').closest('form').addClass('wp-review-comment-form'); 344 } 345 346 $(document).on('click', '.wp-review-comment-img-field a', function(e){ 347 e.preventDefault(); 348 $(this).parents('.wp-review-comment-form-photo').find('.hide').removeClass('hide'); 349 $(this).parent().addClass('hide').find('input').val(''); 350 return false; 351 }); 352 353 $(document).on('change', '.wp-review-comment-attachment-source .input-file', function(e){ 354 e.preventDefault(); 355 var $this = $(this); 356 357 if ($this.parents('.wp-review-comment-form-photo').find('#comment_image_spinner').length != 0) { 358 return; 359 } 360 361 $this.parents('form').find('input[type="submit"]').attr('disabled', 'disabled'); 362 363 $('<i id="comment_image_spinner" class="fa fa-spinner fa-spin"></i>').insertAfter($this.parent('p')); 364 365 var $fd = new FormData(), 366 files = $(this)[0].files[0]; 367 368 $fd.append("files[]", files); 369 $fd.append('action', 'wpr-upload-comment-image'); 370 $fd.append( '_ajax_nonce', wpreview.commentImageUploadNonce ); 371 $.ajax({ 372 type: 'POST', 373 url: wpreview.ajaxurl, 374 processData: false, 375 contentType: false, 376 data: $fd, 377 success: function (response) { 378 if(response) { 379 $this.next('input').val(response); 380 } else { 381 alert('Something went wrong. Please upload different image.'); 382 } 383 $this.parents('form').find('input[type="submit"]').removeAttr('disabled'); 384 $this.parents('.wp-review-comment-form-photo').find('#comment_image_spinner').remove(); 385 }, 386 error: function() { 387 alert('Something went wrong. Please upload different image.'); 388 $this.parents('form').find('input[type="submit"]').removeAttr('disabled'); 389 $this.parents('.wp-review-comment-form-photo').find('#comment_image_spinner').remove(); 390 } 391 }); 392 return false; 393 }); 394 395}); 396 397function wp_review_rate( $elem ) {// rating, postId, nonce ) { 398 var is_comment_rating = ($elem.is('.wp-review-comment-rating-star') || !!$elem.closest('.wp-review-comment-rating-star').length); 399 if ( is_comment_rating ) { 400 return ''; // don't do anything if it's a comment rating element 401 } 402 var rating = $elem.find('.wp-review-user-rating-val').val(); 403 var postId = $elem.find('.wp-review-user-rating-postid').val(); 404 var token = $elem.find('.wp-review-user-rating-nonce').val(); 405 var $target = $elem; 406 407 if ( ! $target.is('.wp-review-user-rating') ) 408 $target = $elem.closest('.wp-review-user-rating'); 409 410 if ( rating == 0 ) { 411 return ''; 412 } 413 414 jQuery.ajax ({ 415 beforeSend: function() { 416 $target.addClass('wp-review-loading'); 417 }, 418 data: { action: 'wp_review_rate', post_id: postId, nonce: token, review: rating }, 419 type: 'post', 420 dataType: 'json', 421 url: wpreview.ajaxurl, 422 success: function( response ){ 423 $target.removeClass('wp-review-loading'); 424 if (typeof response.html !== 'undefined' && response.html != '') { 425 $target.empty().append(response.html).addClass('has-rated').removeClass('wp-review-user-rating'); 426 } 427 428 // update text total 429 if (typeof response.rating_total !== 'undefined' && response.rating_total != '') { 430 $target.parent().find('.wp-review-user-rating-total').text(response.rating_total); 431 } 432 // update rating count 433 if (typeof response.rating_count !== 'undefined' && response.rating_count != '') { 434 $target.parent().find('.wp-review-user-rating-counter').text(response.rating_count); 435 } 436 if ( response.awaiting_moderation != undefined ) { 437 $target.parent().find('.user-total-wrapper .awaiting-response-wrapper').text(response.awaiting_moderation); 438 } 439 440 // Update cookie. 441 Cookies.set( 'wpr_visitor_has_reviewed_post_' + postId, 1, { 442 expires: 315360000000 // 10 years. 443 }); 444 } 445 }); 446}
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.