1.0.1 • Published 6 years ago
pushjs-notification v1.0.1
pushjs-notification
pushjs-notification is the fastest way to get up and running with Javascript desktop and mobile notifications. The Notification API allows modern browsers such as Chrome, Safari, Firefox, and IE 9+ to push notifications to a user's desktop.
Installation
Install the plugin using the NPM.
npm install pushjs-notification --saveBasic Implementation
Import the package in your component
import {jsPushNotification} from 'pushjs-notification';
@Component({
///
})
export class AppComponent {
...
generateNotification() {
let jsPush = new jsPushNotification();
jsPush.NotificationTitle = 'pushjs-notification';
jsPush.ClickEnable = true;
jsPush.NavigateUrl = 'https://www.npmjs.com/package/pushjs.notification';
jsPush.Options.body = 'The plugin supports modern browsers such as Chrome, Safari, Firefox, and IE 9+ to push notifications to a users desktop';
jsPush.Options.icon = 'favicon.ico';
jsPush.Options.image = 'bannerImage.ico';
jsPush.showNotification();
}
...
}Options
Inputs
- NotificationTitle
string: Defines a title for the notification, which will be shown at the top of the notification window when it is fired. - ClickEnable
boolean: Specifies whether click event is enabled or not (Default value isfalse) - NavigateUrl
string: If the ClickEnable istrue, then when the notification is clicked, it will redirect to specified url. - Options
object: An options object containing any custom settings that you want to apply to the notification.(These are optional settings) The possible options are:- dir
string: The direction in which to display the notification. It defaults toauto, which just adopts the browser's language setting behavior, but you can override that behaviour by setting values ofltrandrtl(although most browsers seem to ignore these settings.) - body
string: ADOMStringrepresenting the body text of the notification, which will be displayed below the title. - tag
string: ADOMStringrepresenting an identifying tag for the notification. - icon
string: AUSVStringcontaining the URL of an icon to be displayed in the notification. - image
string: AUSVStringcontaining the URL of an image to be displayed in the notification. - data
string: Arbitrary data that you want associated with the notification. This can be of any data type. - vibrate
string: AVibration Patternfor the device's vibration hardware to emit when the notification fires. - renotify
boolean: A Boolean specifying whether the user should be notified after a new notification replaces an old one. The default isfalse, which means they won't be notified. - requireInteraction
boolean: Indicates that a notification should remain active until the user clicks or dismisses it, rather than closing automatically. The default value isfalse.
- dir
API Reference
showNotification() function: Used to generate the notification.
Note: Before calling
sendNotification()you need to initialize above specified Input properties for the customization.
Todos
- Write MORE Tests
- Add additional features
- Web Workers compatibility
License
MIT
Free Software, Hell Yeah!