@@ -34,26 +34,13 @@ export const PLACEMENTS = {
3434 LEFT : 'left' ,
3535} ;
3636
37- export function isIE11 ( ) {
38- /* istanbul ignore next */
39- return ! ! window . MSInputMethodContext && ! ! document . documentMode ;
40- }
41-
42- export function isIE10 ( ) {
43- return window . navigator . appVersion . indexOf ( 'MSIE 10' ) !== - 1 ;
44- }
45-
4637export function getComputedStyle ( el ) {
4738 return window . getComputedStyle ( el ) ;
4839}
4940
5041export function getViewportSize ( ) {
51- /* istanbul ignore next */
52- const width =
53- Math . max ( document . documentElement . clientWidth , window . innerWidth ) || 0 ;
54- /* istanbul ignore next */
55- const height =
56- Math . max ( document . documentElement . clientHeight , window . innerHeight ) || 0 ;
42+ const width = window . innerWidth || 0 ;
43+ const height = window . innerHeight || 0 ;
5744 return { width, height } ;
5845}
5946
@@ -95,12 +82,10 @@ export function getScrollbarWidth(recalculate = false) {
9582}
9683
9784export function on ( element , event , handler ) {
98- /* istanbul ignore next */
9985 element . addEventListener ( event , handler ) ;
10086}
10187
10288export function off ( element , event , handler ) {
103- /* istanbul ignore next */
10489 element . removeEventListener ( event , handler ) ;
10590}
10691
@@ -116,44 +101,21 @@ export function addClass(el, className) {
116101 if ( ! isElement ( el ) ) {
117102 return ;
118103 }
119- if ( el . className ) {
120- const classes = el . className . split ( ' ' ) ;
121- if ( classes . indexOf ( className ) < 0 ) {
122- classes . push ( className ) ;
123- el . className = classes . join ( ' ' ) ;
124- }
125- } else {
126- el . className = className ;
127- }
104+ el . classList . add ( className ) ;
128105}
129106
130107export function removeClass ( el , className ) {
131108 if ( ! isElement ( el ) ) {
132109 return ;
133110 }
134- if ( el . className ) {
135- const classes = el . className . split ( ' ' ) ;
136- const newClasses = [ ] ;
137- for ( let i = 0 , l = classes . length ; i < l ; i ++ ) {
138- if ( classes [ i ] !== className ) {
139- newClasses . push ( classes [ i ] ) ;
140- }
141- }
142- el . className = newClasses . join ( ' ' ) ;
143- }
111+ el . classList . remove ( className ) ;
144112}
145113
146114export function hasClass ( el , className ) {
147115 if ( ! isElement ( el ) ) {
148116 return false ;
149117 }
150- const classes = el . className . split ( ' ' ) ;
151- for ( let i = 0 , l = classes . length ; i < l ; i ++ ) {
152- if ( classes [ i ] === className ) {
153- return true ;
154- }
155- }
156- return false ;
118+ return el . classList . contains ( className ) ;
157119}
158120
159121export function setDropdownPosition ( dropdown , trigger , options = { } ) {
@@ -364,10 +326,9 @@ export function toggleBodyOverflow(enable) {
364326 node . style . paddingRight = null ;
365327 } ) ;
366328 } else {
367- const browsersWithFloatingScrollbar = isIE10 ( ) || isIE11 ( ) ;
368329 const documentHasScrollbar =
369330 hasScrollbar ( document . documentElement ) || hasScrollbar ( document . body ) ;
370- if ( documentHasScrollbar && ! browsersWithFloatingScrollbar ) {
331+ if ( documentHasScrollbar ) {
371332 const scrollbarWidth = getScrollbarWidth ( ) ;
372333 body . style . paddingRight = `${ scrollbarWidth } px` ;
373334 [ ...document . querySelectorAll ( FIXED_CONTENT ) ] . forEach ( ( node ) => {
@@ -379,16 +340,10 @@ export function toggleBodyOverflow(enable) {
379340}
380341
381342export function getClosest ( el , selector ) {
382- let parent ;
383- let _el = el ;
384- while ( _el ) {
385- parent = _el . parentElement ;
386- if ( parent && parent . matches ( selector ) ) {
387- return parent ;
388- }
389- _el = parent ;
343+ if ( ! isElement ( el ) ) {
344+ return null ;
390345 }
391- return null ;
346+ return el . closest ( selector ) ;
392347}
393348
394349export function getParents ( el , selector , until = null ) {
0 commit comments