Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

novicell-lazyload

Package Overview
Dependencies
Maintainers
9
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

novicell-lazyload - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

dist/lazy-images.js

64

js/lazy-images.js

@@ -8,4 +8,4 @@ 'use strict';

import 'lazysizes';
import debounce from 'novicell-debounce/js/novicell.debounce';
import dynamicImage from './novicell.dynamic-image';
import debounce from 'lodash/debounce';
import {dynamicImage} from './novicell.dynamic-image';

@@ -22,2 +22,3 @@ var lastRefreshWidth = 0;

*/
const NovicellLazyLoad = {

@@ -27,25 +28,20 @@ lazyLoad: function (e) {

e.preventDefault = function () {
Object.defineProperty(this, 'defaultPrevented', {
get: function () {
return true;
}
});
Object.defineProperty(this, 'defaultPrevented', {get: function () {return true;}});
};
var target = e.target;
var preventLoad = target.classList.contains('lazyload-measure') || target.classList.contains('lazyload-bg');
var preventLoad = target.classList.contains('lazyload-measure') || target.classList.contains('lazyload-bg');
var setMeasuredUrl = target.classList.contains('lazyload-measure');
var setSrcSet = target.hasAttribute('data-srcset') && target.hasAttribute('data-query-obj');
var setSrc = target.hasAttribute('data-src') && target.hasAttribute('data-query-obj');
if (preventLoad) {
if(preventLoad) {
e.preventDefault();
}
if (setMeasuredUrl) {
var setBg = target.classList.contains('lazyload-bg');
if(setMeasuredUrl) {
var setBg = target.classList.contains('lazyload-bg');
var url = dynamicImage().getUrl(target);
if (setBg) {
target.parentNode.style.backgroundImage = 'url(' + url + ')';
if(setBg) {
target.parentNode.style.backgroundImage = 'url(' + url + ')';
target.style.visibility = 'hidden';

@@ -55,4 +51,5 @@ } else {

}
} else if (setSrcSet) {
}
else if(setSrcSet) {
var query = target.getAttribute('data-query-obj');

@@ -62,7 +59,7 @@ var srcset = target.getAttribute('data-srcset').split(',');

var newSrcset = [];
srcset.forEach(function (src) {
srcset.forEach(function(src){
src = src.trim();
src = src.split(' ');
var url = src[0];

@@ -74,10 +71,11 @@ var bp = src[1];

});
target.setAttribute('srcset', newSrcset.join(', '));
target.setAttribute('src', dynamicImage().queryUrl(src, query));
} else if (setSrc) {
}
else if(setSrc) {
var query = target.getAttribute('data-query-obj');
var src = target.getAttribute('data-src');
var url = dynamicImage().queryUrl(src, query);
target.setAttribute('src', url);

@@ -91,9 +89,11 @@ }

checkImages: function () {
checkImages: function() {
if (window.innerWidth > lastRefreshWidth + refreshWidth || window.innerWidth < lastRefreshWidth - refreshWidth) {
var loadedElements = document.body.querySelectorAll('.lazyloaded');
loadedElements.forEach(function (el) {
el.classList.remove('lazyloaded');
el.classList.add('lazyload');
});
var loadedElements = Array.prototype.slice.call(document.body.querySelectorAll('.lazyloaded'));
if(loadedElements.length > 0) {
loadedElements.map(function(el){
el.classList.remove('lazyloaded');
el.classList.add('lazyload');
});
}
lastRefreshWidth = window.innerWidth;

@@ -110,2 +110,2 @@ };

document.addEventListener('lazybeforeunveil', NovicellLazyLoad.lazyLoad, true);
window.addEventListener('resize', debounce(NovicellLazyLoad.checkImages), 100, false);
window.addEventListener('resize', debounce(NovicellLazyLoad.checkImages), 100, false);

@@ -55,2 +55,2 @@ 'use strict';

export default dynamicImage;
export { dynamicImage };
{
"name": "novicell-lazyload",
"version": "2.0.1",
"version": "2.0.2",
"description": "Novicell script for lazyloading images.",
"main": "index.js",
"main": "dist/lazy-images.js",
"scripts": {

@@ -33,3 +33,7 @@ "test": "echo \"Error: no test specified\" && exit 1"

"novicell-debounce": "^2.0.0"
},
"devDependencies": {
"cssnano": "^4.1.8",
"lodash": "^4.17.11"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc