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

Commit

Permalink
added onStart, onEnd callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed Aug 10, 2012
1 parent 567f85c commit ff332bb
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions js/hopscotch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
* http://daneden.me/animate/ for bounce animation
*
* multiple start/end callbacks
*
*/

(function() {
Expand Down Expand Up @@ -867,6 +869,7 @@
tmpOpt[prop] = tour[prop];
}
}
opt = {}; // reset all options so there are no surprises
this.configure(tmpOpt);

// Get existing tour state, if it exists.
Expand Down Expand Up @@ -957,6 +960,10 @@
currSubstepNum = 0;
}

if (opt.onStart && currStepNum === 0 && !currSubstepNum) {
opt.onStart(currTour.id);
}

this.showStep(currStepNum, currSubstepNum);
bubble = getBubble().show();

Expand All @@ -979,7 +986,7 @@
currStepNum = stepIdx;
currSubstepNum = substepIdx;

if (typeof substepIdx !== undefinedStr) {
if (typeof substepIdx !== undefinedStr && isInMultiPartStep()) {
step = step[substepIdx];
cookieVal += '-' + substepIdx;
}
Expand Down Expand Up @@ -1035,14 +1042,18 @@
var bubble = getBubble();
clearCookie = utils.valOrDefault(clearCookie, true);
currStepNum = 0;
currSubstepNum = 0;
currSubstepNum = undefined;
cookieTourStep = undefined;

bubble.hide();
if (clearCookie) {
utils.clearState(opt.cookieName);
}
this.isActive = false;

if (opt.onEnd) {
opt.onEnd(currTour.id);
}
return this;
};

Expand Down Expand Up @@ -1088,6 +1099,8 @@
* ('4', '5', '6', etc.) will be used as default.
*/
this.configure = function(options) {
var bubble;

if (!opt) {
opt = {};
}
Expand All @@ -1105,22 +1118,26 @@
opt.bubbleBorder = utils.valOrDefault(opt.bubbleBorder, 6);
opt.arrowWidth = utils.valOrDefault(opt.arrowWidth, 20);
opt.onNext = utils.valOrDefault(opt.onNext, null);
opt.onStart = utils.valOrDefault(opt.onStart, null);
opt.onEnd = utils.valOrDefault(opt.onEnd, null);
opt.cookieName = utils.valOrDefault(opt.cookieName, 'hopscotch.tour.state');

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

bubble = getBubble();

if (opt.animate) {
getBubble().initAnimate();
bubble.initAnimate();
}
else {
getBubble().removeAnimate();
bubble.removeAnimate();
}

getBubble().showPrevButton(opt.showPrevButton, true);
getBubble().showNextButton(opt.showNextButton, true);
getBubble().showCloseButton(opt.showCloseButton, true);
bubble.showPrevButton(opt.showPrevButton, true);
bubble.showNextButton(opt.showNextButton, true);
bubble.showCloseButton(opt.showCloseButton, true);
return this;
};

Expand Down

0 comments on commit ff332bb

Please sign in to comment.