commit
06190b1ec8
@ -6,6 +6,28 @@ describe("Map", function () {
|
||||
spy = jasmine.createSpy();
|
||||
});
|
||||
|
||||
describe("#remove", function () {
|
||||
it("undefines container._leaflet", function () {
|
||||
var container = document.createElement('div'),
|
||||
map = new L.Map(container);
|
||||
map.remove();
|
||||
expect(container._leaflet).toBeUndefined();
|
||||
});
|
||||
|
||||
it("unbinds events", function () {
|
||||
var container = document.createElement('div'),
|
||||
map = new L.Map(container).setView([0, 0], 1);
|
||||
map.on('click dblclick mousedown mouseup mousemove', spy);
|
||||
map.remove();
|
||||
happen.click(container);
|
||||
happen.dblclick(container);
|
||||
happen.mousedown(container);
|
||||
happen.mouseup(container);
|
||||
happen.mousemove(container);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCenter', function () {
|
||||
it ('throws if not set before', function () {
|
||||
expect(function () {
|
||||
|
@ -12,7 +12,8 @@ for (var i=0; i < libSources.length; i++) {
|
||||
files = [].concat([
|
||||
JASMINE,
|
||||
JASMINE_ADAPTER,
|
||||
"before.js"
|
||||
"before.js",
|
||||
"testacular.js"
|
||||
], libSources, [
|
||||
"after.js",
|
||||
"happen.js",
|
||||
|
7
spec/testacular.js
Normal file
7
spec/testacular.js
Normal file
@ -0,0 +1,7 @@
|
||||
// PhantomJS has `'ontouchstart' in document.documentElement`, but
|
||||
// doesn't actually support touch. So force touch not to be used.
|
||||
//
|
||||
// http://code.google.com/p/phantomjs/issues/detail?id=375
|
||||
// https://github.com/ariya/phantomjs/pull/408
|
||||
// https://github.com/Leaflet/Leaflet/pull/1434#issuecomment-13843151
|
||||
window.L_NO_TOUCH = true;
|
@ -239,6 +239,12 @@ L.Map = L.Class.extend({
|
||||
return this;
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this._initEvents('off');
|
||||
delete this._container._leaflet;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
// public methods for getting map state
|
||||
|
||||
@ -571,21 +577,23 @@ L.Map = L.Class.extend({
|
||||
|
||||
// map events
|
||||
|
||||
_initEvents: function () {
|
||||
_initEvents: function (onOff) {
|
||||
if (!L.DomEvent) { return; }
|
||||
|
||||
L.DomEvent.on(this._container, 'click', this._onMouseClick, this);
|
||||
onOff = onOff || 'on';
|
||||
|
||||
L.DomEvent[onOff](this._container, 'click', this._onMouseClick, this);
|
||||
|
||||
var events = ['dblclick', 'mousedown', 'mouseup', 'mouseenter',
|
||||
'mouseleave', 'mousemove', 'contextmenu'],
|
||||
i, len;
|
||||
|
||||
for (i = 0, len = events.length; i < len; i++) {
|
||||
L.DomEvent.on(this._container, events[i], this._fireMouseEvent, this);
|
||||
L.DomEvent[onOff](this._container, events[i], this._fireMouseEvent, this);
|
||||
}
|
||||
|
||||
if (this.options.trackResize) {
|
||||
L.DomEvent.on(window, 'resize', this._onResize, this);
|
||||
L.DomEvent[onOff](window, 'resize', this._onResize, this);
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user