document.addEventListener('keydown', e => {
if (e.key === 'Escape') {
const popups = document.querySelectorAll('#popupClient, #popupPartner');
popups.forEach(n => n.classList.remove('popup--open'));
}
});
const chainScripts = src =>
src.reduce((acc, n) => {
return acc.then(() => new Promise((resolve, reject) => {
const s = document.createElement('script');
s.onload = resolve;
s.onerror = reject;
s.src = n;
document.head.appendChild(s);
}));
}, Promise.resolve());
const inputs = new DOMParser()
.parseFromString(str, 'text/html')
.querySelectorAll('input');
// или
const { elements: inputs } = document
.createRange()
.createContextualFragment(str)
.querySelector('form');
// или
const inputs =
(el => (el.innerHTML = str, el.getElementsByTagName('input')))
(document.createElement('div'));const getName = el => el.name;
// или
const getName = el => el.getAttribute('name');
// или
const getName = el => el.attributes.name.value;const names = Array.from(inputs, getName);
// или
const names = Array.prototype.map.call(inputs, getName);
// или
const names = [];
for (const n of inputs) {
names.push(getName(n));
}
// или
const names = [];
for (let i = 0; i < inputs.length; i++) {
names[i] = getName(inputs[i]);
}
// или
const names = (function get(i, n = inputs.item(i)) {
return n ? [ getName(n), ...get(i + 1) ] : [];
})(0);
- e.originalEvent.target.getAttribute('data-id')
+ e.originalEvent.target.closest('[data-id]').dataset.idЭто верстка шаблона маркера 2гис, отдельно навешивать на нее обработчики нельзя
DG.divIcon? Да, туда нельзя. А на сам маркер - можно:const marker = DG.marker(...
marker.on('click', onMarkerClick);function onMarkerClick(e) {
// ...
}Я вообще сделал это чтобы как то понять на какой маркер кликнули
target.this.markers - это DG.featureGroup. Оставляете общий обработчик клика, смотрите у события свойство eventTargets, это массив, внутри будет кликнутый маркер.
this.message = this.rules.map(n => n(this.input)).find(n => n !== true);
const nodeToObj = node => ({
type: node.nodeType,
value: node.nodeValue,
tag: node.tagName,
childNodes: Array.from(node.childNodes, nodeToObj),
attributes: node.attributes && Array.from(
node.attributes,
({ name, value }) => ({ name, value })
),
});
const nodeToJSON = (node, ...args) =>
JSON.stringify(nodeToObj(node), ...args);const json = nodeToJSON(document.querySelector('.menu'), null, 2);
document.body.insertAdjacentHTML('beforeend', `<pre>${json}</pre>`);
const class1 = 'item';
const class2 = 'in';
const key = 'price';
const attr = `data-${key}`;const getValue = el => +el.dataset[key];
// или
const getValue = el => parseFloat(el.getAttribute(attr));
// или
const getValue = el => Number(el.attributes[attr].value);const sum = Array.prototype.reduce.call(
document.querySelectorAll(`.${class1}.${class2}`),
(acc, n) => acc + getValue(n),
0
);
// или
let sum = 0;
for (const n of document.getElementsByClassName(class1)) {
sum += getValue(n) * n.classList.contains(class2);
}
const getNested = (root, ...keys) => keys
.flat(Infinity)
.flatMap(n => typeof n === 'string' ? n.split('.') : n)
.reduce((p, c) => p != null ? p[c] : void 0, root);const id = getNested(e, 'path.1.attributes.uid.textContent');
// или
const id = getNested(e, 'path', 1, 'attributes', 'uid', 'textContent');
// или
const id = getNested(e, 'path.1', [ 'attributes', [ 'uid' ] ], 'textContent');const id = e?.path?.[1]?.attributes?.uid?.textContent;
zoom(change) {
this.map.setZoom(this.map.getZoom() + change);
},<div @click="zoom(+1)">zoom in</div>
<div @click="zoom(-1)">zoom out</div>
function handler(e) {
console.log('hello, world!!');
this.removeEventListener(e.type, handler);
}
document.addEventListener('click', handler);document.addEventListener('click', handler, { once: true });
@click="$emit('remove')".@remove="removeFromBasket(item)".
computed: {
declarantKind() {
return this.dsec.reduce((acc, n) => (
acc[n.dsec_nnn] = n.dsec_declarant_kind,
acc
), {});
},
},watch: {
declarantKind(newVal, oldVal) {
const [ key ] = Object
.entries(newVal)
.find(([ k, v ]) => oldVal.hasOwnProperty(k) && oldVal[k] !== v) || [];
if (key) {
const item = this.dsec.find(n => n.dsec_nnn === key);
console.log('объект:', item);
console.log(`было: ${oldVal[key]}`);
console.log(`стало: ${newVal[key]}`);
}
},
},
modals.entries() судя по документации должен предоставить [key, value]
[...modals.entries()].map(([ id, modal ]) => (
))