Created
April 26, 2014 14:04
-
-
Save ssskip/11320838 to your computer and use it in GitHub Desktop.
implement html5 web notification support chrome Safari
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
;(function (window) { | |
"use strict"; | |
void function () { | |
var notify= null, i = -1, EVENT_TYPE = {show: 1, error: 1, close: 1, click: 1}, DesktopNotify = {isSupport: function () { | |
return "Notification" in window || "webkitNotifications" in window | |
}, show: function (e, i, n) { | |
notify = this.create(e, i, n), notify.show() | |
}, showHTML: function (e) { | |
notify = this.createHTML(e), notify.show() | |
}, hide: function (callback) { | |
notify && notify.close && t.close(), callback && callback() | |
}, destroy: function () { | |
notify = null, i = -1 | |
}, checkPermission: function () { | |
return i = webkitNotifications.checkPermission() | |
}, isPermitted: function () { | |
return 0 === this.checkPermission() | |
}, requestPermission: function (e) { | |
this.isPermitted() ? e && e() : webkitNotifications.requestPermission(e) | |
}, create: function (e, t, i) { | |
return webkitNotifications.createNotification(e, t, i) | |
}, createHTML: function (e) { | |
return webkitNotifications.createHTMLNotification(e) | |
}, on: function (e, callback) { | |
EVENT_TYPE[e] && notify && notify.addEventListener(e, callback, !1) | |
}, un: function (e, callback) { | |
EVENT_TYPE[e] && notify && notify.removeEventListener(e, callback, !1) | |
}}; | |
window || (window = {}), window.DesktopNotify = DesktopNotify | |
}() | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment