Coder Social home page Coder Social logo

notify.js's Introduction

Notify.js

Build Status

A handy wrapper for using the Web Notifications API. Notify.js aims to simplify requesting user permission and associated Web Notification API events, as well as providing a few extra callbacks and convenience methods.

Installation

  • Download: zip
  • NPM: npm install notifyjs
  • Bower: bower install notify.js
  • Git: git clone https://github.com/alexgibson/notify.js

Setup

This component can be used as an AMD module, CommonJS module, or a global.

for AMD module:

define(['./notify'], function(Notify) {
     var myNotification = new Notify();
    // ...
});

for CommonJS:

var Notify = require('notifyjs');

To initialize a web notification create a new Notify instance, passing the message title as well as any other options you wish to use.

var myNotification = new Notify('Yo dawg!', {
	body: 'This is an awesome notification',
	notifyShow: onNotifyShow
});

function onNotifyShow() {
	console.log('notification was shown!');
}

Then show the notification.

myNotification.show();

Required parameters

  • title (string) - notification title

Optional parameters

  • body: (string) - notification message body
  • icon: (string) - path for icon to display in notification
  • tag: (string) - unique identifier to stop duplicate notifications
  • timeout: (integer) - number of seconds to close the notification automatically
  • notifyShow: (function) - callback when notification is shown
  • notifyClose: (function) - callback when notification is closed
  • notifyClick: (function) - callback when notification is clicked
  • notifyError: (function) - callback when notification throws an error
  • permissionGranted: (function) - callback when user has granted permission
  • permissionDenied: (function) - callback when user has denied permission

Static methods and properties

  • Notify.requestPermission(onPermissionGrantedCallback, onPermissionDeniedCallback) - requests permission from the user if needed and handles permission callbacks.
  • Notify.isSupported - Boolean property to test for Web Notifications API browser support
  • Notify.needsPermission - Boolean property to check if permission is needed for the user to receive notifications.
  • Notify.permissionLevel - shows the user's current permission level (granted, denied or default), returns null if notifications are not supported.

A note about Chrome

Prior to Chrome v37, Notification.requestPermission could not be called on page load events, it required a user interaction such as a click event. This has been fixed in current versions to be more consistent with other browsers, but please keep this in mind when writing your application. You can find out more in the Chromium bug for this issue.

Testing

Install Node. Testing relies on the Karma test-runner, which can be installed globally using the following command.

npm install -g karma

In the project root, to perform a single pass of the tests using Firefox run:

npm test

Browser support

  • Chrome (desktop)
  • Safari
  • Firefox
  • Firefox OS (v1.2+)
  • Firefox Mobile (Android)

notify.js's People

Contributors

alexgibson avatar superkarn avatar toddmotto avatar fcsonline avatar kitbrennan90 avatar mdu avatar xosofox avatar

Watchers

James Cloos avatar  avatar  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.