2022-12-11 13:55:49 +05:00
|
|
|
|
/*добавляем коментарий*/
|
2023-02-13 16:05:33 +05:00
|
|
|
|
$('#add_comment').submit(function(event) {
|
2022-12-11 13:55:49 +05:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
var formData = new FormData(this);
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST', // Тип запроса
|
2023-02-13 16:05:33 +05:00
|
|
|
|
url: '/act/page', // Скрипт обработчика
|
2022-12-11 13:55:49 +05:00
|
|
|
|
data: formData, // Данные которые мы передаем
|
|
|
|
|
cache: false, // В запросах POST отключено по умолчанию, но перестрахуемся
|
|
|
|
|
contentType: false, // Тип кодирования данных мы задали в форме, это отключим
|
|
|
|
|
processData: false,
|
|
|
|
|
success: function(data) {
|
|
|
|
|
// alert(data);
|
|
|
|
|
console.log(data);
|
|
|
|
|
/* printMessage('#result', data);*/
|
|
|
|
|
},
|
|
|
|
|
error: function(data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-13 16:05:33 +05:00
|
|
|
|
$("textarea").val('');
|
2022-12-11 13:55:49 +05:00
|
|
|
|
$("#div-commen-add").removeClass("hidden");
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-13 16:05:33 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
11.02.2023
|
|
|
|
|
Модерируем коментарии
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
$(".moder").click(function(event) {
|
|
|
|
|
var id=$(this).data("id");
|
|
|
|
|
var tip=$(this).data("tip");
|
|
|
|
|
$(".comment-" + id).addClass("hidden");
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST', // Тип запроса
|
|
|
|
|
url: '/act/blog_moder_comments', // Скрипт обработчика
|
|
|
|
|
data: "act=moder&tip=" + tip + "&id=" + id, // Данные которые мы передаем
|
|
|
|
|
success: function(data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2022-12-11 13:55:49 +05:00
|
|
|
|
/* Скрываем уведомление о модерации */
|
|
|
|
|
|
|
|
|
|
$("#textarea_txt").click(function(event) {
|
|
|
|
|
$("#div-commen-add").addClass("hidden");
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/* Удаление коментариев */
|
|
|
|
|
|
|
|
|
|
$(".a_del_comment").click(function(event) {
|
|
|
|
|
|
|
|
|
|
var id = $(this).attr('href');
|
|
|
|
|
$("#div-comment-id-" + id).hide("800");
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Кнопка лайка */
|
|
|
|
|
function setlike(i) {
|
|
|
|
|
if (i == '1') {
|
|
|
|
|
var a = Number.parseInt($("#likes").text()) + 1;
|
|
|
|
|
$("#likes").text(a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$('a.like-btn').click(function(event) {
|
|
|
|
|
var id = $(this).data('id');
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST', // Тип запроса
|
|
|
|
|
url: '/act/page', // Скрипт обработчика
|
|
|
|
|
data: 'id=' + id + '&act=like', // Данные которые мы передаем
|
|
|
|
|
success: function(data) {
|
|
|
|
|
setlike(data);
|
|
|
|
|
/* printMessage('#result', data);*/
|
|
|
|
|
},
|
|
|
|
|
error: function(data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//Лайки комментам:
|
|
|
|
|
$('.r_comment').click(function(event) {
|
|
|
|
|
//alert(1);
|
|
|
|
|
var id = $(this).data('id'); //ид коммента
|
|
|
|
|
var r = $(this).data('r'); // текущий рейтинг
|
|
|
|
|
var t = $(this).data('t'); // up/down
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST', // Тип запроса
|
|
|
|
|
url: '/act/page', // Скрипт обработчика
|
|
|
|
|
data: 'id=' + id + '&r=' + r + '&t=' + t + '&act=r_comment', // Данные которые мы передаем
|
|
|
|
|
success: function(data) {
|
|
|
|
|
$("#r_comment_" + id).text(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/* загрузчик изображений */
|
|
|
|
|
// ************************ Drag and drop ***************** //
|
|
|
|
|
let dropArea = document.getElementById("drop-area")
|
|
|
|
|
|
|
|
|
|
// Prevent default drag behaviors
|
|
|
|
|
;
|
|
|
|
|
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
|
|
|
|
dropArea.addEventListener(eventName, preventDefaults, false)
|
|
|
|
|
document.body.addEventListener(eventName, preventDefaults, false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Highlight drop area when item is dragged over it
|
|
|
|
|
;
|
|
|
|
|
['dragenter', 'dragover'].forEach(eventName => {
|
|
|
|
|
dropArea.addEventListener(eventName, highlight, false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
['dragleave', 'drop'].forEach(eventName => {
|
|
|
|
|
dropArea.addEventListener(eventName, unhighlight, false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Handle dropped files
|
|
|
|
|
dropArea.addEventListener('drop', handleDrop, false)
|
|
|
|
|
|
|
|
|
|
function preventDefaults(e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function highlight(e) {
|
|
|
|
|
dropArea.classList.add('highlight')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unhighlight(e) {
|
|
|
|
|
dropArea.classList.remove('active')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleDrop(e) {
|
|
|
|
|
var dt = e.dataTransfer
|
|
|
|
|
var files = dt.files
|
|
|
|
|
|
|
|
|
|
handleFiles(files)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let uploadProgress = []
|
|
|
|
|
let progressBar = document.getElementById('progress-bar')
|
|
|
|
|
|
|
|
|
|
function initializeProgress(numFiles) {
|
|
|
|
|
progressBar.value = 0
|
|
|
|
|
uploadProgress = []
|
|
|
|
|
|
|
|
|
|
for (let i = numFiles; i > 0; i--) {
|
|
|
|
|
uploadProgress.push(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateProgress(fileNumber, percent) {
|
|
|
|
|
uploadProgress[fileNumber] = percent
|
|
|
|
|
let total = uploadProgress.reduce((tot, curr) => tot + curr, 0) / uploadProgress.length
|
|
|
|
|
console.debug('update', fileNumber, percent, total)
|
|
|
|
|
progressBar.value = total
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleFiles(files) {
|
|
|
|
|
files = [...files]
|
|
|
|
|
initializeProgress(files.length)
|
|
|
|
|
files.forEach(uploadFile)
|
|
|
|
|
files.forEach(previewFile)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function previewFile(file) {
|
|
|
|
|
let reader = new FileReader()
|
|
|
|
|
reader.readAsDataURL(file)
|
|
|
|
|
reader.onloadend = function() {
|
|
|
|
|
let img = document.createElement('img')
|
|
|
|
|
img.src = reader.result
|
|
|
|
|
document.getElementById('gallery').appendChild(img)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uploadFile(file, i) {
|
|
|
|
|
var url = '/act/page'
|
|
|
|
|
var xhr = new XMLHttpRequest()
|
|
|
|
|
var formData = new FormData()
|
|
|
|
|
xhr.open('POST', url, true)
|
|
|
|
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
|
|
|
|
|
|
|
|
|
// Update progress (can be used to show progress indicator)
|
|
|
|
|
xhr.upload.addEventListener("progress", function(e) {
|
|
|
|
|
updateProgress(i, (e.loaded * 100.0 / e.total) || 100)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
xhr.addEventListener('readystatechange', function(e) {
|
|
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
|
|
|
updateProgress(i, 100) // <- Add this
|
|
|
|
|
} else if (xhr.readyState == 4 && xhr.status != 200) {
|
|
|
|
|
// Error. Inform the user
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
formData.append('upload_preset', 'ujpu6gyk')
|
|
|
|
|
formData.append('act', 'upload')
|
|
|
|
|
formData.append('file', file)
|
|
|
|
|
xhr.send(formData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//интерактивное изменение
|
|
|
|
|
//h1
|
|
|
|
|
$("h1").dblclick(function(event) {
|
|
|
|
|
|
|
|
|
|
$(this).addClass('hidden');
|
|
|
|
|
$('input.h1-edit').removeClass('hidden');
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$("input.h1-edit").dblclick(function(event) {
|
|
|
|
|
$("h1").text($(this).val());
|
|
|
|
|
$('h1').removeClass('hidden');
|
|
|
|
|
$('input.h1-edit').addClass('hidden');
|
|
|
|
|
|
|
|
|
|
})
|