Merge pull request #1446 from jfirebaugh/unload

Fire an unload event on removal
This commit is contained in:
Vladimir Agafonkin 2013-02-21 21:53:39 -08:00
commit f0a75c9d08
2 changed files with 19 additions and 0 deletions

View File

@ -7,6 +7,22 @@ describe("Map", 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 () {
var container = document.createElement('div'),
map = new L.Map(container);

View File

@ -240,6 +240,9 @@ L.Map = L.Class.extend({
},
remove: function () {
if (this._loaded) {
this.fire('unload');
}
this._initEvents('off');
delete this._container._leaflet;
return this;