@@ -15,18 +15,25 @@ define([
15
15
var originalMatchMedia , originalModernizr , stopEventFn ;
16
16
17
17
function extractStopEvent ( source ) {
18
- var start = source . indexOf ( 'function stopEvent' ) ;
18
+ let start = source . indexOf ( 'function stopEvent' ) ,
19
+ braceStart ,
20
+ depth ,
21
+ i ,
22
+ end ,
23
+ ch ;
24
+
19
25
if ( start === - 1 ) {
20
26
return undefined ;
21
27
}
22
- var braceStart = source . indexOf ( '{' , start ) ;
23
- var depth = 0 , i = braceStart , end = - 1 ;
28
+ braceStart = source . indexOf ( '{' , start ) ;
29
+ depth = 0 , i = braceStart , end = - 1 ;
24
30
for ( ; i < source . length ; i ++ ) {
25
- var ch = source [ i ] ;
31
+ ch = source [ i ] ;
26
32
if ( ch === '{' ) {
27
33
depth ++ ;
28
34
} else if ( ch === '}' ) {
29
35
depth -- ;
36
+ // eslint-disable-next-line max-depth
30
37
if ( depth === 0 ) {
31
38
end = i + 1 ;
32
39
break ;
@@ -37,7 +44,7 @@ define([
37
44
return undefined ;
38
45
}
39
46
// eslint-disable-next-line no-new-func
40
- return ( new Function ( 'return (' + source . slice ( start , end ) + ');' ) ) ( ) ;
47
+ return new Function ( 'return (' + source . slice ( start , end ) + ');' ) ( ) ;
41
48
}
42
49
43
50
beforeAll ( function ( ) {
@@ -66,33 +73,37 @@ define([
66
73
}
67
74
68
75
it ( 'prevents default and stops propagation on mobile touchend' , function ( ) {
69
- window . matchMedia = function ( ) { return { matches : true } ; } ;
70
76
var e = mockEvent ( 'touchend' ) ;
77
+
78
+ window . matchMedia = function ( ) { return { matches : true } ; } ;
71
79
stopEventFn ( e ) ;
72
80
expect ( e . preventDefault ) . toHaveBeenCalled ( ) ;
73
81
expect ( e . stopPropagation ) . toHaveBeenCalled ( ) ;
74
82
} ) ;
75
83
76
84
it ( 'prevents default on desktop click when Modernizr.touch is false' , function ( ) {
85
+ var e = mockEvent ( 'click' ) ;
86
+
77
87
window . matchMedia = function ( ) { return { matches : false } ; } ;
78
88
window . Modernizr . touch = false ;
79
- var e = mockEvent ( 'click' ) ;
80
89
stopEventFn ( e ) ;
81
90
expect ( e . preventDefault ) . toHaveBeenCalled ( ) ;
82
91
} ) ;
83
92
84
93
it ( 'does not prevent default on desktop click when Modernizr.touch is true' , function ( ) {
94
+ var e = mockEvent ( 'click' ) ;
95
+
85
96
window . matchMedia = function ( ) { return { matches : false } ; } ;
86
97
window . Modernizr . touch = true ;
87
- var e = mockEvent ( 'click' ) ;
88
98
stopEventFn ( e ) ;
89
99
expect ( e . preventDefault ) . not . toHaveBeenCalled ( ) ;
90
100
} ) ;
91
101
92
102
it ( 'stops propagation when second argument is true' , function ( ) {
103
+ var e = mockEvent ( 'click' ) ;
104
+
93
105
window . matchMedia = function ( ) { return { matches : false } ; } ;
94
106
window . Modernizr . touch = false ;
95
- var e = mockEvent ( 'click' ) ;
96
107
stopEventFn ( e , true ) ;
97
108
expect ( e . stopPropagation ) . toHaveBeenCalled ( ) ;
98
109
} ) ;
0 commit comments