forked from ttsvetko/HTML5-Desktop-Notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop-notify-min.js
1 lines (1 loc) · 2.8 KB
/
desktop-notify-min.js
1
(function(e){function m(t,n){var r;if(e.Notification){r=new e.Notification(t,{icon:c(n.icon)?n.icon:n.icon.x32,body:n.body||u,tag:n.tag||u})}else if(e.webkitNotifications){r=e.webkitNotifications.createNotification(n.icon,t,n.body);r.show()}else if(navigator.mozNotification){r=navigator.mozNotification.createNotification(t,n.body,n.icon);r.show()}else if(e.external&&e.external.msIsSiteMode()){e.external.msSiteModeClearIconOverlay();e.external.msSiteModeSetIconOverlay(c(n.icon)?n.icon:n.icon.x16,t);e.external.msSiteModeActivate();r={ieVerification:f+1}}if(n.onclick){r.onclick=n.onclick}if(n.onclose){r.onclose=n.onclose}if(n.ondisplay){if(e.Notification){r.onshow=n.ondisplay}else{r.ondisplay=n.ondisplay}}if(n.onerror){r.onerror=n.onerror}return r}function g(t){return{close:function(){if(t){if(t.close){t.close()}else if(t.cancel){t.cancel()}else if(e.external&&e.external.msIsSiteMode()){if(t.ieVerification===f){e.external.msSiteModeClearIconOverlay()}}}}}}function y(t){if(!a){return}var n=l(t)?t:d;if(e.webkitNotifications&&e.webkitNotifications.checkPermission){e.webkitNotifications.requestPermission(n)}else if(e.Notification&&e.Notification.requestPermission){e.Notification.requestPermission(n)}}function b(){var r;if(!a){return}if(e.Notification&&e.Notification.permissionLevel){r=e.Notification.permissionLevel()}else if(e.webkitNotifications&&e.webkitNotifications.checkPermission){r=i[e.webkitNotifications.checkPermission()]}else if(e.Notification&&e.Notification.permission){r=e.Notification.permission}else if(navigator.mozNotification){r=n}else if(e.external&&e.external.msIsSiteMode()!==undefined){r=e.external.msIsSiteMode()?n:t}return r}function w(e){if(e&&h(e)){p(v,e)}return v}function E(){return v.pageVisibility?document.hidden||document.msHidden||document.mozHidden||document.webkitHidden:true}function S(t,r){var i,s;if(a&&E()&&c(t)&&r&&(c(r.icon)||h(r.icon))&&b()===n){i=m(t,r)}s=g(i);if(v.autoClose&&i&&!i.ieVerification&&i.addEventListener){i.addEventListener("show",function(){var t=s;e.setTimeout(function(){t.close()},v.autoClose)})}return s}var t="default",n="granted",r="denied",i=[n,t,r],s={pageVisibility:false,autoClose:0},o={},u="",a=function(){var t=false;try{t=!!(e.Notification||e.webkitNotifications||navigator.mozNotification||e.external&&e.external.msIsSiteMode()!==undefined)}catch(n){}return t}(),f=Math.floor(Math.random()*10+1),l=function(e){return e&&e.constructor===Function},c=function(e){return e&&e.constructor===String},h=function(e){return e&&e.constructor===Object},p=function(e,t){var n,r;for(n in t){r=t[n];if(!(n in e)||e[n]!==r&&(!(n in o)||o[n]!==r)){e[n]=r}}return e},d=function(){},v=s;e.notify={PERMISSION_DEFAULT:t,PERMISSION_GRANTED:n,PERMISSION_DENIED:r,isSupported:a,config:w,createNotification:S,permissionLevel:b,requestPermission:y};if(l(Object.seal)){Object.seal(e.notify)}})(window)