Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll selected container instead of the document.body #154

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1eb8863
Allow specyfing element to scroll, instead of always using the docume…
Jan 11, 2021
5ab8e20
#1 show next button whenever showNext parameter is set to true
Jan 11, 2021
6466459
prevent user interaction within highlighted area
Jan 11, 2021
6b2599e
#2 ensure that duplicated events don't cause steps to be skipped
Jan 11, 2021
16977a8
pause until an element becomes visible or event is triggered
Jan 11, 2021
dd28fa6
Merge branch 'bug-skippedStep'
Jan 11, 2021
9595e59
Merge branch 'feature-preventEvents'
Jan 11, 2021
bd62e0e
Merge branch 'feature-pausedUntil'
Jan 11, 2021
d111193
Update README.md
mikocot Jan 11, 2021
785e6d1
ensure that onSkip is called also when steps are skipped programmatic…
Jan 11, 2021
cf81c7a
Merge branch 'master' of https://github.com/mikocot/enjoyhint
Jan 11, 2021
3fa1bd7
propagate changes to the right source file
Jan 11, 2021
d50e21c
propagate changes to the right source file
Jan 11, 2021
54e274c
propagate fixes to the right source files
Jan 11, 2021
7ea5ebf
proapgate changes to the right source file
Jan 11, 2021
d0b9abc
propagate bugfix to the source file
Jan 11, 2021
3cc4fde
Merge branch 'bug-showNext'
Jan 11, 2021
16ba042
Merge branch 'bug-skippedStep'
Jan 11, 2021
14c100e
Merge branch 'feature-pausedUntil'
Jan 11, 2021
6c0ee13
also scroll the right element whenever browser size changes
Jan 11, 2021
b6a4933
propagate changes to the source files
Jan 11, 2021
6136cff
Merge branch 'feature-elementToScroll'
Jan 11, 2021
843943a
Merge branch 'feature-preventEvents'
Jan 11, 2021
ef75c76
Bump version to 4.1.0
Jan 11, 2021
b4a1cb5
Merge branch 'master' into 4.1.0
Jan 11, 2021
57ebabe
Update README.md
mikocot Jan 11, 2021
56f0b08
Update README.md
mikocot Jan 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ EnjoyHint
**EnjoyHint** is a web-tool that provides the simplest way to create interactive tutorials and hints for your site or web-application. It can also be used to highlight and sign application elements.

EnjoyHint is free software distributed under the terms of MIT license.


#### Improvements
Comparing to the original library this version was modified to support more advanced scenarios:

##### Added features
* Pause tour until specified element becomes visible or event is triggered
* Prevent user interaction within highlighted element
* Ability to specify which container is being scrolled

##### Fixed Issues
* Next button not showing with 'click' and 'custom' events
* OnSkip not called when skipping steps programmatically
* Several steps can be skipped at once if triggered event is duplicated


#### Demo
* [TODO app demo](http://xbsoftware.github.io/enjoyhint/) ([downloadable package](http://xbsoftware.github.io/enjoyhint/enjoyhint_todo_demo.zip))
* [A small guide on EnjoyHint](http://xbsoftware.github.io/enjoyhint/example1.html)
Expand Down Expand Up @@ -164,7 +178,18 @@ var enjoyhint_script_steps = [

#### Release notes

##### v.4
##### v.4.1.0
Improvements:
* Disable user interaction within highlighted area (`preventEvents` step property)
* Pause and hide overlay until element becomes visible or event is triggered (`pausedUntil` step property)
* Specify which container should be scrolled (`elementToScroll` option)

Bug Fixes:
* Fixed Next button not showing
* Fixed skippind steps when event is duplicated
* Fixed OnSkip method not called when skipping steps programmatically

##### v.4.x

* Fixed label position bugs
* Fixed arrow position bugs
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"enjoyhint.js",
"enjoyhint.css"
],
"version": "4.0.1",
"version": "4.1.0",
"homepage": "https://github.com/xbsoftware/enjoyhint",
"authors": [
"XB Software"
Expand Down
139 changes: 110 additions & 29 deletions enjoyhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
var SHAPE_BACKGROUND_COLOR = _options.backgroundColor || "rgba(0,0,0,0.6)";

var body = "body"; // TODO: Is it possible case when we need to define enjoyhint somewhere else?
var elementAvailableEventName = "enjoyhint-element-available";

var defaults = {
onStart: function() {},

onEnd: function() {},

onSkip: function() {},

onNext: function() {}

onNext: function () { },

elementToScroll: document.body
};

var options = $.extend(defaults, _options);
Expand Down Expand Up @@ -62,7 +65,8 @@
options.onSkip();
skipAll();
},
fill: SHAPE_BACKGROUND_COLOR
fill: SHAPE_BACKGROUND_COLOR,
elementToScroll: options.elementToScroll
});
};

