aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue/src/platforms/web/runtime/class-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/vue/src/platforms/web/runtime/class-util.js')
-rw-r--r--node_modules/vue/src/platforms/web/runtime/class-util.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/node_modules/vue/src/platforms/web/runtime/class-util.js b/node_modules/vue/src/platforms/web/runtime/class-util.js
new file mode 100644
index 00000000..709526c2
--- /dev/null
+++ b/node_modules/vue/src/platforms/web/runtime/class-util.js
@@ -0,0 +1,61 @@
+/* @flow */
+
+/**
+ * Add class with compatibility for SVG since classList is not supported on
+ * SVG elements in IE
+ */
+export function addClass (el: HTMLElement, cls: ?string) {
+ /* istanbul ignore if */
+ if (!cls || !(cls = cls.trim())) {
+ return
+ }
+
+ /* istanbul ignore else */
+ if (el.classList) {
+ if (cls.indexOf(' ') > -1) {
+ cls.split(/\s+/).forEach(c => el.classList.add(c))
+ } else {
+ el.classList.add(cls)
+ }
+ } else {
+ const cur = ` ${el.getAttribute('class') || ''} `
+ if (cur.indexOf(' ' + cls + ' ') < 0) {
+ el.setAttribute('class', (cur + cls).trim())
+ }
+ }
+}
+
+/**
+ * Remove class with compatibility for SVG since classList is not supported on
+ * SVG elements in IE
+ */
+export function removeClass (el: HTMLElement, cls: ?string) {
+ /* istanbul ignore if */
+ if (!cls || !(cls = cls.trim())) {
+ return
+ }
+
+ /* istanbul ignore else */
+ if (el.classList) {
+ if (cls.indexOf(' ') > -1) {
+ cls.split(/\s+/).forEach(c => el.classList.remove(c))
+ } else {
+ el.classList.remove(cls)
+ }
+ if (!el.classList.length) {
+ el.removeAttribute('class')
+ }
+ } else {
+ let cur = ` ${el.getAttribute('class') || ''} `
+ const tar = ' ' + cls + ' '
+ while (cur.indexOf(tar) >= 0) {
+ cur = cur.replace(tar, ' ')
+ }
+ cur = cur.trim()
+ if (cur) {
+ el.setAttribute('class', cur)
+ } else {
+ el.removeAttribute('class')
+ }
+ }
+}