Skip to content

Commit 7a95ded

Browse files
authored
Merge pull request #140 from AndVikVin/fixes
Fixes
2 parents e72a35f + 665a65b commit 7a95ded

File tree

3 files changed

+235
-200
lines changed

3 files changed

+235
-200
lines changed

src/enjoyhint.js

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
var $event_element;
1818
var that = this;
1919
var _options = configs || {};
20-
var BTN_NEXT_TEXT = _options.btnNextText || "Next";
21-
var BTN_SKIP_TEXT = _options.btnSkipText || "Skip";
20+
var BTN_NEXT_TEXT = _options.btnNextText;
21+
var BTN_SKIP_TEXT = _options.btnSkipText;
2222

2323
var SHAPE_BACKGROUND_COLOR = _options.backgroundColor || "rgba(0,0,0,0.6)";
2424

@@ -55,7 +55,9 @@
5555
onNextClick: function() {
5656
nextStep();
5757
},
58-
58+
onPrevClick: function(){
59+
prevStep();
60+
},
5961
onSkipClick: function() {
6062
options.onSkip();
6163
skipAll();
@@ -85,30 +87,34 @@
8587
};
8688

8789
function hideCurrentHint(){
88-
$body.enjoyhint('render_circle', []);
89-
$('#enjoyhint_label').remove();
90-
$('#enjoyhint_arrpw_line').remove();
91-
$body.enjoyhint('hide_next');
92-
$body.enjoyhint('hide_skip');
90+
$body.enjoyhint("render_circle", []);
91+
$("#enjoyhint_label").remove();
92+
$("#enjoyhint_arrpw_line").remove();
93+
$body.enjoyhint("hide_prev");
94+
$body.enjoyhint("hide_next");
95+
$body.enjoyhint("hide_skip");
9396
};
94-
97+
9598
var stepAction = function() {
9699
if (!(data && data[current_step])) {
97100
$body.enjoyhint("hide");
98101
options.onEnd();
99102
destroyEnjoy();
100103
return;
101104
}
102-
105+
103106
options.onNext();
104107

105108
var $enjoyhint = $(".enjoyhint");
106109

107110
$enjoyhint.removeClass("enjoyhint-step-" + current_step);
108111
$enjoyhint.removeClass("enjoyhint-step-" + (current_step + 1));
112+
$enjoyhint.removeClass("enjoyhint-step-" + (current_step + 2));
109113
$enjoyhint.addClass("enjoyhint-step-" + (current_step + 1));
110114

111115
var step_data = data[current_step];
116+
117+
var scrollSpeed = step_data.scrollAnimationSpeed;
112118

113119
if (
114120
step_data.onBeforeStart &&
@@ -142,25 +148,30 @@
142148
setTimeout(function() {
143149
that.clear();
144150
}, 250);
145-
151+
146152
var isHintInViewport = $(step_data.selector).get(0).getBoundingClientRect();
147153
if(isHintInViewport.top < 0 || isHintInViewport.bottom > (window.innerHeight || document.documentElement.clientHeight)){
148154
hideCurrentHint();
149155
$(document.body).scrollTo(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -200});
150156
}
157+
else {
158+
// if previous button has been clicked and element are in viewport to prevent custom step scrollAnimationSpeed set scrollSpeed to default
159+
scrollSpeed = 250;
160+
}
151161

152162
setTimeout(function() {
153163
var $element = $(step_data.selector);
154164
var event = makeEventName(step_data.event);
155-
156165
$body.enjoyhint("show");
157-
$body.enjoyhint("hide_next");
158166
$event_element = $element;
159167

160168
if (step_data.event_selector) {
161169
$event_element = $(step_data.event_selector);
162170
}
163-
171+
172+
$event_element.off(event)
173+
$element.off("keydown");
174+
164175
if (!step_data.event_type && step_data.event == "key") {
165176
$element.keydown(function(event) {
166177
if (event.which == step_data.keyCode) {
@@ -170,18 +181,23 @@
170181
});
171182
}
172183

173-
if (step_data.showNext == true) {
174-
$body.enjoyhint("show_next");
184+
if (step_data.showNext !== true) {
185+
$body.enjoyhint("hide_next");
175186
}
176-
187+
188+
$body.enjoyhint("hide_prev");
189+
190+
if(current_step !== 0) {
191+
$body.enjoyhint("show_prev");
192+
}
193+
194+
177195
if (step_data.showSkip == false) {
178196
$body.enjoyhint("hide_skip");
179197
} else {
180198
$body.enjoyhint("show_skip");
181199
}
182200

183-
if (step_data.showSkip == true) {
184-
}
185201

186202
if (step_data.nextButton) {
187203
var $nextBtn = $(".enjoyhint_next_btn");
@@ -208,12 +224,9 @@
208224
case "click":
209225
break;
210226
}
211-
212227
current_step++;
213228
stepAction();
214-
215229
return;
216-
break;
217230

218231
case "custom":
219232
on(step_data.event, function() {
@@ -235,12 +248,10 @@
235248
}
236249

237250
current_step++;
238-
$(this).off(event);
239-
240251
stepAction(); // clicked
241252
});
242253
}
243-
254+
244255
var max_habarites = Math.max(
245256
$element.outerWidth(),
246257
$element.outerHeight()
@@ -280,14 +291,20 @@
280291
}
281292

282293
$body.enjoyhint("render_label_with_shape", shape_data, that.stop);
283-
}, step_data.scrollAnimationSpeed + 20 || 270);
294+
295+
}, scrollSpeed + 20 || 270);
284296
}, timeout);
285297
};
286298

