Commit f981b279 authored by Remon Huijts's avatar Remon Huijts
Browse files

Combine installClick and installHover into one installHandler

parent b8afef88
......@@ -123015,10 +123015,7 @@ var interactions = {
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
// To support mobile, both click and hover will trigger the
// defined onclick action:
interactions.installClick(handler, graph, triggerNodes);
interactions.installHover(handler, graph, triggerNodes);
interactions.installHandler(handler, graph, triggerNodes);
});
}
 
......@@ -123026,28 +123023,37 @@ var interactions = {
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
// To support mobile, both click and hover will trigger the
// defined onhover action:
interactions.installClick(handler, graph, triggerNodes);
interactions.installHover(handler, graph, triggerNodes);
interactions.installHandler(handler, graph, triggerNodes);
});
}
});
},
 
/**
* Function: installClick
* Function: installHandler
*
* Install event handlers to run a handler when the given node is clicked.
* Install an event handler to be triggered when the specified nodes are
* clicked or hovered over. Click and hover are treated as the same trigger
* to ensure compatibility between desktop and mobile usage.
*
* Parameters:
*
* handler - handler function representing action to run
* graph - graph object to install handlers for
* nodes - nodes that should trigger the action when clicked
* nodes - nodes that should trigger the action when clicked or hovered
*/
installClick: function(handler, graph, nodes) {
installHandler: function(handler, graph, nodes) {
nodes.forEach(function(node) {
// Let the handler be triggered by hover events:
var reset;
node.addEventListener('mouseover', function(e) {
reset = handler(graph);
});
node.addEventListener('mouseout', function(e) {
reset();
});
// let the handler be triggerd by click events:
node.addEventListener('click', function(e) {
var reset = handler(graph);
// Install a handler to run the `reset` function of the given
......@@ -123063,30 +123069,6 @@ var interactions = {
});
},
 
/**
* Function: installHover
*
* Install event handlers to run an action when the given node is hovered
* over.
*
* Parameters:
*
* handler - handler function representing action to run
* graph - graph object to install handlers for
* nodes - nodes that should trigger the action when hovered over
*/
installHover: function(handler, graph, nodes) {
nodes.forEach(function(node) {
var reset;
node.addEventListener('mouseover', function(e) {
reset = handler(graph);
});
node.addEventListener('mouseout', function(e) {
reset();
});
});
},
/**
* Function: createEventHandlers
*
......@@ -43,10 +43,7 @@ var interactions = {
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
// To support mobile, both click and hover will trigger the
// defined onclick action:
interactions.installClick(handler, graph, triggerNodes);
interactions.installHover(handler, graph, triggerNodes);
interactions.installHandler(handler, graph, triggerNodes);
});
}
......@@ -54,28 +51,37 @@ var interactions = {
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
// To support mobile, both click and hover will trigger the
// defined onhover action:
interactions.installClick(handler, graph, triggerNodes);
interactions.installHover(handler, graph, triggerNodes);
interactions.installHandler(handler, graph, triggerNodes);
});
}
});
},
/**
* Function: installClick
* Function: installHandler
*
* Install event handlers to run a handler when the given node is clicked.
* Install an event handler to be triggered when the specified nodes are
* clicked or hovered over. Click and hover are treated as the same trigger
* to ensure compatibility between desktop and mobile usage.
*
* Parameters:
*
* handler - handler function representing action to run
* graph - graph object to install handlers for
* nodes - nodes that should trigger the action when clicked
* nodes - nodes that should trigger the action when clicked or hovered
*/
installClick: function(handler, graph, nodes) {
installHandler: function(handler, graph, nodes) {
nodes.forEach(function(node) {
// Let the handler be triggered by hover events:
var reset;
node.addEventListener('mouseover', function(e) {
reset = handler(graph);
});
node.addEventListener('mouseout', function(e) {
reset();
});
// let the handler be triggerd by click events:
node.addEventListener('click', function(e) {
var reset = handler(graph);
// Install a handler to run the `reset` function of the given
......@@ -91,30 +97,6 @@ var interactions = {
});
},
/**
* Function: installHover
*
* Install event handlers to run an action when the given node is hovered
* over.
*
* Parameters:
*
* handler - handler function representing action to run
* graph - graph object to install handlers for
* nodes - nodes that should trigger the action when hovered over
*/
installHover: function(handler, graph, nodes) {
nodes.forEach(function(node) {
var reset;
node.addEventListener('mouseover', function(e) {
reset = handler(graph);
});
node.addEventListener('mouseout', function(e) {
reset();
});
});
},
/**
* Function: createEventHandlers
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment