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

Commit

Permalink
make CTA button callback to close automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed May 15, 2013
1 parent 26e630d commit d2cae5e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions js/hopscotch-0.0.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,27 @@
return this;
},

_setupCTAButton: function(step) {
var callback,
self = this;

this._showButton(this.ctaBtnEl, !!step.showCTAButton);
if (step.showCTAButton && step.ctaLabel) {
this.ctaBtnEl.innerHTML = step.ctaLabel;
callback = function() {
utils.removeEvtListener(self.ctaBtnEl, 'click', callback);
if (!self.opt.isTourBubble) {
// This is a callout. Close the callout when CTA is clicked.
winHopscotch.getCalloutManager().removeCallout(step.id);
}
if (step.onCTA && typeof step.onCTA === 'function') {
step.onCTA();
}
};
utils.addEvtListener(this.ctaBtnEl, 'click', callback);
}
},

/**
* Renders the bubble according to the step JSON.
*
Expand Down Expand Up @@ -819,24 +840,7 @@
}

// Show/hide CTA button
this._showButton(this.ctaBtnEl, !!step.showCTAButton);
if (step.showCTAButton) {
this.ctaBtnEl.innerHTML = step.ctaLabel;

if (step.onCTA) {
if (this.onCTA) {
utils.removeEvtListener(this.ctaBtnEl, 'click', this.onCTA);
}

utils.addEvtListener(this.ctaBtnEl, 'click', step.onCTA);
this.onCTA = step.onCTA; // cache for removing later
}
}
else if (this.onCTA) {
// Remove previous CTA callback.
utils.removeEvtListener(this.ctaBtnEl, 'click', this.onCTA);
this.onCTA = null;
}
this._setupCTAButton(step);

this._setArrow(step.placement);

Expand Down

0 comments on commit d2cae5e

Please sign in to comment.