Created
April 28, 2014 06:18
-
-
Save ssskip/11363024 to your computer and use it in GitHub Desktop.
notify.js
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, perm = -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, perm = -1 | |
}, checkPermission: function () { | |
return perm = 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.DesktopNotify.lm_show = function (icoUrl, content, url, callback) { | |
return this.isSupport() ? (this.requestPermission(function () { | |
window.DesktopNotify.show(icoUrl, content, url), "undefined" !== callback && "function" == typeof callback && (window.DesktopNotify.on("click", callback), window.DesktopNotify.on("click", function () { | |
window.DesktopNotify.hide() | |
})), setTimeout(function () { | |
window.DesktopNotify.hide() | |
}, 10000) | |
}), void 0) : 0 | |
} | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment