react-desktop-notification
Advanced tools
Comparing version 1.0.1 to 1.0.2
69
index.js
@@ -7,42 +7,45 @@ /** | ||
var Notifier = React.createClass({ | ||
statics: { | ||
start:function (title,context,url,icon) { | ||
if (!Notification) { | ||
alert("你的浏览器不支持桌面通知,请使用chrome浏览器。"); | ||
return; | ||
} | ||
statics: { | ||
start: function(title, context, url, icon) { | ||
if (!Notification) { | ||
console.log("Your browser is not support desktop notifications, please try Chrome or Firefox."); | ||
return false; | ||
} | ||
if (!(icon.match(/\.(jpeg|jpg|gif|png)$/) != null)) { | ||
return false; | ||
} | ||
if (Notification.permission !== "granted") | ||
Notification.requestPermission(); | ||
else { | ||
var notification = new Notification(title, { | ||
icon: icon||"http://ob9oayzh3.bkt.clouddn.com/images.png", | ||
body: context, | ||
}); | ||
notification.onclick = function () { | ||
window.open(url); | ||
}; | ||
} | ||
if (Notification.permission !== "granted") { | ||
Notification.requestPermission(); | ||
} else { | ||
var notification = new Notification(title, { | ||
icon: icon || "http://ob9oayzh3.bkt.clouddn.com/images.png", | ||
body: context, | ||
}); | ||
notification.onclick = function() { | ||
window.open(url); | ||
}; | ||
} | ||
}, | ||
} | ||
}, | ||
shouldComponentUpdate: function () { | ||
return false; | ||
}, | ||
shouldComponentUpdate: function() { | ||
return false; | ||
}, | ||
getScript: function () { | ||
var script = 'document.addEventListener("DOMContentLoaded", function () { if (Notification.permission !== "granted") Notification.requestPermission(); });'; | ||
return script; | ||
}, | ||
getScript: function() { | ||
var script = 'document.addEventListener("DOMContentLoaded", function () { if (Notification.permission !== "granted") Notification.requestPermission(); });'; | ||
return script; | ||
}, | ||
render: function () { | ||
return React.createElement("script", { | ||
type: "text/javascript", | ||
dangerouslySetInnerHTML: { | ||
__html: this.getScript() | ||
} | ||
}); | ||
} | ||
render: function() { | ||
return React.createElement("script", { | ||
type: "text/javascript", | ||
dangerouslySetInnerHTML: { | ||
__html: this.getScript() | ||
} | ||
}); | ||
} | ||
}); | ||
module.exports = Notifier; |
{ | ||
"name": "react-desktop-notification", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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", |
## react-desktop-notification | ||
## install | ||
``` | ||
``` | ||
npm install --save react-desktop-notification | ||
``` | ||
``` | ||
## usage | ||
``` | ||
import Notifier from "react-desktop-notification" | ||
gotNewNotification(){ | ||
... | ||
Notifier.start("Title","Here is context","www.google.com"); | ||
... | ||
} | ||
``` | ||
``` | ||
import Notifier from "react-desktop-notification" | ||
gotNewNotification(){ | ||
... | ||
//Here will pop a notifier. | ||
Notifier.start("Title","Here is context","www.google.com","validated image url"); | ||
... | ||
} | ||
``` | ||
## git | ||
https://github.com/leejaen/React-Desktop-Notification.git |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2147
4
44
23