Code Monkey home page Code Monkey logo

toastr's Introduction

toastr

toastr is a Javascript library for non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.

Build Status Browser testing provided by BrowserStack.

Current Version

2.1.4

Demo

CDNs

cdnjs jsdelivr

Toastr is hosted at cdnjs and jsdelivr

Debug

Minified

Install

Install-Package toastr
bower install toastr
npm install --save toastr
yarn add toastr
# Gemfile

gem 'toastr-rails'
# application.coffee

#= require toastr
// application.scss

@import "toastr";

Wiki and Change Log

Wiki including Change Log

Breaking Changes

Animation Changes

The following animations options have been deprecated and should be replaced:

  • Replace options.fadeIn with options.showDuration
  • Replace options.onFadeIn with options.onShown
  • Replace options.fadeOut with options.hideDuration
  • Replace options.onFadeOut with options.onHidden

Quick Start

3 Easy Steps

For other API calls, see the demo.

  1. Link to toastr.css <link href="toastr.css" rel="stylesheet"/>

  2. Link to toastr.js <script src="toastr.js"></script>

  3. use toastr to display a toast for info, success, warning or error

    // Display an info toast with no title
    toastr.info('Are you the 6 fingered man?')

Other Options

// Display a warning toast, with no title
toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!')

// Display a success toast, with a title
toastr.success('Have fun storming the castle!', 'Miracle Max Says')

// Display an error toast, with a title
toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')

// Immediately remove current toasts without using animation
toastr.remove()

// Remove current toasts using animation
toastr.clear()

// Override global options
toastr.success('We do have the Kapua suite available.', 'Turtle Bay Resort', {timeOut: 5000})

Escape HTML characters

In case you want to escape HTML characters in title and message

toastr.options.escapeHtml = true;

Close Button

Optionally enable a close button

toastr.options.closeButton = true;

Optionally override the close button's HTML.

toastr.options.closeHtml = '<button><i class="icon-off"></i></button>';

You can also override the CSS/LESS for #toast-container .toast-close-button

Optionally override the hide animation when the close button is clicked (falls back to hide configuration).

toastr.options.closeMethod = 'fadeOut';
toastr.options.closeDuration = 300;
toastr.options.closeEasing = 'swing';

Display Sequence

Show newest toast at bottom (top is default)

toastr.options.newestOnTop = false;

Callbacks

// Define a callback for when the toast is shown/hidden/clicked
toastr.options.onShown = function() { console.log('hello'); }
toastr.options.onHidden = function() { console.log('goodbye'); }
toastr.options.onclick = function() { console.log('clicked'); }
toastr.options.onCloseClick = function() { console.log('close button clicked'); }

Animation Options

Toastr will supply default animations, so you do not have to provide any of these settings. However you have the option to override the animations if you like.

Easings

Optionally override the animation easing to show or hide the toasts. Default is swing. swing and linear are built into jQuery.

toastr.options.showEasing = 'swing';
toastr.options.hideEasing = 'linear';
toastr.options.closeEasing = 'linear';

