Created
March 25, 2016 22:12
-
-
Save freckletonj/d25249308bdc8381378f to your computer and use it in GitHub Desktop.
ClojureScript Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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