1
1
import config from '../config'
2
+ import { isIE9 } from './env'
2
3
import { warn } from './debug'
3
4
import { camelize } from './lang'
4
5
import { removeWithTransition } from '../transition/index'
@@ -163,6 +164,22 @@ export function off (el, event, cb) {
163
164
el . removeEventListener ( event , cb )
164
165
}
165
166
167
+ /**
168
+ * In IE9, setAttribute('class') will result in empty class
169
+ * if the element also has the :class attribute; However in
170
+ * PhantomJS, setting `className` does not work on SVG elements...
171
+ * So we have to do a conditional detection here.
172
+ */
173
+
174
+ const setClass = isIE9
175
+ ? function ( el , cls ) {
176
+ /* istanbul ignore next */
177
+ el . className = cls
178
+ }
179
+ : function ( el , cls ) {
180
+ el . setAttribute ( 'class' , cls )
181
+ }
182
+
166
183
/**
167
184
* Add class with compatibility for IE & SVG
168
185
*
@@ -176,7 +193,7 @@ export function addClass (el, cls) {
176
193
} else {
177
194
var cur = ' ' + ( el . getAttribute ( 'class' ) || '' ) + ' '
178
195
if ( cur . indexOf ( ' ' + cls + ' ' ) < 0 ) {
179
- el . className = ( cur + cls ) . trim ( )
196
+ setClass ( el , ( cur + cls ) . trim ( ) )
180
197
}
181
198
}
182
199
}
@@ -197,7 +214,7 @@ export function removeClass (el, cls) {
197
214
while ( cur . indexOf ( tar ) >= 0 ) {
198
215
cur = cur . replace ( tar , ' ' )
199
216
}
200
- el . className = cur . trim ( )
217
+ setClass ( el , cur . trim ( ) )
201
218
}
202
219
if ( ! el . className ) {
203
220
el . removeAttribute ( 'class' )
0 commit comments