Comparing version 1.0.9 to 1.1.0
@@ -1,4 +0,4 @@ | ||
/*! lozad.js - v1.0.9 - 2017-10-25 | ||
/*! lozad.js - v1.1.0 - 2018-01-18 | ||
* https://github.com/ApoorvSaxena/lozad.js | ||
* Copyright (c) 2017 Apoorv Saxena; Licensed MIT */ | ||
* Copyright (c) 2018 Apoorv Saxena; Licensed MIT */ | ||
@@ -53,2 +53,12 @@ | ||
var getElements = function getElements(selector) { | ||
if (selector instanceof Element) { | ||
return [selector]; | ||
} | ||
if (selector instanceof NodeList) { | ||
return selector; | ||
} | ||
return document.querySelectorAll(selector); | ||
}; | ||
var lozad = function () { | ||
@@ -74,3 +84,4 @@ var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.lozad'; | ||
observe: function observe() { | ||
var elements = document.querySelectorAll(selector); | ||
var elements = getElements(selector); | ||
for (var i = 0; i < elements.length; i++) { | ||
@@ -77,0 +88,0 @@ if (isLoaded(elements[i])) { |
@@ -1,4 +0,4 @@ | ||
/*! lozad.js - v1.0.9 - 2017-10-25 | ||
/*! lozad.js - v1.1.0 - 2018-01-18 | ||
* https://github.com/ApoorvSaxena/lozad.js | ||
* Copyright (c) 2017 Apoorv Saxena; Licensed MIT */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.lozad=e()}(this,function(){"use strict";function t(t){t.setAttribute("data-loaded",!0)}var e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},r={rootMargin:"0px",threshold:0,load:function(t){t.getAttribute("data-src")&&(t.src=t.getAttribute("data-src")),t.getAttribute("data-srcset")&&(t.srcset=t.getAttribute("data-srcset")),t.getAttribute("data-background-image")&&(t.style.backgroundImage="url("+t.getAttribute("data-background-image")+")")}},o=function(t){return"true"===t.getAttribute("data-loaded")},n=function(e){return function(r,n){r.forEach(function(r){r.intersectionRatio>0&&(n.unobserve(r.target),o(r.target)||(e(r.target),t(r.target)))})}};return function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:".lozad",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=e({},r,i),d=u.rootMargin,c=u.threshold,s=u.load,g=void 0;return window.IntersectionObserver&&(g=new IntersectionObserver(n(s),{rootMargin:d,threshold:c})),{observe:function(){for(var e=document.querySelectorAll(a),r=0;r<e.length;r++)o(e[r])||(g?g.observe(e[r]):(s(e[r]),t(e[r])))},triggerLoad:function(e){o(e)||(s(e),t(e))}}}}); | ||
* Copyright (c) 2018 Apoorv Saxena; Licensed MIT */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.lozad=e()}(this,function(){"use strict";function t(t){t.setAttribute("data-loaded",!0)}var e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},r={rootMargin:"0px",threshold:0,load:function(t){t.getAttribute("data-src")&&(t.src=t.getAttribute("data-src")),t.getAttribute("data-srcset")&&(t.srcset=t.getAttribute("data-srcset")),t.getAttribute("data-background-image")&&(t.style.backgroundImage="url("+t.getAttribute("data-background-image")+")")}},n=function(t){return"true"===t.getAttribute("data-loaded")},o=function(e){return function(r,o){r.forEach(function(r){r.intersectionRatio>0&&(o.unobserve(r.target),n(r.target)||(e(r.target),t(r.target)))})}},a=function(t){return t instanceof Element?[t]:t instanceof NodeList?t:document.querySelectorAll(t)};return function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:".lozad",u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},d=e({},r,u),c=d.rootMargin,s=d.threshold,f=d.load,g=void 0;return window.IntersectionObserver&&(g=new IntersectionObserver(o(f),{rootMargin:c,threshold:s})),{observe:function(){for(var e=a(i),r=0;r<e.length;r++)n(e[r])||(g?g.observe(e[r]):(f(e[r]),t(e[r])))},triggerLoad:function(e){n(e)||(f(e),t(e))}}}}); |
@@ -5,3 +5,3 @@ { | ||
"description": "A light-weight JS library to lazy load any HTML element such as images, ads, videos etc.", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/ApoorvSaxena/lozad.js", | ||
@@ -17,3 +17,4 @@ "scripts": { | ||
"serve": "browser-sync start --server \"demo\" --server \".\" --files \"demo\" --files \"dist\" --port 3000", | ||
"dev": "run-p -r serve build:watch" | ||
"dev": "run-p -r serve build:watch", | ||
"tag": "npm version minor --no-git-tag-version && npm run build && PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git commit -am \"$PACKAGE_VERSION release\" && git tag v$PACKAGE_VERSION" | ||
}, | ||
@@ -20,0 +21,0 @@ "author": { |
@@ -83,2 +83,8 @@ # Lozad.js [![npm version](https://badge.fury.io/js/lozad.svg)](https://badge.fury.io/js/lozad) [![Build Status](https://travis-ci.org/ApoorvSaxena/lozad.js.svg?branch=master)](https://travis-ci.org/ApoorvSaxena/lozad.js) [![](https://data.jsdelivr.com/v1/package/npm/lozad/badge)](https://www.jsdelivr.com/package/npm/lozad) | ||
``` | ||
or with a DOM `Element` reference: | ||
```js | ||
const el = document.querySelector('img'); | ||
const observer = lozad(el); // passing a `NodeList` (e.g. `document.querySelectorAll()`) is also valid | ||
observer.observe(); | ||
``` | ||
or with custom options: | ||
@@ -154,2 +160,3 @@ ```js | ||
* [gis.utah.gov](https://gis.utah.gov) | ||
* *[Add your site]* - See [Contributing section](./CONTRIBUTING.md) | ||
@@ -156,0 +163,0 @@ |
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
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
14697
101
179