Fire an unload event on removal
Plugins that need to bind events to `window` or `document` can attach a listener for this event and unbind their event handlers. However, for symmetry, unload is fired only if load has been fired.
This commit is contained in:
parent
2aae4a0556
commit
46dddc895c
@ -7,6 +7,22 @@ describe("Map", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#remove", function () {
|
describe("#remove", function () {
|
||||||
|
it("fires an unload event if loaded", function () {
|
||||||
|
var container = document.createElement('div'),
|
||||||
|
map = new L.Map(container).setView([0, 0], 0);
|
||||||
|
map.on('unload', spy);
|
||||||
|
map.remove();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fires no unload event if not loaded", function () {
|
||||||
|
var container = document.createElement('div'),
|
||||||
|
map = new L.Map(container);
|
||||||
|
map.on('unload', spy);
|
||||||
|
map.remove();
|
||||||
|
expect(spy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("undefines container._leaflet", function () {
|
it("undefines container._leaflet", function () {
|
||||||
var container = document.createElement('div'),
|
var container = document.createElement('div'),
|
||||||
map = new L.Map(container);
|
map = new L.Map(container);
|
||||||
|
@ -240,6 +240,9 @@ L.Map = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
remove: function () {
|
remove: function () {
|
||||||
|
if (this._loaded) {
|
||||||
|
this.fire('unload');
|
||||||
|
}
|
||||||
this._initEvents('off');
|
this._initEvents('off');
|
||||||
delete this._container._leaflet;
|
delete this._container._leaflet;
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user