Using the jQuery Easing plugin (http://www.gsgd.co.uk/sandbox/jquery/easing/)

toastr.options.showEasing = 'easeOutBounce';
toastr.options.hideEasing = 'easeInBack';
toastr.options.closeEasing = 'easeInBack';

Animation Method

Use the jQuery show/hide method of your choice. These default to fadeIn/fadeOut. The methods fadeIn/fadeOut, slideDown/slideUp, and show/hide are built into jQuery.

toastr.options.showMethod = 'slideDown';
toastr.options.hideMethod = 'slideUp';
toastr.options.closeMethod = 'slideUp';

Prevent Duplicates

Rather than having identical toasts stack, set the preventDuplicates property to true. Duplicates are matched to the previous toast based on their message content.

toastr.options.preventDuplicates = true;

Timeouts

Control how toastr interacts with users by setting timeouts appropriately.

toastr.options.timeOut = 30; // How long the toast will display without user interaction
toastr.options.extendedTimeOut = 60; // How long the toast will display after a user hovers over it

Prevent from Auto Hiding

To prevent toastr from closing based on the timeouts, set the timeOut and extendedTimeOut options to 0. The toastr will persist until selected.

toastr.options.timeOut = 0;
toastr.options.extendedTimeOut = 0;

Progress Bar

Visually indicate how long before a toast expires.

toastr.options.progressBar = true;

rtl

Flip the toastr to be displayed properly for right-to-left languages.

toastr.options.rtl = true;

Building Toastr

To build the minified and css versions of Toastr you will need node installed. (Use Homebrew or Chocolatey.)

npm install -g gulp karma-cli
npm install

At this point the dependencies have been installed and you can build Toastr

  • Run the analytics gulp analyze
  • Run the test gulp test
  • Run the build gulp

Contributing

For a pull request to be considered it must resolve a bug, or add a feature which is beneficial to a large audience.

Pull requests must pass existing unit tests, CI processes, and add additional tests to indicate successful operation of a new feature, or the resolution of an identified bug.

Requests must be made against the develop branch. Pull requests submitted against the master branch will not be considered.

All pull requests are subject to approval by the repository owners, who have sole discretion over acceptance or denial.

Authors

John Papa

Tim Ferrell

Hans Fjällemark

Credits

Inspired by https://github.com/Srirangan/notifer.js/.

Copyright

Copyright © 2012-2015

License

toastr is under MIT license - http://www.opensource.org/licenses/mit-license.php

toastr's People

Contributors

abaschen avatar alexkalinin avatar claushellsing avatar ddotm avatar digia avatar drewfreyling avatar getsetbro avatar jimf avatar johnpapa avatar johnw86 avatar jonaslewin avatar jstawski avatar lancscoder avatar martypowell avatar mholt avatar mrono avatar mrydengren avatar nestalk avatar nickdeis avatar nschonni avatar realityking avatar sbero avatar sergeyzwezdin avatar shashankanataraj avatar showwin avatar stevewillcock avatar timferrell avatar tradiff avatar vcarreno-1 avatar vingiarrusso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toastr's Issues

Trying to use toastr

Sorry for simple question.

I included toastr.js, toastr.cs and toastr.-responsive.css
This works:
toastr.info("Hello world");

But this doesn't work. And I don't get any error in browser console.
toastr.options.positionClass = "toast-top-full-width"; toastr.info("Hello world");

What would be the cause ?

Prevent infinite mouseenter mouseleave

add this function on click event to prevent infinite "mouseenter mouseleave" loop.
(after hover at line 123)

            $toastElement.hover(stickAround, fadeAway)

            $toastElement.click(function() {
                $(this).off('mouseenter mouseleave');
                fadeAway();
            })

Option to use Font Awesome icons

It would be nice if there was a way to optionally pass in your own icon, or better yet, pass in a Font Awesome icon.

Great library though, thanks!

Please use Git tags in repo for versions

We're using Bower to pull down the source.

If you could use tags in your repo, this would help us out a lot to control versioning.

You can go back and retroactively tag SHAs... for instance 51855e9 should be 1.1.1, etc.

Thanks!

URL on click

Can we have an option to set the url when a notification is clicked? Instead of just closing it.

Update docs/demo site

Update docs/demo site with new features introduced in 1.0.3.

  • onclick handler for custom logic on toast click
  • more..?

Full Bar Notification

We recently have started using toastr due to the simple nature of calling it versus other javascript notifications. One fallback that was causing me to look at other options was the ability to display messages across the top or bottom of the screen as a full bar. I think toastr is very user friendly as a simple corner notification, but for some apps my users will want a notification that says "Stop!" and not a simple corner notification.

Not working.

From nuget, I install into a fresh MVC 3 project jQuery 1.9.1, then toastr 1.2.1 using the nuget package manager.

The following html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
    <meta charset="utf-8"/>
    <link href="Content/toastr.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="Scripts/toastr.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            toastr.options = { debug: true };
            toastr.info("Hello? Is This thing on?");
            toastr.success("Anything");
            toastr.error("Nada.");
        });
    </script>
</head>
<body>

</body>
</html>

shows nothing in Google Chrome v 25.0.1364.97 m nor IE 9 on Windows 7.

