Skip to content

Commit 9ce299b

Browse files
committed
fix SVG class manipulation in PhantomJS
1 parent 747a628 commit 9ce299b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/util/dom.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import config from '../config'
2+
import { isIE9 } from './env'
23
import { warn } from './debug'
34
import { camelize } from './lang'
45
import { removeWithTransition } from '../transition/index'
@@ -163,6 +164,22 @@ export function off (el, event, cb) {
163164
el.removeEventListener(event, cb)
164165
}
165166

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+
166183
/**
167184
* Add class with compatibility for IE & SVG
168185
*
@@ -176,7 +193,7 @@ export function addClass (el, cls) {
176193
} else {
177194
var cur = ' ' + (el.getAttribute('class') || '') + ' '
178195
if (cur.indexOf(' ' + cls + ' ') < 0) {
179-
el.className = (cur + cls).trim()
196+
setClass(el, (cur + cls).trim())
180197
}
181198
}
182199
}
@@ -197,7 +214,7 @@ export function removeClass (el, cls) {
197214
while (cur.indexOf(tar) >= 0) {
198215
cur = cur.replace(tar, ' ')
199216
}
200-
el.className = cur.trim()
217+
setClass(el, cur.trim())
201218
}
202219
if (!el.className) {
203220
el.removeAttribute('class')

0 commit comments

Comments
 (0)