diff --git a/cytoscape-expand-collapse.js b/cytoscape-expand-collapse.js index 997e856..0e642c2 100644 --- a/cytoscape-expand-collapse.js +++ b/cytoscape-expand-collapse.js @@ -308,15 +308,6 @@ module.exports = function (params, cy, api) { cy.on('pan zoom', data.ePosition); - cy.on('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse = function () { - var delay = 50 + (params.animate ? params.animationDuration : 0); - setTimeout(() => { - if (this.selected()) { - drawExpandCollapseCue(this); - } - }, delay); - }); - // write options to data data.hasEventFields = true; setData(data); @@ -340,7 +331,6 @@ module.exports = function (params, cy, api) { .off('position', 'node', data.ePosition) .off('pan zoom', data.ePosition) .off('select unselect', data.eSelect) - .off('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse) .off('free', 'node', data.eFree) .off('resize', data.eCyResize); }, @@ -360,7 +350,6 @@ module.exports = function (params, cy, api) { .on('position', 'node', data.ePosition) .on('pan zoom', data.ePosition) .on('select unselect', data.eSelect) - .on('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse) .on('free', 'node', data.eFree) .on('resize', data.eCyResize); } @@ -2246,4 +2235,4 @@ module.exports = function (cy, api) { },{}]},{},[7])(7) }); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYm91bmRpbmdCb3hVdGlsaXRpZXMuanMiLCJzcmMvY3VlVXRpbGl0aWVzLmpzIiwic3JjL2RlYm91bmNlLmpzIiwic3JjL2RlYm91bmNlMi5qcyIsInNyYy9lbGVtZW50VXRpbGl0aWVzLmpzIiwic3JjL2V4cGFuZENvbGxhcHNlVXRpbGl0aWVzLmpzIiwic3JjL2luZGV4LmpzIiwic3JjL3VuZG9SZWRvVXRpbGl0aWVzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3M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xlbWVudC5zY3JvbGxMZWZ0XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgdmFyIF9zaXplQ2FudmFzID0gZGVib3VuY2UoZnVuY3Rpb24gKCkge1xuICAgICAgICAkY2FudmFzLmhlaWdodCA9IGN5LmNvbnRhaW5lcigpLm9mZnNldEhlaWdodDtcbiAgICAgICAgJGNhbnZhcy53aWR0aCA9IGN5LmNvbnRhaW5lcigpLm9mZnNldFdpZHRoO1xuICAgICAgICAkY2FudmFzLnN0eWxlLnBvc2l0aW9uID0gJ2Fic29sdXRlJztcbiAgICAgICAgJGNhbnZhcy5zdHlsZS50b3AgPSAwO1xuICAgICAgICAkY2FudmFzLnN0eWxlLmxlZnQgPSAwO1xuICAgICAgICAkY2FudmFzLnN0eWxlLnpJbmRleCA9IG9wdGlvbnMoKS56SW5kZXg7XG5cbiAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbiAoKSB7XG4gICAgICAgICAgdmFyIGNhbnZhc0JiID0gb2Zmc2V0KCRjYW52YXMpO1xuICAgICAgICAgIHZhciBjb250YWluZXJCYiA9IG9mZnNldCgkY29udGFpbmVyKTtcbiAgICAgICAgICAkY2FudmFzLnN0eWxlLnRvcCA9IC0oY2FudmFzQmIudG9wIC0gY29udGFpbmVyQmIudG9wKTtcbiAgICAgICAgICAkY2FudmFzLnN0eWxlLmxlZnQgPSAtKGNhbnZhc0JiLmxlZnQgLSBjb250YWluZXJCYi5sZWZ0KTtcblxuICAgICAgICAgIC8vIHJlZnJlc2ggdGhlIGN1ZXMgb24gY2FudmFzIHJlc2l6ZVxuICAgICAgICAgIGlmIChjeSkge1xuICAgICAgICAgICAgY2xlYXJEcmF3cyh0cnVlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0sIDApO1xuXG4gICAgICB9LCAyNTApO1xuXG4gICAgICBmdW5jdGlvbiBzaXplQ2FudmFzKCkge1xuICAgICAgICBfc2l6ZUNhbnZhcygpO1xuICAgICAgfVxuXG4gICAgICBzaXplQ2F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ZXJlZEVuZFkgKyBleHBhbmRjb2xsYXBzZVJlbmRlcmVkUmVjdFNpemUgKiBmYWN0b3IpIHtcbiAgICAgICAgICBpZiAob3B0cy51bmRvYWJsZSAmJiAhdXIpIHtcbiAgICAgICAgICAgIHVyID0gY3kudW5kb1JlZG8oeyBkZWZhdWx0QWN0aW9uczogZmFsc2UgfSk7XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgaWYgKGFwaS5pc0NvbGxhcHNpYmxlKG5vZGUpKSB7XG4gICAgICAgICAgICBjbGVhckRyYXdzKCk7XG4gICAgICAgICAgICBpZiAob3B0cy51bmRvYWJsZSkge1xuICAgICAgICAgICAgICB1ci5kbyhcImNvbGxhcHNlXCIsIHtcbiAgICAgICAgICAgICAgICBub2Rlczogbm9kZSxcbiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHRzXG4gICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgIGFwaS5jb2xsYXBzZShub2RlLCBvcHRzKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSBpZiAoYXBpLmlzRXhwYW5kYWJsZShub2RlKSkge1xuICAgICAgICAgICAgY2xlYXJEcmF3cygpO1xuICAgICAgICAgICAgaWYgKG9wdHMudW5kb2FibGUpIHtcbiAgICAgICAgICAgICAgdXIuZG8oXCJleHBhbmRcIiwgeyBub2Rlczogbm9kZSwgb3B0aW9uczogb3B0cyB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGVsc2Uge1xuICAgICAgICAgICAgICBhcGkuZXhwYW5kKG5vZGUsIG9wdHMpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAobm9kZS5zZWxlY3RhYmxlKCkpIHtcbiAgICAgICAgICAgIG5vZGUudW5zZWxlY3RpZnkoKTtcbiAgICAgICAgICAgIGN5LnNjcmF0Y2goJ19jeUV4cG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3VuY2UoZnVuYywgd2FpdCwgb3B0aW9ucykge1xuICAgIHZhciBhcmdzLFxuICAgICAgICAgICAgbWF4VGltZW91dElkLFxuICAgICAgICAgICAgcmVzdWx0LFxuICAgICAgICAgICAgc3RhbXAsXG4gICAgICAgICAgICB0aGlzQXJnLFxuICAgICAgICAgICAgdGltZW91dElkLFxuICAgICAgICAgICAgdHJhaWxpbmdDYWxsLFxuICAgICAgICAgICAgbGFzdENhbGxlZCA9IDAsXG4gICAgICAgICAgICBtYXhXYWl0ID0gZmFsc2UsXG4gICAgICAgICAgICB0cmFpbGluZyA9IHRydWU7XG5cbiAgICBpZiAodHlwZW9mIGZ1bmMgIT0gJ2Z1bmN0aW9uJykge1xuICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihGVU5DX0VSUk9SX1RFWFQpO1xuICAgIH1cbiAgICB3YWl0ID0gd2FpdCA8IDAgPyAwIDogKCt3YWl0IHx8IDApO1xuICAgIGlmIChvcHRpb25zID09PSB0cnVlKSB7XG4gICAgICB2YXIgbGVhZGluZyA9IHRydWU7XG4gICAgICB0cmFpbGluZyA9IGZhbHNlO1xuICAgIH0gZWxzZSBpZiAoaXNPYmplY3Qob3B0aW9ucykpIHtcbiAgICAgIGxlYWRpbmcgPSAhIW9wdGlvbnMubGVhZGluZztcbiAgICAgIG1heFdhaXQgPSAnbWF4V2FpdCcgaW4gb3B0aW9ucyAmJiBuYXRpdmVNYXgoK29wdGlvbnMubWF4V2FpdCB8fCAwLCB3YWl0KTtcbiAgICAgIHRyYWlsaW5nID0gJ3RyYWlsaW5nJyBpbiBvcHRpb25zID8gISFvcHRpb25zLnRyYWlsaW5nIDogdHJhaWxpbmc7XG4gICAgfVxuXG4gICAgZnVuY3Rpb24gY2FuY2VsKCkge1xuICAgICAgaWYgKHRpbWVvdXRJZCkge1xuICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dElkKTtcbiAgICAgIH1cbiAgICAgIGlmIChtYXhUaW1lb3V0SWQpIHtcbiAgIC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BkZWJvdW5jZWQoKSB7XG4gICAgICBhcmdzID0gYXJndW1lbnRzO1xuICAgICAgc3RhbXAgPSBub3coKTtcbiAgICAgIHRoaXNBcmcgPSB0aGlzO1xuICAgICAgdHJhaWxpbmdDYWxsID0gdHJhaWxpbmcgJiYgKHRpbWVvdXRJZCB8fCAhbGVhZGluZyk7XG5cbiAgICAgIGlmIChtYXhXYWl0ID09PSBmYWxzZSkge1xuICAgICAgICB2YXIgbGVhZGluZ0NhbGwgPSBsZWFkaW5nICYmICF0aW1lb3V0SWQ7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBpZiAoIW1heFRpbWVvdXRJZCAmJiAhbGVhZGluZykge1xuICAgICAgICAgIGxhc3RDYWxsZWQgPSBzdGFtcDtcbiAgICAgICAgfVxuICAgICAgICB2YXIgcmVtYWluaW5nID0gbWF4V2FpdCAtIChzdGFtcCAtIGxhc3RDYWxsZWQpLFxuICAgICAgICAgICAgICAgIGlzQ2FsbGVkID0gcmVtYWluaW5nIDw9IDAgfHwgcmVtYWluaW5nID4gbWF4V2FpdDtcblxuICAgICAgICBpZiAoaXNDYWxsZWQpIHtcbiAgICAgICAgICBpZiAobWF4VGltZW91dElkKSB7XG4gICAgICAgICAgICBtYXhUaW1lb3V0SWQgPSBjbGVhclRpbWVvdXQobWF4VGltZW91dElkKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgbGFzdENhbGxlZCA9IHN0YW1wO1xuICAgICAgICAgIHJlc3VsdCA9IGZ1bmMuYXBwbHkodGhpc0FyZywgYXJncyk7XG4gICAgICAgIH1cbiAgICAgICAgZWxzZSBpZiAoIW1heFRpbWVvdXRJZCkge1xuICAgICAgICAgIG1heFRpbWVvdXRJZCA9IHNldFRpbWVvdXQobWF4RGVsYXllZCwgcmVtYWluaW5nKTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgaWYgKGlzQ2FsbGVkICYmIHRpbWVvdXRJZCkge1xuICAgICAgICB0aW1lb3V0SWQgPSBjbGVhclRp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ZCB6b29tXG4gICAgICAgICAgaWYgKGFuaW1hdGUpIHtcbiAgICAgICAgICAgIGN5LmFuaW1hdGUoe1xuICAgICAgICAgICAgICBwYW46IHZpZXdQb3J0LnBhbixcbiAgICAgICAgICAgICAgem9vbTogdmlld1BvcnQuem9vbSxcbiAgICAgICAgICAgICAgY29tcGxldGU6IGZ1bmN0aW9uICgpIHtcbiAgICAgICAgICAgICAgICBjb21tb25FeHBhbmRPcGVyYXRpb24obm9kZSwgYXBwbHlGaXNoRXllVmlldywgc2luZ2xlLCBhbmltYXRlLCBsYXlvdXRCeSwgYW5pbWF0aW9uRHVyYXRpb24pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LCB7XG4gICAgICAgICAgICAgIGR1cmF0aW9uOiBhbmltYXRpb25EdXJhdGlvbiB8fCAxMDAwXG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICB9XG4gICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICBjeS56b29tKHZpZXdQb3J0Lnpvb20pO1xuICAgICAgICAgICAgY3kucGFuKHZpZXdQb3J0LnBhbik7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICBcbiAgICAgIC8vIElmIGFuaW1hdGluZyBpcyBub3QgdHJ1ZSB3ZSBuZWVkIHRvIGNhbGwgY29tbW9uRXhwYW5kT3BlcmF0aW9uIGhlcmVcbiAgICAgIGlmICghYW5pbWF0aW5nKSB7XG4gICAgICAgIGNvbW1vbkV4cGFuZE9wZXJhdGlvbihub2RlLCBhcHBseUZpc2hFeWVWaWV3LCBzaW5nbGUsIGFuaW1hdGUsIGxheW91dEJ5LCBhbmltYXRpb25EdXJhdGlvbik7XG4gICAgICB9XG4gICAgICBcbiAgICAgIC8vcmV0dXJuIHRoZSBub2RlIHRvIHVuZG8gdGhlIG9wZXJhdGlvblxuICAgICAgcmV0dXJuIG5vZGU7XG4gICAgfVxuICB9LFxuICAvL2NvbGxhcHNlIHRoZSBnaXZlbiBub2Rl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AgICAgICAgICBlbHNlIGlmIChhcGkuaXNFeHBhbmRhYmxlKG5vZGUpKSB7XG4gICAgICAgICAgICBjbGVhckRyYXdzKCk7XG4gICAgICAgICAgICBpZiAob3B0cy51bmRvYWJsZSkge1xuICAgICAgICAgICAgICB1ci5kbyhcImV4cGFuZFwiLCB7IG5vZGVzOiBub2RlLCBvcHRpb25zOiBvcHRzIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgIGFwaS5leHBhbmQobm9kZSwgb3B0cyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmIChub2RlLnNlbGVjdGFibGUoKSkge1xuICAgICAgICAgICAgbm9kZS51bnNlbGVjdGlmeSgpO1xuICAgICAgICAgICAgY3kuc2NyYXRjaCgnX2N5RXhwYW5kQ29sbGFwc2UnKS5zZWxlY3RhYmxlQ2hhbmdlZCA9IHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9KTtcblxuICAgICAgY3kub24oJ3Bvc2l0aW9uJywgJ25vZGUnLCBkYXRhLmVQb3NpdGlvbiA9IGRlYm91bmNlMihkYXRhLmVTZWxlY3QsIENVRV9QT1NfVVBEQVRFX0RFTEFZLCBjbGVhckRyYXdzKSk7XG5cbiAgICAgIGN5Lm9uKCdwYW4gem9vbScsIGRhdGEuZVBvc2l0aW9uKTtcblxuICAgICAgLy8gd3JpdGUgb3B0aW9ucyB0byBkYXRhXG4gICAgICBkYXRhLmhhc0V2ZW50RmllbGRzID0gdHJ1ZTtcbiAgICAgIHNldERhdGEoZGF0YSk7XG4gICAgfSxcbiAgICB1bmJpbmQ6IGZ1bmN0aW9uICgpIHtcbiAgICAgIC8vIHZhciAkY29udGFpbmVyID0gdGhpcztcbiAgICAgIHZhciBkYXRhID0gZ2V0RGF0YSgpO1xuXG4gICAgICBpZiAoIWRhdGEuaGFzRXZlbnRGaWVsZHMpIHtcbiAgICAgICAgY29uc29sZS5sb2coJ2V2ZW50cyB0byB1bmJpbmQgZG9lcyBub3QgZXhpc3QnKTtcbiAgICAgICAgcmV0dXJuO1xuICAgICAgfVxuXG4gICAgICBjeS50cmlnZ2VyKCdleHBhbmRjb2xsYXBzZS5jbGVhcnZpc3VhbGN1ZScpO1xuXG4gICAgICBjeS5vZmYoJ21vdXNlZG93bicsICdub2RlJywgZGF0YS5lTW91c2VEb3duKVxuICAgICAgICAub2ZmKCdtb3VzZXVwJywgJ25vZGUnLCBkYXRhLmVNb3VzZVVwKVxuICAgICAgICAub2ZmKCdyZW1vdmUnLCAnbm9kZScsIGRhdGEuZVJlbW92ZSlcbiAgICAgICAgLm9mZigndGFwJywgJ25vZGUnLCBkYXRhLmVUYXApXG4gICAgICAgIC5vZmYoJ2FkZCcsICdub2RlJywgZGF0YS5lQWRkKVxuICAgICAgICAub2ZmKCdwb3NpdGlvbicsICdub2RlJywgZGF0YS5lUG9zaXRpb24pXG4gICAgICAgIC5vZmYoJ3BhbiB6b29tJywgZGF0YS5lUG9zaXRpb24pXG4gICAgICAgIC5vZmYoJ3NlbGVjdCB1bnNlbGVjdCcsIGRhdGEuZVNlbGVjdClcbiAgICAgICAgLm9mZignZnJlZScsICdub2RlJywgZGF0YS5lRnJlZSlcbiAgICAgICAgLm9mZigncmVzaXplJywgZGF0YS5lQ3lSZXNpemUpO1xuICAgIH0sXG4gICAgcmViaW5kOiBmdW5jdGlvbiAoKSB7XG4gICAgICB2YXIgZGF0YSA9IGdldERhdGEoKTtcblxuICAgICAgaWYgKCFkYXRhLmhhc0V2ZW50RmllbGRzKSB7XG4gICAgICAgIGNvbnNvbGUubG9nKCdldmVudHMgdG8gcmViaW5kIGRvZXMgbm90IGV4aXN0Jyk7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cblxuICAgICAgY3kub24oJ21vdXNlZG93bicsICdub2RlJywgZGF0YS5lTW91c2VEb3duKVxuICAgICAgICAub24oJ21vdXNldXAnLCAnbm9kZScsIGRhdGEuZU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gICAgICB9XG5cbiAgICAgIGZ1bmN0aW9uIGlzT25seTFQYWlyKGVkZ2VzKSB7XG4gICAgICAgIGxldCByZWxhdGVkRWRnZXNBcnIgPSBbXTtcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBlZGdlcy5sZW5ndGg7IGkrKykge1xuICAgICAgICAgIGNvbnN0IHNyY0lkID0gZWRnZXNbaV0uc291cmNlKCkuaWQoKTtcbiAgICAgICAgICBjb25zdCB0YXJnZXRJZCA9IGVkZ2VzW2ldLnRhcmdldCgpLmlkKCk7XG4gICAgICAgICAgY29uc3Qgb2JqID0ge307XG4gICAgICAgICAgb2JqW3NyY0lkXSA9IHRydWU7XG4gICAgICAgICAgb2JqW3RhcmdldElkXSA9IHRydWU7XG4gICAgICAgICAgcmVsYXRlZEVkZ2VzQXJyLnB1c2gob2JqKTtcbiAgICAgICAgfVxuICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJlbGF0ZWRFZGdlc0Fyci5sZW5ndGg7IGkrKykge1xuICAgICAgICAgIGZvciAobGV0IGogPSBpICsgMTsgaiA8IHJlbGF0ZWRFZGdlc0Fyci5sZW5ndGg7IGorKykge1xuICAgICAgICAgICAgY29uc3Qga2V5czEgPSBPYmplY3Qua2V5cyhyZWxhdGVkRWRnZXNBcnJbaV0pO1xuICAgICAgICAgICAgY29uc3Qga2V5czIgPSBPYmplY3Qua2V5cyhyZWxhdGVkRWRnZXNBcnJbal0pO1xuICAgICAgICAgICAgY29uc3QgYWxsS2V5cyA9IG5ldyBTZXQoa2V5czEuY29uY2F0KGtleXMyKSk7XG4gICAgICAgICAgICBpZiAoYWxsS2V5cy5zaXplICE9IGtleXMxLmxlbmd0aCB8fCBhbGxLZXlzLnNpemUgIT0ga2V5czIubGVuZ3RoKSB7XG4gICAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIHRydWU7XG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xuICAgcmVzdWx0LmVkZ2VzID0gYXJncy5vbGRFZGdlcztcbiAgIHJlc3VsdC5vbGRFZGdlcyA9IGFyZ3MuZWRnZXM7XG4gICBpZihhcmdzLmVkZ2VzLmxlbmd0aCA+IDAgJiYgYXJncy5vbGRFZGdlcy5sZW5ndGggPiAwKXtcbiAgICBjeS5yZW1vdmUoYXJncy5lZGdlcyk7XG4gICAgY3kuYWRkKGFyZ3Mub2xkRWRnZXMpO1xuICAgIH1cbiAgIFxuICB9XG5cbiAgcmV0dXJuIHJlc3VsdDtcbiB9XG4gXG4gXG4gIHVyLmFjdGlvbihcImNvbGxhcHNlRWRnZXNcIiwgY29sbGFwc2VFZGdlcywgZXhwYW5kRWRnZXMpO1xuICB1ci5hY3Rpb24oXCJleHBhbmRFZGdlc1wiLCBleHBhbmRFZGdlcywgY29sbGFwc2VFZGdlcyk7XG5cbiAgdXIuYWN0aW9uKFwiY29sbGFwc2VFZGdlc0JldHdlZW5Ob2Rlc1wiLCBjb2xsYXBzZUVkZ2VzQmV0d2Vlbk5vZGVzLCBleHBhbmRFZGdlc0JldHdlZW5Ob2Rlcyk7XG4gIHVyLmFjdGlvbihcImV4cGFuZEVkZ2VzQmV0d2Vlbk5vZGVzXCIsIGV4cGFuZEVkZ2VzQmV0d2Vlbk5vZGVzLCBjb2xsYXBzZUVkZ2VzQmV0d2Vlbk5vZGVzKTtcblxuICB1ci5hY3Rpb24oXCJjb2xsYXBzZUFsbEVkZ2VzXCIsIGNvbGxhcHNlQWxsRWRnZXMsIGV4cGFuZEFsbEVkZ2VzKTtcbiAgdXIuYWN0aW9uKFwiZXhwYW5kQWxsRWRnZXNcIiwgZXhwYW5kQWxsRWRnZXMsIGNvbGxhcHNlQWxsRWRnZXMpO1xuXG4gXG5cblxuICBcblxuXG59O1xuIl19 diff --git a/src/cueUtilities.js b/src/cueUtilities.js index b6ee535..543be54 100644 --- a/src/cueUtilities.js +++ b/src/cueUtilities.js @@ -286,15 +286,6 @@ module.exports = function (params, cy, api) { cy.on('pan zoom', data.ePosition); - cy.on('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse = function () { - var delay = 50 + (params.animate ? params.animationDuration : 0); - setTimeout(() => { - if (this.selected()) { - drawExpandCollapseCue(this); - } - }, delay); - }); - // write options to data data.hasEventFields = true; setData(data); @@ -318,7 +309,6 @@ module.exports = function (params, cy, api) { .off('position', 'node', data.ePosition) .off('pan zoom', data.ePosition) .off('select unselect', data.eSelect) - .off('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse) .off('free', 'node', data.eFree) .off('resize', data.eCyResize); }, @@ -338,7 +328,6 @@ module.exports = function (params, cy, api) { .on('position', 'node', data.ePosition) .on('pan zoom', data.ePosition) .on('select unselect', data.eSelect) - .on('expandcollapse.afterexpand expandcollapse.aftercollapse', 'node', data.eAfterExpandCollapse) .on('free', 'node', data.eFree) .on('resize', data.eCyResize); }