Skip to content

Commit 676e602

Browse files
committed
feat (theme): remove js each function
1 parent cfa1e15 commit 676e602

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/js/classes/Header.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import AbstractDomElement from './AbstractDomElement'
2-
import each from '../utils/each'
32
import { Tween } from 'oneloop.js'
43
import isRTL from '../utils/isRTL'
54

@@ -14,10 +13,10 @@ class Header extends AbstractDomElement {
1413

1514
const that = this
1615
const el = this._element
17-
const toggle = el.getElementsByClassName('header__menu-toggle')[0]
18-
const menuList = el.getElementsByClassName('header__menu-list')[0]
19-
const liWithChidren = el.getElementsByClassName('menu-item-has-children')
20-
const menu = el.getElementsByClassName('header__menu')[0]
16+
const toggle = el.querySelector('.header__menu-toggle')
17+
const menuList = el.querySelector('.header__menu-list')
18+
const liWithChidren = el.querySelectorAll('.menu-item-has-children')
19+
const menu = el.querySelector('.header__menu')
2120

2221
this._menu = menu
2322
this._toggle = toggle
@@ -30,11 +29,7 @@ class Header extends AbstractDomElement {
3029
easing: 'easeInOutExpo',
3130
onUpdate: function (timestamp, tick, percent) {
3231
const bp = 768
33-
let direction = window.innerWidth >= bp ? -1 : 1
34-
35-
if (isRTL()) {
36-
direction = window.innerWidth >= bp ? 1 : -1
37-
}
32+
let direction = (window.innerWidth >= bp ? -1 : 1) * (isRTL() ? -1 : 1)
3833

3934
menu.style.transform = 'translateX(' + 100 * (percent - 1) * direction + '%)'
4035
},
@@ -48,18 +43,18 @@ class Header extends AbstractDomElement {
4843

4944
// avoid error for empty theme
5045
if (menuList) {
51-
each(menuList.children, function (li) {
46+
for (const li of menuList.children) {
5247
li.addEventListener('mouseenter', onMouseEnterFirstLevelLi.bind(that))
53-
})
48+
}
5449

55-
each(liWithChidren, function (li) {
50+
for (const li of liWithChidren) {
5651
const subMenuToggle = li.children[1]
5752
li.addEventListener('mouseenter', onMouseEnterLi.bind(that))
5853
li.addEventListener('mouseleave', onMouseLeaveLi.bind(that))
5954

6055
subMenuToggle.addEventListener('keypress', onKeyPressSubMenuToggle.bind(that))
6156
subMenuToggle.addEventListener('touchstart', onTouchStartSubMenuToggle.bind(that))
62-
})
57+
}
6358

6459
toggle.addEventListener('click', onClickToggle.bind(this))
6560
document.addEventListener('keyup', onKeyup.bind(this))

src/js/utils/each.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)