From 00d4a1614b457912176c7d2037f9ebaae992f99d Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 6 May 2017 19:16:20 +0200 Subject: [PATCH] protect frame-picker destroy if frame picker init() was not called --- .../dialogs/importwizard/steps/AbstractImportStep.js | 4 ++++ .../controller/dialogs/importwizard/steps/InsertLocation.js | 3 +++ src/js/controller/dialogs/importwizard/steps/SelectMode.js | 3 --- src/js/widgets/FramePicker.js | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/js/controller/dialogs/importwizard/steps/AbstractImportStep.js b/src/js/controller/dialogs/importwizard/steps/AbstractImportStep.js index 5a6dc86d..f8450929 100644 --- a/src/js/controller/dialogs/importwizard/steps/AbstractImportStep.js +++ b/src/js/controller/dialogs/importwizard/steps/AbstractImportStep.js @@ -23,6 +23,10 @@ }; ns.AbstractImportStep.prototype.destroy = function () { + if (this.framePickerWidget) { + this.framePickerWidget.destroy(); + } + pskl.utils.Event.removeAllEventListeners(this); }; diff --git a/src/js/controller/dialogs/importwizard/steps/InsertLocation.js b/src/js/controller/dialogs/importwizard/steps/InsertLocation.js index 9528486c..e0833e93 100644 --- a/src/js/controller/dialogs/importwizard/steps/InsertLocation.js +++ b/src/js/controller/dialogs/importwizard/steps/InsertLocation.js @@ -35,7 +35,10 @@ }; ns.InsertLocation.prototype.onShow = function () { + // Initialize the frame picker on show, to be able to calculate correctly the + // container's offsetWidth and offsetHeight. this.currentPiskelFramePickerWidget.init(); + var currentFrameIndex = this.piskelController.getCurrentFrameIndex(); this.currentPiskelFramePickerWidget.setFrameIndex(currentFrameIndex + 1); this.currentPiskelFramePickerWidget.setFirstFrameIndex(0); diff --git a/src/js/controller/dialogs/importwizard/steps/SelectMode.js b/src/js/controller/dialogs/importwizard/steps/SelectMode.js index 937f09cb..2b473941 100644 --- a/src/js/controller/dialogs/importwizard/steps/SelectMode.js +++ b/src/js/controller/dialogs/importwizard/steps/SelectMode.js @@ -28,9 +28,6 @@ }; ns.SelectMode.prototype.destroy = function () { - if (this.framePickerWidget) { - this.framePickerWidget.destroy(); - } this.superclass.destroy.call(this); }; diff --git a/src/js/widgets/FramePicker.js b/src/js/widgets/FramePicker.js index 798af80f..48f8e6ea 100644 --- a/src/js/widgets/FramePicker.js +++ b/src/js/widgets/FramePicker.js @@ -59,7 +59,10 @@ }; ns.FramePicker.prototype.destroy = function () { - this.container.removeChild(this.wrapper); + if (this.wrapper.parentNode) { + this.wrapper.parentNode.removeChild(this.wrapper); + } + pskl.utils.Event.removeAllEventListeners(this); };