document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://site.com/thanks';
setTimeout(() => window.open('https://site.com/thanks2', "_blank"))
}, false );
const arr = [
{
"name": "Грузинская ж. д.",
"Щебень гранитный не поименованный в алфавите": {
"amount": 275,
"stavka": 0,
"revenue": 0
}
},
{
"name": "Московская ж. д.",
"Щебень гранитный не поименованный в алфавите": {
"amount": 138,
"stavka": 0,
"revenue": 0
}
}
]
console.log(arr.map(n => ({ name: n.name, ...Object.values(n)[1] }) ))
Но когда я дописываю скрипт на проверку пагинации, он не работает
function is_paged() {
return window.location.pathname.split("/").includes('page')
}
какой код для фильтра писать, чтобы добавлялся класс я не знаю.
function isFilter(){
return window.location.pathname.split("/").some(n => n.split('=').includes('?filter_type_test'))
}
MutationObserver
const subtract = (v1, v2) => ({
x: v1.x - v2.x,
y: v1.y - v2.y
});
const magnitude = ({ x, y }) => Math.sqrt(x * x + y * y);
const pointDistance = (point1, point2) => magnitude(subtract(point1, point2));
const curveLength = (points) => {
let lastPoint = points[0];
const pointsSansFirst = points.slice(1);
return pointsSansFirst.reduce((acc, point) => {
const dist = pointDistance(point, lastPoint);
lastPoint = point;
return acc + dist;
}, 0);
};
$(document).on('change', 'input.variable_manage_stock', function (event) {
const variation = event.target.closest('.woocommerce_variation');
const checkbox = event.target;
const checkbox_on_off = checkbox.matches('input.variable_manage_stock:checked') && checkbox.value;
if (checkbox_on_off == 'on' && variation){}
if (checkbox_on_off == 'false'){}
});
let n = 0;
const interval = setInterval(() => {
if(n == 5){
clearInterval(interval);
return;
}
++n;
let t = n;
console.log(`вызов setInterval № ${t} спустя ${100}мс`)
setTimeout(() => {
console.log(`вызов setTimeout № ${t} спустя ${5000}мс`)
}, 5000)
}, 100)
const deleteBaggagePrice = price = price.filter( //проверка price на наличие свойства baggageID
(prop) => !prop.hasOwnProperty("baggageID") //если есь удалить объект
);
<div class="wrapper">
<div class="piechart"></div>
</div>
.wrapper{
border: 2px solid green;
display: inline-flex;
}
.piechart{
display: flex;
justify-content: center;
align-items: center;
position: relative;
width: 18rem;
height: 18rem;
border-radius: 50%;
background: conic-gradient(#fff 0 25deg, red 0 65deg, #fff 0 270deg);
}
.piechart:after{
content: '';
width: 85%;
height: 85%;
background: #fff;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<canvas width="1000px" height="1000px"></canvas>
const canvas = document.querySelector('canvas')
const ctx = canvas.getContext('2d');
const drawRect = (color, x, y, width, height) => {
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
return {
color, x, y, width, height
}
}
drawRect('blue', 50, 50, 20, 20)
drawRect('black', 150, 150, 50, 150)
const drawLine = (x1,y1,x2,y2) => {
ctx.lineWidth = '3';
ctx.strokeStyle = 'violet';
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.closePath();
ctx.stroke();
}
canvas.addEventListener('click', (e) => {
canvas.width += 0;
const npc = drawRect('blue', 50, 50, 20, 20)
const house = drawRect('black', 150, 150, 50, 150)
drawRect('green', e.clientX, e.clientY, 20, 20)
const x1 = npc.x, y1 = npc.y, x2 = e.clientX, y2 = e.clientY;
const points = [];
for(let i = 0.0; i <= 1; i = i+0.01){
const gg = getPositionAlongTheLine(x1,y1,x2,y2, i);
drawRect('aqua' ,gg.x, gg.y, 2 , 2)
points.push({x: gg.x, y: gg.y, width: 10, height: 10})
}
for(let i = 0; i < points.length; i++){
if(collides({...points[i], width: 2, height: 2}, house)){
console.log('есть препятствие')
return;
}
}
drawLine(x1, y1, x2, y2)
})
// отдает координаты равные проценту расстояния: percentage максимум = 1
function getPositionAlongTheLine(x1, y1, x2, y2, percentage) {
return {x : x1 * (1.0 - percentage) + x2 * percentage, y : y1 * (1.0 - percentage) + y2 * percentage};
}
function collides(a,b){
return a.x < b.x + b.width &&
a.x + a.width > b.x &&
a.y < b.y + b.height &&
a.y + a.height > b.y;
}
const dropDownBtns = document.querySelectorAll('.dropdown__btn');
const dropDowns = document.querySelectorAll('.filter__dropdown');
const removeAllActive = () => {
return dropDowns.forEach(item => item.classList.remove('active'));
};
dropDownBtns.forEach(btn => {
btn.addEventListener('click', async (e) => {
await removeAllActive();
e.target.parentNode.classList.add('active')
});
});
document.addEventListener('click', removeAllActive)