Файл: adultscript-2.0.3-pro/files/templates/defboot/js/photo.js
Строк: 242
<?php
$(document).ready(function() {
var photo_id = $("input[name='photo_id']").val();
$("#image").hover(
function() {
var height = $("#image").height();
var half = height/2;
$("a[id='prev']").css('top', half + 'px');
$("a[id='next']").css('top', half + 'px');
$("a[id='next']").css('right', '3px');
$("a[id='prev']").show();
$("a[id='next']").show();
}, function() {
$("a[id='prev']").hide();
$("a[id='next']").hide();
}
);
$("button[id='like'],button[id='dislike']").click(function(e) {
e.preventDefault();
var rating = 1;
if ($(this).attr('id') == 'dislike') {
rating = 0;
}
$.ajax({
url: base_url + '/ajax.php?s=photo_rate',
cache: false,
type: "POST",
dataType: "json",
data: {photo_id: photo_id, rating: rating},
success: function(response) {
if (response.status == '1') {
var color = 'text-success';
var id = 'like-icon';
if (rating == '0') {
color = 'text-muted';
id = 'dislike-icon';
}
$("i[id='" + id + "']").addClass(color);
$("button[id='rating']").html(response.code);
$("button[id='like'],button[id='dislike']").prop('disabled', true);
} else {
$("#response").html(close + response.msg);
$("#response").removeClass('alert-success').addClass('alert-danger');
$("#response").show();
}
}
});
});
$("button[id='share']").click(function(e) {
e.preventDefault();
if ($("#share-container").is(':visible')) {
$("#share-container").hide();
} else {
$("#share-container").show();
}
});
$("button[id='favorite']").click(function(e) {
e.preventDefault();
$.ajax({
url: base_url + '/ajax.php?s=photo_favorite',
cache: false,
type: "POST",
dataType: "json",
data: {photo_id: photo_id},
success: function(response) {
if (response.status == '1') {
$("i[id='favorite-icon']").addClass('text-danger');
$("button[id='favorite']").prop('disabled', true);
$("span[id='total-favorites']").text(response.total);
} else {
$("#response").html(close + response.msg);
$("#response").removeClass('alert-success').addClass('alert-danger');
$("#response").show();
}
}
});
});
$("button[id='report']").click(function(e) {
e.preventDefault();
$.get(base_url + '/ajax.php?s=photo_report&modal=1', function(response) {
$("#report-container").removeClass();
$("#report-container").html(response);
$("#report-container").show();
$("#report-modal").modal();
});
});
$("#report-container").on('click', '#report-send', function() {
var reason = $("input[name='reason']").val();
var message = $("textarea[name='message']").val();
$.ajax({
url: base_url + '/ajax.php?s=photo_report',
cache: false,
type: "POST",
dataType: "json",
data: {photo_id: photo_id, reason: reason, message: message},
success: function(response) {
$("#report-modal").modal('hide');
if (response.status == '1') {
$("button[id='report']").addClass('text-success');
$("button[id='report']").prop('disabled', true);
} else {
$("#response").html(close + response.msg);
$("#response").removeClass('alert-success').addClass('alert-danger');
$("#response").show();
}
}
});
});
$("button[id='post-comment']").click(function(e) {
e.preventDefault();
var comment = $("textarea[name='comment']").val();
var nickname = $("input[name='nickname']").val();
var error = false;
var message = 'Your message has been posted!';
if (comment == '') {
message = 'Please enter your comment!';
error = true;
} else if (comment.length > 500) {
message = 'Comment can contain maximum 500 characters!';
error = true;
}
if (error) {
$("#response-comment").html(message);
$("#response-comment").removeClass('alert-succes').addClass('alert-danger');
$("#response-comment").show();
}
$.ajax({
url: base_url + '/ajax.php?s=photo_comment',
cache: false,
type: "POST",
dataType: "json",
data: { photo_id: photo_id, comment: comment, nickname: nickname },
success: function(response) {
if (response.status == '1') {
$("input[id='nickname']").val();
$("textarea[name='comment']").val('');
$("#total-comments").text(response.total);
$("#no-comments").hide();
$("#comments-container").prepend(response.code);
$("#response-comment").removeClass('alert-danger').addClass('alert-success');
} else {
$("#response-comment").removeClass('alert-success').addClass('alert-danger');
}
$("#response-comment").html(close + response.msg);
$("#response-comment").show();
}
});
});
$("#comments-container").on('click', "button[id^='comment-delete-']", function(e) {
e.preventDefault();
var comment_id = $(this).attr('id').match(/comment-delete-(.*)/)[1];
$.ajax({
url: base_url + '/ajax.php?s=photo_comment_delete',
cache: false,
type: "POST",
dataType: "json",
data: { comment_id: comment_id },
success: function(response) {
if (response.status == '1') {
$("#comment-" + comment_id).css('border', '1px solid red');
$("#comment-" + comment_id).fadeOut(1000);
}
if (!$(".media:visible").length) {
$("#comments-container").html('<div id="no-comments" class="none">No comments yet!</div>');
}
}
});
});
$("button[id='comment-pagination']").click(function(e) {
e.preventDefault();
var page = $("input[name='comment-page']").val();
$.ajax({
url: base_url + '/ajax.php?s=photo_comment_pagination',
cache: false,
type: "POST",
dataType: "json",
data: { photo_id: photo_id, page: page },
success: function(response) {
if (response.status == '1') {
$("input[name='comment-page']").val(response.page);
$("#comments-container").append(response.code);
if (response.end == '1') {
$("button[id='comment-pagination']").fadeOut();
}
}
}
});
});
});
?>