Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
totem
ind
Commits
d1f39f80
Commit
d1f39f80
authored
Nov 21, 2019
by
Remon Huijts
Browse files
Delegate input checks to make code more DRY and robust
parent
f981b279
Changes
2
Hide whitespace changes
Inline
Side-by-side
grapheditorxblock/public/js/grapheditorxblock.js
View file @
d1f39f80
...
...
@@ -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 on
hover
attribute)
*
and create
the corresponding event handlers.
* Parse the action string (e.g., value of an on
click
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;
grapheditorxblock/src/js/interactions.js
View file @
d1f39f80
...
...
@@ -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 on
hover
attribute)
*
and create
the corresponding event handlers.
* Parse the action string (e.g., value of an on
click
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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment