BigW Consortium Gitlab

notify.js 1.42 KB
Newer Older
Fatih Acet committed
1 2 3 4 5 6 7 8
(function() {
  (function(w) {
    var notificationGranted, notifyMe, notifyPermissions;
    notificationGranted = function(message, opts, onclick) {
      var notification;
      notification = new Notification(message, opts);
      setTimeout(function() {
        return notification.close();
9
      // Hide the notification after X amount of seconds
Fatih Acet committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
      }, 8000);
      if (onclick) {
        return notification.onclick = onclick;
      }
    };
    notifyPermissions = function() {
      if ('Notification' in window) {
        return Notification.requestPermission();
      }
    };
    notifyMe = function(message, body, icon, onclick) {
      var opts;
      opts = {
        body: body,
        icon: icon
      };
26
      // Let's check if the browser supports notifications
Fatih Acet committed
27 28
      if (!('Notification' in window)) {

29
      // do nothing
Fatih Acet committed
30
      } else if (Notification.permission === 'granted') {
31
        // If it's okay let's create a notification
Fatih Acet committed
32 33 34
        return notificationGranted(message, opts, onclick);
      } else if (Notification.permission !== 'denied') {
        return Notification.requestPermission(function(permission) {
35
          // If the user accepts, let's create a notification
Fatih Acet committed
36 37 38 39 40 41 42 43 44 45 46
          if (permission === 'granted') {
            return notificationGranted(message, opts, onclick);
          }
        });
      }
    };
    w.notify = notifyMe;
    return w.notifyPermissions = notifyPermissions;
  })(window);

}).call(this);