<TreePicker
locale={{
searchPlaceholder: 'hello, world!!',
}}
const flatObj = obj =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
v instanceof Object && !Array.isArray(v)
? Object.assign(acc, flatObj(v))
: acc[k] = v,
acc
), {});
document.querySelectorAll('h2').forEach(n => {
const [ season, , episode ] = n.innerText.split(' ');
if (+episode === 1) {
n.id = `season-${season}`;
}
});
[...document.querySelectorAll('h2')]
.filter(n => n.innerText.endsWith(', 1 серия'))
.forEach((n, i) => n.id = `season-${i + 1}`);
document.querySelectorAll('h2').forEach((n, i, a) => {
const prev = i && a[i - 1].innerText.match(/\d+/)[0];
const curr = n.innerText.match(/\d+/)[0];
if (curr !== prev) {
n.id = `season-${curr}`;
}
});
Array
.from(document.querySelectorAll('h2'))
.reduce((acc, n) => (acc[parseInt(n.innerText)] ??= n, acc), [])
.forEach((n, i) => n.id = `season-${i}`);
function rotateArray($arr, $shift) {
$shift %= count($arr);
array_unshift($arr, ...array_splice($arr, -$shift));
return $arr;
}
$arr = range(1, 7);
echo implode(', ', rotateArray($arr, 1)); // 7, 1, 2, 3, 4, 5, 6
echo implode(', ', rotateArray($arr, -3)); // 4, 5, 6, 7, 1, 2, 3
echo implode(', ', rotateArray($arr, 69)); // 2, 3, 4, 5, 6, 7, 1
<div class="slider">
$('.slick').slick({
data-category="orange"
var filterClass = $(this).data('category');
$('.slick').slick('slickFilter', filterClass);
$('.category__menu').on('click', 'li', function() {
$('.slider').slick('slickUnfilter');
const category = $(this).data('category');
if (category !== 'allPost') {
$('.slider').slick('slickFilter', `.${category}`);
}
});
const transpose = matrix => Array.from(
{ length: matrix[0]?.length ?? 0 },
(_, i) => matrix.map(n => n[i])
);
function transpose(matrix) {
const result = Array(matrix.length && matrix[0].length);
for (let i = 0; i < result.length; i++) {
result[i] = [];
for (let j = 0; j < matrix.length; j++) {
result[i][j] = matrix[j][i];
}
}
return result;
}
const groupAdjacent = (arr, newGroup) =>
arr.reduce((acc, n, i, a) => (
(!i || newGroup(n, a[~-i])) && acc.push([]),
acc[~-acc.length].push(n),
acc
), []);
const result = groupAdjacent(arr, (c, p) => c !== -~p);
function group(data, key) {
const grouped = new Map;
let i = -1;
for (const n of data) {
const k = key(n, ++i);
grouped.set(k, grouped.get(k) ?? []).get(k).push(n);
}
return grouped;
}
const result = [...group(arr, (n, i) => n - i).values()];
const [ form, setForm ] = useState({
login: '',
password: '',
});
const onChange = ({ target: t }) => setForm({ ...form, [t.name]: t.value });
<input name="login" value={form.login} onChange={onChange} />
<input name="password" value={form.password} onChange={onChange} />
$('.js-cropped-word').text((i, text) => text.replace(/(?<=\S{19,}).+/, '...'));
В Сафари не работает
document.querySelectorAll('.js-cropped-word').forEach(n => {
n.textContent = n.textContent.replace(/(\S{19}).+/, '$1...');
});
const max = 19;
for (const n of document.getElementsByClassName('js-cropped-word')) {
const words = n.innerText.split(' ');
const i = words.findIndex(n => n.length > max);
if (i !== -1) {
words.length = i + 1;
words[i] = words[i].slice(0, max) + '...';
n.innerText = words.join(' ');
}
}
const elements = document.querySelectorAll('input[type="button"]');
const tag = 'div';
const className = 'block';
elements.forEach(n => {
n.after(document.createElement(tag));
n.nextSibling.className = className;
n.nextSibling.append(n);
});
for (const n of elements) {
const wrapper = document.createElement(tag);
wrapper.classList.add(className);
wrapper.appendChild(n.parentNode.replaceChild(wrapper, n));
}
for (let i = 0; i < elements.length; i++) {
const wrapper = document.createElement(tag);
elements[i].replaceWith(wrapper);
wrapper.classList.value = className;
wrapper.insertAdjacentElement('afterbegin', elements[i]);
}
(function wrap(i, n = elements.item(i)) {
if (n) {
n.outerHTML = `<${tag} class="${className}">${n.outerHTML}</${tag}>`;
wrap(-~i);
}
})(0);
const select = document.querySelector('вам виднее, что тут должно быть');
const values = [ '1', '2', '3' ];
[...select].forEach(n => values.includes(n.value) && n.remove());
for (const n of select.querySelectorAll(values.map(n => `[value="${n}"]`))) {
select.removeChild(n);
}
select.replaceChildren(...Array.prototype.filter.call(
select,
((values, n) => !values.has(n.value)).bind(null, new Set(values))
));
Array.prototype.reduceRight.call(
select.options,
(_, n) => ~values.indexOf(n.value) && n.replaceWith(),
null
);
select.innerHTML = Array
.from(select.children)
.filter(function(n) {
return n.matches(this);
}, `:not(${values.map(n => `[value="${n}"]`)})`)
.map(n => n.outerHTML)
.join('');
(function next(i, n = select.item(--i)) {
if (n) {
for (const v of values) {
if (v === n.value) {
n.outerHTML = '';
break;
}
}
next(i);
}
})(select.length);
Обычный img у меня не сработал.
product.amount = 1;
на Vue.set(product, 'amount', 1);
.product.amount = 1;
state.items.push(product);
state.items.push({
...product,
amount: 1,
});
const filterArrByObj = (arr, obj) =>
Object.entries(obj).reduce((arr, [ k, v ]) => {
return arr.filter(Array.isArray(v)
? n => v.includes(n[k])
// !v.length || v.includes(n[k]), если при пустом массиве допустимо любое значение
: n => v === n[k]
// n[k].includes(v), если точное соответствие не нужно
);
}, arr);
computed: {
filteredData() {
return filterArrByObj(this.data, this.filters);
},
},
<tr v-for="n in filteredData">
...
calc__price
и calc__payment
заменить на общий calc
.const $price = $('#price');
const $firstPayment = $('#first-payment');
function update($elem) {
$elem.closest('.calc').find('output').text($elem.val());
$('.payment-percent').html(Math.round($firstPayment.val() * 100 / $price.val()) + '%');
}
$price.closest('.calc').on('input', function() {
const val = $price.val();
$firstPayment
.val((i, v) => Math.min(v, val))
.attr('max', val)
.rangeslider('update', true);
update($firstPayment);
});
$price.add($firstPayment)
.rangeslider({ polyfill: false })
.closest('.calc')
.on('input', e => update($(e.target)))
.end()
.trigger('input');
function walkNested(val, callback) {
callback(val);
if (val instanceof Object) {
Object.values(val).forEach(n => walkNested(n, callback));
}
}
function walkNested(val, callback) {
for (const stack = [ val ]; stack.length;) {
const n = stack.pop();
callback(n);
if (n instanceof Object) {
stack.push(...Object.values(n));
}
}
}
walkNested(obj, n => n?.touched === true && (n.touched = false));