PageSourceSearch

https://usadf.gov/themes/custom/usadf/js/cbpScroller.js?tgserb

js usadf.gov collected 2026-10-02 06:17:39 UTC 4,884 bytes, 158 lines download raw bytes

1/**
2 * cbpScroller.js v1.0.0
3 * http://www.codrops.com
4 *
5 * Licensed under the MIT license.
6 * http://www.opensource.org/licenses/mit-license.php
7 *
8 * Copyright 2013, Codrops
9 * http://www.codrops.com
10 */
11;
12(function(window) {
13  'use strict';
14  var docElem = window.document.documentElement;
15
16  function getViewportH() {
17    var client = docElem['clientHeight'],
18      inner = window['innerHeight'];
19    if (client < inner) return inner;
20    else return client;
21  }
22
23  function scrollY() {
24    return window.pageYOffset || docElem.scrollTop;
25  }
26  // http://stackoverflow.com/a/5598797/989439
27  function getOffset(el) {
28    var offsetTop = 0,
29      offsetLeft = 0;
30    do {
31      if (!isNaN(el.offsetTop)) {
32        offsetTop += el.offsetTop;
33      }
34      if (!isNaN(el.offsetLeft)) {
35        offsetLeft += el.offsetLeft;
36      }
37    } while (el = el.offsetParent)
38    return {
39      top: offsetTop,
40      left: offsetLeft
41    }
42  }
43
44  function inViewport(el, h) {
45    var elH = el.offsetHeight,
46      scrolled = scrollY(),
47      viewed = scrolled + getViewportH(),
48      elTop = getOffset(el).top,
49      elBottom = elTop + elH,
50      // if 0, the element is considered in the viewport as soon as it enters.
51      // if 1, the element is considered in the viewport only when it's fully inside
52      // value in percentage (1 >= h >= 0)
53      h = h || 0;
54    return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
55  }
56
57  function extend(a, b) {
58    for (var key in b) {
59      if (b.hasOwnProperty(key)) {
60        a[key] = b[key];
61      }
62    }
63    return a;
64  }
65
66  function cbpScroller(el, options) {
67    this.el = el;
68    this.options = extend(this.defaults, options);
69    this._init(this.el);
70  }
71  cbpScroller.prototype = {
72    defaults: {
73      // The viewportFactor defines how much of the appearing item has to be visible in order to trigger the animation
74      // if we'd use a value of 0, this would mean that it would add the animation class as soon as the item is in the viewport.
75      // If we were to use the value of 1, the animation would only be triggered when we see all of the item in the viewport (100% of it)
76      viewportFactor: 0.5
77    },
78    _init: function(elemen) {
79      //if( Modernizr.touch ) return;
80      this.sections = elemen;
81      this.didScroll = false;
82      var self = this;
83      // the sections already shown...
84      Array.prototype.forEach.call(this.sections, function(el) {
85        // Do stuff here
86        if (!inViewport(el)) {
87          classie.add(el, 'cbp-so-init');
88        } else {
89          classie.add(el, 'cbp-so-animate');
90        }
91        //for anim once
92        // if ($(el).hasClass('anim-once')) {
93        //   if (!inViewport(el)) {
94        //     classie.add(el, 'content-loaded');
95        //   }
96        // }
97      });
98      /*this.sections.forEach( function( el, i ) {
99        if( !inViewport( el ) ) {
100          classie.add( el, 'cbp-so-init' );
101        }
102      } );*/
103      var scrollHandler = function() {
104          if (!self.didScroll) {
105            self.didScroll = true;
106            setTimeout(function() {
107              self._scrollPage();
108            }, 60);
109          }
110        },
111        resizeHandler = function() {
112          function delayed() {
113            self._scrollPage();
114            self.resizeTimeout = null;
115          }
116          if (self.resizeTimeout) {
117            clearTimeout(self.resizeTimeout);
118          }
119          self.resizeTimeout = setTimeout(delayed, 200);
120        };
121      window.addEventListener('scroll', scrollHandler, false);
122      window.addEventListener('resize', resizeHandler, false);
123    },
124    _scrollPage: function() {
125      var self = this;
126      /*this.sections.forEach( function( el, i ) {
127        if( inViewport( el, self.options.viewportFactor ) ) {
128          classie.add( el, 'cbp-so-animate' );
129        }
130        else {
131          // this add class init if it doesn't have it. This will ensure that the items initially in the viewport will also animate on scroll
132          classie.add( el, 'cbp-so-init' );
133
134          classie.remove( el, 'cbp-so-animate' );
135        }
136      });*/
137      Array.prototype.forEach.call(this.sections, function(el) {
138        // Do stuff here
139        if (inViewport(el, self.options.viewportFactor)) {
140          classie.add(el, 'cbp-so-animate');
141        } else {
142          // this add class init if it doesn't have it. This will ensure that the items initially in the viewport will also animate on scroll
143          classie.add(el, 'cbp-so-init');
144          // classie.remove(el, 'cbp-so-animate');
145        }
146        //for anim once
147        if ($(el).hasClass('anim-once')) {
148          if (inViewport(el, self.options.viewportFactor)) {
149            classie.add(el, 'content-loaded');
150          }
151        }
152      });
153      this.didScroll = false;
154    }
155  }
156  // add to global namespace
157  window.cbpScroller = cbpScroller;
158})(window);

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.