PageSourceSearch

https://greenbrooktwp.org/js/jquery.lazyload.js

js greenbrooktwp.org collected 2026-10-02 19:19:28 UTC 8,319 bytes, 227 lines download raw bytes

vendor: 5,492 bytes, lines 1-156
1/*
2 * Lazy Load - jQuery plugin for lazy loading images
3 *
4 * Copyright (c) 2007-2012 Mika Tuupola
5 *
6 * Licensed under the MIT license:
7 *   http://www.opensource.org/licenses/mit-license.php
8 *
9 * Project home:
10 *   http://www.appelsiini.net/projects/lazyload
11 *
12 * Version:  1.8.3
13 *
14 */
15(function($, window, document, undefined) {
16    var $window = $(window);
17
18    $.fn.lazyload = function(options) {
19        var elements = this;
20        var $container;
21        var settings = {
22            threshold       : 0,
23            failure_limit   : 0,
24            event           : "scroll",
25            effect          : "show",
26            container       : window,
27            data_attribute  : "original",
28            skip_invisible  : true,
29            appear          : null,
30            load            : null
31        };
32
33        function update() {
34            var counter = 0;
35      
36            elements.each(function() {
37                var $this = $(this);
38                if (settings.skip_invisible && !$this.is(":visible")) {
39                    return;
40                }
41                if ($.abovethetop(this, settings) ||
42                    $.leftofbegin(this, settings)) {
43                        /* Nothing. */
44                } else if (!$.belowthefold(this, settings) &&
45                    !$.rightoffold(this, settings)) {
46                        $this.trigger("appear");
47                        /* if we found an image we'll load, reset the counter */
48                        counter = 0;
49                } else {
50                    if (++counter > settings.failure_limit) {
51                        return false;
52                    }
53                }
54            });
55
56        }
57
58        if(options) {
59            /* Maintain BC for a couple of versions. */
60            if (undefined !== options.failurelimit) {
61                options.failure_limit = options.failurelimit; 
62                delete options.failurelimit;
63            }
64            if (undefined !== options.effectspeed) {
65                options.effect_speed = options.effectspeed; 
66                delete options.effectspeed;
67            }
68
69            $.extend(settings, options);
70        }
71
72        /* Cache container as jQuery as object. */
73        $container = (settings.container === undefined ||
74                      settings.container === window) ? $window : $(settings.container);
75
76        /* Fire one scroll event per scroll. Not one scroll event per image. */
77        if (0 === settings.event.indexOf("scroll")) {
78            $container.bind(settings.event, function(event) {
79                return update();
80            });
81        }
82
83        this.each(function() {
84            var self = this;
85            var $self = $(self);
86
87            self.loaded = false;
88
89            /* When appear is triggered load original image. */
90            $self.one("appear", function() {
91                if (!this.loaded) {
92                    if (settings.appear) {
93                        var elements_left = elements.length;
94                        settings.appear.call(self, elements_left, settings);
95                    }
96                    $("<img />")
97                        .bind("load", function() {
98                            $self
99                                .hide()
100                                .attr("src", $self.data(settings.data_attribute))
101                                [settings.effect](settings.effect_speed);
102                            self.loaded = true;
103
104                            /* Remove image from array so it is not looped next time. */
105                            var temp = $.grep(elements, function(element) {
106                                return !element.loaded;
107                            });
108                            elements = $(temp);
109
110                            if (settings.load) {
111                                var elements_left = elements.length;
112                                settings.load.call(self, elements_left, settings);
113                            }
114                        })
115                        .attr("src", $self.data(settings.data_attribute));
116                }
117            });
118
119            /* When wanted event is triggered load original image */
120            /* by triggering appear.                              */
121            if (0 !== settings.event.indexOf("scroll")) {
122                $self.bind(settings.event, function(event) {
123                    if (!self.loaded) {
124                        $self.trigger("appear");
125                    }
126                });
127            }
128        });
129
130        /* Check if something appears when window is resized. */
131        $window.bind("resize", function(event) {
132            update();
133        });
134              
135        /* With IOS5 force loading images when navigating with back button. */
136        /* Non optimal workaround. */
137        if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
138            $window.bind("pageshow", function(event) {
139                if (event.originalEvent.persisted) {
140                    elements.each(function() {
141                        $(this).trigger("appear");
142                    });
143                }
144            });
145        }
146
147        /* Force initial check if images should appear. */
148        $(window).load(function() {
149            update();
150        });
151        
152        return this;
153    };
154
155    /* Convenience methods in jQuery namespace.           */
156    /* Use as  $.belowthefold(element, {threshold : 100, container : window}
vendor: 2,827 bytes, lines 156-227
156) */
157
158    $.belowthefold = function(element, settings) {
159        var fold;
160        
161        if (settings.container === undefined || settings.container === window) {
162            fold = $window.height() + $window.scrollTop();
163        } else {
164            fold = $(settings.container).offset().top + $(settings.container).height();
165        }
166
167        return fold <= $(element).offset().top - settings.threshold;
168    };
169    
170    $.rightoffold = function(element, settings) {
171        var fold;
172
173        if (settings.container === undefined || settings.container === window) {
174            fold = $window.width() + $window.scrollLeft();
175        } else {
176            fold = $(settings.container).offset().left + $(settings.container).width();
177        }
178
179        return fold <= $(element).offset().left - settings.threshold;
180    };
181        
182    $.abovethetop = function(element, settings) {
183        var fold;
184        
185        if (settings.container === undefined || settings.container === window) {
186            fold = $window.scrollTop();
187        } else {
188            fold = $(settings.container).offset().top;
189        }
190
191        return fold >= $(element).offset().top + settings.threshold  + $(element).height();
192    };
193    
194    $.leftofbegin = function(element, settings) {
195        var fold;
196        
197        if (settings.container === undefined || settings.container === window) {
198            fold = $window.scrollLeft();
199        } else {
200            fold = $(settings.container).offset().left;
201        }
202
203        return fold >= $(element).offset().left + settings.threshold + $(element).width();
204    };
205
206    $.inviewport = function(element, settings) {
207         return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
208                !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
209     };
210
211    /* Custom selectors for your convenience.   */
212    /* Use as $("img:below-the-fold").something() or */
213    /* $("img").filter(":below-the-fold").something() which is faster */
214
215    $.extend($.expr[':'], {
216        "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); },
217        "above-the-top"  : function(a) { return !$.belowthefold(a, {threshold : 0}); },
218        "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); },
219        "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); },
220        "in-viewport"    : function(a) { return $.inviewport(a, {threshold : 0}); },
221        /* Maintain BC for couple of versions. */
222        "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
223        "right-of-fold"  : function(a) { return $.rightoffold(a, {threshold : 0}); },
224        "left-of-fold"   : function(a) { return !$.rightoffold(a, {threshold : 0}); }
225    });
226
227})(jQuery, window, document);

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.