Socket
Socket
Sign inDemoInstall

lazyload

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-beta.2 to 2.0.0-rc.1

29

lazyload.js
/*!
* Lazy Load - JavaScript plugin for lazy loading images
*
* Copyright (c) 2007-2017 Mika Tuupola
* Copyright (c) 2007-2019 Mika Tuupola
*

@@ -12,3 +12,3 @@ * Licensed under the MIT license:

*
* Version: 2.0.0-beta.2
* Version: 2.0.0-rc.1
*

@@ -21,3 +21,3 @@ */

} else if (typeof define === "function" && define.amd) {
define([], factory(root));
define([], factory);
} else {

@@ -30,6 +30,13 @@ root.LazyLoad = factory(root);

if (typeof define === "function" && define.amd){
root = window;
}
const defaults = {
src: "data-src",
srcset: "data-srcset",
selector: ".lazyload"
selector: ".lazyload",
root: null,
rootMargin: "0px",
threshold: 0
};

@@ -98,9 +105,9 @@

let observerConfig = {
root: null,
rootMargin: "0px",
threshold: [0]
root: this.settings.root,
rootMargin: this.settings.rootMargin,
threshold: [this.settings.threshold]
};
this.observer = new IntersectionObserver(function(entries) {
entries.forEach(function (entry) {
Array.prototype.forEach.call(entries, function (entry) {
if (entry.intersectionRatio > 0) {

@@ -124,3 +131,3 @@ self.observer.unobserve(entry.target);

this.images.forEach(function (image) {
Array.prototype.forEach.call(this.images, function (image) {
self.observer.observe(image);

@@ -140,3 +147,3 @@ });

let self = this;
this.images.forEach(function (image) {
Array.prototype.forEach.call(this.images, function (image) {
let src = image.getAttribute(self.settings.src);

@@ -152,3 +159,3 @@ let srcset = image.getAttribute(self.settings.srcset);

} else {
image.style.backgroundImage = "url(" + src + ")";
image.style.backgroundImage = "url('" + src + "')";
}

@@ -155,0 +162,0 @@ });

@@ -1,2 +0,2 @@

/*! Lazy Load 2.0.0-beta.2 - MIT license - Copyright 2007-2017 Mika Tuupola */
!function(t,e){"object"==typeof exports?module.exports=e(t):"function"==typeof define&&define.amd?define([],e(t)):t.LazyLoad=e(t)}("undefined"!=typeof global?global:this.window||this.global,function(t){"use strict";function e(t,e){this.settings=r(s,e||{}),this.images=t||document.querySelectorAll(this.settings.selector),this.observer=null,this.init()}const s={src:"data-src",srcset:"data-srcset",selector:".lazyload"},r=function(){let t={},e=!1,s=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],s++);for(;s<o;s++)!function(s){for(let o in s)Object.prototype.hasOwnProperty.call(s,o)&&(e&&"[object Object]"===Object.prototype.toString.call(s[o])?t[o]=r(!0,t[o],s[o]):t[o]=s[o])}(arguments[s]);return t};if(e.prototype={init:function(){if(!t.IntersectionObserver)return void this.loadImages();let e=this,s={root:null,rootMargin:"0px",threshold:[0]};this.observer=new IntersectionObserver(function(t){t.forEach(function(t){if(t.intersectionRatio>0){e.observer.unobserve(t.target);let s=t.target.getAttribute(e.settings.src),r=t.target.getAttribute(e.settings.srcset);"img"===t.target.tagName.toLowerCase()?(s&&(t.target.src=s),r&&(t.target.srcset=r)):t.target.style.backgroundImage="url("+s+")"}})},s),this.images.forEach(function(t){e.observer.observe(t)})},loadAndDestroy:function(){this.settings&&(this.loadImages(),this.destroy())},loadImages:function(){if(!this.settings)return;let t=this;this.images.forEach(function(e){let s=e.getAttribute(t.settings.src),r=e.getAttribute(t.settings.srcset);"img"===e.tagName.toLowerCase()?(s&&(e.src=s),r&&(e.srcset=r)):e.style.backgroundImage="url("+s+")"})},destroy:function(){this.settings&&(this.observer.disconnect(),this.settings=null)}},t.lazyload=function(t,s){return new e(t,s)},t.jQuery){const s=t.jQuery;s.fn.lazyload=function(t){return t=t||{},t.attribute=t.attribute||"data-src",new e(s.makeArray(this),t),this}}return e});
/*! Lazy Load 2.0.0-rc.1 - MIT license - Copyright 2007-2019 Mika Tuupola */
!function(t,e){"object"==typeof exports?module.exports=e(t):"function"==typeof define&&define.amd?define([],e):t.LazyLoad=e(t)}("undefined"!=typeof global?global:this.window||this.global,function(t){"use strict";function e(t,e){this.settings=s(r,e||{}),this.images=t||document.querySelectorAll(this.settings.selector),this.observer=null,this.init()}"function"==typeof define&&define.amd&&(t=window);const r={src:"data-src",srcset:"data-srcset",selector:".lazyload",root:null,rootMargin:"0px",threshold:0},s=function(){let t={},e=!1,r=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],r++);for(;r<o;r++)!function(r){for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e&&"[object Object]"===Object.prototype.toString.call(r[o])?t[o]=s(!0,t[o],r[o]):t[o]=r[o])}(arguments[r]);return t};if(e.prototype={init:function(){if(!t.IntersectionObserver)return void this.loadImages();let e=this,r={root:this.settings.root,rootMargin:this.settings.rootMargin,threshold:[this.settings.threshold]};this.observer=new IntersectionObserver(function(t){Array.prototype.forEach.call(t,function(t){if(t.intersectionRatio>0){e.observer.unobserve(t.target);let r=t.target.getAttribute(e.settings.src),s=t.target.getAttribute(e.settings.srcset);"img"===t.target.tagName.toLowerCase()?(r&&(t.target.src=r),s&&(t.target.srcset=s)):t.target.style.backgroundImage="url("+r+")"}})},r),Array.prototype.forEach.call(this.images,function(t){e.observer.observe(t)})},loadAndDestroy:function(){this.settings&&(this.loadImages(),this.destroy())},loadImages:function(){if(!this.settings)return;let t=this;Array.prototype.forEach.call(this.images,function(e){let r=e.getAttribute(t.settings.src),s=e.getAttribute(t.settings.srcset);"img"===e.tagName.toLowerCase()?(r&&(e.src=r),s&&(e.srcset=s)):e.style.backgroundImage="url('"+r+"')"})},destroy:function(){this.settings&&(this.observer.disconnect(),this.settings=null)}},t.lazyload=function(t,r){return new e(t,r)},t.jQuery){const r=t.jQuery;r.fn.lazyload=function(t){return t=t||{},t.attribute=t.attribute||"data-src",new e(r.makeArray(this),t),this}}return e});
The MIT License (MIT)
=====================
Copyright (c) 2007-2017 Mika Tuupola
Copyright (c) 2007-2019 Mika Tuupola

@@ -6,0 +6,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "lazyload",
"version": "2.0.0-beta.2",
"version": "2.0.0-rc.1",
"description": "Vanilla JavaScript plugin for lazyloading images",
"main": "lazyload.js",
"repository": "https://github.com/tuupola/jquery_lazyload.git",
"repository": "https://github.com/tuupola/lazyload.git",
"author": "Mika Tuupola <tuupola@appelsiini.net>",

@@ -8,0 +8,0 @@ "license": "MIT",

@@ -12,3 +12,3 @@ # [WIP] Lazy Load Remastered

```html
<script src="https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.1/lazyload.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lazyload@2.0.0-rc.1/lazyload.js"></script>

@@ -39,2 +39,12 @@ <img class="lazyload" data-src="img/example.jpg" width="765" height="574" />

The core IntersectionObserver can be configured by passing an additional argument
```js
new LazyLoad(images, {
root: null,
rootMargin: "0px",
threshold: 0
});
```
## Additional API

@@ -41,0 +51,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc