PageSourceSearch

https://associationheadquarters.com/themes/custom/ah/js/counterup-lazy.js?v=1.1.1

js associationheadquarters.com collected 2026-10-01 14:43:46 UTC 2,759 bytes, 109 lines download raw bytes

1(function (Drupal, once, drupalSettings) {
2  'use strict';
3
4  function getCounterupSettings() {
5    return drupalSettings.ah && drupalSettings.ah.counterupLazy ?
6      drupalSettings.ah.counterupLazy :
7      {};
8  }
9
10  function addSeparators(value) {
11    var parts = value.toString().split('.');
12    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
13    return parts.join('.');
14  }
15
16  function getCounterData(counter) {
17    var original = counter.textContent.trim();
18    var normalized = original.replace(/,/g, '');
19    var value = parseFloat(normalized);
20    var decimalParts = normalized.split('.');
21
22    if (!isFinite(value)) {
23      return null;
24    }
25
26    return {
27      original: original,
28      value: value,
29      decimals: decimalParts.length > 1 ? decimalParts[1].length : 0,
30      hasSeparators: original.indexOf(',') !== -1
31    };
32  }
33
34  function formatCounterValue(data, value) {
35    var output = data.decimals ? value.toFixed(data.decimals) : Math.floor(value).toString();
36    return data.hasSeparators ? addSeparators(output) : output;
37  }
38
39  function animateCounter(counter, options) {
40    var data = getCounterData(counter);
41    var duration = options.time || 1500;
42    var delay = options.delay || 16;
43    var startTime;
44
45    if (!data) {
46      return;
47    }
48
49    counter.textContent = formatCounterValue(data, 0);
50    startTime = Date.now();
51
52    function tick() {
53      var progress = Math.min((Date.now() - startTime) / duration, 1);
54      counter.textContent = progress < 1 ?
55        formatCounterValue(data, data.value * progress) :
56        data.original;
57
58      if (progress < 1) {
59        window.setTimeout(tick, delay);
60      }
61    }
62
63    window.setTimeout(tick, delay);
64  }
65
66  function runCounters(counters) {
67    var settings = getCounterupSettings();
68    var options = settings.options || {
69      delay: 16,
70      time: 1500
71    };
72
73    counters.forEach(function (counter) {
74      animateCounter(counter, options);
75    });
76  }
77
78  Drupal.behaviors.ahCounterupLazy = {
79    attach: function (context) {
80      var counters = once('ah-counterup-lazy', '.counter', context);
81
82      if (!counters.length) {
83        return;
84      }
85
86      if (!('IntersectionObserver' in window)) {
87        runCounters(counters);
88        return;
89      }
90
91      var started = false;
92      var observer = new IntersectionObserver(function (entries) {
93        entries.forEach(function (entry) {
94          if (!started && entry.isIntersecting) {
95            started = true;
96            observer.disconnect();
97            runCounters(counters);
98          }
99        });
100      }, {
101        rootMargin: '0px'
102      });
103
104      counters.forEach(function (counter) {
105        observer.observe(counter);
106      });
107    }
108  };
109})(Drupal, once, drupalSettings);

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.