Make function more sensible
Redo the getParent function: * Rename to findAncestorWithClass, which is a better name. * There's no reason the mouse event's target should not be allowed to be the popup's container itself, so check the element itself too. * Return null if nothing found instead of false.
This commit is contained in:
parent
b2c86c9a94
commit
77ceb6fa47
1 changed files with 11 additions and 13 deletions
|
@ -87,10 +87,10 @@ $(document).ready(function() {
|
|||
|
||||
// get the element that the mouse hovered onto
|
||||
var target = e.originalEvent.fromElement || e.originalEvent.relatedTarget;
|
||||
var parent = this._getParent(target, "leaflet-popup");
|
||||
var ancestor = this._findAncestorWithClass(target, "leaflet-popup");
|
||||
|
||||
// check to see if the element is a popup, and if it is this marker's popup
|
||||
if (parent == this._popup._container)
|
||||
if (ancestor && ancestor === this._popup._container)
|
||||
return true;
|
||||
|
||||
this.openPopup();
|
||||
|
@ -103,7 +103,7 @@ $(document).ready(function() {
|
|||
var target = e.originalEvent.toElement || e.originalEvent.relatedTarget;
|
||||
|
||||
// check to see if the element is a popup
|
||||
if (this._getParent(target, "leaflet-popup")) {
|
||||
if (this._findAncestorWithClass(target, "leaflet-popup")) {
|
||||
L.DomEvent.on(this._popup._container, "mouseout", this._popupMouseOut, this);
|
||||
return true;
|
||||
}
|
||||
|
@ -122,26 +122,24 @@ $(document).ready(function() {
|
|||
var target = e.toElement || e.relatedTarget;
|
||||
|
||||
// check to see if the element is a popup
|
||||
if (this._getParent(target, "leaflet-popup"))
|
||||
if (this._findAncestorWithClass(target, "leaflet-popup"))
|
||||
return true;
|
||||
|
||||
// check to see if the marker was hovered back onto
|
||||
if (target == this._icon)
|
||||
if (target === this._icon)
|
||||
return true;
|
||||
|
||||
this.closePopup();
|
||||
},
|
||||
|
||||
_getParent: function(element, className) {
|
||||
var parent = element.parentNode;
|
||||
|
||||
while (parent) {
|
||||
if (parent.className && L.DomUtil.hasClass(parent, className))
|
||||
return parent;
|
||||
parent = parent.parentNode;
|
||||
_findAncestorWithClass: function(element, className) {
|
||||
while (element) {
|
||||
if (element.className && L.DomUtil.hasClass(element, className))
|
||||
return element;
|
||||
element = element.parentNode;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue