Код: Выделить всё
$(document).on("mousedown", "#orders_products_table > tr", function(e){
e.preventDefault();
let product = $(this).children("td").eq(0).text();
let category = $("#orders_categoriesbt").text();
switch(e.which){
case 1:
if(!$(this).is(":first-child")){
$("#orders_products_table > tr").removeClass("principal-tr-yellow");
$(this).addClass("principal-tr-yellow");
LoadAdditions(category, product);
}
break;
case 3:
if(!$(this).is(":first-child")){
$("#orders_products_table > tr").removeClass("principal-tr-yellow");
$(this).addClass("principal-tr-yellow");
$(this).contextmenu(function(e){
e.preventDefault();
$("#orders-context-menu").css("display", "block");
if((e.pageX + $("#orders-context-menu")[0].scrollWidth) >= $(window).width() && (e.pageY + $("#orders-context-menu")[0].scrollHeight) >= $(window).height()){
$("#orders-context-menu").css({
top: (e.pageY - $("#orders-context-menu")[0].scrollHeight) + "px",
left: (e.pageX - $("#orders-context-menu")[0].scrollWidth) + "px"
});
}else if((e.pageX + $("#orders-context-menu")[0].scrollWidth) >= $(window).width() && (e.pageY + $("#orders-context-menu")[0].scrollHeight) < $(window).height()){
$("#orders-context-menu").css({
top: e.pageY + "px",
left: (e.pageX - $("#orders-context-menu")[0].scrollWidth) + "px"
});
}else if((e.pageX + $("#orders-context-menu")[0].scrollWidth) < $(window).width() && (e.pageY + $("#orders-context-menu")[0].scrollHeight) > $(window).height()){
$("#orders-context-menu").css({
top: (e.pageY - $("#orders-context-menu")[0].scrollHeight) + "px",
left: e.pageX + "px"
});
}else{
$("#orders-context-menu").css({
top: e.pageY + "px",
left: e.pageX + "px"
});
}
row_selected = $(this);
});
}
break;
}
DOM
HTML
Код: Выделить всё
{{langorders[session['lang']]['additions-title']}}
Код: Выделить всё
function removeautoattr(){
$("#orders_products_table > tr").children("td").removeAttr("d__");
}
function LoadProducts(category){
$.ajax({
type:"GET",
url: "/orderspage_loadproducts",
headers:{
"Content-type":"application/json",
"Accept":"application/json"
},
data:{
p_category: category
},
success:function(response){
$("#orders_products_table").html(response["html"]);
setTimeout(removeautoattr, 2000);
},
error:function(xhr, status, error){
console.error(xhr);
}
});
}
Я сделал таймер, чтобы удалить атрибут d__ через 2 секунды или заблокировать функцию на 2 секунды, прежде чем пользователь сможет щелкнуть. Оба работают, но мне не нравится решение.
Подробнее здесь: https://stackoverflow.com/questions/788 ... -quickly-a
Мобильная версия