Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #56 from Calvein/patch-2

Use classList if the browser support it
  • Loading branch information...
commit 8ac54da7e69bb0d8f7ddd590b20577d769d4adab 2 parents cee9d6b + 3003af4
@ded authored
Showing with 14 additions and 5 deletions.
  1. +14 −5 bonzo.js
View
19 bonzo.js
@@ -53,6 +53,7 @@
if (props[i] in e.style) return props[i]
}
}()
+ , classList: 'classList' in e
}
}()
, trimReplace = /(^\s*|\s*$)/g
@@ -209,14 +210,22 @@
}
- function hasClass(el, c) {
+ var hasClass = features.classList ? function (el, c) {
+ return el.classList.contains(c)
+ } : function (el, c) {
return classReg(c).test(el.className)
}
- function addClass(el, c) {
- el.className = trim(el.className + ' ' + c)
+
+ var addClass = features.classList ? function (el, c) {
+ return el.classList.add(c)
+ } : function (el, c) {
+ return el.className = trim(el.className + ' ' + c)
}
- function removeClass(el, c) {
- el.className = trim(el.className.replace(classReg(c), ' '))
+
+ var removeClass = features.classList ? function (el, c) {
+ return el.classList.remove(c)
+ } : function (el, c) {
+ return el.className = trim(el.className.replace(classReg(c), ' '))
}
// this allows method calling for setting values
Please sign in to comment.
Something went wrong with that request. Please try again.