Commit 1a922ed8 authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

Merge branch '31-add-highlight-action' into 'master'

Resolve "Add Highlight action"

Closes #31

See merge request totem/ind!17
parents 4d525819 04c64d40
......@@ -59,6 +59,27 @@ function setCellVisibility(graph, cell, visible) {
});
}
/**
* Function: highlightCell
*
* Highlight a cell with a border of given colour.
*
* Returns a highlight object that can be used to remove the highlight,
* by calling its hide() method.
*
* Parameters:
*
* graph - graph object to operate on
* cell - cell object to highlight
* colour - colour of the highlight (css property string)
*/
function highlightCell(graph, cell, colour) {
var thickness = 3;
var h = new mxCellHighlight(graph, colour, thickness);
h.highlight(graph.view.getState(cell));
return h;
}
/**
* Function: parseAction
*
......@@ -81,24 +102,33 @@ function parseAction(graph, actionString) {
}
var cell = graph.getModel().getCell(argument);
setCellVisibility(graph, cell, false);
return {
start: function(graph) {
setCellVisibility(graph, cell, true);
},
reset: function(graph) {
return function(graph) {
setCellVisibility(graph, cell, true);
return function() {
setCellVisibility(graph, cell, false);
}
};
};
case 'highlight':
if (typeof argument == 'undefined') {
debug("missing popup argument");
break;
}
var cellId;
var colour;
[cellId, colour] = argument.split(',');
var cell = graph.getModel().getCell(cellId);
return function(graph) {
var h = highlightCell(graph, cell, colour);
return function() {
h.hide();
};
};
default:
return function(graph) {
debug("action \"" + actionName + "\" not found");
return function() {};
};
}
return {
start: function(graph) {
debug("action \"" + actionName + "\" not found");
},
reset: function(graph) {
debug("action \"" + actionName + "\" not found");
}
};
}
/**
......@@ -130,7 +160,6 @@ function installInteractions(graph) {
}
if (cell.value.getAttribute('onhover') != null) {
action = parseAction(graph, cell.value.getAttribute('onhover'));
installClick(action, graph, node);
installHover(action, graph, node);
}
});
......@@ -150,7 +179,7 @@ function installInteractions(graph) {
function installClick(action, graph, node) {
node.addEventListener('click', function(e) {
// Run the `start` function of the given action object.
action.start(graph);
var reset = action(graph);
// Install a handler to run the `reset` function of the given action
// object when the node is clicked again.
$(node).one('click', function(e) {
......@@ -158,7 +187,7 @@ function installClick(action, graph, node) {
// for anything else.
e.stopPropagation();
// Run the `reset` function of the given action object.
action.reset(graph);
reset();
});
});
}
......@@ -175,10 +204,11 @@ function installClick(action, graph, node) {
* node - node that should initiate the action when hovered over
*/
function installHover(action, graph, node) {
var reset;
node.addEventListener('mouseover', function(e) {
action.start(graph);
reset = action(graph);
});
node.addEventListener('mouseout', function(e) {
action.reset(graph);
reset();
});
}
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