Skip to content

Instantly share code, notes, and snippets.

@freckletonj
Created March 25, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freckletonj/d25249308bdc8381378f to your computer and use it in GitHub Desktop.
Save freckletonj/d25249308bdc8381378f to your computer and use it in GitHub Desktop.
ClojureScript Notifications
;; this is very much a gist, and it can be tweaked
;; ;; NOTIFICATIONS ----------
;; if (typeof Notification !== 'undefined') {
;; alert('Please us a modern version of Chrome, Firefox, Opera or Safari.');
;; return;
;; }
;; Notification.requestPermission(function (permission) {
;; if (permission !== 'granted') return;
;; var notification = new Notification('Here is the title', {
;; icon: 'http://path.to/my/icon.png',
;; body: 'Some body text',
;; });
;; notification.onclick = function () {
;; window.focus();
;; };
;; });
(let [title "Here is the title"
js-opts (js-obj "icon" "http://path.to/my/icon.png"
"body" "Some body text")
js-notification (js/Notification. title js-opts)]
(aset js-notification "onclick"
(fn []
(this-as js-this
(.log js/console "hi there")
#_(.close js-this)
(js/alert "alerrrt")
#_(.focus js/window)))))
(do (js* "
Notification.requestPermission(function (permission) {
if (permission !== 'granted') return 'false';
var notification = new Notification('Here is the title', {
icon: 'http://path.to/my/icon.png',
body: 'Some body text',
});
notification.onclick = function () {
window.focus();
return 'true';
};
});"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment