diff --git a/anno.js b/anno.js
index 4a20e85..b4162b8 100644
--- a/anno.js
+++ b/anno.js
@@ -151,6 +151,22 @@ Anno = (function() {
_returnFromOnShow = null;
+ Anno.prototype.onComplete = function(anno) {};
+
+ Anno.prototype.complete = function() {
+ this.hide();
+ this.onComplete(this);
+ return this;
+ };
+
+ Anno.prototype.onDismissed = function(anno) {};
+
+ Anno.prototype.dismissed = function() {
+ this.hide();
+ this.onDismissed(this);
+ return this;
+ };
+
Anno.prototype.hide = function() {
this.hideAnno();
this.hideOverlay();
@@ -291,7 +307,7 @@ Anno = (function() {
Anno.prototype.overlayClassName = '';
Anno.prototype.overlayClick = function(anno, evt) {
- return anno.hide();
+ return this.dismissed();
};
Anno.prototype.hideOverlay = function() {
@@ -531,6 +547,8 @@ AnnoButton = (function() {
AnnoButton.prototype.buttonElem = function(anno) {
return $("").html(this.textFn(anno)).addClass(this.className).click((function(_this) {
return function(evt) {
+ evt.stopPropagation();
+ evt.preventDefault();
return _this.click.call(anno, anno, evt);
};
})(this));
@@ -554,7 +572,7 @@ AnnoButton = (function() {
if (anno._chainNext != null) {
return anno.switchToChainNext();
} else {
- return anno.hide();
+ return anno.complete();
}
};
@@ -568,7 +586,7 @@ AnnoButton = (function() {
AnnoButton.DoneButton = new AnnoButton({
text: 'Done',
click: function() {
- return this.hide();
+ return this.complete();
}
});
diff --git a/src/anno.litcoffee b/src/anno.litcoffee
index e5dfe7f..d4e5601 100644
--- a/src/anno.litcoffee
+++ b/src/anno.litcoffee
@@ -204,6 +204,24 @@ Note: whatever you return from your `onShow` function will be passed into the `o
_returnFromOnShow = null
+ onComplete: (anno) ->
+
+Complete is called when an anno chain reaches the end.
+
+ complete: () ->
+ @hide()
+ @onComplete(this)
+ return this
+
+Dismissed is called when a user effectively ends a tour by clicking on the overlay background.
+
+ onDismissed: (anno) ->
+
+ dismissed: () ->
+ @hide()
+ @onDismissed(this)
+ return this
+
Hiding is done in two stages so that you can re-use one overlay element for a long chain of Anno's.
hide: () ->
@@ -345,7 +363,8 @@ Semi-transparent overlay and other effects
click( (evt) => @overlayClick.call(this, this, evt) )
overlayClassName: '' # TODO talk about .anno-hidden
- overlayClick: (anno, evt) -> anno.hide()
+
+ overlayClick: (anno, evt) -> anno.dismissed()
hideOverlay: () ->
$('.anno-overlay').addClass 'anno-hidden'
@@ -558,7 +577,10 @@ Buttons
return $("").
html( @textFn(anno) ).
addClass( @className ).
- click( (evt) => @click.call(anno, anno, evt) )
+ click( (evt) => {
+ evt.preventDefault();
+ @click.call(anno, anno, evt)
+ })
textFn: (anno) ->
if @text? then @text
@@ -576,14 +598,14 @@ fat arrow.
if anno._chainNext?
anno.switchToChainNext()
else
- anno.hide()
+ anno.complete()
These are some handy presets that you can use by adding `AnnoButton.NextButton` to your Anno object's
`buttons` list.
@NextButton: new AnnoButton({ text: 'Next' , click: () -> @switchToChainNext() })
- @DoneButton: new AnnoButton({ text: 'Done' , click: () -> @hide() })
+ @DoneButton: new AnnoButton({ text: 'Done' , click: () -> @complete() })
@BackButton: new AnnoButton(
text: 'Back'