Skip to content

Commit f9d48c3

Browse files
author
AZhurav1ev
committed
Added possibility to customize Previous button
1 parent a0847cd commit f9d48c3

File tree

5 files changed

+60
-34
lines changed

5 files changed

+60
-34
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ var enjoyhint_script_steps = [
9797
* `left` - left margin for the shape of "rect" type
9898
* `scrollAnimationSpeed` - sets the auto scroll speed (ms).
9999
* `nextButton` - allows applying its classes and names for the button Nеxt.
100-
* `skipButton` - allows applying its classes and names for the button Skip. For the example :
100+
* `skipButton` - allows applying its classes and names for the button Skip.
101+
* `prevButton` - allows applying its classes and names for the button Previous. For the example :
101102
```javascript
102103
var options = {
103104
"next #block": 'Hello.',
104-
"nextButton" : {className: "myNext", text: "NEXT"},
105-
"skipButton" : {className: "mySkip", text: "SKIP"},
106-
105+
"nextButton" : {className: "myNext", text: "myNEXT"},
106+
"skipButton" : {className: "mySkip", text: "mySKIP"},
107+
"prevButton" : {className: "myPrev", text: "myPREV"}
107108
}
108109
```
109110
* `showSkip` - shows or hides the Skip button (true|false)
@@ -165,13 +166,14 @@ var enjoyhint_script_steps = [
165166

166167
##### v.4
167168

168-
* Fix label position bugs
169-
* Fix arrow position bugs
170-
* Fix resize bugs
171-
* Add responsive design
172-
* Add mobile support
173-
* Add possibility to go back to previous step
174-
* Add possibility to select the color of a marker
169+
* Fixed label position bugs
170+
* Fixed arrow position bugs
171+
* Fixed resize bugs
172+
* Added responsive design
173+
* Added mobile support
174+
* Added possibility to go back to previous step
175+
* Added possibility to select the color of a marker
176+
* Added possibility to customize previous button
175177

176178

177179

enjoyhint.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
that.clear = function() {
8080
var $nextBtn = $(".enjoyhint_next_btn");
8181
var $skipBtn = $(".enjoyhint_skip_btn");
82-
82+
var $prevBtn = $(".enjoyhint_prev_btn");
83+
84+
$prevBtn.removeClass(that.prevUserClass);
8385
$nextBtn.removeClass(that.nextUserClass);
8486
$nextBtn.text(BTN_NEXT_TEXT);
8587
$skipBtn.removeClass(that.skipUserClass);
@@ -209,7 +211,15 @@
209211
$nextBtn.text(step_data.nextButton.text || "Next");
210212
that.nextUserClass = step_data.nextButton.className;
211213
}
212-
214+
215+
if (step_data.prevButton) {
216+
var $prevBtn = $(".enjoyhint_prev_btn");
217+
218+
$prevBtn.addClass(step_data.prevButton.className || "");
219+
$prevBtn.text(step_data.prevButton.text || "Previous");
220+
that.prevUserClass = step_data.prevButton.className;
221+
}
222+
213223
if (step_data.skipButton) {
214224
var $skipBtn = $(".enjoyhint_skip_btn");
215225

@@ -285,8 +295,9 @@
285295
scroll: step_data.scroll
286296
};
287297

288-
if (step_data.nextButton) {
289-
shape_data.nextBtnInitValue = step_data.nextButton.text
298+
var customBtnProps = {
299+
nextButton: step_data.nextButton,
300+
prevButton: step_data.prevButton
290301
}
291302

292303
if (shape_data.center_x === 0 && shape_data.center_y === 0) {
@@ -304,7 +315,7 @@
304315
shape_data.height = h + shape_margin;
305316
}
306317

307-
$body.enjoyhint("render_label_with_shape", shape_data, that.stop);
318+
$body.enjoyhint("render_label_with_shape", shape_data, that.stop, customBtnProps);
308319

309320
}, scrollSpeed + 20 || 270);
310321
}, timeout);
@@ -748,7 +759,7 @@
748759
that.stepData.width = newDataCoords.width + 11;
749760
that.stepData.height = newDataCoords.height + 11;
750761

751-
that.renderLabelWithShape(that.stepData);
762+
that.renderLabelWithShape(that.stepData, that.customBtnProps);
752763
$('.enjoyhint_next_btn').css('visibility', 'visible');
753764
$('.enjoyhint_prev_btn').css('visibility', 'visible');
754765
$('.enjoyhint_skip_btn').css('visibility', 'visible');
@@ -1128,8 +1139,9 @@
11281139
};
11291140
})($);
11301141

1131-
that.renderLabelWithShape = function(data) {
1142+
that.renderLabelWithShape = function(data, customBtnProps) {
11321143
that.stepData = data;
1144+
that.customBtnProps = customBtnProps;
11331145

11341146
function findParentDialog(element) {
11351147
if (element.tagName === "MD-DIALOG") {
@@ -1425,8 +1437,8 @@
14251437
else {
14261438
distance = initial_distance;
14271439
ver_button_position = initial_ver_position;
1428-
that.$next_btn.html(that.stepData.nextBtnInitValue || 'Next');
1429-
that.$prev_btn.html('Previous');
1440+
that.$next_btn.html(customBtnProps.nextButton ? customBtnProps.nextButton.text : 'Next');
1441+
that.$prev_btn.html(customBtnProps.prevButton ? customBtnProps.prevButton.text : 'Previous');
14301442
}
14311443

14321444
that.$prev_btn.css({
@@ -1574,10 +1586,10 @@
15741586
return this;
15751587
},
15761588

1577-
render_label_with_shape: function(data, stopFunction) {
1589+
render_label_with_shape: function(data, stopFunction, customBtnProps) {
15781590
this.each(function() {
15791591
that.stopFunction = stopFunction;
1580-
this.enjoyhint_obj.renderLabelWithShape(data);
1592+
this.enjoyhint_obj.renderLabelWithShape(data, customBtnProps);
15811593
});
15821594

15831595
return this;

0 commit comments

Comments
 (0)