PageSourceSearch

https://intef.es/wp-content/themes/Tema_INTEF/js/imgLoaded.js?ver=1

js intef.es collected 2026-10-01 10:13:17 UTC 14,146 bytes, 488 lines download raw bytes

vendor: 14,146 bytes, lines 1-488
1/*!
2* imagesLoaded PACKAGED v4.1.0
3* JavaScript is all like "You images are done yet or what?"
4* MIT License
5*/
6
7/**
8* EvEmitter v1.0.1
9* Lil' event emitter
10* MIT License
11*/
12
13/* jshint unused: true, undef: true, strict: true */
14
15(function (global, factory) {
16    // universal module definition
17    /* jshint strict: false */ /* globals define, module */
18    if (typeof define == 'function' && define.amd) {
19        // AMD - RequireJS
20        define('ev-emitter/ev-emitter', factory);
21    } else if (typeof module == 'object' && module.exports) {
22        // CommonJS - Browserify, Webpack
23        module.exports = factory();
24    } else {
25        // Browser globals
26        global.EvEmitter = factory();
27    }
28
29} (this, function () {
30
31
32
33    function EvEmitter() { }
34
35    var proto = EvEmitter.prototype;
36
37    proto.on = function (eventName, listener) {
38        if (!eventName || !listener) {
39            return;
40        }
41        // set events hash
42        var events = this._events = this._events || {};
43        // set listeners array
44        var listeners = events[eventName] = events[eventName] || [];
45        // only add once
46        if (listeners.indexOf(listener) == -1) {
47            listeners.push(listener);
48        }
49
50        return this;
51    };
52
53    proto.once = function (eventName, listener) {
54        if (!eventName || !listener) {
55            return;
56        }
57        // add event
58        this.on(eventName, listener);
59        // set once flag
60        // set onceEvents hash
61        var onceEvents = this._onceEvents = this._onceEvents || {};
62        // set onceListeners array
63        var onceListeners = onceEvents[eventName] = onceEvents[eventName] || [];
64        // set flag
65        onceListeners[listener] = true;
66
67        return this;
68    };
69
70    proto.off = function (eventName, listener) {
71        var listeners = this._events && this._events[eventName];
72        if (!listeners || !listeners.length) {
73            return;
74        }
75        var index = listeners.indexOf(listener);
76        if (index != -1) {
77            listeners.splice(index, 1);
78        }
79
80        return this;
81    };
82
83    proto.emitEvent = function (eventName, args) {
84        var listeners = this._events && this._events[eventName];
85        if (!listeners || !listeners.length) {
86            return;
87        }
88        var i = 0;
89        var listener = listeners[i];
90        args = args || [];
91        // once stuff
92        var onceListeners = this._onceEvents && this._onceEvents[eventName];
93
94        while (listener) {
95            var isOnce = onceListeners && onceListeners[listener];
96            if (isOnce) {
97                // remove listener
98                // remove before trigger to prevent recursion
99                this.off(eventName, listener);
100                // unset once flag
101                delete onceListeners[listener];
102            }
103            // trigger listener
104            listener.apply(this, args);
105            // get next listener
106            i += isOnce ? 0 : 1;
107            listener = listeners[i];
108        }
109
110        return this;
111    };
112
113    return EvEmitter;
114
115}));
116
117/*!
118* imagesLoaded v4.1.0
119* JavaScript is all like "You images are done yet or what?"
120* MIT License
121*/
122
123(function (window, factory) {
124    'use strict';
125    // universal module definition
126
127    /*global define: false, module: false, require: false */
128
129    if (typeof define == 'function' && define.amd) {
130        // AMD
131        define([
132      'ev-emitter/ev-emitter'
133    ], function (EvEmitter) {
134        return factory(window, EvEmitter);
135    });
136    } else if (typeof module == 'object' && module.exports) {
137        // CommonJS
138        module.exports = factory(
139      window,
140      require('ev-emitter')
141    );
142    } else {
143        // browser global
144        window.imagesLoaded = factory(
145      window,
146      window.EvEmitter
147    );
148    }
149
150})(window,
151
152// --------------------------  factory -------------------------- //
153
154function factory(window, EvEmitter) {
155
156
157
158    var $ = window.jQuery;
159    var console = window.console;
160
161    // -------------------------- helpers -------------------------- //
162
163    // extend objects
164    function extend(a, b) {
165        for (var prop in b) {
166            a[prop] = b[prop];
167        }
168        return a;
169    }
170
171    // turn element or nodeList into an array
172    function makeArray(obj) {
173        var ary = [];
174        if (Array.isArray(obj)) {
175            // use object if already an array
176            ary = obj;
177        } else if (typeof obj.length == 'number') {
178            // convert nodeList to array
179            for (var i = 0; i < obj.length; i++) {
180                ary.push(obj[i]);
181            }
182        } else {
183            // array of single index
184            ary.push(obj);
185        }
186        return ary;
187    }
188
189    // -------------------------- imagesLoaded -------------------------- //
190
191    /**
192    * @param {Array, Element, NodeList, String} elem
193    * @param {Object or Function} options - if function, use as callback
194    * @param {Function} onAlways - callback function
195    */
196    function ImagesLoaded(elem, options, onAlways) {
197        // coerce ImagesLoaded() without new, to be new ImagesLoaded()
198        if (!(this instanceof ImagesLoaded)) {
199            return new ImagesLoaded(elem, options, onAlways);
200        }
201        // use elem as selector string
202        if (typeof elem == 'string') {
203            elem = document.querySelectorAll(elem);
204        }
205
206        this.elements = makeArray(elem);
207        this.options = extend({}, this.options);
208
209        if (typeof options == 'function') {
210            onAlways = options;
211        } else {
212            extend(this.options, options);
213        }
214
215        if (onAlways) {
216            this.on('always', onAlways);
217        }
218
219        this.getImages();
220
221        if ($) {
222            // add jQuery Deferred object
223            this.jqDeferred = new $.Deferred();
224        }
225
226        // HACK check async to allow time to bind listeners
227        setTimeout(function () {
228            this.check();
229        } .bind(this));
230    }
231
232    ImagesLoaded.prototype = Object.create(EvEmitter.prototype);
233
234    ImagesLoaded.prototype.options = {};
235
236    ImagesLoaded.prototype.getImages = function () {
237        this.images = [];
238
239        // filter & find items if we have an item selector
240        this.elements.forEach(this.addElementImages, this);
241    };
242
243    /**
244    * @param {Node} element
245    */
246    ImagesLoaded.prototype.addElementImages = function (elem) {
247        // filter siblings
248        if (elem.nodeName == 'IMG') {
249            this.addImage(elem);
250        }
251        // get background image on element
252        if (this.options.background === true) {
253            this.addElementBackgroundImages(elem);
254        }
255
256        // find children
257        // no non-element nodes, #143
258        var nodeType = elem.nodeType;
259        if (!nodeType || !elementNodeTypes[nodeType]) {
260            return;
261        }
262        var childImgs = elem.querySelectorAll('img');
263        // concat childElems to filterFound array
264        for (var i = 0; i < childImgs.length; i++) {
265            var img = childImgs[i];
266            this.addImage(img);
267        }
268
269        // get child background images
270        if (typeof this.options.background == 'string') {
271            var children = elem.querySelectorAll(this.options.background);
272            for (i = 0; i < children.length; i++) {
273                var child = children[i];
274                this.addElementBackgroundImages(child);
275            }
276        }
277    };
278
279    var elementNodeTypes = {
280        1: true,
281        9: true,
282        11: true
283    };
284
285    ImagesLoaded.prototype.addElementBackgroundImages = function (elem) {
286        var style = getComputedStyle(elem);
287        if (!style) {
288            // Firefox returns null if in a hidden iframe https://bugzil.la/548397
289            return;
290        }
291        // get url inside url("...")
292        var reURL = /url\((['"])?(.*?)\1\)/gi;
293        var matches = reURL.exec(style.backgroundImage);
294        while (matches !== null) {
295            var url = matches && matches[2];
296            if (url) {
297                this.addBackground(url, elem);
298            }
299            matches = reURL.exec(style.backgroundImage);
300        }
301    };
302
303    /**
304    * @param {Image} img
305    */
306    ImagesLoaded.prototype.addImage = function (img) {
307        var loadingImage = new LoadingImage(img);
308        this.images.push(loadingImage);
309    };
310
311    ImagesLoaded.prototype.addBackground = function (url, elem) {
312        var background = new Background(url, elem);
313        this.images.push(background);
314    };
315
316    ImagesLoaded.prototype.check = function () {
317        var _this = this;
318        this.progressedCount = 0;
319        this.hasAnyBroken = false;
320        // complete if no images
321        if (!this.images.length) {
322            this.complete();
323            return;
324        }
325
326        function onProgress(image, elem, message) {
327            // HACK - Chrome triggers event before object properties have changed. #83
328            setTimeout(function () {
329                _this.progress(image, elem, message);
330            });
331        }
332
333        this.images.forEach(function (loadingImage) {
334            loadingImage.once('progress', onProgress);
335            loadingImage.check();
336        });
337    };
338
339    ImagesLoaded.prototype.progress = function (image, elem, message) {
340        this.progressedCount++;
341        this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
342        // progress event
343        this.emitEvent('progress', [this, image, elem]);
344        if (this.jqDeferred && this.jqDeferred.notify) {
345            this.jqDeferred.notify(this, image);
346        }
347        // check if completed
348        if (this.progressedCount == this.images.length) {
349            this.complete();
350        }
351
352        if (this.options.debug && console) {
353            console.log('progress: ' + message, image, elem);
354        }
355    };
356
357    ImagesLoaded.prototype.complete = function () {
358        var eventName = this.hasAnyBroken ? 'fail' : 'done';
359        this.isComplete = true;
360        this.emitEvent(eventName, [this]);
361        this.emitEvent('always', [this]);
362        if (this.jqDeferred) {
363            var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve';
364            this.jqDeferred[jqMethod](this);
365        }
366    };
367
368    // --------------------------  -------------------------- //
369
370    function LoadingImage(img) {
371        this.img = img;
372    }
373
374    LoadingImage.prototype = Object.create(EvEmitter.prototype);
375
376    LoadingImage.prototype.check = function () {
377        // If complete is true and browser supports natural sizes,
378        // try to check for image status manually.
379        var isComplete = this.getIsImageComplete();
380        if (isComplete) {
381            // report based on naturalWidth
382            this.confirm(this.img.naturalWidth !== 0, 'naturalWidth');
383            return;
384        }
385
386        // If none of the checks above matched, simulate loading on detached element.
387        this.proxyImage = new Image();
388        this.proxyImage.addEventListener('load', this);
389        this.proxyImage.addEventListener('error', this);
390        // bind to image as well for Firefox. #191
391        this.img.addEventListener('load', this);
392        this.img.addEventListener('error', this);
393        this.proxyImage.src = this.img.src;
394    };
395
396    LoadingImage.prototype.getIsImageComplete = function () {
397        return this.img.complete && this.img.naturalWidth !== undefined;
398    };
399
400    LoadingImage.prototype.confirm = function (isLoaded, message) {
401        this.isLoaded = isLoaded;
402        this.emitEvent('progress', [this, this.img, message]);
403    };
404
405    // ----- events ----- //
406
407    // trigger specified handler for event type
408    LoadingImage.prototype.handleEvent = function (event) {
409        var method = 'on' + event.type;
410        if (this[method]) {
411            this[method](event);
412        }
413    };
414
415    LoadingImage.prototype.onload = function () {
416        this.confirm(true, 'onload');
417        this.unbindEvents();
418    };
419
420    LoadingImage.prototype.onerror = function () {
421        this.confirm(false, 'onerror');
422        this.unbindEvents();
423    };
424
425    LoadingImage.prototype.unbindEvents = function () {
426        this.proxyImage.removeEventListener('load', this);
427        this.proxyImage.removeEventListener('error', this);
428        this.img.removeEventListener('load', this);
429        this.img.removeEventListener('error', this);
430    };
431
432    // -------------------------- Background -------------------------- //
433
434    function Background(url, element) {
435        this.url = url;
436        this.element = element;
437        this.img = new Image();
438    }
439
440    // inherit LoadingImage prototype
441    Background.prototype = Object.create(LoadingImage.prototype);
442
443    Background.prototype.check = function () {
444        this.img.addEventListener('load', this);
445        this.img.addEventListener('error', this);
446        this.img.src = this.url;
447        // check if image is already complete
448        var isComplete = this.getIsImageComplete();
449        if (isComplete) {
450            this.confirm(this.img.naturalWidth !== 0, 'naturalWidth');
451            this.unbindEvents();
452        }
453    };
454
455    Background.prototype.unbindEvents = function () {
456        this.img.removeEventListener('load', this);
457        this.img.removeEventListener('error', this);
458    };
459
460    Background.prototype.confirm = function (isLoaded, message) {
461        this.isLoaded = isLoaded;
462        this.emitEvent('progress', [this, this.element, message]);
463    };
464
465    // -------------------------- jQuery -------------------------- //
466
467    ImagesLoaded.makeJQueryPlugin = function (jQuery) {
468        jQuery = jQuery || window.jQuery;
469        if (!jQuery) {
470            return;
471        }
472        // set local variable
473        $ = jQuery;
474        // $().imagesLoaded()
475        $.fn.imagesLoaded = function (options, callback) {
476            var instance = new ImagesLoaded(this, options, callback);
477            return instance.jqDeferred.promise($(this));
478        };
479    };
480    // try making plugin
481    ImagesLoaded.makeJQueryPlugin();
482
483    // --------------------------  -------------------------- //
484
485    return ImagesLoaded;
486
487});
488

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.