react-desktop-notification
Advanced tools
Comparing version 1.0.6 to 1.0.7
25
index.js
@@ -29,7 +29,26 @@ /** | ||
notification.onclick = function() { | ||
parent.focus(); | ||
window.focus(); //just in case, older browsers | ||
this.close(); | ||
window.open(url, name); | ||
}; | ||
} | ||
}, | ||
focus:function(title, context, url, icon){ | ||
if (!Notification) { | ||
console.log("Your browser is not support desktop notifications, please try Chrome or Firefox."); | ||
return false; | ||
} | ||
if (Notification.permission !== "granted") { | ||
Notification.requestPermission(); | ||
} else { | ||
icon=(icon&&icon.match(/^.*\.(jpeg|jpg|gif|png)/gi))?icon:"http://ob9oayzh3.bkt.clouddn.com/images.png" | ||
var notification = new Notification(title, { | ||
icon: icon, | ||
body: context, | ||
}); | ||
notification.onclick = function() { | ||
parent.focus(); | ||
window.focus(); //just in case, older browsers | ||
this.close(); | ||
}; | ||
} | ||
} | ||
@@ -36,0 +55,0 @@ }, |
{ | ||
"name": "react-desktop-notification", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Use browser's desktop notification in React. It depends on notifications API of chrome or else browser's other way.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,23 +6,29 @@ ## react-desktop-notification | ||
npm install --save react-desktop-notification | ||
``` | ||
OR | ||
yarn add react-desktop-notification``` | ||
## usage | ||
``` | ||
import Notifier from "react-desktop-notification" | ||
import Notifier from "react-desktop-notification" | ||
gotNewNotification(){ | ||
... | ||
//Here will pop a notifier and always open in a new window when clicked. | ||
Notifier.start("Title","Here is context","www.google.com","validated image url"); | ||
gotNewNotification(){ | ||
... | ||
//Here will pop a notifier and always open in a new window when clicked. | ||
Notifier.start("Title","Here is context","www.google.com","validated image url"); | ||
//Here will pop notifier and open in a specified name window "popwin1" when clicked. | ||
Notifier.start("Title","Here is context","www.google.com","validated image url","popwin1"); | ||
... | ||
} | ||
//Here will pop notifier and open in a specified name window "popwin1" when clicked. | ||
Notifier.start("Title","Here is context","www.google.com","validated image url","popwin1"); | ||
//Here will pop notifier and focus parent window only when clicked. | ||
Notifier.focus("Title","Here is context","www.google.com","validated image url"); | ||
... | ||
} | ||
``` | ||
## API | ||
Notifier.start(notifier_title, notifier_context, opening_url, icon_url, window_name) | ||
`Notifier.start(notifier_title, notifier_context, opening_url, icon_url, window_name)` | ||
`Notifier.focus(notifier_title, notifier_context, opening_url, icon_url)` | ||
## git | ||
https://github.com/leejaen/React-Desktop-Notification.git |
3665
68
34