Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Make the tour advance on more events (blur, change, focus, select) #104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -160,8 +160,16 @@ The comprehensive list of step options are listed below:

* `fixedElement` [BOOLEAN] - set to true if the target element has fixed positioning. *Default*: false.

* `nextOnTargetBlur` [BOOLEAN] - triggers nextStep() when the target loses the focus. *Default*: false.

* `nextOnTargetChange` [BOOLEAN] - triggers nextStep() when the content or state of the target changes. *Default*: false.

* `nextOnTargetClick` [BOOLEAN] - triggers nextStep() when the target is clicked. *Default*: false.

* `nextOnTargetFocus` [BOOLEAN] - triggers nextStep() when the target gets the focus. *Default*: false.

* `nextOnTargetSelect` [BOOLEAN] - triggers nextStep() when the user selects some text within the target. *Default*: false.

* `onPrev` [FUNCTION] - callback for when 'Previous' button is clicked

* `onNext` [FUNCTION] - callback for when 'Next' button is clicked
Expand Down Expand Up @@ -198,8 +206,16 @@ Tour options can be specified either through the tour JSON object, or through a

* `skipIfNoElement` [BOOLEAN] - If a specified target element is not found, should we skip to the next step? *Default*: true.

* `nextOnTargetBlur` [BOOLEAN] - Should we advance to the next step when the target loses focus? *Default*: false.

* `nextOnTargetChange` [BOOLEAN] - Should we advance to the next step when the content or state of the target changes? *Default*: false.

* `nextOnTargetClick` [BOOLEAN] - Should we advance to the next step when the user clicks on the target? *Default*: false.

* `nextOnTargetFocus` [BOOLEAN] - Should we advance to the next step when the target gets the focus? *Default*: false.

* `nextOnTargetSelect` [BOOLEAN] - Should we advance to the next step when the user selects some text within the target? *Default*: false.

* `onNext` [FUNCTION] - Invoked after every click on a "Next" button.

* `onPrev` [FUNCTION] - Invoked after every click on a "Prev" button.
Expand Down
38 changes: 31 additions & 7 deletions src/js/hopscotch.js
Expand Up @@ -1181,7 +1181,7 @@
* @param {Object} initOptions Options to be passed to `configure()`.
*/
Hopscotch = function(initOptions) {
var self = this, // for targetClickNextFn
var self = this, // for targetInteractNextFn
bubble,
calloutMgr,
opt,
Expand Down Expand Up @@ -1252,11 +1252,11 @@
},

/**
* Used for nextOnTargetClick
* Used for nextOnTarget[Blur|Change|Click|Focus|Select]
*
* @private
*/
targetClickNextFn = function() {
targetInteractNextFn = function() {
self.nextStep();
},

Expand Down Expand Up @@ -1635,9 +1635,21 @@
showBubble();
}

// If we want to advance to next step when user clicks on target.
// If we want to advance to next step when user interacts with a target.
if (step.nextOnTargetBlur) {
utils.addEvtListener(targetEl, 'blur', targetInteractNextFn);
}
if (step.nextOnTargetChange) {
utils.addEvtListener(targetEl, 'change', targetInteractNextFn);
}
if (step.nextOnTargetClick) {
utils.addEvtListener(targetEl, 'click', targetClickNextFn);
utils.addEvtListener(targetEl, 'click', targetInteractNextFn);
}
if (step.nextOnTargetFocus) {
utils.addEvtListener(targetEl, 'focus', targetInteractNextFn);
}
if (step.nextOnTargetSelect) {
utils.addEvtListener(targetEl, 'select', targetInteractNextFn);
}
});

Expand Down Expand Up @@ -1799,9 +1811,21 @@
var step = getCurrStep(),
targetEl = utils.getStepTarget(step);

// Detach the listener after we've interacted with the target OR clicked the next button.
if (step.nextOnTargetBlur) {
utils.removeEvtListener(targetEl, 'blur', targetInteractNextFn);
}
if (step.nextOnTargetChange) {
utils.removeEvtListener(targetEl, 'change', targetInteractNextFn);
}
if (step.nextOnTargetClick) {
// Detach the listener after we've clicked on the target OR the next button.
utils.removeEvtListener(targetEl, 'click', targetClickNextFn);
utils.removeEvtListener(targetEl, 'click', targetInteractNextFn);
}
if (step.nextOnTargetFocus) {
utils.removeEvtListener(targetEl, 'focus', targetInteractNextFn);
}
if (step.nextOnTargetSelect) {
utils.removeEvtListener(targetEl, 'select', targetInteractNextFn);
}
changeStep.call(this, doCallbacks, 1);
return this;
Expand Down