PageSourceSearch

https://www.pastapadre.com/wordpress/wp-content/plugins/wp-gfycat/js/gfyCollection.js?ver=6.7.9

js pastapadre.com collected 2026-10-02 11:41:04 UTC 4,398 bytes, 133 lines download raw bytes

1/**
2 * Copyright 2014-2016 Gfycat, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS-IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18/**
19 * gfyCollection:
20 * Global object to be called on page load.
21 * This runs through the page DOM for elements
22 * with class "gfyitem" and attempts to convert
23 * them to gfycat embeds by creating a new
24 * gfyObject with the element.
25 * Can also be used _after_ page load
26 * by calling gfyCollection.get() to get
27 * the collection of gfycat objects on the page
28 * and re-initialize them or interact with them
29 * as desired.
30 */
31var gfyCollection = function() {
32
33    var collection = [],
34        gfyClass = "gfyitem",
35        scrollTop;
36
37    // Helper function -- only required because some browsers do not have get by class name
38    function byClass(className, obj) {
39        if (obj.getElementsByClassName) {
40            return obj.getElementsByClassName(className);
41        } else {
42            var retnode = [];
43            var elem = obj.getElementsByTagName('*');
44            for (var i = 0; i < elem.length; i++) {
45                if ((' ' + elem[i].className + ' ').indexOf(' ' + className + ' ') > -1) retnode.push(elem[i]);
46            }
47            return retnode;
48        }
49    }
50
51    function init(classname) {
52        if (typeof GfyAnalytics !== 'undefined') GfyAnalytics.initGA();
53        classname = typeof classname==="string" ? classname : gfyClass;
54        scan(classname);
55        attachEventListeners();
56    }
57
58    var scrollTimer;
59
60    function scrollHandler() {
61      if (scrollTimer) {
62        clearTimeout(scrollTimer);
63      }
64      scrollTimer = setTimeout(function() {
65        scrollTop = document.body.scrollTop;
66        for (var i = 0; i < collection.length; i++) {
67          collection[i].checkScroll(scrollTop);
68        }
69      }, 100);
70    }
71
72    function onPageUpdate() {
73      scrollTop = document.body.scrollTop;
74      var windowHeight = window.innerHeight;
75      for (var i = 0; i < collection.length; i++) {
76        collection[i].onPageUpdate(windowHeight, scrollTop);
77      }
78    }
79
80    function attachEventListeners() {
81      if (window.addEventListener) {
82        addEventListener('DOMContentLoaded', onPageUpdate, false);
83        addEventListener('load', onPageUpdate, false);
84        addEventListener('resize', onPageUpdate, false);
85        addEventListener('scroll', scrollHandler, false);
86      } else if (window.attachEvent) {
87        attachEvent('DOMContentLoaded', onPageUpdate, false);
88        attachEvent('load', onPageUpdate, false);
89        attachEvent('resize', onPageUpdate, false);
90        attachEvent('scroll', scrollHandler, false);
91      }
92    }
93
94    function scan(classname) {
95        classname = typeof classname==="string" ? classname : gfyClass;
96
97        // this can be run multiple times, so we'll add to any existing gfycats
98        var last = collection.length;
99        // find each gfycat on page and run its init
100        var elem_coll = byClass(classname, document);
101        for (var i = 0; i < elem_coll.length; i++) {
102            // don't need to worry about finding existing gfyitems - they are
103            // replaced by gfyObject
104            var gfyObj = new gfyObject(elem_coll[i], classname);
105            collection.push(gfyObj);
106        }
107        // run init _after_ all are collected, because the init function deletes and recreates
108        for (var i = last; i < collection.length; i++) {
109            collection[i].init();
110        }
111    }
112
113    function get() {
114        // optional interface for an external script to interact with all objects on a page
115        return collection;
116    }
117
118    init();
119
120    return {
121        init: init,
122        get: get,
123        scan: scan
124    };
125}();
126
127if (document.addEventListener) {
128  document.addEventListener("DOMContentLoaded", function() {
129      gfyCollection.init();
130  }, false);
131} else {
132  document.attachEvent("onreadystatechange", gfyCollection.init);
133}

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.