Files
Testing/mongolian3/mgVideoChat/partials/mgNotifications.js
sean 0e8a8b3028
Some checks failed
deploy-testing / deploy (push) Has been cancelled
Initial testing snapshot
2026-11-17 16:15:01 -05:00

57 lines
1.9 KiB
JavaScript

//mgNotifications - notifications helper
(function( $, window, document, undefined ){
$.fn.mgNotifications = function(rtc){
var notificationsHelper = {
grant: function(cb){
if(this.checkActive()){
return true;
}
// Otherwise, we need to ask the user for permission
window.Notification.requestPermission(function (permission) {
if(cb){
cb(permission);
}
});
},
checkActive: function(){
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
return false;
}
// granted already
if (window.Notification.permission === "granted") {
return true;
}
//deniend already
if (window.Notification.permission === 'denied') {
return false;
}
},
notify: function(title, options, showOnVisible) {
if(!showOnVisible && !document.hidden){
return false;
}
console.log('notify', title, showOnVisible, document.hidden);
if(!this.checkActive()){
return false;
}
var notification = new Notification(title, options);
//open window on click
notification.onclick = function(event) {
event.preventDefault();
window.focus();
this.close();
};
}
};
return notificationsHelper;
};
})( jQuery, window , document ); // pass the jQuery object to this function