Code Monkey home page Code Monkey logo

simple-web-notification's Introduction

simple-web-notification

Bower Version NPM Version Build Status Coverage Status bitHound Code Inline docs
License Known Vulnerabilities Retire Status

Web Notifications made easy

Overview

The simple-web-notification is a simplified web notifications API with automatic permissions support.

This library requires no external dependencies, however the browser must support the Notification API or have a polyfill available.

See W3 Specification for more information.

Demo

Live Demo

Usage

In order to use the simplified web notification API you first must add the relevant dependencies:

<script type="text/javascript" src="web-notification.js"></script>

Now you can use the API anywhere in your application, for example:

$('.some-button').on('click', function onClick() {
    webNotification.showNotification('Example Notification', {
        body: 'Notification Text...',
        icon: 'my-icon.ico',
        onClick: function onNotificationClicked() {
            console.log('Notification clicked.');
        },
        autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
    }, function onShow(error, hide) {
        if (error) {
            window.alert('Unable to show notification: ' + error.message);
        } else {
            console.log('Notification Shown.');

            setTimeout(function hideNotification() {
                console.log('Hiding notification....');
                hide(); //manually close the notification (you can skip this if you use the autoClose option)
            }, 5000);
        }
    });
});

When using an AMD loader (such as RequireJS) or CommonJS type loader, the webNotification object is not automatically defined on the window scope.

Installation

Run bower install in your project as follows:

bower install simple-web-notification --save

Or if you are using NPM to download client libraries, you can install it as follows:

npm install --save simple-web-notification

Limitations

The web notifications API is not fully supported in all browsers.

Please see supported browser versions for more information on the official spec support.

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

Date Version Description
2017-05-01 v1.0.19 Maintenance
2017-01-31 v1.0.3 Removed polyfill dependency
2017-01-22 v1.0.2 Maintenance
2017-01-22 v1.0.0 Official release
2017-01-22 v0.0.2 Initial release

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

simple-web-notification's People

Contributors

sagiegurari avatar

Watchers

James Cloos avatar Praveen Kumar avatar

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.