If I uninstall toastr 1.2.1 and Install-Package toastr -Version 1.1.4.2 it works just dandy.

With 1.2.1 I get nothing - the debug messages print, but don't seem to contain anything useful.

Thanks!

default close button option

hi,
great library, but can we have a default close button in the corner of a toaster so when user click it closes the toaster instance ?

thanks in advanced

Easier way to use ToastR options

Per my conversation with John, it would be nice if you can set up the object that contains the various options and have that be received as an argument in the Toastr call so a) it can apply to only one toast, and b) you can do it inline with the call and have less code. It's still handy to have it apply to all toasts if you leave it out as an argument.

Group toasts by type

I noticed that at certain times the user finds it difficult to read a sequence of notifications, because they disappear quickly.

I suggest an option to group the toast by type (success, info, warning, error) showing the number of notifications that have the same type.

and then, when you dismiss a toast, the toast that is "behind" is displayed and the number of notifications decreased.

Responsive sizes

Bootstrap currently uses other ranges for responsiveness.
I think the following sizes should be used to get messages resized at the same time with the rest of the layout:
@media all and (min-width: 241px) and (max-width: 319px) ...
@media all and (min-width: 320px) and (max-width: 479px) ...
@media all and (min-width: 480px) and (max-width: 767px) ...
@media all and (min-width: 768px) ...

Support for jQuery 1.4.4

This is a great plugin! Would it be possible to have toastr work with jQuery 1.4.4?
The reason being is I am using the Drupal 7 framework which forces developers to use 1.4.4.

Checkboxes in form could be nice?

I really like the form it allows to have in a toast and I was wondering if it would be hard to allow checkboxes and radio buttons since right now a simple click on a checkbox would dismiss the toast.

Communicating with ASP.Net back end

I read about this plug in in Visual Studio magazine and it looks awesome. I am pretty new to jQuery and am trying to fibure out how to communicate with my ASP.Net backend. Say, I have an update occuring on a page, how do I get the message (error or otherwise) from the c# code to the plug in and then trigger the display.

Sorry for the newbie question.

Middle Position

You can position it on the left or the right, but I don't see any way to position the message in the centre of the page. Would it be possible to add this?

BOM in files

Hi, is it necessary to save all files with BOM ? I notice problem in some automatic assets management libraries. I think you can safely remove it without any problem. Thanks

Reset fadeout on mouse over

It would be nice to emulate what Outlook popups do when the user hovers the mouse over it.

So you'd need to reset the timer, but if the fadeout has already begun, you'd need to fade back in, and reset the timer.

BTW, nice work guys.

Luc

All Sticky Option

Currently, hovering over a node only makes the notification that you are hovering over sticky. I spent a couple of hours trying to write an option that would cause hovering over a notification to keep all displayed notifications sticky but I don't have a real good feel for how to do this.

I not exactly comfortable in JavaScript, and my attempts failed. I made a little bit of progress. I was able to make all the notifications not fade out when hovering one, all notifications fade out when hovering stops, but there were a lot of bugs that I couldn't work out after a while.

So, I figured I would throw it up here in case someone else wants to take a crack at the idea.

Some of the systems I use may have multiple notifications pop-up at once and the user doesn't have time to read them all before they start disappearing. I could set them to click to remove, but they don't want the extra clicks. Neither do they want longer timeouts for messages that they aren't interested in. So, hover over one to keep all on the screen seems an appropriate feature (and has been used by the system in the past).

If someone wants to give me tips on how to go about it, I would be more than happy to take another crack at it.

Associate toast with a dom Node

It would be great if I could have a toast appear on any container that I would set rather than just the body tag at large

Close button for sticky toasts?

I've implemented toastr on a website but I'm finding that more than a few users are confused about how to close the toasts that do not disappear on their own.

I initialize them as such: {timeOut: 0, extendedTimeOut: 0} and while it works fine functionally, it doesn't convey to the user how to dismiss the toast.

So I was wondering if there could also be an option to show a small 'X' close button/text in the top right corner of the toast to help make it obvious that they have to click to close it?

add close button

hi,
beautiful library,
but could we add a small close button on any corner so user can know that the notification can be closed ?

thanks in advanced.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.