Welcome to mirror list, hosted at ThFree Co, Russian Federation.

notification.service.js « notification « angularjs « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 637af734fa43b7d8e4cc3d23fe098d37f71ddcd6 (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
42
43
44
45
46
47
48
49
50
51
52
53
/*!
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
(function () {
    angular.module('piwikApp').factory('notifications', NotificationFactory);

    NotificationFactory.$inject = [];

    function NotificationFactory() {

        return {
            parseNotificationDivs: parseNotificationDivs,
            clearTransientNotifications: clearTransientNotifications,
        };

        function parseNotificationDivs() {
            var UI = require('piwik/UI');

            var $notificationNodes = $('[data-role="notification"]');

            $notificationNodes.each(function (index, notificationNode) {
                $notificationNode = $(notificationNode);
                var attributes = $notificationNode.data();
                var message    = $notificationNode.html();

                if (message) {
                    var notification   = new UI.Notification();
                    attributes.animate = false;
                    notification.show(message, attributes);
                }

                $notificationNodes.remove();
            });
        }

        function clearTransientNotifications() {
            $('[piwik-notification][type=transient]').each(function () {
                var $element = angular.element(this);
                $element.scope().$destroy();
                $element.remove();
            });
        }
    }

    angular.module('piwikApp').run(['notifications', function (notifications) {
        $(function () {
            notifications.parseNotificationDivs();
        });
    }]);
})();