function createTree(arr, idKey, parentKey) {
const tree = {};
arr.forEach(n => tree[n[idKey]] = Object.assign({}, n));
return Object.values(tree).reduce((acc, n) => {
const parent = tree[n[parentKey]];
(parent ? parent.children = parent.children || {} : acc)[n[idKey]] = n;
return acc;
}, {});
}
const tree = createTree(data, 'id', 'parent_id');
.size-otherBtn {
display: grid;
grid-template-columns: 50px 50px 50px 50px;
grid-template-rows: auto;
grid-template-areas:
"mSize lSize xlSize xxlSize"
"sizeGuide sizeGuide shopNow shopNow";
}
$teacherID = чему-то там равен, неважно...
$itemsByTeacherID = [];
foreach ($days as $day) {
foreach ($day['day_items'] as $item) {
if ($item['teacher'] === $teacherID) {
$itemsByTeacherID[$day['day']][] = $item;
}
}
}
$('input').on('focus blur', function(e) {
$(this).toggleClass('active', e.type === 'focus');
});
const onFocus = e => e.target.classList.toggle('active', e.type === 'focus');
document.querySelectorAll('input').forEach(n => {
n.addEventListener('focus', onFocus);
n.addEventListener('blur', onFocus);
});
$brands = array_filter($brands, function($n) {
return isset($n['alias']);
});
data: () => ({
activeComponent: null,
components: [
{ name: 'component-1', label: '#1' },
{ name: 'component-2', label: 'а я второй' },
{ name: 'component-3', label: 'третьим буду' },
],
}),
v-model
:<select v-model="activeComponent">
<option v-for="n in components" :value="n.name">{{ n.label }}</option>
</select>
<component v-if="activeComponent" :is="activeComponent"></component>
document.querySelector('table').addEventListener('input', function(e) {
e.target.style.backgroundColor =
e.target.innerHTML имеет какое надо значение
? 'lime'
: 'red';
});
import lightbox from 'vlightbox'
Vue.use(lightbox)
short int x = 0x6543;
char a = x & 0xff;
char b = (x & 0xff00) >> 8;
function toggleSubmenu() {
const submenu = this.closest('li').querySelector('.rz-child-menu');
submenu.classList.toggle('opened');
}
const vvOpen = document.querySelectorAll('.rz-open-menu-element');
vvOpen.forEach(n => n.addEventListener('click', toggleSubmenu));
.rz-left-menu ul li ul.rz-child-menu.opened {
display: block;
}
document.querySelector('.rz-left-menu').addEventListener('click', function(e) {
if (e.target.classList.contains('rz-open-menu-element')) {
e.target.closest('li').querySelector('.rz-child-menu').classList.toggle('opened');
}
});
const events = [ 'mousemove', 'mouseleave', 'mousedown', ... ];
$element.on(events.join(' '), function(e) { ... })
"on<тип события>"
:const events = [];
for (const k in element) {
if (k.indexOf('on') === 0) {
events.push(k.slice(2));
}
}
$(element).on(events.join(' '), function(e) {
console.log(e.type);
});
let
вместо var
- тогда closeBtn[i]
будет таким, как вам надо.for (const n of document.querySelectorAll('.closebtn')) {
n.addEventListener('click', onClick);
}
function onClick(e) {
const parent = e.currentTarget.parentNode;
// ...
}
wrap.on('mousemove', function(e) {
if (!e.buttons) {
return;
}
// здесь ваш код
});
$.fn.trackCoords = function(options) {
return this.each(function() {
const $element = $(this);
// ...
});
};
$element.mouseover(function(e) {
if (this !== e.target) {
// чужое событие - не интересно, не обрабатываем
return;
}
// ...
});