PageSourceSearch

https://doctorunite.com/modules/custom/skipta_statistics/js/skipta_statistics_impression.js?v=1.10.x

js doctorunite.com collected 2026-10-09 01:24:22 UTC 6,686 bytes, 168 lines download raw bytes

1/**
2 * @file
3 * impression count on post.
4 */
5(function ($, Drupal) {
6  var divArrayFocusIn = {};
7  var divArrayFocusOut = {};
8  var debug = false;
9
10  Drupal.behaviors.skiptaStatisticsImpression = {
11    attach: function (context, settings) {
12      $(document).ready(function (px) {
13        var focusInCallCount = 0;
14        var focusOutCallCount = 0;
15        var oldId2 = 0;
16        var isTabActive = false;
17        var entity_id, entity_type, entity_bundle, focusTime, type;
18
19        window.onblur = function () {
20          isTabActive = true;
21        };
22
23        // Fire focus-out for all open records when user leaves the page.
24        function sendFocusOutForAll() {
25          $.each(divArrayFocusIn, function (divId, data) {
26            var focusOutData = {
27              'entity_id'       : data.entity_id,
28              'entity_type'     : data.entity_type,
29              'entity_bundle'   : data.entity_bundle,
30              'focusTime'       : Math.floor(Date.now() / 1000),
31              'type'            : 'focus-out',
32              'scroll'          : data.scroll,
33              'skuid'           : drupalSettings.skuid,
34              'media_partner_id': data.media_partner_id,
35            };
36            navigator.sendBeacon(
37              drupalSettings.path.baseUrl + 'skipta-statistics/view',
38              JSON.stringify(focusOutData)
39            );
40          });
41          divArrayFocusIn = {};
42        }
43
44        $(window).on('beforeunload pagehide', function () {
45          sendFocusOutForAll();
46        });
47
48        //console.log(window.isTabActive ? 'tab active' : ' tab inactive');
49
50        $(".stream-posts").each(function (px) {
51          $(this).inViewport(function (px) {
52            var h = $(this).height();
53            var divId = $(this).attr('id');
54            var isHalfVisible = px >= h / 4;
55
56            // $(this).css({background: isHalfVisible ? "green" : "red"});
57                        
58            if (isHalfVisible) {
59              var keyExistFocusIn = divArrayFocusIn.hasOwnProperty(divId);
60
61              if (!keyExistFocusIn && !$(this).hasClass('skipta-focus')) {
62
63                entity_id = $(this).find('.skipta-statistics-views').data('view-entity-id');
64                entity_type = $(this).find('.skipta-statistics-views').data('view-entity-type');
65                entity_bundle = $(this).find('.skipta-statistics-views').data('view-entity-bundle');
66                
67                focusTime = Math.floor(Date.now() / 1000);
68                type = 'focus-in';
69
70                var $scrollBox = $('#' + divId + ' #scroll-row .row');
71                var currY = $scrollBox.scrollTop();
72                var postHeight = $scrollBox.height();
73                var scrollHeight = $('#' + divId + ' #scroll-row .row div:first').height();
74                var scrollPercent = (currY / (scrollHeight - postHeight)) * 100;
75                var scroll = Number.parseFloat(scrollPercent).toFixed(0);
76
77                // set media partner id
78                window.skiptaPartnerService.setMediaPartnerId();
79
80
81                divArrayFocusIn[divId] = {
82                  'entity_id' : entity_id, 
83                  'entity_type' : entity_type, 
84                  'entity_bundle' : entity_bundle, 
85                  'focusTime' : focusTime, 
86                  'type' : type,
87                  'scroll': scroll,
88                  'media_partner_id': window.skiptaPartnerService.getMediaPartnerId(),
89                };
90
91                if (debug) {
92                  console.log(focusInCallCount + ' Focus on div id: ' + entity_id);
93                }
94
95                skiptaStatisticsService.impression(divArrayFocusIn[divId]);
96                focusInCallCount++;
97              }
98
99              $(this).addClass("skipta-focus");
100            }
101            
102            divArrayFocusOut = {};
103            if (!isHalfVisible) {
104              if (oldId2 != 0 && $(this).hasClass("skipta-focus")) {
105                focusTime = Math.floor(Date.now() / 1000);
106                var keyExistFocusOut = divArrayFocusIn.hasOwnProperty(divId);
107                if (keyExistFocusOut) {
108                  delete divArrayFocusIn[divId];
109                  focusOutCallCount++;
110                  type = 'focus-out';
111
112                  entity_id = $(this).find('.skipta-statistics-views').data('view-entity-id');
113                  entity_type = $(this).find('.skipta-statistics-views').data('view-entity-type');
114                  entity_bundle = $(this).find('.skipta-statistics-views').data('view-entity-bundle');
115
116                  var $scrollBox = $('#' + divId + ' #scroll-row .row');
117                  var currY = $scrollBox.scrollTop();
118                  var postHeight = $scrollBox.height();
119                  var scrollHeight = $('#' + divId + ' #scroll-row .row div
119:first').height();
120                  var scrollPercent = (currY / (scrollHeight - postHeight)) * 100;
121                  var scroll = Number.parseFloat(scrollPercent).toFixed(0);
122                  var skuid = drupalSettings.skuid;
123
124                  // set media partner id
125                  window.skiptaPartnerService.setMediaPartnerId();
126
127                  divArrayFocusOut[divId] = {
128                    'entity_id' : entity_id, 
129                    'entity_type' : entity_type, 
130                    'entity_bundle' : entity_bundle, 
131                    'focusTime' : focusTime, 
132                    'type' : type,
133                    'scroll': scroll,
134                    'skuid': skuid,
135                    'media_partner_id': window.skiptaPartnerService.getMediaPartnerId(),
136                  };
137
138                  if (debug) {
139                    console.log(focusOutCallCount + ' Focus out div id: ' + entity_id);
140                    console.log(divArrayFocusOut);
141                  }
142
143                  var currentId = $(this).attr('id');
144                  var impressionOutJsonData = JSON.stringify(divArrayFocusOut[divId]);
145                  $.ajax({
146                    type: "POST",
147                    url: drupalSettings.path.baseUrl + 'skipta-statistics/view',
148                    data: impressionOutJsonData,
149                    dataType: 'json',
150                    success: function (response) {
151                      if (response) {
152                        if (response.views) {
153                          $('#' + currentId).find('li.social__item.views').text(response.views);
154                        }
155                      }
156                    }
157                  });
158                }
159                $(".stream-posts").removeClass("skipta-focus");
160              }
161            }
162            oldId2 = divId;
163          });
164        });
165      });
166    }
167  };
168})(jQuery, Drupal);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.