add and use DomUtil.remove

This commit is contained in:
Vladimir Agafonkin 2013-12-05 14:35:39 +02:00
parent cf3e63adad
commit 6b9731283d
10 changed files with 20 additions and 26 deletions

View File

@ -55,10 +55,8 @@ L.Control = L.Class.extend({
},
removeFrom: function (map) {
var pos = this.getPosition(),
corner = map._controlCorners[pos];
L.DomUtil.remove(this._container);
corner.removeChild(this._container);
this._map = null;
if (this.onRemove) {
@ -112,6 +110,6 @@ L.Map.include({
},
_clearControlPos: function () {
this._container.removeChild(this._controlContainer);
L.DomUtil.remove(this._controlContainer);
}
});

View File

@ -96,6 +96,13 @@ L.DomUtil = {
return el;
},
remove: function (el) {
var parent = el.parentNode;
if (parent) {
parent.removeChild(el);
}
},
hasClass: function (el, name) {
if (el.classList !== undefined) {
return el.classList.contains(name);

View File

@ -35,7 +35,7 @@ L.ImageOverlay = L.Class.extend({
},
onRemove: function (map) {
map.getPanes().overlayPane.removeChild(this._image);
L.DomUtil.remove(this._image);
map.off('viewreset', this._reset, this);

View File

@ -74,17 +74,11 @@ L.Popup = L.Class.extend({
},
onRemove: function (map) {
var pane = this._getPane();
var removeFromPane = function () {
pane.removeChild(this._container);
};
if (map.options.fadeAnimation) {
L.DomUtil.setOpacity(this._container, 0);
setTimeout(L.bind(removeFromPane, this), 200);
setTimeout(L.bind(L.DomUtil.remove, L.DomUtil, this._container), 200);
} else {
removeFromPane();
L.DomUtil.remove(this._container);
}
map.off(this._getEvents(), this);

View File

@ -46,7 +46,7 @@ L.GridLayer = L.Class.extend({
onRemove: function (map) {
this._clearBgBuffer();
this._getPane().removeChild(this._container);
L.DomUtil.remove(this._container);
map.off(this._getEvents(), this);
@ -368,9 +368,7 @@ L.GridLayer = L.Class.extend({
_removeTile: function (key) {
var tile = this._tiles[key];
if (tile.parentNode) {
tile.parentNode.removeChild(tile);
}
L.DomUtil.remove(tile);
delete this._tiles[key];

View File

@ -172,7 +172,7 @@ L.TileLayer = L.GridLayer.extend({
tile.onerror = L.Util.falseFn;
tile.src = L.Util.emptyImageUrl;
tile.parentNode.removeChild(tile);
L.DomUtil.remove(tile);
}
}
}

View File

@ -215,7 +215,7 @@ L.Map.include({
// Hack to make flicker on drag end on mobile webkit less irritating
if (L.Browser.mobileWebkit) {
pane.removeChild(root);
L.DomUtil.remove(root);
}
L.DomUtil.setPosition(root, min);

View File

@ -65,7 +65,7 @@ L.Path = L.Class.extend({
},
onRemove: function (map) {
map._pathRoot.removeChild(this._container);
L.DomUtil.remove(this._container);
// Need to fire remove event before we set _map to null as the event hooks might need the object
this.fire('remove');

View File

@ -295,7 +295,8 @@ L.Map = L.Class.extend({
this._container._leaflet = undefined;
}
this._clearPanes();
L.DomUtil.remove(this._mapPane);
if (this._clearControlPos) {
this._clearControlPos();
}
@ -533,10 +534,6 @@ L.Map = L.Class.extend({
return L.DomUtil.create('div', className, container || this._panes.objectsPane);
},
_clearPanes: function () {
this._container.removeChild(this._mapPane);
},
_addLayers: function (layers) {
layers = layers ? (L.Util.isArray(layers) ? layers : [layers]) : [];

View File

@ -75,7 +75,7 @@ L.Map.BoxZoom = L.Handler.extend({
_finish: function () {
if (this._moved) {
this._pane.removeChild(this._box);
L.DomUtil.remove(this._box);
this._container.style.cursor = '';
}