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.67 KB
/
desktop-notify.min.js
1
(function(d){var u="default",e="granted",g="denied",h=[e,u,g],f={pageVisibility:false,autoClose:0},i={},v="",w=(function(){var x=false;try{x=!!(d.Notification||d.webkitNotifications||navigator.mozNotification||(d.external&&d.external.msIsSiteMode()!==undefined))}catch(y){}return x}()),a=Math.floor((Math.random()*10)+1),b=function(x){return(x&&(x).constructor===Function)},k=function(x){return(x&&(x).constructor===String)},j=function(x){return(x&&(x).constructor===Object)},n=function(A,z){var x,y;for(x in z){y=z[x];if(!(x in A)||(A[x]!==y&&(!(x in i)||i[x]!==y))){A[x]=y}}return A},c=function(){},p=f;function t(z,x){var y;if(d.Notification){y=new d.Notification(z,{icon:k(x.icon)?x.icon:x.icon.x32,body:x.body||v,tag:x.tag||v})}else{if(d.webkitNotifications){y=d.webkitNotifications.createNotification(x.icon,z,x.body);y.show()}else{if(navigator.mozNotification){y=navigator.mozNotification.createNotification(z,x.body,x.icon);y.show()}else{if(d.external&&d.external.msIsSiteMode()){d.external.msSiteModeClearIconOverlay();d.external.msSiteModeSetIconOverlay((k(x.icon)?x.icon:x.icon.x16),z);d.external.msSiteModeActivate();y={ieVerification:a+1}}}}}return y}function s(x){return{close:function(){if(x){if(x.close){x.close()}else{if(d.external&&d.external.msIsSiteMode()){if(x.ieVerification===a){d.external.msSiteModeClearIconOverlay()}}}}}}}function l(y){if(!w){return}var x=b(y)?y:c;if(d.webkitNotifications&&d.webkitNotifications.checkPermission){d.webkitNotifications.requestPermission(x)}else{if(d.Notification&&d.Notification.requestPermission){d.Notification.requestPermission(x)}}}function o(){var x;if(!w){return}if(d.Notification&&d.Notification.permissionLevel){x=d.Notification.permissionLevel()}else{if(d.webkitNotifications&&d.webkitNotifications.checkPermission){x=h[d.webkitNotifications.checkPermission()]}else{if(navigator.mozNotification){x=e}else{if(d.Notification&&d.Notification.permission){x=d.Notification.permission}else{if(d.external&&(d.external.msIsSiteMode()!==undefined)){x=d.external.msIsSiteMode()?e:u}}}}}return x}function r(x){if(x&&j(x)){n(p,x)}return p}function q(){return p.pageVisibility?(document.hidden||document.msHidden||document.mozHidden||document.webkitHidden):true}function m(A,x){var z,y;if(w&&q()&&k(A)&&(x&&(k(x.icon)||j(x.icon)))&&(o()===e)){z=t(A,x)}y=s(z);if(p.autoClose&&z&&!z.ieVerification&&z.addEventListener){z.addEventListener("show",function(){var B=y;d.setTimeout(function(){B.close()},p.autoClose)})}z.onclick=function(){window.location.href=x.link};return y}d.notify={PERMISSION_DEFAULT:u,PERMISSION_GRANTED:e,PERMISSION_DENIED:g,isSupported:w,config:r,createNotification:m,permissionLevel:o,requestPermission:l};if(b(Object.seal)){Object.seal(d.notify)}}(window));