как сделать, чтобы можно было выбрать максимум 5 дней
кстати когда убираю кусок кода, который переводит на русский, все работает
А как в таком случае сбросить начальную и конечную дату, если нужно другие числа выбрать?
const parentSelector = '.menu';
const indices = [ 0, 1, 4, 8 ];
const $elems = $(parentSelector).children().filter(i => indices.includes(i));
// или
const $elems = $(indices.map(n => `> :eq(${n})`).join(', '), parentSelector);
const elems = Array.prototype.filter.call(
document.querySelector(parentSelector).children,
(n, i) => indices.includes(i)
);
// или
const elems = document
.querySelector(parentSelector)
.querySelectorAll(indices.map(n => `:scope > :nth-child(${n + 1})`));
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let X, Y;
document.addEventListener('mousemove', function(e) {
X = e.clientX;
Y = e.clientY;
});
function drawRect(x, y, w, h) {
const dx = x + w / 2;
const dy = y + h / 2;
const angle = Math.atan2(X - dx, Y - dy);
ctx.save();
ctx.translate(dx, dy);
ctx.rotate(-angle);
ctx.translate(-dx, -dy);
ctx.strokeRect(x, y, w, h);
ctx.restore();
}
function draw() {
ctx.clearRect(0, 0, innerWidth, innerHeight);
drawRect(50, 50, 50, 50);
requestAnimationFrame(draw);
}
draw();
const foo = () =>
(
0
+
{
}
)
[
7
]
+
(
0
+
{
}
)
[
2
]
+
(
!
1
+
`
`
)
[
3
]
+
(
0
+
{
}
)
[
7
]
+
(
!
1
+
`
`
)
[
4
]
+
(
!
0
+
`
`
)
[
1
]
`
X
`
[
1
]
$('body').html(Array.from({ length: 4 }, (n, i) => `
<svg width="40px" viewBox="0 0 40 40" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle class="border" cx="20" cy="20" r="18"/>
<circle class="fill" cx="20" cy="20" r="18"/>
<text x="12" y="25" class="small">0${i + 1}</text>
</svg>
`));
const $elements = $('.fill');
function animateElem(index) {
$elements.removeClass('animation').eq(index).addClass('animation');
}
$(document).on('animationend', function(e) {
$(e.target).removeClass('animation');
const index = (1 + $elements.index(e.target)) % $elements.length;
animateElem(index);
});
$(document).on('click', 'svg', function(e) {
animateElem($elements.index($('.fill', this)));
});
.border {
fill: transparent;
stroke: #ccc;
stroke-width: 2px;
}
.fill {
fill: transparent;
stroke: #000;
stroke-width: 2px;
stroke-dasharray: 120;
stroke-dashoffset: 120;
transform: rotate(-90deg);
transform-origin: center;
}
.animation {
animation: spin 2s both linear;
}
@keyframes spin {
to {
stroke-dashoffset: 1;
}
}
const parentSelectors = [ '.maplabels', '#map' ];
const activeClass = 'active';
$(document).on('click', parentSelectors.map(n => `${n} >`).join(','), e => {
const index = $(e.currentTarget).index();
parentSelectors.forEach(n => $(n)
.children()
.removeClass(activeClass)
.eq(index)
.addClass(activeClass)
);
});
const parents = parentSelectors.map(n => document.querySelector(n));
document.addEventListener('click', ({ target: t }) => {
const parent = parents.find(n => n !== t && n.contains(t));
if (parent) {
const index = [...parent.children].findIndex(n => n.contains(t));
for (const { children } of parents) {
for (let i = 0; i < children.length; i++) {
children[i].classList.toggle(activeClass, i === index);
}
}
}
});
const nestedVal = {
get(path, root) {
return path.split('.').reduce((p, c) => p[c], root);
},
set(path, root, val) {
path = path.split('.');
const key = path.pop();
nestedVal.get(path.join('.'), root)[key] = val;
}
};
moment().add(1, 'months').date(10).unix()
const randomItem = arr => arr[Math.random() * arr.length | 0];
// одно значение
const randomName = randomItem(arr_names);
// или сразу несколько
const randomNames = Array.from(
{ length: 5 },
randomItem.bind(null, arr_names)
);
// работать можно не только с массивами, но и, например, со строками
const randomChar = randomItem('abcdefg');
// и HTMLCollection тоже будет как надо обработана
const randomImage = randomItem(document.images);
$('#text-column').prop('scrollHeight')
// или
$('#text-column').get(0).scrollHeight
// или
$('#text-column')[0].scrollHeight
$('.va-city-list').on('click', '.list-city', function() {
console.log($(this).data('city'));
});
$('.list-city').click(e => console.log($(e.target).attr('data-city')));
document.querySelector('.va-city-list').addEventListener('click', e => {
const { city } = e.target.dataset;
if (city) {
console.log(city);
}
});
const onClick = e => console.log(e.target.getAttribute('data-city'));
document.querySelectorAll('.list-city').forEach(n => n.addEventListener('click', onClick));
for (const n of document.getElementsByClassName('list-city')) {
n.onclick = onClick;
}
function onClick() {
console.log(this.attributes['data-city'].value);
}
const keyboard = [
'abcde123',
'fghij456',
'klmno789',
'pqrst.@0',
'uvwxyz_/',
].reduce((acc, [...row], iRow) => {
row.forEach((key, iCol) => acc[key] = [ iRow, iCol ]);
return acc;
}, {});
function tvRemote(word) {
let steps = word.length;
let prev = [ 0, 0 ];
for (const n of word) {
const curr = keyboard[n];
steps += Math.abs(prev[0] - curr[0]) + Math.abs(prev[1] - curr[1]);
prev = curr;
}
return steps;
}
.close
- наоборот, закрыть.const modal = document.querySelector('.modal');
const close = modal.querySelector('.close');
document.addEventListener('click', function(e) {
if (e.target === modal || e.target === close) {
modal.style.display = 'none';
}
if (e.target.tagName === 'BUTTON') {
modal.style.display = 'block';
}
});
let count = null;
while (1) {
count = prompt('Введите количество колонок для таблицы умножения') | 0;
if (count > 0) {
break;
}
alert('Введите корректное число');
}