PageSourceSearch

https://www.prodital.it/js/vendor/owl.lazyload.js

js prodital.it collected 2026-10-04 22:25:13 UTC 3,375 bytes, 134 lines download raw bytes

vendor: 3,375 bytes, lines 1-134
1/**
2 * Lazy Plugin
3 * @version 2.0.0
4 * @author Bartosz Wojciechowski
5 * @license The MIT License (MIT)
6 */
7;(function($, window, document, undefined) {
8
9	/**
10	 * Creates the lazy plugin.
11	 * @class The Lazy Plugin
12	 * @param {Owl} carousel - The Owl Carousel
13	 */
14	var Lazy = function(carousel) {
15
16		/**
17		 * Reference to the core.
18		 * @protected
19		 * @type {Owl}
20		 */
21		this._core = carousel;
22
23		/**
24		 * Already loaded items.
25		 * @protected
26		 * @type {Array.<jQuery>}
27		 */
28		this._loaded = [];
29
30		/**
31		 * Event handlers.
32		 * @protected
33		 * @type {Object}
34		 */
35		this._handlers = {
36			'initialized.owl.carousel change.owl.carousel': $.proxy(function(e) {
37				if (!e.namespace) {
38					return;
39				}
40
41				if (!this._core.settings || !this._core.settings.lazyLoad) {
42					return;
43				}
44
45				if ((e.property && e.property.name == 'position') || e.type == 'initialized') {
46					var settings = this._core.settings,
47						n = (settings.center && Math.ceil(settings.items / 2) || settings.items),
48						i = ((settings.center && n * -1) || 0),
49						position = ((e.property && e.property.value) || this._core.current()) + i,
50						clones = this._core.clones().length,
51						load = $.proxy(function(i, v) { this.load(v) }, this);
52
53					while (i++ < n) {
54						this.load(clones / 2 + this._core.relative(position));
55						clones && $.each(this._core.clones(this._core.relative(position)), load);
56						position++;
57					}
58				}
59			}, this)
60		};
61
62		// set the default options
63		this._core.options = $.extend({}, Lazy.Defaults, this._core.options);
64
65		// register event handler
66		this._core.$element.on(this._handlers);
67	}
68
69	/**
70	 * Default options.
71	 * @public
72	 */
73	Lazy.Defaults = {
74		lazyLoad: false
75	}
76
77	/**
78	 * Loads all resources of an item at the specified position.
79	 * @param {Number} position - The absolute position of the item.
80	 * @protected
81	 */
82	Lazy.prototype.load = function(position) {
83		var $item = this._core.$stage.children().eq(position),
84			$elements = $item && $item.find('.owl-lazy');
85
86		if (!$elements || $.inArray($item.get(0), this._loaded) > -1) {
87			return;
88		}
89
90		$elements.each($.proxy(function(index, element) {
91			var $element = $(element), image,
92				url = (window.devicePixelRatio > 1 && $element.attr('data-src-retina')) || $element.attr('data-src');
93
94			this._core.trigger('load', { element: $element, url: url }, 'lazy');
95
96			if ($element.is('img')) {
97				$element.one('load.owl.lazy', $.proxy(function() {
98					$element.css('opacity', 1);
99					this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
100				}, this)).attr('src', url);
101			} else {
102				image = new Image();
103				image.onload = $.proxy(function() {
104					$element.css({
105						'background-image': 'url(' + url + ')',
106						'opacity': '1'
107					});
108					this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
109				}, this);
110				image.src = url;
111			}
112		}, this));
113
114		this._loaded.push($item.get(0));
115	}
116
117	/**
118	 * Destroys the plugin.
119	 * @public
120	 */
121	Lazy.prototype.destroy = function() {
122		var handler, property;
123
124		for (handler in this.handlers) {
125			this._core.$element.off(handler, this.handlers[handler]);
126		}
127		for (property in Object.getOwnPropertyNames(this)) {
128			typeof this[property] != 'function' && (this[property] = null);
129		}
130	};
131
132	$.fn.owlCarousel.Constructor.Plugins.Lazy = Lazy;
133
134})(window.Zepto || window.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.