use classList for class ops where available; ref #2164
makes it much faster, and also makes adding/removing classes work for SVG elements
This commit is contained in:
parent
edfa2acb70
commit
9babc039f0
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user