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

Commit

Permalink
change how options are defaulted, plus few other bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed Aug 23, 2012
1 parent 3cce1dc commit c1f3069
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
47 changes: 25 additions & 22 deletions js/hopscotch.js
Expand Up @@ -235,7 +235,7 @@
c;

if (hasSessionStorage) {
return localStorage.getItem(name);
return sessionStorage.getItem(name);
}
else {
for(i=0;i < ca.length;i++) {
Expand Down Expand Up @@ -432,10 +432,7 @@
el.appendChild(containerEl);

this.initNavButtons();

if (opt && opt.showCloseButton) {
this.initCloseButton();
}
this.initCloseButton();

this.initArrow();

Expand Down Expand Up @@ -900,7 +897,8 @@
tmpOpt[prop] = tour[prop];
}
}
opt = {}; // reset all options so there are no surprises

this.resetDefaultOptions(); // reset all options so there are no surprises
_configure.call(this, tmpOpt, true);

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

if (step.multiPage) {
if (step.multipage) {
cookieVal += ':mp';
}

Expand Down Expand Up @@ -1121,7 +1119,7 @@
if (clearCookie) {
utils.clearState(opt.cookieName);
}
this.isActive = false;
winHopscotch.isActive = false;

if (doCallback) {
utils.invokeCallbacks('end', [currTour.id]);
Expand Down Expand Up @@ -1233,6 +1231,24 @@
return this;
};

this.resetDefaultOptions = function() {
opt = {
animate: false,
smoothScroll: true,
scrollDuration: 1000,
scrollTopMargin: 200,
showCloseButton: true,
showPrevButton: false,
showNextButton: true,
bubbleWidth: 280,
bubblePadding: 15,
bubbleBorder: 6,
arrowWidth: 20,
skipIfNoElement: false,
cookieName: 'hopscotch.tour.state'
};
};

/**
* _configure
* ==========
Expand Down Expand Up @@ -1285,23 +1301,10 @@
var bubble;

if (!opt) {
opt = {};
this.resetDefaultOptions();
}

utils.extend(opt, options);
opt.animate = utils.valOrDefault(opt.animate, false);
opt.smoothScroll = utils.valOrDefault(opt.smoothScroll, true);
opt.scrollDuration = utils.valOrDefault(opt.scrollDuration, 1000);
opt.scrollTopMargin = utils.valOrDefault(opt.scrollTopMargin, 200);
opt.showCloseButton = utils.valOrDefault(opt.showCloseButton, true);
opt.showPrevButton = utils.valOrDefault(opt.showPrevButton, false);
opt.showNextButton = utils.valOrDefault(opt.showNextButton, true);
opt.bubbleWidth = utils.valOrDefault(opt.bubbleWidth, 280);
opt.bubblePadding = utils.valOrDefault(opt.bubblePadding, 15);
opt.bubbleBorder = utils.valOrDefault(opt.bubbleBorder, 6);
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
opt.skipIfNoElement = utils.valOrDefault(opt.skipIfNoElement, false);
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');

if (options) {
utils.extend(HopscotchI18N, options.i18n);
Expand Down
42 changes: 22 additions & 20 deletions js/hopscotch_jquery.js
Expand Up @@ -359,10 +359,7 @@
.append($containerEl);

this.initNavButtons();

if (opt && opt.showCloseButton) {
this.initCloseButton();
}
this.initCloseButton();

this.initArrow();

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

if (step.multiPage) {
if (step.multipage) {
cookieVal += ':mp';
}

Expand Down Expand Up @@ -979,7 +976,7 @@
if (clearCookie) {
utils.clearState(opt.cookieName);
}
this.isActive = false;
winHopscotch.isActive = false;

if (doCallback) {
utils.invokeCallbacks('end', [currTour.id]);
Expand Down Expand Up @@ -1089,6 +1086,24 @@
return this;
};

this.resetDefaultOptions = function() {
opt = {
animate: false,
smoothScroll: true,
scrollDuration: 1000,
scrollTopMargin: 200,
showCloseButton: true,
showPrevButton: false,
showNextButton: true,
bubbleWidth: 280,
bubblePadding: 15,
bubbleBorder: 6,
arrowWidth: 20,
skipIfNoElement: false,
cookieName: 'hopscotch.tour.state'
};
};

/**
* _configure
* ==========
Expand Down Expand Up @@ -1141,23 +1156,10 @@
var bubble;

if (!opt) {
opt = {};
this.resetDefaultOptions();
}

utils.extend(opt, options);
opt.animate = utils.valOrDefault(opt.animate, false);
opt.smoothScroll = utils.valOrDefault(opt.smoothScroll, true);
opt.scrollDuration = utils.valOrDefault(opt.scrollDuration, 1000);
opt.scrollTopMargin = utils.valOrDefault(opt.scrollTopMargin, 200);
opt.showCloseButton = utils.valOrDefault(opt.showCloseButton, true);
opt.showPrevButton = utils.valOrDefault(opt.showPrevButton, false);
opt.showNextButton = utils.valOrDefault(opt.showNextButton, true);
opt.bubbleWidth = utils.valOrDefault(opt.bubbleWidth, 280);
opt.bubblePadding = utils.valOrDefault(opt.bubblePadding, 15);
opt.bubbleBorder = utils.valOrDefault(opt.bubbleBorder, 6);
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
opt.skipIfNoElement = utils.valOrDefault(opt.skipIfNoElement, false);
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');

if (options) {
utils.extend(HopscotchI18N, options.i18n);
Expand Down

0 comments on commit c1f3069

Please sign in to comment.