novicell-lazyload
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106656
8
1352
2
1
2