PageSourceSearch

https://elizabethfiend.com/blog/wp-content/plugins/nextgen-gallery…ery.waitforimages-2.4.0-modded.js?ver=4.2.1

js elizabethfiend.com collected 2026-10-10 01:36:09 UTC 8,016 bytes, 233 lines download raw bytes

vendor: 3,338 bytes, lines 1-103
1/*! waitForImages jQuery Plugin - v2.4.0 - 2018-02-13
2* https://github.com/alexanderdickson/waitForImages
3* Copyright (c) 2018 Alex Dickson; Licensed MIT */
4/**
5 * Modded by Imagely:
6 * - Replaced all $.type and $.isFunction calls with typeof operator
7 */
8;(function (factory) {
9    if (typeof define === 'function' && define.amd) {
10        // AMD. Register as an anonymous module.
11        define(['jquery'], factory);
12    } else if (typeof exports === 'object') {
13        // CommonJS / nodejs module
14        module.exports = factory(require('jquery'));
15    } else {
16        // Browser globals
17        factory(jQuery);
18    }
19}(function ($) {
20    // Namespace all events.
21    var eventNamespace = 'waitForImages';
22
23    // Is srcset supported by this browser?
24    var hasSrcset = (function(img) {
25        return img.srcset && img.sizes;
26    })(new Image());
27
28    // CSS properties which contain references to images.
29    $.waitForImages = {
30        hasImageProperties: [
31            'backgroundImage',
32            'listStyleImage',
33            'borderImage',
34            'borderCornerImage',
35            'cursor'
36        ],
37        hasImageAttributes: ['srcset']
38    };
39
40    // Custom selector to find all `img` elements with a valid `src` attribute.
41    $.expr.pseudos['has-src'] = function (obj) {
42        // Ensure we are dealing with an `img` element with a valid
43        // `src` attribute.
44        return $(obj).is('img[src][src!=""]');
45    };
46
47    // Custom selector to find images which are not already cached by the
48    // browser.
49    $.expr.pseudos.uncached = function (obj) {
50        // Ensure we are dealing with an `img` element with a valid
51        // `src` attribute.
52        if (!$(obj).is(':has-src')) {
53            return false;
54        }
55
56        return !obj.complete;
57    };
58
59    $.fn.waitForImages = function () {
60
61        var allImgsLength = 0;
62        var allImgsLoaded = 0;
63        var deferred = $.Deferred();
64        var originalCollection = this;
65        var allImgs = [];
66
67        // CSS properties which may contain an image.
68        var hasImgProperties = $.waitForImages.hasImageProperties || [];
69        // Element attributes which may contain an image.
70        var hasImageAttributes = $.waitForImages.hasImageAttributes || [];
71        // To match `url()` references.
72        // Spec: http://www.w3.org/TR/CSS2/syndata.html#value-def-uri
73        var matchUrl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
74
75        var finishedCallback;
76        var eachCallback;
77        var waitForAll;
78
79        // Handle options object (if passed).
80        if ($.isPlainObject(arguments[0])) {
81
82            waitForAll = arguments[0].waitForAll;
83            eachCallback = arguments[0].each;
84            finishedCallback = arguments[0].finished;
85
86        } else {
87
88            // Handle if using deferred object and only one param was passed in.
89            if (arguments.length === 1 && typeof(arguments[0]) === 'boolean') {
90                waitForAll = arguments[0];
91            } else {
92                finishedCallback = arguments[0];
93                eachCallback = arguments[1];
94                waitForAll = arguments[2];
95            }
96
97        }
98
99        // Handle missing callbacks.
100        finishedCallback = finishedCallback || $.noop;
101        eachCallback = eachCallback || $.noop;
102
103        // Convert waitForAll to Boolean.
104        waitForAll = !! waitForAll;
105
106        // Ensure callbacks are functions.
107        if (typeof(finishedCallback) !== "function" || typeof(eachCallback) !== "function"
vendor: 4,508 bytes, lines 107-233
107) {
108            throw new TypeError('An invalid callback was supplied.');
109        }
110
111        this.each(function () {
112            // Build a list of all imgs, dependent on what images will
113            // be considered.
114            var obj = $(this);
115
116            if (waitForAll) {
117
118                // Get all elements (including the original), as any one of
119                // them could have a background image.
120                obj.find('*').addBack().each(function () {
121                    var element = $(this);
122
123                    // If an `img` element, add it. But keep iterating in
124                    // case it has a background image too.
125                    if (element.is('img:has-src') &&
126                        !element.is('[srcset]')) {
127                        allImgs.push({
128                            src: element.attr('src'),
129                            element: element[0]
130                        });
131                    }
132
133                    $.each(hasImgProperties, function (i, property) {
134                        var propertyValue = element.css(property);
135                        var match;
136
137                        // If it doesn't contain this property, skip.
138                        if (!propertyValue) {
139                            return true;
140                        }
141
142                        // Get all url() of this element.
143                        while (match = matchUrl.exec(propertyValue)) {
144                            allImgs.push({
145                                src: match[2],
146                                element: element[0]
147                            });
148                        }
149                    });
150
151                    $.each(hasImageAttributes, function (i, attribute) {
152                        var attributeValue = element.attr(attribute);
153                        var attributeValues;
154
155                        // If it doesn't contain this property, skip.
156                        if (!attributeValue) {
157                            return true;
158                        }
159
160                        allImgs.push({
161                            src: element.attr('src'),
162                            srcset: element.attr('srcset'),
163                            element: element[0]
164                        });
165                    });
166                });
167            } else {
168                // For images only, the task is simpler.
169                obj.find('img:has-src')
170                    .each(function () {
171                    allImgs.push({
172                        src: this.src,
173                        element: this
174                    });
175                });
176            }
177        });
178
179        allImgsLength = allImgs.length;
180        allImgsLoaded = 0;
181
182        // If no images found, don't bother.
183        if (allImgsLength === 0) {
184            finishedCallback.call(originalCollection);
185            deferred.resolveWith(originalCollection);
186        }
187
188        // Now that we've found all imgs in all elements in this,
189        // load them and attach callbacks.
190        $.each(allImgs, function (i, img) {
191
192            var image = new Image();
193            var events =
194              'load.' + eventNamespace + ' error.' + eventNamespace;
195
196            // Handle the image loading and error with the same callback.
197            $(image).one(events, function me (event) {
198                // If an error occurred with loading the image, set the
199                // third argument accordingly.
200                var eachArguments = [
201                    allImgsLoaded,
202                    allImgsLength,
203                    event.type == 'load'
204                ];
205                allImgsLoaded++;
206
207                eachCallback.apply(img.element, eachArguments);
208                deferred.notifyWith(img.element, eachArguments);
209
210                // Unbind the event listeners. I use this in addition to
211                // `one` as one of those events won't be called (either
212                // 'load' or 'error' will be called).
213                $(this).off(events, me);
214
215                if (allImgsLoaded == allImgsLength) {
216                    finishedCallback.call(originalCollection[0]);
217                    deferred.resolveWith(originalCollection[0]);
218                    return false;
219                }
220
221            });
222
223            if (hasSrcset && img.srcset) {
224                image.srcset = img.srcset;
225                image.sizes = img.sizes;
226            }
227            image.src = img.src;
228        });
229
230        return deferred.promise();
231
232    };
233}));

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.