[Pkg-javascript-commits] [leaflet] 228/301: use classList for class ops where available; ref #2164
Jonas Smedegaard
js at moszumanska.debian.org
Mon Jan 27 22:22:53 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet.
commit 9babc039f0936b1731ea8ef9393e75c6c2cdc6c2
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date: Tue Nov 12 17:50:45 2013 +0200
use classList for class ops where available; ref #2164
makes it much faster, and also makes adding/removing classes work for
SVG elements
---
src/dom/DomUtil.js | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js
index 186cfde..6b399f2 100644
--- a/src/dom/DomUtil.js
+++ b/src/dom/DomUtil.js
@@ -104,18 +104,30 @@ L.DomUtil = {
},
hasClass: function (el, name) {
+ if ('classList' in el) {
+ return el.classList.contains(name);
+ }
return (el.className.length > 0) &&
new RegExp('(^|\\s)' + name + '(\\s|$)').test(el.className);
},
addClass: function (el, name) {
- if (!L.DomUtil.hasClass(el, name)) {
+ if ('classList' in el) {
+ var classes = L.Util.splitWords(name);
+ for (var i = 0, len = classes.length; i < len; i++) {
+ el.classList.add(classes[i]);
+ }
+ } else if (!L.DomUtil.hasClass(el, name)) {
el.className += (el.className ? ' ' : '') + name;
}
},
removeClass: function (el, name) {
- el.className = L.Util.trim((' ' + el.className + ' ').replace(' ' + name + ' ', ' '));
+ if ('classList' in el) {
+ el.classList.remove(name);
+ } else {
+ el.className = L.Util.trim((' ' + el.className + ' ').replace(' ' + name + ' ', ' '));
+ }
},
setOpacity: function (el, value) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git
More information about the Pkg-javascript-commits
mailing list