Skip to content

Commit

Permalink
Fix manipulation examples for Network (almende#3266)
Browse files Browse the repository at this point in the history
Fix for almende#2856

- Toolbar gets reshown when cancelling edit node dialog
- No shadow displayed upon save in edit node dialog

The latter is actually a more general problem. Function `mergeOptions` in `util.js`
made an assumption as to the correct value of field `enabled`. It now takes the value
from `globalOptions`, if present.
  • Loading branch information
wimrijnders authored and Primoz Susa committed Jan 3, 2019
1 parent 08eb548 commit fca577c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions examples/network/other/manipulationEditEdgeNoDrag.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@
addNode: function (data, callback) {
// filling in the popup DOM elements
document.getElementById('node-operation').innerHTML = "Add Node";
editNode(data, callback);
editNode(data, clearNodePopUp, callback);
},
editNode: function (data, callback) {
// filling in the popup DOM elements
document.getElementById('node-operation').innerHTML = "Edit Node";
editNode(data, callback);
editNode(data, cancelNodeEdit, callback);
},
addEdge: function (data, callback) {
if (data.from == data.to) {
Expand All @@ -142,13 +142,14 @@
network = new vis.Network(container, data, options);
}

function editNode(data, callback) {
function editNode(data, cancelAction, callback) {
document.getElementById('node-label').value = data.label;
document.getElementById('node-saveButton').onclick = saveNodeData.bind(this, data, callback);
document.getElementById('node-cancelButton').onclick = clearNodePopUp.bind();
document.getElementById('node-cancelButton').onclick = cancelAction.bind(this, callback);
document.getElementById('node-popUp').style.display = 'block';
}

// Callback passed as parameter is ignored
function clearNodePopUp() {
document.getElementById('node-saveButton').onclick = null;
document.getElementById('node-cancelButton').onclick = null;
Expand Down
7 changes: 6 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,12 @@ exports.mergeOptions = function (mergeTarget, options, option, allowDeletion = f
}
else {
if (options[option].enabled === undefined) {
mergeTarget[option].enabled = true;
if (globalOptions[option].enabled !== undefined) {
mergeTarget[option].enabled = globalOptions[option].enabled;
} else {
// assume this is the correct value
mergeTarget[option].enabled = true;
}
}
for (var prop in options[option]) {
if (options[option].hasOwnProperty(prop)) {
Expand Down

0 comments on commit fca577c

Please sign in to comment.