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

Commit c1f3069

Browse files
author
Gordon Koo
committed
change how options are defaulted, plus few other bug fixes
1 parent 3cce1dc commit c1f3069

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

js/hopscotch.js

+25-22
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
c;
236236

237237
if (hasSessionStorage) {
238-
return localStorage.getItem(name);
238+
return sessionStorage.getItem(name);
239239
}
240240
else {
241241
for(i=0;i < ca.length;i++) {
@@ -432,10 +432,7 @@
432432
el.appendChild(containerEl);
433433

434434
this.initNavButtons();
435-
436-
if (opt && opt.showCloseButton) {
437-
this.initCloseButton();
438-
}
435+
this.initCloseButton();
439436

440437
this.initArrow();
441438

@@ -900,7 +897,8 @@
900897
tmpOpt[prop] = tour[prop];
901898
}
902899
}
903-
opt = {}; // reset all options so there are no surprises
900+
901+
this.resetDefaultOptions(); // reset all options so there are no surprises
904902
_configure.call(this, tmpOpt, true);
905903

906904
// Get existing tour state, if it exists.
@@ -1025,7 +1023,7 @@
10251023
isLast = (stepIdx === numTourSteps - 1) || (substepIdx >= step.length - 1);
10261024
bubble.renderStep(step, stepIdx, substepIdx, isLast, adjustWindowScroll);
10271025

1028-
if (step.multiPage) {
1026+
if (step.multipage) {
10291027
cookieVal += ':mp';
10301028
}
10311029

@@ -1121,7 +1119,7 @@
11211119
if (clearCookie) {
11221120
utils.clearState(opt.cookieName);
11231121
}
1124-
this.isActive = false;
1122+
winHopscotch.isActive = false;
11251123

11261124
if (doCallback) {
11271125
utils.invokeCallbacks('end', [currTour.id]);
@@ -1233,6 +1231,24 @@
12331231
return this;
12341232
};
12351233

1234+
this.resetDefaultOptions = function() {
1235+
opt = {
1236+
animate: false,
1237+
smoothScroll: true,
1238+
scrollDuration: 1000,
1239+
scrollTopMargin: 200,
1240+
showCloseButton: true,
1241+
showPrevButton: false,
1242+
showNextButton: true,
1243+
bubbleWidth: 280,
1244+
bubblePadding: 15,
1245+
bubbleBorder: 6,
1246+
arrowWidth: 20,
1247+
skipIfNoElement: false,
1248+
cookieName: 'hopscotch.tour.state'
1249+
};
1250+
};
1251+
12361252
/**
12371253
* _configure
12381254
* ==========
@@ -1285,23 +1301,10 @@
12851301
var bubble;
12861302

12871303
if (!opt) {
1288-
opt = {};
1304+
this.resetDefaultOptions();
12891305
}
12901306

12911307
utils.extend(opt, options);
1292-
opt.animate = utils.valOrDefault(opt.animate, false);
1293-
opt.smoothScroll = utils.valOrDefault(opt.smoothScroll, true);
1294-
opt.scrollDuration = utils.valOrDefault(opt.scrollDuration, 1000);
1295-
opt.scrollTopMargin = utils.valOrDefault(opt.scrollTopMargin, 200);
1296-
opt.showCloseButton = utils.valOrDefault(opt.showCloseButton, true);
1297-
opt.showPrevButton = utils.valOrDefault(opt.showPrevButton, false);
1298-
opt.showNextButton = utils.valOrDefault(opt.showNextButton, true);
1299-
opt.bubbleWidth = utils.valOrDefault(opt.bubbleWidth, 280);
1300-
opt.bubblePadding = utils.valOrDefault(opt.bubblePadding, 15);
1301-
opt.bubbleBorder = utils.valOrDefault(opt.bubbleBorder, 6);
1302-
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
1303-
opt.skipIfNoElement = utils.valOrDefault(opt.skipIfNoElement, false);
1304-
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');
13051308

13061309
if (options) {
13071310
utils.extend(HopscotchI18N, options.i18n);

js/hopscotch_jquery.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,7 @@
359359
.append($containerEl);
360360

361361
this.initNavButtons();
362-
363-
if (opt && opt.showCloseButton) {
364-
this.initCloseButton();
365-
}
362+
this.initCloseButton();
366363

367364
this.initArrow();
368365

@@ -883,7 +880,7 @@
883880
isLast = (stepIdx === numTourSteps - 1) || (substepIdx >= step.length - 1);
884881
bubble.renderStep(step, stepIdx, substepIdx, isLast, adjustWindowScroll);
885882

886-
if (step.multiPage) {
883+
if (step.multipage) {
887884
cookieVal += ':mp';
888885
}
889886

@@ -979,7 +976,7 @@
979976
if (clearCookie) {
980977
utils.clearState(opt.cookieName);
981978
}
982-
this.isActive = false;
979+
winHopscotch.isActive = false;
983980

984981
if (doCallback) {
985982
utils.invokeCallbacks('end', [currTour.id]);
@@ -1089,6 +1086,24 @@
10891086
return this;
10901087
};
10911088

1089+
this.resetDefaultOptions = function() {
1090+
opt = {
1091+
animate: false,
1092+
smoothScroll: true,
1093+
scrollDuration: 1000,
1094+
scrollTopMargin: 200,
1095+
showCloseButton: true,
1096+
showPrevButton: false,
1097+
showNextButton: true,
1098+
bubbleWidth: 280,
1099+
bubblePadding: 15,
1100+
bubbleBorder: 6,
1101+
arrowWidth: 20,
1102+
skipIfNoElement: false,
1103+
cookieName: 'hopscotch.tour.state'
1104+
};
1105+
};
1106+
10921107
/**
10931108
* _configure
10941109
* ==========
@@ -1141,23 +1156,10 @@
11411156
var bubble;
11421157

11431158
if (!opt) {
1144-
opt = {};
1159+
this.resetDefaultOptions();
11451160
}
11461161

11471162
utils.extend(opt, options);
1148-
opt.animate = utils.valOrDefault(opt.animate, false);
1149-
opt.smoothScroll = utils.valOrDefault(opt.smoothScroll, true);
1150-
opt.scrollDuration = utils.valOrDefault(opt.scrollDuration, 1000);
1151-
opt.scrollTopMargin = utils.valOrDefault(opt.scrollTopMargin, 200);
1152-
opt.showCloseButton = utils.valOrDefault(opt.showCloseButton, true);
1153-
opt.showPrevButton = utils.valOrDefault(opt.showPrevButton, false);
1154-
opt.showNextButton = utils.valOrDefault(opt.showNextButton, true);
1155-
opt.bubbleWidth = utils.valOrDefault(opt.bubbleWidth, 280);
1156-
opt.bubblePadding = utils.valOrDefault(opt.bubblePadding, 15);
1157-
opt.bubbleBorder = utils.valOrDefault(opt.bubbleBorder, 6);
1158-
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
1159-
opt.skipIfNoElement = utils.valOrDefault(opt.skipIfNoElement, false);
1160-
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');
11611163

11621164
if (options) {
11631165
utils.extend(HopscotchI18N, options.i18n);

0 commit comments

Comments
 (0)