From b5b82de76fe8e3721126486b0a4bb5a59cb9a53c Mon Sep 17 00:00:00 2001 From: Nemeth Balazs Date: Wed, 27 Sep 2017 21:00:48 -0400 Subject: [PATCH 1/3] Add API to destroy a JS created step --- app/tour-controller.js | 16 ++++++++++++++++ app/tour-step-service.js | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/tour-controller.js b/app/tour-controller.js index ea3a903..f1c7bcd 100644 --- a/app/tour-controller.js +++ b/app/tour-controller.js @@ -579,6 +579,22 @@ export default function uiTourController($timeout, $q, $filter, $document, TourC return step; }; + /** + * Destroy a step with destroying the created popup as well + * + * @protected + * @param step + */ + self.destroyStep = function (step) { + var index = stepList.indexOf(step); + + if (index !== -1) { + const stepItem = stepList[index]; + TourStepService.destroyPopup(stepItem); + self.removeStep(step); + } + }; + /** * returns a copy of the current step (copied to avoid breaking internal functions) * diff --git a/app/tour-step-service.js b/app/tour-step-service.js index e3a06a3..214d2bc 100644 --- a/app/tour-step-service.js +++ b/app/tour-step-service.js @@ -56,7 +56,16 @@ export default function (Tether, $compile, $document, $templateCache, $rootScope } } - /** + /** + * Destroy a step's popover + * + * @param {{}} step - Step options + */ + service.destroyPopup = function (step) { + step.popup.remove(); + }; + + /** * Initializes a step from a config object * * @param {{}} step - Step options From 8e889df9f0daa48b4acb8e7acd38ffdcdb5808e5 Mon Sep 17 00:00:00 2001 From: Nemeth Balazs Date: Wed, 27 Sep 2017 21:03:40 -0400 Subject: [PATCH 2/3] Doc added --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a3173b1..120cc93 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ scope of the uiTour directive, and can be required as `TourController` in direct | goTo() | Hides the current step and jumps to the provided one.
**Parameters:** _step_ Can be step object, step ID string, or step index
**Returns:** _Promise_ Resolved when provided step is shown, rejects if no step provided or found. | | getStatus() | Returns the current status of the tour based on TourStatus enum.
**Parameters:** \
**Returns:** TourStatus (ON, OFF, PAUSED, WAITING). Usage example: after tour starts: `tour.getStatus() === tour.Status.ON; //true` | | createStep() | Adds a step via a step configuration object.
**Parameters:** _step_ - a step config object: must contain an `element` (jQLite object) or `selector` (string) attribute. `selector` is resolved the first time a step is shown. | +| destroyStep()| Remove a step from the tour as well as remove its popup from the DOM as well.
**Parameters:** _step_ - a step returned by `createStep()`. | | reposition() | Forces the active step popover and backdrop (if visible) to reposition around the step target. This is useful when the size of the target changes dynamically after the step is activated. | ### `createStep()` Example From 81a3e77b57c326db3fde46b40eca484998b4dc49 Mon Sep 17 00:00:00 2001 From: Nemeth Balazs Date: Wed, 27 Sep 2017 21:09:51 -0400 Subject: [PATCH 3/3] Add build file --- app/tour-controller.js | 5 ++--- dist/angular-ui-tour.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/tour-controller.js b/app/tour-controller.js index f1c7bcd..1ad78fe 100644 --- a/app/tour-controller.js +++ b/app/tour-controller.js @@ -589,9 +589,8 @@ export default function uiTourController($timeout, $q, $filter, $document, TourC var index = stepList.indexOf(step); if (index !== -1) { - const stepItem = stepList[index]; - TourStepService.destroyPopup(stepItem); - self.removeStep(step); + TourStepService.destroyPopup(stepList[index]); + self.removeStep(step); } }; diff --git a/dist/angular-ui-tour.js b/dist/angular-ui-tour.js index c2d93f7..d6bf114 100644 --- a/dist/angular-ui-tour.js +++ b/dist/angular-ui-tour.js @@ -3275,12 +3275,21 @@ return /******/ (function(modules) { // webpackBootstrap } /** - * Initializes a step from a config object + * Destroy a step's popover * * @param {{}} step - Step options - * @param {{}} tour - The tour to which the step belongs - * @returns {*} configured step */ + service.destroyPopup = function (step) { + step.popup.remove(); + }; + + /** + * Initializes a step from a config object + * + * @param {{}} step - Step options + * @param {{}} tour - The tour to which the step belongs + * @returns {*} configured step + */ service.createStep = function (step, tour) { if (!step.element && !step.elementId && !step.selector) { throw { @@ -3997,6 +4006,21 @@ return /******/ (function(modules) { // webpackBootstrap return step; }; + /** + * Destroy a step with destroying the created popup as well + * + * @protected + * @param step + */ + self.destroyStep = function (step) { + var index = stepList.indexOf(step); + + if (index !== -1) { + TourStepService.destroyPopup(stepList[index]); + self.removeStep(step); + } + }; + /** * returns a copy of the current step (copied to avoid breaking internal functions) *