PluginProbe
Tagembed: Social Media Feeds and Customer Reviews Widget / 7.8
Tagembed: Social Media Feeds and Customer Reviews Widget v7.8
7.8 7.5 7.6 7.7 7.4 trunk 3.10 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 All 43 releases
← All changes | assets/js/lazyload.js +22 -64 4.0 → 7.8 View file →
@@ -1,19 +1,4 @@
1 -/*!
2 - * Lazy Load - JavaScript plugin for lazy loading images
3 - *
4 - * Copyright (c) 2007-2019 Mika Tuupola
5 - *
6 - * Licensed under the MIT license:
7 - * http://www.opensource.org/licenses/mit-license.php
8 - *
9 - * Project home:
10 - * https://appelsiini.net/projects/lazyload
11 - *
12 - * Version: 2.0.0-rc.2
13 - *
14 - */
15 -
16 1 (function (root, factory) {
17 2 if (typeof exports === "object") {
18 3 module.exports = factory(root);
19 4 } else if (typeof define === "function" && define.amd) {
@@ -18,18 +3,15 @@
18 3 module.exports = factory(root);
19 4 } else if (typeof define === "function" && define.amd) {
20 5 define([], factory);
21 6 } else {
22 - root.LazyLoad = factory(root);
7 + root.__tagembed__LazyLoad = factory(root);
23 8 }
24 -}) (typeof global !== "undefined" ? global : this.window || this.global, function (root) {
25 -
9 +})(typeof global !== "undefined" ? global : this.window || this.global, function (root) {
26 10 "use strict";
27 -
28 - if (typeof define === "function" && define.amd){
11 + if (typeof define === "function" && define.amd) {
29 12 root = window;
30 13 }
31 -
32 14 const defaults = {
33 15 src: "data-src",
34 16 srcset: "data-srcset",
35 17 selector: ".lazyload",
@@ -36,30 +18,17 @@
36 18 root: null,
37 19 rootMargin: "0px",
38 20 threshold: 0
39 21 };
40 -
41 - /**
42 - * Merge two or more objects. Returns a new object.
43 - * @private
44 - * @param {Boolean} deep If true, do a deep (or recursive) merge [optional]
45 - * @param {Object} objects The objects to merge together
46 - * @returns {Object} Merged values of defaults and options
47 - */
48 - const extend = function () {
49 -
22 + const extend = function () {
50 23 let extended = {};
51 24 let deep = false;
52 25 let i = 0;
53 26 let length = arguments.length;
54 -
55 - /* Check if a deep merge */
56 27 if (Object.prototype.toString.call(arguments[0]) === "[object Boolean]") {
57 28 deep = arguments[0];
58 29 i++;
59 30 }
60 -
61 - /* Merge the object into the extended object */
62 31 let merge = function (obj) {
63 32 for (let prop in obj) {
64 33 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
65 34 /* If deep merge and property is an object, merge properties */
@@ -70,34 +39,26 @@
70 39 }
71 40 }
72 41 }
73 42 };
74 -
75 - /* Loop through each object and conduct a merge */
76 43 for (; i < length; i++) {
77 44 let obj = arguments[i];
78 45 merge(obj);
79 46 }
80 -
81 47 return extended;
82 48 };
83 -
84 - function LazyLoad(images, options) {
49 + function __tagembed__LazyLoad(images, options) {
85 50 this.settings = extend(defaults, options || {});
86 51 this.images = images || document.querySelectorAll(this.settings.selector);
87 52 this.observer = null;
88 53 this.init();
89 54 }
90 -
91 - LazyLoad.prototype = {
92 - init: function() {
93 -
94 - /* Without observers load everything and bail out early. */
55 + __tagembed__LazyLoad.prototype = {
56 + init: function () {
95 57 if (!root.IntersectionObserver) {
96 58 this.loadImages();
97 59 return;
98 60 }
99 -
100 61 let self = this;
101 62 let observerConfig = {
102 63 root: this.settings.root,
103 64 rootMargin: this.settings.rootMargin,
@@ -102,10 +63,9 @@
102 63 root: this.settings.root,
103 64 rootMargin: this.settings.rootMargin,
104 65 threshold: [this.settings.threshold]
105 66 };
106 -
107 - this.observer = new IntersectionObserver(function(entries) {
67 + this.observer = new IntersectionObserver(function (entries) {
108 68 Array.prototype.forEach.call(entries, function (entry) {
109 69 if (entry.isIntersecting) {
110 70 self.observer.unobserve(entry.target);
111 71 let src = entry.target.getAttribute(self.settings.src);
@@ -122,23 +82,23 @@
122 82 }
123 83 }
124 84 });
125 85 }, observerConfig);
126 -
127 86 Array.prototype.forEach.call(this.images, function (image) {
128 87 self.observer.observe(image);
129 88 });
130 89 },
131 -
132 90 loadAndDestroy: function () {
133 - if (!this.settings) { return; }
91 + if (!this.settings) {
92 + return;
93 + }
134 94 this.loadImages();
135 95 this.destroy();
136 96 },
137 -
138 97 loadImages: function () {
139 - if (!this.settings) { return; }
140 -
98 + if (!this.settings) {
99 + return;
100 + }
141 101 let self = this;
142 102 Array.prototype.forEach.call(this.images, function (image) {
143 103 let src = image.getAttribute(self.settings.src);
144 104 let srcset = image.getAttribute(self.settings.srcset);
@@ -153,28 +113,26 @@
153 113 image.style.backgroundImage = "url('" + src + "')";
154 114 }
155 115 });
156 116 },
157 -
158 117 destroy: function () {
159 - if (!this.settings) { return; }
118 + if (!this.settings) {
119 + return;
120 + }
160 121 this.observer.disconnect();
161 122 this.settings = null;
162 123 }
163 124 };
164 -
165 - root.lazyload = function(images, options) {
166 - return new LazyLoad(images, options);
125 + root.__tagembed__lazyload = function (images, options) {
126 + return new __tagembed__LazyLoad(images, options);
167 127 };
168 -
169 128 if (root.jQuery) {
170 129 const $ = root.jQuery;
171 - $.fn.lazyload = function (options) {
130 + $.fn.__tagembed__lazyload = function (options) {
172 131 options = options || {};
173 132 options.attribute = options.attribute || "data-src";
174 - new LazyLoad($.makeArray(this), options);
133 + new __tagembed__LazyLoad($.makeArray(this), options);
175 134 return this;
176 135 };
177 136 }
178 -
179 - return LazyLoad;
137 + return __tagembed__LazyLoad;
180 138 });