Skip to content

Commit

Permalink
onTap callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzepinski authored and Foxandxss committed Aug 29, 2015
1 parent 1d93b26 commit c353cc4
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ app.config(function(toastrConfig) {
newestOnTop: true,
onHidden: null,
onShown: null,
onTap: null,
positionClass: 'toast-top-right',
preventDuplicates: false,
preventOpenDuplicates: false,
Expand Down Expand Up @@ -163,6 +164,7 @@ Those are the default values, you can pick what you need from it and override wi
* **newestOnTop**: Add new toasts on top of the old one. Put on false to put them on the bottom.
* **onHidden**: A callback function called when a toast gets hidden. It receives a boolean parameter to see whether it was closed via click or not.
* **onShown**: A callback function called when a toast is shown.
* **onTap**: A callback function called when it is clicked.
* **positionClass**: The position where the toasts are added.
* **preventDuplicates**: Prevent duplicates of the last toast.
* **preventOpenDuplicates**: Prevent duplicates of open toasts.
Expand Down Expand Up @@ -243,6 +245,7 @@ There you can override:
* **messageClass**: If you want to modify the message look.
* **onHidden**: Function to call when the toast gets hidden. It receives a boolean parameter to see whether it was closed via click or not.
* **onShown**: Function to call when the toast is shown.
* **onTap**: A callback function called when it is clicked.
* **progressBar** Show a progress bar for the toast.
* **tapToDismiss**: If you want a concrete toast to toggle the close on click.
* **timeOut**: For that concrete toast timeout.
Expand Down
14 changes: 11 additions & 3 deletions dist/angular-toastr.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
messageClass: options.messageClass,
onHidden: options.onHidden,
onShown: options.onShown,
onTap: options.onTap,
progressBar: options.progressBar,
tapToDismiss: options.tapToDismiss,
timeOut: options.timeOut,
Expand All @@ -223,7 +224,7 @@
};
newToast.iconClass = map.iconClass;
if (map.optionsOverride) {
options = angular.extend(options, cleanOptionsOverride(map.optionsOverride));
angular.extend(options, cleanOptionsOverride(map.optionsOverride));
newToast.iconClass = map.optionsOverride.iconClass || newToast.iconClass;
}

Expand Down Expand Up @@ -293,6 +294,7 @@
newestOnTop: true,
onHidden: null,
onShown: null,
onTap: null,
positionClass: 'toast-top-right',
preventDuplicates: false,
preventOpenDuplicates: false,
Expand Down Expand Up @@ -414,7 +416,7 @@
var button = angular.element(scope.options.closeHtml),
$compile = $injector.get('$compile');
button.addClass('toast-close-button');
button.attr('ng-click', 'close()');
button.attr('ng-click', 'close(true, $event)');
$compile(button)(scope);
element.prepend(button);
}
Expand All @@ -436,12 +438,18 @@
});

scope.tapToast = function () {
if (angular.isFunction(scope.options.onTap)) {
scope.options.onTap();
}
if (scope.options.tapToDismiss) {
scope.close(true);
}
};

scope.close = function (wasClicked) {
scope.close = function (wasClicked, $event) {
if ($event && angular.isFunction($event.stopPropagation)) {
$event.stopPropagation();
}
toastr.remove(scope.toastId, wasClicked);
};

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-toastr.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c353cc4

Please sign in to comment.