Commit 27c44d47 authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

Merge branch '26-get-object-id-from-graph' into 'master'

Resolve "Get object ID from graph"

Closes #26

See merge request totem/ind!16
parents 1a922ed8 58cc6872
......@@ -67,6 +67,43 @@ function GraphEditorXBlock(runtime, element, data) {
});
}
/**
* Function: pickCell
*
* Enter a mode in which the user can pick a cell, without changing the
* selection. When the user has picked the cell, a callback function is run
* with the cell as argument.
*
* Parameters:
*
* graph - graph object to operate on
* callback - callback function to run after picking cell
*/
function pickCell(graph, callback) {
var listener = {
mouseDown: function(sender, evt) {},
mouseMove: function(sender, evt) {},
mouseUp: function(sender, evt) {
// Only perform the callback if we clicked on a cell, not elsewhere
// on the canvas.
if (typeof evt.state !== 'undefined') {
callback(evt.state.cell);
}
// Consuime the event, so it will not also trigger a change of
// selection.
evt.consume();
// Remove the new listener.
graph.removeMouseListener(listener);
// Make the graph writable again.
graph.setEnabled(true);
}
};
// Add our new listener.
graph.mouseListeners.unshift(listener);
// Make the graph read-only while the user is picking their cell.
graph.setEnabled(false);
}
/**
* Save to the XBlock data.
*
......
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