PageSourceSearch

https://ifswf.org/modules/contrib/scrollama/js/scrollama.js?tm77nm

js ifswf.org collected 2026-10-02 06:40:09 UTC 3,137 bytes, 110 lines download raw bytes

1(function (Drupal, debounce, once) {
2  Drupal.scrollama = {};
3
4  Drupal.scrollama.getScrollamaItemsData = function (elements) {
5    const elementsData = [];
6
7    function validTimeUnit(string) {
8      const match = string.match(/^((?:0.)?\d+)s?$/);
9
10      if (match) {
11        return match[1];
12      }
13      return false;
14    }
15
16    elements.forEach((element) => {
17      const init = element.getAttribute('data-scroll-init');
18      const exit = element.getAttribute('data-scroll-exit');
19      const delay = element.getAttribute('data-scroll-delay');
20
21      if (!init) {
22        throw new Error(
23          'You must provide at least a value for "data-scroll-init"',
24        );
25      }
26      const data = {
27        element,
28        init: init.trim().split(/\s+/),
29      };
30
31      if (exit) {
32        data.exit = exit.trim().split(/\s+/);
33      }
34
35      if (delay) {
36        // Delete the "s" unit and detect wrong options.
37        const filteredDelay = validTimeUnit(delay);
38
39        if (filteredDelay) {
40          data.delay = parseInt(filteredDelay, 10);
41        } else {
42          throw new Error(
43            'Please express your data-scroll-delay in seconds (i.e: "0.75" or "0.75s")',
44          );
45        }
46      } else {
47        data.delay = 0;
48      }
49
50      elementsData.push(data);
51    });
52
53    return elementsData.length > 0 ? elementsData : false;
54  };
55
56  Drupal.behaviors.scrollama = {
57    attach(context, settings) {
58      const elements = once('scrollama', '[data-scroll-init]', context);
59
60      // Quick exit if there are no scroll-enabled elements.
61      if (elements.length <= 0) {
62        return;
63      }
64
65      // Get all the element's data in order to cache it in a variable
66      // and improve performance.
67      const elementsData = Drupal.scrollama.getScrollamaItemsData(elements);
68
69      if (settings.scrollama.debug) {
70        console.table(
71          elementsData.map(function (item) {
72            return {
73              item: item.element,
74              init: item.init.join(' '),
75              exit: item.exit ? item.exit.join(' ') : false,
76              delay: item.delay ? `${item.delay}s` : false,
77            };
78          }),
79        );
80      }
81
82      const scroller = scrollama();
83      scroller
84        .setup({
85          step: elements,
86          offset: settings.scrollama.offset,
87          debug: settings.scrollama.debug,
88          once: settings.scrollama.once,
89          order: settings.scrollama.order,
90        })
91        .onStepEnter(function (response) {
92          const elementData = elementsData[response.index];
93          setTimeout(function () {
94            elementData.element.classList.add(elementData.init);
95          }, elementData.delay * 1000);
96        })
97        .onStepExit(function (response) {
98          const elementData = elementsData[response.index];
99
100          if (elementData.exit) {
101            setTimeout(function () {
102              elementData.element.classList.add(elementData.exit);
103            }, elementData.delay * 1000);
104          }
105        });
106
107      window.addEventListener('resize', debounce(scroller.resize, 500));
108    },
109  };
110})(Drupal, Drupal.debounce, once);

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.