Giter VIP home page Giter VIP logo

flashjs's Introduction

FlashJS

Flash.js is a simple JavaScript library allowing you to create and handle HTML flash messages. You can try it yourself here.

Installation :

You only have to include the flash.js script into your HTML. That's it !

<script src="path/to/flash.min.js"></script>

Getting started :

Vanilla JS

Use flash.js is very easy. To display a success flash message, you just have to add this line below.

window.FlashMessage.success('This is a successs flash message !');

By default, four verbs are availables : success, warning, error and info.

You can add custom verbs with by call the static method addCustomVerbs on the FlashMessage class :

window.FlashMessage.addCustomVerbs('forbidden', 'example', 'custom');
window.FlashMessage.forbidden('My custom forbidden flash message !');

In the example above, three custom verbs have been added. As you can see, you can now use thses verbs !


You can also create a flash message by instanciating the FlashMessage class or by using the static method create :

new window.FlashMessage('This is a successs flash message !', 'success');

// OR

window.FlashMessage.create('Flash.js is awesome !', 'success')

Flash.js also allows you to simply add flash behavior on existing DOM elements (especially if HTML is rendered server-side) :

HTML
<div class="flash-container">
  <div class="flash-message" data-type="success" data-timeout="8000">My awesome success message !</div>
  <div class="flash-message" data-type="error" data-timeout="8000">My sadly sad error message !</div>
</div
JS
new window.Flash('.flash-message');

// OR

window.Flash.create('.flash-message');

jQuery

However, you can easily use flash.js with the jQuery plugin (by adding behavior on existing DOM elements, when HTML is rendered server-side for example) :

HTML
<div class="flash-container">
  <div class="flash-message flash-success">My awesome success message with the Flash.js jQuery plugin !</div>
  <div class="flash-message flash-error">My sadly sad error message with the Flash.js jQuery plugin !</div>
</div>

<!-- Don't forget to add flash.js jQuery plugin script right after the flash.js library ! -->
<script src="path/to/flash.min.js"></script>
<script src="path/to/flash.jquery.min.js"></script>
JS
$('document').ready(function () {

  $('.flash-message').flashjs({
    timeout: 5000
  });

});

Options :

Flash.js can optionnaly takes an object in parameter, as following :

window.FlashMessage.info('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', {
  progress: true, // displays a progress bar at the bottom of the flash message
  interactive: true, // Define flash message actions (pause on mouseover, close on click) 
  timeout: 8000, // Flash message timeout
  appear_delay: 200, // Delay before flash message appears
  container: '.flash-container', // Flash messages container element selector
  theme: 'default', // CSS theme (availables: default, dark)
  classes: {
      container: 'flash-container', // Custom container css class
      flash: 'flash-message', // Flash message element css class
      visible: 'is-visible', // Flash message element css visible class
      progress: 'flash-progress', // Flash message progress bar element css class
      progress_hidden: 'is-hidden' // Flash message progress bar element hidden css class
  }
});

You can read the documentation for more informations.

flashjs's People

Contributors

betaweb 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

Watchers

 avatar  avatar  avatar  avatar

flashjs's Issues

flash message repeats itsel 4 or 5 times.

Hi Cyprien, I hope you can help me with the issue I'm having.
Every time I get an error, I call:
window.FlashMessage.error('xyz');
it works fine, but the problem is that the flash message repeats itsel 4 or 5 times.
What could it be the problem ?
Thanks in advance for any help or hint.

repeated-flash-messages

Font Awesome Version Mismatch

If you already use a different version of Font Awesome in your project, the side icons may not appear correctly.
Check if your font awesome version is 4.7.0 or not.

Failed to execute 'removeChild' on 'Node' -> Fix

Unsure if @betaWeb still maintains this, but if so:

When clicking on a flash message, this causes the next error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node. Even on the demo/example site.

To fix this, we want to turn removeChild() into remove() so we can properly target all children of the flash container.

I could make a pull request for merging if you'd like? (or fork it anyway?)

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.