fix tests, misc cleanup

This commit is contained in:
Patrick Arlt 2014-12-29 13:50:23 -08:00
parent 940452ace0
commit 2d709141a8
3 changed files with 23 additions and 21 deletions

View File

@ -36,25 +36,23 @@
var features = new L.FeatureGroup();
for (var i = 0; i < 10000; i++) {
var marker = L.marker(getRandomLatLng(map)).addTo(features);
}
var marker = L.marker(getRandomLatLng(map)).addTo(features);
// var line = L.polyline([
// getRandomLatLng(map),
// getRandomLatLng(map),
// getRandomLatLng(map)
// ]).addTo(features);
var line = L.polyline([
getRandomLatLng(map),
getRandomLatLng(map),
getRandomLatLng(map)
]).addTo(features);
// var poly = L.polygon([
// getRandomLatLng(map),
// getRandomLatLng(map),
// getRandomLatLng(map),
// getRandomLatLng(map)
// ]).addTo(features);
var poly = L.polygon([
getRandomLatLng(map),
getRandomLatLng(map),
getRandomLatLng(map),
getRandomLatLng(map)
]).addTo(features);
features.bindPopup(function(layer){
return layer._leaflet_id + 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p><p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque.';
return 'Leaflet ID is ' + layer._leaflet_id;
}).addTo(map);
L.DomUtil.get('change').onclick = function(){

View File

@ -56,9 +56,9 @@ describe('Popup', function () {
happen.click(c);
// toggle open popup
sinon.spy(marker, "openPopup");
sinon.spy(marker, "_openPopup");
marker.fire('click');
expect(marker.openPopup.calledOnce).to.be(true);
expect(marker._openPopup.calledOnce).to.be(true);
expect(map.hasLayer(marker._popup)).to.be(true);
marker.openPopup.restore();

View File

@ -79,12 +79,16 @@ L.Layer.include({
},
_openPopup: function (e) {
this._popup.options.offset = this._popupAnchor(e.layer || e.target);
if(typeof this._popup._content === 'function') {
if(this._popup && this._map && this._map.hasLayer(this._popup) && this._popup._source === e.layer){
this.closePopup();
} else {
this._popup.options.offset = this._popupAnchor(e.layer || e.target);
this._popup._source = e.layer;
this._popup.update();
if(typeof this._popup._content === 'function') {
this._popup.update();
}
this._map.openPopup(this._popup, e.latlng);
}
this._map.openPopup(this._popup, e.latlng);
},
_popupAnchor: function(layer){