From 2933cb51d38098881f57b2e4b9d3ebf408c3b704 Mon Sep 17 00:00:00 2001 From: mrsfy Date: Fri, 15 Jul 2016 21:54:29 +0300 Subject: [PATCH] Fixed multiple initialization bug #3 --- cytoscape-undo-redo.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cytoscape-undo-redo.js b/cytoscape-undo-redo.js index 40270fb..b2eb884 100644 --- a/cytoscape-undo-redo.js +++ b/cytoscape-undo-redo.js @@ -42,10 +42,20 @@ }; - var isInitialized = false; // design implementation cytoscape("core", "undoRedo", function (options, dontInit) { cy = this; + + + + function getScratch() { + if (!cy.scratch("_undoRedo")) { + cy.scratch("_undoRedo", { }); + + } + return cy.scratch("_undoRedo") + } + if (options) { for (var key in options) if (_instance.options.hasOwnProperty(key)) @@ -58,10 +68,12 @@ } - if (!isInitialized && !dontInit) { - if (_instance.options.keyboardShortcuts) { + if (!getScratch().isInitialized && !dontInit) { + if (_instance.options.keyboardShortcuts && !getScratch().isKeyboardShortcutsSet) { var sh = _instance.options.keyboardShortcuts; setKeyboardShortcuts(sh.ctrl_z, sh.ctrl_y, sh.ctrl_shift_z); + getScratch().isKeyboardShortcutsSet = true; + } else setKeyboardShortcuts(false, false, false); var defActions = defaultActions(); @@ -70,8 +82,7 @@ setDragUndo(_instance.options.undoableDrag); - - isInitialized = true; + getScratch().isInitialized = true } _instance.options.ready();