'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
42
43
44
45
46
47
48
49
50
51
52
53
54
var Emitter = require('./Emitter');
var root = require('./root');
var each = require('./each');
var Notification = root.Notification;
exports = function(title, options) {
    var notification = new exports.Notification(title, options);
    notification.show();
};
exports.Notification = Emitter.extend({
    initialize: function Notification(title) {
        var options =
            arguments.length > 1 && arguments[1] !== undefined
                ? arguments[1]
                : {};
        this._options = options;
        this._title = title;
        this.callSuper(Emitter, 'initialize', arguments);
    },
    handleEvent: function(e) {
        this.emit(e.type, e);
    },
    show: function() {
        var _this = this;
        if (!Notification) {
            return this.emit('error', Error('Notification is not supported'));
        }
        if (Notification.permission === 'granted') {
            this._show();
        } else {
            Notification.requestPermission(function(permission) {
                switch (permission) {
                    case 'granted':
                        _this._show();
                        break;
                    case 'denied':
                        _this.emit(
                            'error',
                            Error('Notification permission is denied')
                        );
                        break;
                }
            });
        }
    },
    _show: function() {
        var _this2 = this;
        var notification = new Notification(this._title, this._options);
        each(['show', 'close', 'click'], function(type) {
            notification.addEventListener(type, _this2, false);
        });
    }
});
 
module.exports = exports;