Где ошибки?
.active
недостаточно специфичен. А ещё лучше - надо было сразу скопипастить оригинал как есть, а не пытаться вносить изменения, которых не понимаете.Но выражения в моем понимании это...
function addClickListeners(buttonsSelector, dialogSelector) {
const buttons = document.querySelectorAll(buttonsSelector);
const dialog = document.querySelector(dialogSelector);
buttons.forEach(n => n.addEventListener('click', e => {
e.preventDefault();
dialog.style.display = 'block';
}));
dialog.addEventListener('click', ({ target }) => {
if (target.classList.contains('popup-close')) {
document.getElementById('name_1').disabled = true;
document.getElementById('phone_1').disabled = true;
dialog.style.display = 'none';
} else if (!target.closest('.popup-content')) {
dialog.style.display = 'none';
}
});
}
addClickListeners('header .contacts a', '.popup-call');
addClickListeners('.sentence-btn', '.popup-discount');
addClickListeners('.check-btn', '.popup-check');
document.addEventListener('click', function(e) {
const heading = e.target.closest('.panel-heading');
if (heading) {
e.preventDefault();
heading.closest('.panel-group').querySelectorAll('.panel-collapse').forEach(n => {
n.classList[n === heading.nextElementSibling ? 'toggle' : 'remove']('in');
});
}
});
по какой-то причине срабатывает только первый console.log()
const result = array1.filter(n => !array2.some(m => m.name === n.name));
function diff(data1, data2, key = n => n) {
const result = [];
const getKey = key instanceof Function ? key : n => n[key];
const keys = new Set(Array.from(data2, getKey));
for (const n of data1) {
if (!keys.has(getKey(n))) {
result.push(n);
}
}
return result;
}
// ваш случай
const result = diff(array1, array2, 'name');
// есть и другие варианты применения
diff([ 1, 2, 3, 4, 5 ], [ 1, 2, 3 ]) // [4, 5]
diff(Array(10).keys(), Array(7).keys()) // [7, 8, 9]
diff('abcde', 'ACE', n => n.toLowerCase()) // ['b', 'd']
v-model
.props: {
value: Number,
...
computed: {
item() {
return this.items[this.value];
},
...
<transition name="slide-fade" mode="out-in">
<div class="content" :key="value">
<h2>{{ item.title }}</h2>
<p>{{ item.text }}</p>
</div>
</transition>
methods: {
next(change) {
const len = this.items.length;
this.$emit('input', (this.value + change + len) % len);
},
...
<button @click="next(-1)">Prev</button>
<button @click="next(+1)">Next</button>
data: () => ({
active: 1,
...
<v-slider
v-model="active"
...
const selector = '.all-blocks.color-blocks .block';
const idSuffix = '_2';
$(selector).attr('id', function(i, id) {
return $(this).hasClass(id) ? id + idSuffix : id;
});
document.querySelectorAll(selector).forEach(n => {
n.id += n.classList.contains(n.id) ? idSuffix : '';
});
<option value="[55.751244,37.618423]">Москва</option>
select.addEventListener('change', function() {
map.setCenter(JSON.parse(this.value));
});
.active .block {
border: 1px solid red;
color: red;
}
.active .under-box-text {
display: none;
}
.active .invisible {
display: block;
}
const itemSelector = '.wrapper';
const buttonSelector = '.block, .link';
const activeClass = 'active';
$(itemSelector).on('click', buttonSelector, e => {
$(e.delegateTarget).toggleClass(activeClass);
});
// или
document.querySelectorAll(itemSelector).forEach(function(n) {
n.querySelectorAll(buttonSelector).forEach(m => m.addEventListener('click', this));
}, e => e.currentTarget.closest(itemSelector).classList.toggle(activeClass));
// или
document.querySelectorAll(itemSelector).forEach(n => {
n.addEventListener('click', onClick);
});
function onClick(e) {
const button = e.target.closest(buttonSelector);
if (button) {
this.classList.toggle(activeClass);
}
}
// или
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
const item = button && button.closest(itemSelector);
item && item.classList.toggle(activeClass);
});
{value >= 345 && value <= 500 ? <div>ничего нет</div> : null}
будет ещё больше таких промежутков
const messages = [
{
values: [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ],
message: 'hello, world!!',
},
{
values: [ [ 5, 15 ], [ 100, 200 ], 333, 444, 555 ],
message: 'fuck the world',
},
{
values: [ [ 50, 150 ], [ 250, 350 ], [ 666, 999 ] ],
message: 'fuck everything',
}
];
...
<div>
{messages
.filter(n => n.values.some(v => (
(v instanceof Array && v[0] <= value && value <= v[1]) ||
v === value
)))
.map(n => <div>{n.message}</div>)
}
</div>
data: () => ({
items: [ 'hello, world!!', 'fuck the world', 'fuck everything' ],
focused: null,
}),
<div v-for="(n, i) in items">
<input @focus="focused = i" @blur="focused = null">
<span v-show="focused === i" v-text="n"></span>
</div>
запрос_1()
.then(результат_1 => Promise
.all(результат_1.map(запрос_2))
.then(результат_2 => результат_1.map((значение_1, i) => ({
значение_1: значение_1,
значение_2: результат_2[i],
})))
)
.then(console.log)