var uptoOnline = {
/**
* @description sắp xếp vị trí các ảnh.
*/
sortable: function () {
$("#sortable").sortable({
revert: true,
opacity: 0.7,
start: function (evt, ui) {
//console.log('start')
},
stop: function (evt, ui) {
imageItem = $(".itemImage")
$('.imagestep').each(function (index) {
$(this).attr('src', '/' + $(imageItem[index]).attr('data'));
})
$('.stepfile').each(function (index) {
$(this).val($(imageItem[index]).attr('data'));
})
$('.remove').each(function (index) {
$(this).attr('data', index)
})
$('.steps').each(function (index) {
$(this).attr('id', 'step' + index)
})
}
});
},
saveToOnline: function () {
$('#submitcreatectip').click(function () {
function trySave() {
let saving = localStorage.getItem("saving");
// if (saving === "true") {
// // Có tab khác đang lưu -> chờ 500ms rồi thử lại
// setTimeout(trySave, 4000);
// return;
// }
// Đặt flag cho tất cả tab biết là đang lưu
localStorage.setItem("saving", "true");
let html = "
Đang lưu";
$('#submitcreatectip').html(html);
let formData = $('#createtip').serializeArray();
$.ajax({
type: "post",
url: "/savetip",
dataType: "json",
data: formData,
success: (msg) => {
if (msg[1].indexOf("/") != -1) {
setTimeout(function () {
window.location.href = "http://handmadev.com" + msg[1];
}, 2000);
} else {
$('#saveStatus').html("" + msg[1] + "");
$('#submitcreatectip').html('Lưu hướng dẫn');
}
},
error: function (request, error) {
console.error("Lỗi lưu:", error);
},
complete: function () {
// Quan trọng: clear flag để tab khác có thể lưu
localStorage.setItem("saving", "false");
}
});
}
trySave();
});
},
removeImage: function () {
$('.remove').click(function () {
data = $(this).attr('data');
console.log(data)
$('#step' + data).remove();
$(this).parent().remove();
});
},
uptoDraft: function () {
$('.upToDraft').click(function () {
data = $(this).attr('data');
$('#uploadDraft').html("1111");
token = $('#_token').val();
$.ajax({
type: "post",
url: "/upToDraft",
dataType: "json",
data: {url: data, _token: token},
success: function (msg) {
$('#uploadDraft').html("" + msg + "");
},
error: function (request, error) {
console.log(request, error);
}
});//End ajax
});
},
samePost: function () {
// var height = $('#sortable').height();
// var windowHeight = $(window).height()
// height = windowHeight - height-144;
// $('#samePostList').css({
// height:height+'px',
//
// })
// console.log(height);
$('.samePostInput').change(function () {
value = $(this).val();
uptoOnline.getSamePort(value);
});
},
getSamePort: function (value) {
token = $('#_token').val();
$.ajax({
type: "post",
url: "/getSamePost",
dataType: "json",
data: {value: value, _token: token},
success: function (datas) {
if (datas['checkslug'] > 0) {
$('.countSlug').text('checkSlug: ' + datas['checkslug']);
} else {
$('.countSlug').text('');
}
let data = datas.pinter;
// console.log(data);
$('.result').text(data.length);
$('.result').removeClass('loadingBackground');
$('#samePostList').html('');
let string = '';
$.each(data, function (key, value) {
let numImgs = 0;
if (typeof value.imagestep !== 'undefined') {
numImgs = value.imagestep.length;
}
if (value && value.imageintro && value.imageintro['237'] && value.imageintro['237'].url !== null) {
string += '
This is a link and another link.
'; // Tạo một phần tử div ẩn để chứa chuỗi HTML var tempDiv = document.createElement('div'); tempDiv.innerHTML = htmlString; // Lấy danh sách tất cả các thẻ var anchorTags = tempDiv.getElementsByTagName('a'); // Lặp qua từng thẻ và thay thế nó bằng nội dung bên trong for (var i = anchorTags.length - 1; i >= 0; i--) { var content = anchorTags[i].innerHTML; anchorTags[i].outerHTML = content; } // Lấy chuỗi HTML sau khi xóa các thẻ var filteredString = tempDiv.innerHTML; }, getTitle:function(){ $('#getTitle').click(function () { let title= $('#content').text(); title = title.substring(0, 90); $('#fullTitle').val(title).trigger('change').trigger('keyup'); }); }, convertImageToText: function () { token = $('#_token').val(); //lấy category by name category = $('input[name="category"]:checked').val(); console.log(category); token = $('#_token').val(); id = $('#id').val(); $('.convertImageToText').click(function () { let button = $(this); button.addClass('loadingBackground'); // Thêm hiệu ứng loading button.text('loading'); // Bỏ hiệu ứng loading sau khi hoàn thành url = button.attr('url'); console.log(url); image = button.attr('data'); language = button.attr('language'); console.log(language); //if((language === 'VietNam' || category == 'food') && url !== 'www.tiktok.com'){//nếu là tiếng việt thì thôi if((language === 'VietNam' || category == 'food')){//nếu là tiếng việt thì thôi uptoOnline.showToast('Tiếng việt hoặc food thì không lấy title', 'error'); return; } $.ajax({ type: "post", url: "/convertImageToText", dataType: "json", data: {image: image, language: language, _token: token, categoryItem: category , id: id}, success: function (datas) { $('.convertImagesToTitle').html(datas.data.original + '${key}
`; $.each(value['imagesDownload'], function (key, valueImg) { ins += `${key}
` $.each(value['downloadImage'], function (key, valueImg) { ins += `