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

visitorActions.js « javascripts « Live « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 027a061b2494e141e8197d8358bfff5b755a7820 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
 * Matomo - free/libre analytics platform
 *
 * Actions list in Visitor Log and Profile
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

function initializeVisitorActions(elem) {

    var tooltipIsOpened = false;

    $('a', elem).on('focus', function () {
        // see https://github.com/piwik/piwik/issues/4099
        if (tooltipIsOpened) {
            elem.tooltip('close');
        }
    });

    elem.tooltip({
        items: '[title],.visitorLogIconWithDetails',
        track: true,
        show: false,
        hide: false,
        content: function() {
            if ($(this).hasClass('visitorLogIconWithDetails')) {
                return $('<ul>').html($('ul', $(this)).html());
            }
            var title = $(this).attr('title');
            return $('<a>').text( title ).html().replace(/\n/g, '<br />');
        },
        tooltipClass: 'small',
        open: function() { tooltipIsOpened = true; },
        close: function() { tooltipIsOpened = false; }
    });

    // collapse adjacent content interactions
    $("ol.visitorLog", elem).each(function () {
        var $actions = $(this).find("li");
        $actions.each(function (index) {
            var $li = $(this);
            if (!$li.is('.content')) {
                return;
            }

            if (!$actions[index - 1]
                || !$($actions[index - 1]).is('.content')
                || !$actions[index - 2]
                || !$($actions[index - 2]).is('.content')
            ) {
                return;
            }

            var $collapsedContents = $li;
            while ($collapsedContents.prev().is('.content')) {
                $collapsedContents = $collapsedContents.prev();
            }

            if (!$collapsedContents.is('.collapsed-contents')) {
                $collapsedContents = makeCollapsedContents();
                $collapsedContents.insertBefore($($actions[index - 2]));

                addContentItem($collapsedContents, $($actions[index - 2]));
                addContentItem($collapsedContents, $($actions[index - 1]));
            }

            addContentItem($collapsedContents, $li);

            function makeCollapsedContents() {
                var $li = $('<li/>')
                    .attr('class', 'content collapsed-contents')
                    .attr('title', _pk_translate('Live_ClickToSeeAllContents'));

                $('<div>')
                    .html('<img src="plugins/Morpheus/images/contentimpression.svg" class="action-list-action-icon"/>' +
                        ' <span class="content-impressions">0</span> content impressions <span class="content-interactions">0</span> interactions')
                    .appendTo($li);

                return $li;
            }

            function addContentItem($collapsedContents, $otherLi) {
                if ($otherLi.find('.content-interaction').length) {
                    var $interactions = $collapsedContents.find('.content-interactions');
                    $interactions.text(parseInt($interactions.text()) + 1);
                } else {
                    var $impressions = $collapsedContents.find('.content-impressions');
                    $impressions.text(parseInt($impressions.text()) + 1);
                }

                $otherLi.addClass('duplicate').addClass('collapsed-content-item').val('').attr('style', '');
            }
        });
    });

    // show refresh icon for duplicate page views in a row
    $("li.pageviewActions", elem).each(function () {
        var $divider = $(this).find('.refresh-divider');
        $divider.prevUntil().addClass('duplicate');
        $divider.remove();

        var viewCount = +$(this).attr('data-view-count');
        if (viewCount <= 1
            || isNaN(viewCount)
        ) {
            return;
        }

        var $pageviewAction = $(this).prev();
        $pageviewAction.find('>div').prepend($("<span>"+viewCount+"</span>").attr({'class': 'repeat icon-refresh', 'title': _pk_translate('Live_PageRefreshed')}));

        var actionsCount = +$(this).attr('data-actions-on-page');
        if (actionsCount === 0) {
            $pageviewAction.addClass('noPageviewActions');
        }

        $('a', $(this)).on('focus', function () {
            // see https://github.com/piwik/piwik/issues/4099
            if (tooltipIsOpened) {
                $(this).tooltip('close');
            }
        });

        var $this = $(this);
        $pageviewAction.attr('origtitle', $pageviewAction.attr('title'));
        $pageviewAction.attr('title', _pk_translate('Live_ClickToViewAllActions'));
        $pageviewAction.click(function (e) {
            e.preventDefault();
            e.stopPropagation();

            $pageviewAction.addClass('refreshesExpanded');
            $this.children('.actionList').children().first().removeClass('duplicate').nextUntil('li:not(.duplicate)').removeClass('duplicate');

            window.setTimeout(function() {
                $pageviewAction.attr('title', $pageviewAction.attr('origtitle'));
                $pageviewAction.attr('origtitle', null);
            }, 150);

            $pageviewAction.off('click').find('.icon-refresh').hide();
            $pageviewAction.triggerHandler('mouseleave'); // close tooltip so the title will replace
        });
    });

    // hide expanders if content collapsing removed enough items
    $("ol.actionList", elem).each(function () {
        var actionsToDisplayCollapsed = +piwik.visitorLogActionsToDisplayCollapsed;

        var $items = $(this).find("li:not(.pageviewActions):not(.actionsForPageExpander):not(.duplicate)");
        var hasMoreItemsThanLimit = $items.length > actionsToDisplayCollapsed;

        $(this).children('.actionsForPageExpander')
            .toggle(hasMoreItemsThanLimit)
            .find('.show-actions-count').text($items.length - actionsToDisplayCollapsed);

        // add last-action class to the last action in each list
        setLastActionClass($(this));
    });

    // event handler for content expander/collapser
    elem.on('click', '.collapsed-contents', function () {
        $(this).nextUntil(':not(.content)').toggleClass('duplicate');
        setLastActionClass($(this).closest('ol.actionList'));
    });

    // event handler for action expander/collapser
    elem.on('click', '.show-less-actions,.show-more-actions', function (e) {
        e.preventDefault();

        var actionsToDisplayCollapsed = +piwik.visitorLogActionsToDisplayCollapsed;

        var $actions = $(e.target).closest('.actionList').find('li:not(.duplicate):not(.actionsForPageExpander)');
        $actions.each(function () {
            if ($actions.index(this) >= actionsToDisplayCollapsed) {
                $(this).toggle({
                    duration: 250
                });
            }
         });

        $(e.target)
            .parent().find('.show-less-actions,.show-more-actions').toggle();
        $(e.target)
            .closest('li')
            .toggleClass('expanded collapsed');
    });

    elem.find('.show-less-actions:visible').click();

    function setLastActionClass($list) {
        $list.children(':not(.actionsForPageExpander):not(.duplicate)').removeClass('last-action').last().addClass('last-action');
    }
}