summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/notify.js
blob: 42b6ac0589ed3ac8361dee2a34be4e80f62b3516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function() {
  (function(w) {
    var notificationGranted, notifyMe, notifyPermissions;
    notificationGranted = function(message, opts, onclick) {
      var notification;
      notification = new Notification(message, opts);
      setTimeout(function() {
        return notification.close();
      }, 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
      };
      if (!('Notification' in window)) {

      } else if (Notification.permission === 'granted') {
        return notificationGranted(message, opts, onclick);
      } else if (Notification.permission !== 'denied') {
        return Notification.requestPermission(function(permission) {
          if (permission === 'granted') {
            return notificationGranted(message, opts, onclick);
          }
        });
      }
    };
    w.notify = notifyMe;
    return w.notifyPermissions = notifyPermissions;
  })(window);

}).call(this);