make className utils work for SVG elements in IE9, ref #2164
This commit is contained in:
parent
9babc039f0
commit
c500d5ac1f
@ -104,32 +104,46 @@ L.DomUtil = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
hasClass: function (el, name) {
|
hasClass: function (el, name) {
|
||||||
if ('classList' in el) {
|
if (el.classList !== undefined) {
|
||||||
return el.classList.contains(name);
|
return el.classList.contains(name);
|
||||||
}
|
}
|
||||||
return (el.className.length > 0) &&
|
var className = L.DomUtil._getClass(el);
|
||||||
new RegExp('(^|\\s)' + name + '(\\s|$)').test(el.className);
|
return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
|
||||||
},
|
},
|
||||||
|
|
||||||
addClass: function (el, name) {
|
addClass: function (el, name) {
|
||||||
if ('classList' in el) {
|
if (el.classList !== undefined) {
|
||||||
var classes = L.Util.splitWords(name);
|
var classes = L.Util.splitWords(name);
|
||||||
for (var i = 0, len = classes.length; i < len; i++) {
|
for (var i = 0, len = classes.length; i < len; i++) {
|
||||||
el.classList.add(classes[i]);
|
el.classList.add(classes[i]);
|
||||||
}
|
}
|
||||||
} else if (!L.DomUtil.hasClass(el, name)) {
|
} else if (!L.DomUtil.hasClass(el, name)) {
|
||||||
el.className += (el.className ? ' ' : '') + name;
|
var className = L.DomUtil._getClass(el);
|
||||||
|
L.DomUtil._setClass(el, (className ? className + ' ' : '') + name);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeClass: function (el, name) {
|
removeClass: function (el, name) {
|
||||||
if ('classList' in el) {
|
if (el.classList !== undefined) {
|
||||||
el.classList.remove(name);
|
el.classList.remove(name);
|
||||||
} else {
|
} else {
|
||||||
el.className = L.Util.trim((' ' + el.className + ' ').replace(' ' + name + ' ', ' '));
|
L.DomUtil._setClass(el, L.Util.trim((' ' + L.DomUti._getClass(el) + ' ').replace(' ' + name + ' ', ' ')));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_setClass: function (el, name) {
|
||||||
|
if (el.className.baseVal === undefined) {
|
||||||
|
el.className = name;
|
||||||
|
} else {
|
||||||
|
// in case of SVG element
|
||||||
|
el.className.baseVal = name;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_getClass: function (el) {
|
||||||
|
return el.className.baseVal === undefined ? el.className : el.className.baseVal;
|
||||||
|
},
|
||||||
|
|
||||||
setOpacity: function (el, value) {
|
setOpacity: function (el, value) {
|
||||||
|
|
||||||
if ('opacity' in el.style) {
|
if ('opacity' in el.style) {
|
||||||
|
@ -110,7 +110,7 @@ L.Path = L.Path.extend({
|
|||||||
_initEvents: function () {
|
_initEvents: function () {
|
||||||
if (this.options.clickable) {
|
if (this.options.clickable) {
|
||||||
if (L.Browser.svg || !L.Browser.vml) {
|
if (L.Browser.svg || !L.Browser.vml) {
|
||||||
this._path.setAttribute('class', 'leaflet-clickable');
|
L.DomUtil.addClass(this._path, 'leaflet-clickable');
|
||||||
}
|
}
|
||||||
|
|
||||||
L.DomEvent.on(this._container, 'click', this._onMouseClick, this);
|
L.DomEvent.on(this._container, 'click', this._onMouseClick, this);
|
||||||
@ -160,14 +160,14 @@ L.Map.include({
|
|||||||
this._panes.overlayPane.appendChild(this._pathRoot);
|
this._panes.overlayPane.appendChild(this._pathRoot);
|
||||||
|
|
||||||
if (this.options.zoomAnimation && L.Browser.any3d) {
|
if (this.options.zoomAnimation && L.Browser.any3d) {
|
||||||
this._pathRoot.setAttribute('class', ' leaflet-zoom-animated');
|
L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-animated');
|
||||||
|
|
||||||
this.on({
|
this.on({
|
||||||
'zoomanim': this._animatePathZoom,
|
'zoomanim': this._animatePathZoom,
|
||||||
'zoomend': this._endPathZoom
|
'zoomend': this._endPathZoom
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._pathRoot.setAttribute('class', ' leaflet-zoom-hide');
|
L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on('moveend', this._updateSvgViewport);
|
this.on('moveend', this._updateSvgViewport);
|
||||||
|
Loading…
Reference in New Issue
Block a user