mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
/*
|
|
The hover behavior adds the `.hover` class on mouseover to all elements to which
|
|
the identical datum is bound, and removes it on mouseout.
|
|
|
|
The :hover pseudo-class is insufficient for iD's purposes because a datum's visual
|
|
representation may consist of several elements scattered throughout the DOM hierarchy.
|
|
Only one of these elements can have the :hover pseudo-class, but all of them will
|
|
have the .hover class.
|
|
*/
|
|
iD.behavior.Hover = function () {
|
|
var hover = function(selection) {
|
|
selection.on('mouseover.hover', function () {
|
|
var datum = d3.event.target.__data__;
|
|
if (datum) {
|
|
selection.selectAll('*')
|
|
.filter(function (d) { return d === datum; })
|
|
.classed('hover', true);
|
|
}
|
|
});
|
|
|
|
selection.on('mouseout.hover', function () {
|
|
selection.selectAll('.hover')
|
|
.classed('hover', false);
|
|
});
|
|
};
|
|
|
|
hover.off = function(selection) {
|
|
selection.on('mouseover.hover', null)
|
|
.on('mouseout.hover', null);
|
|
};
|
|
|
|
return hover;
|
|
};
|