addClass, hasClass utility methods

This commit is contained in:
Mourner 2011-03-23 18:28:03 +02:00
parent 06e0c90d75
commit 7e9d530f98

View File

@ -54,6 +54,18 @@ L.DomUtil = {
this._onselectstart = null; this._onselectstart = null;
}, },
CLASS_RE: /(\\s|^)'+cls+'(\\s|$)/,
hasClass: function(el, name) {
return (el.className.length > 0) &&
new RegExp("(^|\\s)" + name + "(\\s|$)").test(el.className);
},
addClass: function(el, name) {
if (!L.DomUtil.hasClass(el, name)) {
el.className += (el.className ? ' ' : '') + name;
}
},
//TODO refactor away this ugly translate/position mess //TODO refactor away this ugly translate/position mess