[Pkg-javascript-commits] [leaflet] 229/301: make className utils work for SVG elements in IE9, 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 c500d5ac1f9b907cd48236cf91bdf83bb6376edd
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date: Tue Nov 12 18:52:13 2013 +0200
make className utils work for SVG elements in IE9, ref #2164
---
src/dom/DomUtil.js | 28 +++++++++++++++++++++-------
src/layer/vector/Path.SVG.js | 6 +++---
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js
index 6b399f2..4eced9c 100644
--- a/src/dom/DomUtil.js
+++ b/src/dom/DomUtil.js
@@ -104,32 +104,46 @@ L.DomUtil = {
},
hasClass: function (el, name) {
- if ('classList' in el) {
+ if (el.classList !== undefined) {
return el.classList.contains(name);
}
- return (el.className.length > 0) &&
- new RegExp('(^|\\s)' + name + '(\\s|$)').test(el.className);
+ var className = L.DomUtil._getClass(el);
+ return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
},
addClass: function (el, name) {
- if ('classList' in el) {
+ if (el.classList !== undefined) {
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;
+ var className = L.DomUtil._getClass(el);
+ L.DomUtil._setClass(el, (className ? className + ' ' : '') + name);
}
},
removeClass: function (el, name) {
- if ('classList' in el) {
+ if (el.classList !== undefined) {
el.classList.remove(name);
} 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) {
if ('opacity' in el.style) {
diff --git a/src/layer/vector/Path.SVG.js b/src/layer/vector/Path.SVG.js
index d9e36c5..3abdfb8 100644
--- a/src/layer/vector/Path.SVG.js
+++ b/src/layer/vector/Path.SVG.js
@@ -110,7 +110,7 @@ L.Path = L.Path.extend({
_initEvents: function () {
if (this.options.clickable) {
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);
@@ -160,14 +160,14 @@ L.Map.include({
this._panes.overlayPane.appendChild(this._pathRoot);
if (this.options.zoomAnimation && L.Browser.any3d) {
- this._pathRoot.setAttribute('class', ' leaflet-zoom-animated');
+ L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-animated');
this.on({
'zoomanim': this._animatePathZoom,
'zoomend': this._endPathZoom
});
} else {
- this._pathRoot.setAttribute('class', ' leaflet-zoom-hide');
+ L.DomUtil.addClass(this._pathRoot, 'leaflet-zoom-hide');
}
this.on('moveend', this._updateSvgViewport);
--
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