Expand Down Expand Up @@ -97,7 +101,7 @@
$body.enjoyhint("hide_skip");
};

var stepAction = function() {
var stepAction = function(unpause) {
if (!(data && data[current_step])) {
$body.enjoyhint("hide");
options.onEnd();
Expand All @@ -113,9 +117,63 @@
$enjoyhint.removeClass("enjoyhint-step-" + (current_step + 1));
$enjoyhint.removeClass("enjoyhint-step-" + (current_step + 2));
$enjoyhint.addClass("enjoyhint-step-" + (current_step + 1));

var step_data = data[current_step];

$body.off(elementAvailableEventName);

//loops waiting until specified element becomes visible
var waitUntilAvailable = function (selector, interval) {
if (interval == null)
interval = 150;

var triggerIfAvailable = function () {
if ($(selector).is(":visible")) {
$body.trigger(elementAvailableEventName);
}
else {
setTimeout(triggerIfAvailable, interval)
}
};

setTimeout(triggerIfAvailable, 0);
}

//if pausedUntil was specified, hide current overlay and wait until specified event occurs
if (!unpause && step_data.pausedUntil != null && step_data.pausedUntil.event != null) {
//hide current overlay during waiting time
$body.enjoyhint("hide");

//if 'available' event was chosen wait for the custom event, which is triggered when the element becomes visible
if (step_data.pausedUntil.event === 'available') {
$body.on(elementAvailableEventName, function () {
stepAction(true); //restart the step without pause
$body.off(elementAvailableEventName);
});

//check if element is available every 150ms
waitUntilAvailable(step_data.pausedUntil.selector);
}
else {
//delay the actual action until 'the event' happens on body or selector
if (step_data.pausedUntil.selector == null) {
on(step_data.pausedUntil.event, function () {
stepAction(true); //restart the step without pause
off(step_data.pausedUntil.event);
});
}
else {
$(step_data.pausedUntil.selector).on(step_data.pausedUntil.event, function () {
stepAction(true); //restart the step without pause
$(step_data.pausedUntil.selector).off(step_data.pausedUntil.event)
});
}
}

//the rest of the logic will be executed whenever the step is restarted
return;
}

var scrollSpeed = step_data.scrollAnimationSpeed;

if (
Expand Down Expand Up @@ -154,7 +212,7 @@
var isHintInViewport = $(step_data.selector).get(0).getBoundingClientRect();
if(isHintInViewport.top < 0 || isHintInViewport.bottom > (window.innerHeight || document.documentElement.clientHeight)){
hideCurrentHint();
$(document.body).scrollTo(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -200});
$(options.elementToScroll).scrollTo(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -200});
}
else {
// if previous button has been clicked and element are in viewport to prevent custom step scrollAnimationSpeed set scrollSpeed to default
Expand Down Expand Up @@ -186,6 +244,9 @@
if (step_data.showNext !== true) {
$body.enjoyhint("hide_next");
}
else {
$body.enjoyhint("show_next");
}

$body.enjoyhint("hide_prev");

Expand Down Expand Up @@ -255,13 +316,20 @@
break;
}
} else {
$event_element.on(event, function(e) {
if (step_data.keyCode && e.keyCode != step_data.keyCode) {
return;
}

current_step++;
stepAction(); // clicked
var alreadyTriggered = false;
$event_element.one(event, function (e) { //one should ensure that event is handled only once, but that's not always enough
if (alreadyTriggered) //make sure that the step is not changed twice handling the same event
return;

alreadyTriggered = true;
if (step_data.keyCode && e.keyCode != step_data.keyCode) {
return;
}

$event_element.off(event); //unregister the event

current_step++;
stepAction(); //move to the next step
});
}

Expand Down Expand Up @@ -292,7 +360,8 @@
left: step_data.left,
right: step_data.right,
margin: step_data.margin,
scroll: step_data.scroll
scroll: step_data.scroll,
preventEvents: step_data.preventEvents
};

var customBtnProps = {
Expand Down Expand Up @@ -403,6 +472,7 @@

case "skip":
skipAll();
options.onSkip();
break;

default: $body.trigger(makeEventName(event_name, true));
Expand Down Expand Up @@ -767,7 +837,7 @@

doit = setTimeout(function() {
if(boundingClientRect.top < 0 || boundingClientRect.bottom > (window.innerHeight || document.documentElement.clientHeight)){
$(document.body).scrollTo(that.stepData.enjoyHintElementSelector, 150, {offset: -200, onAfter:renderAfterResize});
$(that.options.elementToScroll).scrollTo(that.stepData.enjoyHintElementSelector, 150, {offset: -200, onAfter:renderAfterResize});
}
else renderAfterResize();
}, 150);
Expand Down Expand Up @@ -1103,16 +1173,27 @@
.appendTo(that.enjoyhint);
};

that.disableEventsNearRect = function(rect) {
that.disableEventsNearRect = function(rect, alsoDisableRect) {
var top = rect.top;
var left = rect.left;
var right = rect.right;
var bottom = rect.bottom;

//to disable events also within highlighted rectable, simply remove the gap
if (alsoDisableRect === true) {
top = bottom;
right = left;
}

$top_dis_events
.css({
top: "0",
left: "0"
})
.height(rect.top);
.css({
top: "0",
left: "0"
})
.height(top);

$bottom_dis_events.css({
top: rect.bottom + "px",
top: bottom + "px",
left: "0"
});

Expand All @@ -1121,11 +1202,11 @@
top: "0",
left: 0 + "px"
})
.width(rect.left);
.width(left);

$right_dis_events.css({
top: "0",
left: rect.right + "px"
left: right + "px"
});
};

Expand Down Expand Up @@ -1437,10 +1518,10 @@
else {
distance = initial_distance;
ver_button_position = initial_ver_position;
that.$next_btn.html(customBtnProps.nextButton && customBtnProps.nextButton.text ?
customBtnProps.nextButton.text : 'Next');
that.$prev_btn.html(customBtnProps.prevButton && customBtnProps.prevButton.text ?
customBtnProps.prevButton.text : 'Previous');
that.$next_btn.html(customBtnProps.nextButton && customBtnProps.nextButton.text ?
customBtnProps.nextButton.text : 'Next');
that.$prev_btn.html(customBtnProps.prevButton && customBtnProps.prevButton.text ?
customBtnProps.prevButton.text : 'Previous');
}

that.$prev_btn.css({
Expand Down Expand Up @@ -1481,7 +1562,7 @@
bottom: shape_data.bottom,
left: shape_data.left,
right: shape_data.right
});
}, data.preventEvents);

that.renderArrow({
x_from: x_from,
Expand Down
2 changes: 1 addition & 1 deletion enjoyhint.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enjoyhint",
"version": "4.0.1",
"version": "4.1.0",
"description": "Web-tool that provides the simplest way to create interactive tutorials and hints.",
"main": "enjoyhint.js",
"scripts": {
Expand Down
Loading