Skip to content

Commit

Permalink
Proposed two useful options: "hoverOffToDismiss" (default true) and "…
Browse files Browse the repository at this point in the history
…stickIfFocused" (default true). The first, if false, will keep the message sticky even after hovering away from the toast element. The second, if true, will keep the message sticky if a form element inside is focused/in use.
  • Loading branch information
mholt committed May 10, 2012
1 parent c74b3a1 commit 099ac16
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions toastr.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// By: Hans Fjällemark and John Papa
// https://github.com/KnockedUp/toastr
//
// Modified to support css styling instead of inline styling
// Based on original version at https://github.com/Srirangan/notifer.js/

(function(window, $) {
window.toastr = (function() {
var
defaults = {
tapToDismiss: true,
hoverOffToDismiss: true,
stickIfFocused: true,
toastClass: 'toast',
containerId: 'toast-container',
debug: false,
Expand Down Expand Up @@ -89,6 +85,9 @@
}

var fadeAway = function() {
if ($(':focus', $toastElement).length > 0)
return

var fade = function() {
return $toastElement.fadeOut(options.fadeOut)
}
Expand Down Expand Up @@ -117,8 +116,10 @@
intervalId = setTimeout(fadeAway, options.timeOut)
}

$toastElement.hover(stickAround, fadeAway)

if (options.hoverOffToDismiss) {
$toastElement.hover(stickAround, fadeAway)
}

if (options.tapToDismiss) {
$toastElement.click(fadeAway)
}
Expand Down

0 comments on commit 099ac16

Please sign in to comment.