class EventEmitter {
constructor() {
this.handlers = new Map();
}
on(event, handler) {
const handlers = this.handlers.has(event) ? this.handlers.get(event) : new Set();
handlers.add(handler);
this.handlers.set(event, handlers);
}
emit(event, ...args) {
if (this.handlers.has(event)) {
const handlers = this.handlers.get(event);
for (let handler of handlers) {
handler(...args);
}
}
}
}
on
у CustomSelecton(event, callback) {
this.events.on(event, callback);
}
closeDropdown
дописываем this.events.emit('close');
а для customSelectInstanse
customSelectInstanse.on('close', () => {
console.log('Close');
});
:hover
больше не работает? Ну можно так:<a
:style="getMailStyle(user)"
v-on:mouseover="(event) => changeColor(evebt, user)"
v-on:mouseleave="() => originalColor(user)"
v-bind:href="`mailto:{{ user.commit.author.email }}`"
>{{user.commit.author.email}}</a>
methods: {
getMailStyle: function (user) {
return {
color: user.color
};
},
changeColor: function (e, user) {
e.preventDefault();
user.color = 'red';
},
originalColor: function (user) {
user.color = '#ccc';
}
}
fetch('https://api.github.com/repos/javascript-tutorial/en.javascript.info/commits')
.then(response => response.json())
.then(json => {
this.users = json.map(user => ({
color: '#ccc',
...user
}));
}
assignValue
creditTermRange.value = creditTermRange.value;
меняем на creditTerm.value = creditTermRange.value;
totalAmountOfCredit.innerHtml= `${lounAmount} ₽`;
totalMonthlyPayment.innerHtml= `${monthlyPaymentArounded} ₽`;
totalRecommendedIncome.innerHtml= `${monthlyPaymentArounded + ((monthlyPaymentArounded / 100) * 35)} ₽`
.innerHTML
, но я советую использовать .textContent
denwer
на нечто более стабильное? var_dump
попробуйте header('Content-Type: text/plain; charset=utf-8');
@media screen and (max-width: 992px) {
img {
width: 100vmin;
height: 100vmin;
}
}
function verifyLogin(login) {
return new Promise(function (resolve, reject) {
connection.query(`SELECT login FROM user_data WHERE login = '${login}'`, function (error, results, fields) {
if (error) {
reject(error);
}
if (results[0] !== undefined) {
resolve('Логин уже используется');
} else {
resolve(0);
}
});
});
}
methods: {
playVid: function() {
this.playing = !0,
this.$refs.vid.play()
},
initializeMorph: function() {
var t = this
, e = 0;
this.morphInterval = setInterval((function() {
var a = t.$refs.morph;
!function(t, e, a) {
var r = ["a", "b", "c", "d", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "{", "}", "%", "$", "?", "!"]
, n = 15
, i = e.split("")
, s = a.split("")
, o = i.length
, l = s.length
, c = new Date
, d = c.getTime()
, u = 0
, h = 0
, p = 105 / Math.max(o, l);
!function e() {
c = new Date,
h += c.getTime() - d;
for (var a = u; a < Math.max(o, l); a++) {
var f = Math.floor(Math.random() * (r.length - 1));
i[a] = r[f]
}
if (h >= p) {
u += Math.floor(h / p);
for (var g = 0; g < u; g++)
i[g] = s[g] || null;
h = 0
}
t.textContent = i.join(""),
d = c.getTime(),
u < Math.max(o, l) && setTimeout((function() {
window.requestAnimationFrame(e)
}
), 1e3 / n)
}()
}(a, a.textContent, t.words[e]),
e < t.words.length - 1 ? e++ : e = 0
}
), 3e3)
}
},
beforeDestroy: function() {
clearInterval(this.morphInterval),
clearInterval(this.safariCheck)
}
.card {
position: relative;
}
.card .card__link::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: '';
}
event
и сбрасываем его.menuToggle.addEventListener('click', function (event) {
event.preventDefault();
...
});
this
меняем на menuToggle
.<button class="menu-toggle" id="menu-toggle">
<span class="menu-toggle__span"></span>
</button>
.menu-toggle {
width: 60px;
height: 60px;
padding: 0;
border: none;
display: flex;
justify-content: center;
align-items: center;
background: none;
z-index: 15;
}
.menu-toggle.active .menu-toggle__span {
background-color: transparent;
}
.menu-toggle.active .menu-toggle__span:before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .menu-toggle__span:after {
transform: rotate(-45deg);
top: 0;
}
checkbox
'а внутри «кнопки». array.reduce((accumulator, value, index) => {
if (!(accumulator[index % 2] instanceof Array)) {
accumulator[index % 2] = [];
}
accumulator[index % 2].push(value);
return accumulator;
}, []);
array.reduce((accumulator, value, index) => {
accumulator[index % 2].push(value);
return accumulator;
}, [[], []]);
array.reduce((accumulator, value, index) => (accumulator[index % 2].push(value), accumulator), [[], []]);
array.reduce((a, v, i) => (a[i % 2].push(v), a), [[], []]);
const countOff = (array, count) => array.reduce((accumulator, value, index) => {
accumulator[index % count].push(value);
return accumulator;
}, Array.from({ length: count }, () => []));
countOff([1, 2, 3, 4, 5, 6], 2); // [[1, 3, 5], [2, 4, 6]]
countOff([1, 2, 3, 4, 5, 6], 3); // [[1, 4], [2, 5], [3, 6]]