1
1
import AbstractDomElement from './AbstractDomElement'
2
- import each from '../utils/each'
3
2
import { Tween } from 'oneloop.js'
4
3
import isRTL from '../utils/isRTL'
5
4
@@ -14,10 +13,10 @@ class Header extends AbstractDomElement {
14
13
15
14
const that = this
16
15
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')
21
20
22
21
this . _menu = menu
23
22
this . _toggle = toggle
@@ -30,11 +29,7 @@ class Header extends AbstractDomElement {
30
29
easing : 'easeInOutExpo' ,
31
30
onUpdate : function ( timestamp , tick , percent ) {
32
31
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 )
38
33
39
34
menu . style . transform = 'translateX(' + 100 * ( percent - 1 ) * direction + '%)'
40
35
} ,
@@ -48,18 +43,18 @@ class Header extends AbstractDomElement {
48
43
49
44
// avoid error for empty theme
50
45
if ( menuList ) {
51
- each ( menuList . children , function ( li ) {
46
+ for ( const li of menuList . children ) {
52
47
li . addEventListener ( 'mouseenter' , onMouseEnterFirstLevelLi . bind ( that ) )
53
- } )
48
+ }
54
49
55
- each ( liWithChidren , function ( li ) {
50
+ for ( const li of liWithChidren ) {
56
51
const subMenuToggle = li . children [ 1 ]
57
52
li . addEventListener ( 'mouseenter' , onMouseEnterLi . bind ( that ) )
58
53
li . addEventListener ( 'mouseleave' , onMouseLeaveLi . bind ( that ) )
59
54
60
55
subMenuToggle . addEventListener ( 'keypress' , onKeyPressSubMenuToggle . bind ( that ) )
61
56
subMenuToggle . addEventListener ( 'touchstart' , onTouchStartSubMenuToggle . bind ( that ) )
62
- } )
57
+ }
63
58
64
59
toggle . addEventListener ( 'click' , onClickToggle . bind ( this ) )
65
60
document . addEventListener ( 'keyup' , onKeyup . bind ( this ) )
0 commit comments