├── .gitignore ├── README.md ├── license ├── package.json └── src └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## angular-notify 2 | 3 | [![NPM][notify-icon]][notify-url] 4 | 5 | #### Installation 6 | Installation is super easy, simply add the dependencies to your angular module, and inject ```notify``` in your angular service, component, directive or controller. 7 | 8 | ``` 9 | # use npm 10 | $ npm install angular-notify 11 | ``` 12 | 13 | Add angular-notify to your dependencies 14 | 15 | ``` 16 | angular 17 | .module('yourApp', ['angular-notify']) 18 | .controller('SampleController', function (notify) { 19 | function onClick () { 20 | console.log('clicked notification!') 21 | } 22 | 23 | notify.show('Example Notification', 'path/icon.jpg', 5000, onClick) 24 | }) 25 | ``` 26 | 27 | #### API 28 | ##### *message* 29 | 30 | The first parameter is the message for the notification 31 | 32 | ##### *icon* 33 | 34 | The second parameter is the icon for the notification 35 | 36 | ##### *timeout* 37 | 38 | timeout determines how long to keep the notification, (default is 5000 milliseconds) 39 | 40 | ##### *callback* 41 | 42 | The function you want to call when the notification is clicked 43 | 44 | [notify-icon]: https://nodei.co/npm/angular-notify.png?downloads=true 45 | [notify-url]: https://npmjs.org/package/angular-notify 46 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Jack Hanford (http://www.jackhanford.com/) 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-notify", 3 | "version": "1.2.0", 4 | "description": "Angular service for using browser notifications", 5 | "main": "./src", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hanford/angular-notify.git" 9 | }, 10 | "license": "MIT", 11 | "bugs": { 12 | "url": "https://github.com/hanford/angular-notify/issues" 13 | }, 14 | "keywords": [ 15 | "angular", 16 | "notifications", 17 | "ngNotifications", 18 | "notify", 19 | "window.Notification" 20 | ], 21 | "author": "Jack Hanford (http://www.jackhanford.com/)", 22 | "dependencies": {}, 23 | "devDependencies": { 24 | "angular": "~1.5.0", 25 | "assert-semver-operator": "~1.0.1" 26 | }, 27 | "scripts": { 28 | "test": "standard && assert-operator ./ '~'" 29 | }, 30 | "peerDependencies": { 31 | "angular": ">=1.3 <2" 32 | }, 33 | "files": [ 34 | "src/" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('angular') 2 | .module('angular-notify', []) 3 | .service('notify', Notify) 4 | .name 5 | 6 | Notify.$inject = [ 7 | '$timeout', 8 | '$window' 9 | ] 10 | 11 | function Notify ($timeout, $window) { 12 | // fallback for devices without the notification object, like Mobile Safari. 13 | if ($window.Notification) { 14 | $window.Notification.requestPermission() 15 | } 16 | 17 | var state = { 18 | show: show, 19 | close: close, 20 | notification: {} 21 | } 22 | 23 | function show (message, icon, timeout, clickFn) { 24 | if (!$window.Notification) return 25 | $window.Notification.requestPermission(function (result) { 26 | if (result !== 'granted') return 27 | 28 | if (icon) { 29 | state.notification = new $window.Notification(message, {icon:icon}) 30 | } else { 31 | state.notification = new $window.Notification(message) 32 | } 33 | 34 | if (clickFn) { 35 | state.notification.onclick = function () { 36 | clickFn() 37 | } 38 | } 39 | 40 | $timeout(function () { 41 | state.notification.close() 42 | }, (timeout || 5000)) 43 | }) 44 | } 45 | 46 | function close () { 47 | return state.notification.close() 48 | } 49 | 50 | return state 51 | } 52 | --------------------------------------------------------------------------------