287299
var nextStep = function() {
288300
current_step++;
289301
stepAction();
290302
};
303+
304+
var prevStep = function() {
305+
current_step--;
306+
stepAction();
307+
};
291308

292309
var skipAll = function() {
293310
var step_data = data[current_step];

src/jquery.enjoyhint.css

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,60 @@
7474
border-color 0.3s cubic-bezier(0, 0, 0, 0);
7575
}
7676

77+
.enjoyhint_prev_btn {
78+
min-width: 100px;
79+
position: absolute;
80+
z-index: 1012;
81+
/*display: none;*/
82+
pointer-events: all;
83+
-webkit-box-sizing: content-box;
84+
-moz-box-sizing: content-box;
85+
box-sizing: content-box;
86+
height: 40px;
87+
cursor: pointer;
88+
margin: 0 auto;
89+
border: 2px solid rgb(30, 205, 151);
90+
-webkit-border-radius: 40px;
91+
border-radius: 40px;
92+
font: normal normal normal 17px/40px "Advent Pro", Helvetica, sans-serif;
93+
color: rgb(30, 205, 151);
94+
text-align: center;
95+
-o-text-overflow: clip;
96+
text-overflow: clip;
97+
letter-spacing: 1px;
98+
background: rgba(0, 0, 0, 0);
99+
-webkit-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0),
100+
color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0),
101+
border-width 0.3s cubic-bezier(0, 0, 0, 0),
102+
border-color 0.3s cubic-bezier(0, 0, 0, 0);
103+
-moz-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0),
104+
color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0),
105+
border-width 0.3s cubic-bezier(0, 0, 0, 0),
106+
border-color 0.3s cubic-bezier(0, 0, 0, 0);
107+
-o-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0),
108+
color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0),
109+
border-width 0.3s cubic-bezier(0, 0, 0, 0),
110+
border-color 0.3s cubic-bezier(0, 0, 0, 0);
111+
transition: background-color 0.3s cubic-bezier(0, 0, 0, 0),
112+
color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0),
113+
border-width 0.3s cubic-bezier(0, 0, 0, 0),
114+
border-color 0.3s cubic-bezier(0, 0, 0, 0);
115+
}
116+
117+
.enjoyhint_prev_btn:hover {
118+
color: rgba(255, 255, 255, 1);
119+
background: rgb(30, 205, 151);
120+
}
121+
122+
.enjoyhint_prev_btn:active {
123+
border: 2px solid rgba(33, 224, 163, 1);
124+
background: rgba(33, 224, 163, 1);
125+
-webkit-transition: none;
126+
-moz-transition: none;
127+
-o-transition: none;
128+
transition: none;
129+
}
130+
77131
.enjoyhint_next_btn:hover {
78132
color: rgba(255, 255, 255, 1);
79133
background: rgb(30, 205, 151);
@@ -319,8 +373,11 @@
319373
}
320374

321375
.enjoy_hint_label {
376+
display: inline-block;
377+
max-width: 80%;
322378
position: absolute;
323379
overflow: hidden;
380+
text-align: center;
324381
color: white;
325382
z-index: 107;
326383
font-size: 22px;
@@ -330,6 +387,38 @@
330387
transition: opacity 400ms cubic-bezier(0.42, 0, 0.58, 1);
331388
}
332389

390+
@media (max-width : 640px){
391+
.enjoy_hint_label {
392+
font-size: 16px;
393+
}
394+
395+
.enjoyhint_next_btn {
396+
font-size : 200%;
397+
color : #FFF;
398+
line-height : 1.2em;
399+
min-width: 0px;
400+
width: 35px;
401+
height: 35px;
402+
-webkit-border-radius : 50%;
403+
border-radius : 50%;
404+
}
405+
406+
.enjoyhint_prev_btn {
407+
font-size : 200%;
408+
color : #FFF;
409+
line-height : 1.2em;
410+
min-width: 0px;
411+
width: 35px;
412+
height: 35px;
413+
-webkit-border-radius : 50%;
414+
border-radius : 50%;
415+
}
416+
417+
.enjoyhint_skip_btn {
418+
display: none;
419+
}
420+
}
421+
333422
div.kineticjs-content {
334423
position: absolute !important;
335424
}
@@ -340,7 +429,6 @@ div.kineticjs-content {
340429

341430
.enjoy_hint_label {
342431
display: inline-block;
343-
min-width: 200px;
344432
text-align: center;
345433
max-width: 80%;
346434
}

0 commit comments

Comments
 (0)