const modalWindow = () => {
if (e.target.classList.contains('button_openModal')) {
document.getElementById(e.target.dataset.open)?.classList.add('modal_show');
return;
}
if (e.target.classList.contains('button_closeModal')
|| e.target.closest('.modal_show') === null) {
document.querySelector('.modal_show')?.classList.remove('modal_show');
}
};
document.addEventListener(
'click',
(e) => {
const target = e.target.closest('.media-category__item');
if (!target) {
return;
}
document.querySelector('.media-category__item.active')?.classList.remove('active');
target.classList.add('active');
document.querySelector('.media-tab.active')?.classList.remove('active');
document.querySelector(`.media-tab[data-tab="${target.dataset.category}"]`)?.classList.add('active');
},
);
<page-following>
<page-header
title="Following"
:buttons="buttons"
@buttonPressed="onButtonPressed"
/>
<!-- здесь контент -->
<page-footer />
</page-following>
const parseDate = (date) => Date.parse(date.split('/').reverse().join('-'));
const findClosest = (list, date = (new Date()).toLocaleDateString('en-GB')) => {
const findDate = parseDate(date);
return list.reduce(
(acc, cur) => {
const delta = parseDate(cur.date) - findDate;
return (delta >= 0 && delta < acc.delta) ? { delta, el: cur } : acc;
},
{ delta: Number.MAX_SAFE_INTEGER, el: null },
).el;
};
deepEqual({a: 1}, {b: 1}); // true
deepEqual(null, {b: 1}); // 1
deepEqual({a: 1, b: 2}, {b: 2, a: 1}); // false
const deepEqual = (a, b) => {
if (a === b) {
return true;
}
if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {
return false;
}
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
if (aKeys.length !== bKeys.length) {
return false;
}
for (let i = 0; i < aKeys.length; i += 1) {
const key = aKeys[i];
if (!bKeys.includes(key) || !deepEqual(a[key], b[key])) {
return false;
}
}
return true;
};
listToArray(arrayToList([1, 2, 3])); // Array(3) [ 3, 2, 1 ]
const list = {
value: 2,
rest: {
value: 3,
rest: null,
},
};
prepend(1, list);
/*
Object {
value: 1,
rest: Object {
value: 3,
rest: Object {
value: 2,
rest: null
}
}
}
*/
const arrayToList = (arr, idx = 0) => ({
value: arr[idx],
rest: idx === arr.length - 1
? null
: arrayToList(arr, idx + 1)
});
const listToArray = (list) => (
list.rest === null
? [list.value]
: [list.value, ...listToArray(list.rest)]
);
const prepend = (value, rest) => ({ value, rest });
const nth = (list, idx) => (
idx === 0
? list.value
: (
list.rest === null
? undefined
: nth(list.rest, idx - 1)
)
);
const arrayToList = (arr) => {
const list = null;
for (let i = arr.length - 1; idx >= 0; idx -= 1) {
list = { value: arr[idx], rest: list };
}
return list;
};
const listToArray = (list) => {
const arr = [];
while (list !== null) {
arr.push(list.value);
list = list.rest;
}
return arr;
};
const prepend = (value, rest) => ({ value, rest });
const nth = (list, idx) => {
while (list !== null) {
if (idx === 0) {
return list.value;
}
idx -= 1;
list = list.rest;
}
};
const test = (x) => { console.log(x); return false; };
if (test(1) && test(2)) {
console.log('???');
}