File: /home4/cca63905/public_html/nueva/modules/pmproductvideoreviews/views/js/pmproductvideoreviews.js
/**
* rec.reviews
*
* @author Presta-Module.com <support@presta-module.com> - https://www.presta-module.com
* @copyright Presta-Module - https://www.presta-module.com
* @license see file: LICENSE.txt
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*/
$(document).ready(function () {
// Init the player by default
initPlayer();
// Init the scroll top
$("#pvr_go_top").bind("click", function () {
var targetOffset = $("#pm_div-page-review-list").offset().top;
$("html, body").animate({ scrollTop: targetOffset }, 500);
});
});
window.onload = function () {
// handle the sort review on the product page
$("#pm_sort-reviews").bind("change", function (event) {
var moreDisplayDefault = $("input[name=pvr_show_more_value_default]").val();
$.ajax({
type: "POST",
url: pmproductvideoreviews.ajaxUrl,
dataType: "json",
data: {
ajax: 1,
action: "sortReview",
idProduct: $("#pm_video_review_id_product").val(),
pvrRwSort: $(this).children("option:selected").val(),
iShowMore: moreDisplayDefault,
token: pmproductvideoreviews.token,
},
success: function (jsonData) {
$.getScript(pmproductvideoreviews.pvr_script);
$("#pvr-reviews-container").html();
$("#pvr-reviews-container").html(jsonData.outputHTML);
$("#pm-pvr-see-more-content").show();
if (parseInt(moreDisplayDefault) > 4) {
$("#pvr_go_top").removeClass('hidden-xs-up');
$("#pvr_see_less").removeClass('hidden-xs-up');
}
},
});
});
// handle show more on the product page
$("#pm-pvr-see-more").bind("click", function (event) {
var moreDisplay = $("input[name=pvr_show_more_value]").val();
var totalReview = $("input[name=pvr_total_reviews]").val();
//reset the value
$("#pm-pvr-see-more-content").hide();
$("#pm-pvr-loader_more").show();
$.ajax({
type: "POST",
url: pmproductvideoreviews.ajaxUrl,
dataType: "json",
data: {
ajax: 1,
action: "seeMore",
idProduct: $("#pm_video_review_id_product").val(),
pvrRwSort: $("#pm_sort-reviews").children("option:selected").val(),
iShowMore: moreDisplay,
token: pmproductvideoreviews.token,
},
success: function (jsonData) {
$("#pvr-reviews-container").html();
$("#pvr-reviews-container").html(jsonData.outputHTML);
$("#pm-pvr-see-more-content").show();
$("#pm-pvr-loader_more").hide();
$(".pvr_review_container-block").css("height", "100%");
$("#pm-pvr-see-more").show();
$("#pvr_go_top").removeClass('hidden-xs-up');
$("#pvr_see_less").removeClass('hidden-xs-up');
var targetOffset = $("#pvr_scroll_reviews_bottom").offset().top - 250;
$("html, body").animate({ scrollTop: targetOffset }, 500);
// Adapt the size of progress to prevent scroll cut
if ($(window).width() > 1024) {
$(".progress-distrib").css("max-width", "330px");
}
if (parseInt(totalReview) <= parseInt(moreDisplay)) {
$("#pm-pvr-see-more").hide();
}
initPlayer();
},
});
});
// Handle the see less click
$("#pvr_see_less").bind("click", function (event) {
$("#pm-pvr-loader-text").show();
$("#pm-pvr-see-more-content_less").hide();
var totalReview = $("input[name=pvr_total_reviews]").val();
var moreDisplay = 4;
$.ajax({
type: "POST",
url: pmproductvideoreviews.ajaxUrl,
dataType: "json",
data: {
ajax: 1,
action: "seeMore",
idProduct: $("#pm_video_review_id_product").val(),
pvrRwSort: $("#pm_sort-reviews").children("option:selected").val(),
iShowMore: 4,
token: pmproductvideoreviews.token,
},
success: function (jsonData) {
$("#pvr-reviews-container").html();
$("#pvr-reviews-container").html(jsonData.outputHTML);
$("#pm-pvr-see-more-content_less").show();
$("#pm-pvr-loader-text").hide();
$(".pvr_review_container-block").css("height", "100%");
$("#pm-pvr-see-more").show();
$("#pvr_go_top").addClass('hidden-xs-up');
$("#pvr_see_less").addClass('hidden-xs-up');
var targetOffset = $("#pm_div-page-review-list").offset().top;
$("html, body").animate({ scrollTop: targetOffset }, 500);
// Adapt the size of progress to prevent scroll cut
if ($(window).width() > 1024) {
$(".progress-distrib").css("max-width", "330px");
}
if (parseInt(totalReview) <= parseInt(moreDisplay)) {
$("#pm-pvr-see-more").hide();
}
initPlayer();
},
});
});
};
/** Function to stop hasPlaying video on the DOM **/
function hasPlayingVideo() {
$(".pvr-video-player").each(function (index) {
var videoPlayer = this;
let reviewId = $(this).attr("data-rtg-id");
$("a#review-data-" + reviewId).css("display", "block");
$(this).prop("controls", false);
var is_safari = false;
if(navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')){
is_safari = true;
}
if (is_safari === false) {
videoPlayer.load();
}
});
$(".pvr-video-player-battle").each(function (index) {
var videoPlayer = this;
let reviewId = $(this).attr("data-rtg-id");
$("a#battle-review-data-" + reviewId).css("display", "block");
$(this).prop("controls", false);
var is_safari = false;
if(navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')){
is_safari = true;
}
if (is_safari === false) {
videoPlayer.load();
}
});
}
/** Function init the video player */
function initPlayer() {
$(".pvr-video-player").each(function (index) {
$(this).on("click", function (event) {
// Check if video is running before start a new one
hasPlayingVideo();
// Start the video
var videoPlayer = this;
videoPlayer.play();
let reviewId = $(this).attr("data-rtg-id");
videoPlayer.onplaying = function () {
// Display video controls
$(this).prop("controls", true);
$("a#review-data-" + reviewId).css("display", "none");
};
videoPlayer.addEventListener("ended", (event) => {
$("a#review-data-" + reviewId).css("display", "block");
$(this).prop("controls", false);
var is_safari = false;
if(navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')){
is_safari = true;
}
if (is_safari === false) {
videoPlayer.load();
}
});
});
});
// handle video player on product page
$(".pvr-video-player-battle").each(function (index) {
$(this).on("click", function (event) {
// Check if video is running before start a new one
hasPlayingVideo();
// Start the video
var videoPlayer = this;
videoPlayer.play();
let reviewId = $(this).attr("data-rtg-id");
// Display video controls
videoPlayer.onplaying = function () {
// Display video controls
$(this).prop("controls", true);
$("a#battle-review-data-" + reviewId).css("display", "none");
};
// Handle event at the end of the video playing
videoPlayer.addEventListener("ended", (event) => {
$("a#battle-review-data-" + reviewId).css("display", "block");
$(this).prop("controls", false);
var is_safari = false;
if(navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')){
is_safari = true;
}
if (is_safari === false) {
videoPlayer.load();
}
});
});
});
}