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

Delegate input checks to make code more DRY and robust

parent f981b279
......@@ -123012,20 +123012,14 @@ var interactions = {
var handlers = [];
 
var actionString = cell.value.getAttribute('onclick');
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
}
handlers.concat(interactions.createEventHandlers(graph, actionString));
// Legacy graphs had actions in the onhover attribute as well:
actionString = cell.value.getAttribute('onhover');
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
}
handlers.concat(interactions.createEventHandlers(graph, actionString));
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
});
},
 
......@@ -123072,8 +123066,8 @@ var interactions = {
/**
* Function: createEventHandlers
*
* Parse the action string (e.g., value of an onhover attribute)
* and create the corresponding event handlers.
* Parse the action string (e.g., value of an onclick attribute) and create
* the corresponding event handlers.
*
* The action string should be formatted in json. It should be a list of
* dictionaries, each representing an action. Every dictionary should have
......@@ -123095,9 +123089,14 @@ var interactions = {
* actionString - attribute value to parse
*/
createEventHandlers: function(graph, actionString) {
var rules = JSON.parse(actionString);
var handlers = [];
rules.forEach(function(rule) {
// Check if the actionString is false, zero, null, undefined or empty:
if (!actionString) {
return handlers;
}
JSON.parse(actionString).forEach(function(rule) {
if (typeof rule.action == 'undefined') {
debug("field 'action' not specified");
return;
......@@ -40,20 +40,14 @@ var interactions = {
var handlers = [];
var actionString = cell.value.getAttribute('onclick');
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
}
handlers.concat(interactions.createEventHandlers(graph, actionString));
// Legacy graphs had actions in the onhover attribute as well:
actionString = cell.value.getAttribute('onhover');
if (actionString != null && actionString != '') {
handlers = interactions.createEventHandlers(graph, actionString);
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
}
handlers.concat(interactions.createEventHandlers(graph, actionString));
handlers.forEach(function(handler) {
interactions.installHandler(handler, graph, triggerNodes);
});
});
},
......@@ -100,8 +94,8 @@ var interactions = {
/**
* Function: createEventHandlers
*
* Parse the action string (e.g., value of an onhover attribute)
* and create the corresponding event handlers.
* Parse the action string (e.g., value of an onclick attribute) and create
* the corresponding event handlers.
*
* The action string should be formatted in json. It should be a list of
* dictionaries, each representing an action. Every dictionary should have
......@@ -123,9 +117,14 @@ var interactions = {
* actionString - attribute value to parse
*/
createEventHandlers: function(graph, actionString) {
var rules = JSON.parse(actionString);
var handlers = [];
rules.forEach(function(rule) {
// Check if the actionString is false, zero, null, undefined or empty:
if (!actionString) {
return handlers;
}
JSON.parse(actionString).forEach(function(rule) {
if (typeof rule.action == 'undefined') {
debug("field 'action' not specified");
return;
......
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