diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..57b3aaf3 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "script" + }, + "env": { + "browser": true, + "jest": true + }, + "rules": { + "eqeqeq": "off", + "curly": "error", + "quotes": ["error", "double"] + } +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 897feec5..403b1dbb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,58 +1,48 @@ module.exports = function (grunt) { grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + pkg: grunt.file.readJSON("package.json"), babel: { options: { sourceMap: false, - presets: ['es2015'], + presets: ["es2015"], plugins: ["transform-object-assign"] }, dist: { files: { - 'dist/lazyload.transpiled.js': 'src/lazyload.js' + "dist/lazyload.transpiled.js": "src/lazyload.js" } } }, uglify: { options: { - banner: '', + banner: "", sourceMap: true }, dist: { files: { - 'dist/lazyload.min.js': 'src/lazyload.js', - 'dist/lazyload.transpiled.min.js': 'dist/lazyload.transpiled.js', + "dist/lazyload.min.js": "src/lazyload.js", + "dist/lazyload.transpiled.min.js": "dist/lazyload.transpiled.js", } } }, - jshint: { - files: ['Gruntfile.js', 'src/lazyload.js'], - + eslint: { options: { - // options here to override JSHint defaults - reporterOutput: '', - globals: { - jQuery: true, - console: true, - module: true, - document: true - }, - 'esnext': true - } + configFile: ".eslintrc.json" + }, + src: ["src/lazyload.js"] }, watch: { - files: ['<%= jshint.files %>'], - tasks: ['jshint', 'babel', 'uglify'] + files: ["<%= eslint.src %>"], + tasks: ["eslint", "babel", "uglify"] } }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-babel'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks("gruntify-eslint"); + grunt.loadNpmTasks("grunt-babel"); + grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.registerTask('default', ['jshint', 'babel', 'uglify', 'watch']); - grunt.registerTask('publish', ['jshint', 'babel', 'uglify']); + grunt.registerTask("default", ["eslint", "babel", "uglify"]); + grunt.registerTask("watch", ["eslint", "babel", "uglify", "watch"]); }; \ No newline at end of file diff --git a/__test__/lazyload.test.js b/__test__/lazyload.test.js index 7d4eb255..dfd197c3 100644 --- a/__test__/lazyload.test.js +++ b/__test__/lazyload.test.js @@ -1,11 +1,11 @@ -const LazyLoad = require('../src/lazyLoad'); +const LazyLoad = require("../src/lazyLoad"); test("Public methods", () => { const ll = new LazyLoad(); - ['update', - 'handleScroll', - 'destroy'].forEach((methodName) => { - expect(typeof ll[methodName]).toBe('function'); + ["update", + "handleScroll", + "destroy"].forEach((methodName) => { + expect(typeof ll[methodName]).toBe("function"); }); }); @@ -71,8 +71,8 @@ describe("Constructor", () => { }); test("QueryOriginNode is valid", () => { - const scrollArea = document.createElement('div'); - scrollArea.classList.add('scrollArea'); + const scrollArea = document.createElement("div"); + scrollArea.classList.add("scrollArea"); window.document.documentElement.appendChild(scrollArea); const ll1 = new LazyLoad(); const ll2 = new LazyLoad({ @@ -102,14 +102,14 @@ test("Resize is managed", () => { }); /* - * Can't test _isInsideViewport because the DOM implementation is not correct + * Can"t test _isInsideViewport because the DOM implementation is not correct * (same test on codepen returns true) * will test using Jasmine/Sinon/Karma, maybe */ /* describe("_isInsideViewport", () => { test("...affermative - window container - position static - no threshold", () => { - const img = document.createElement('img'); + const img = document.createElement("img"); img.src="http://placehold.it/1x1"; img.style="width:300px; height:300px;"; document.body.appendChild(img); @@ -126,14 +126,14 @@ describe("_setSourcesForPicture", () => { let img100 = "http://placehold.it/100x100"; let img200 = "http://placehold.it/200x200"; let img400 = "http://placehold.it/400x400"; - let dataSrcSetPartialAttr = 'original-set'; - let dataSrcSetAttr = 'data-' + dataSrcSetPartialAttr; - let srcsetAttr = 'srcset'; + let dataSrcSetPartialAttr = "original-set"; + let dataSrcSetAttr = "data-" + dataSrcSetPartialAttr; + let srcsetAttr = "srcset"; beforeEach(() => { - p = document.createElement('picture'); - p.appendChild(s1 = document.createElement('source')); - p.appendChild(s2 = document.createElement('source')); - p.appendChild(i = document.createElement('img')); + p = document.createElement("picture"); + p.appendChild(s1 = document.createElement("source")); + p.appendChild(s2 = document.createElement("source")); + p.appendChild(i = document.createElement("img")); }); test("...with initially empty srcset", () => { s1.setAttribute(dataSrcSetAttr, img200); @@ -170,14 +170,14 @@ describe("_setSources for image", () => { let img100 = "http://placehold.it/100x100"; let img200 = "http://placehold.it/200x200"; let img400 = "http://placehold.it/400x400"; - let dataSrcPartialAttr = 'original'; - let dataSrcSetPartialAttr = 'original-set'; - let dataSrcAttr = 'data-' + dataSrcPartialAttr; - let dataSrcSetAttr = 'data-' + dataSrcSetPartialAttr; - let srcAttr = 'src'; - let srcSetAttr = 'srcset'; + let dataSrcPartialAttr = "original"; + let dataSrcSetPartialAttr = "original-set"; + let dataSrcAttr = "data-" + dataSrcPartialAttr; + let dataSrcSetAttr = "data-" + dataSrcSetPartialAttr; + let srcAttr = "src"; + let srcSetAttr = "srcset"; beforeEach(() => { - i = document.createElement('img'); + i = document.createElement("img"); }); test("...with initially empty src and srcset", () => { fakeInstance._setSourcesForPicture.mockClear(); @@ -216,11 +216,11 @@ describe("_setSources for iframe", () => { let i; let testFunct = LazyLoad.prototype._setSources; let srcToLoad = "http://www.google.it"; - let dataSrcPartialAttr = 'original'; - let dataSrcAttr = 'data-' + dataSrcPartialAttr; - let srcAttr = 'src'; + let dataSrcPartialAttr = "original"; + let dataSrcAttr = "data-" + dataSrcPartialAttr; + let srcAttr = "src"; beforeEach(() => { - i = document.createElement('iframe'); + i = document.createElement("iframe"); }); test("...with initially empty src", () => { i.setAttribute(dataSrcAttr, srcToLoad); @@ -247,23 +247,23 @@ describe("_setSources for background image", () => { let testFunct = LazyLoad.prototype._setSources; let img100 = "http://placehold.it/100x100"; let img200 = "http://placehold.it/200x200"; - let dataSrcPartialAttr = 'original'; - let dataSrcAttr = 'data-' + dataSrcPartialAttr; + let dataSrcPartialAttr = "original"; + let dataSrcAttr = "data-" + dataSrcPartialAttr; test("...with initially empty style attribute", () => { - i = document.createElement('div'); + i = document.createElement("div"); i.setAttribute(dataSrcAttr, img200); testFunct(i, "", dataSrcPartialAttr); expect(i.style.backgroundImage).toBe("url("+img200+")"); }); test("...with initially present style attribute", () => { - i = document.createElement('div'); + i = document.createElement("div"); i.style.padding = "1px"; i.setAttribute(dataSrcAttr, img200); testFunct(i, "", dataSrcPartialAttr); expect(i.style.backgroundImage).toBe("url("+img200+")"); }); test("...with initially present style and background", () => { - i = document.createElement('div'); + i = document.createElement("div"); i.style.backgroundImage = "url("+img100+")"; i.setAttribute(dataSrcAttr, img200); testFunct(i, "", dataSrcPartialAttr); diff --git a/dist/lazyload.min.js.map b/dist/lazyload.min.js.map index 869c8ac1..eaa78701 100644 --- a/dist/lazyload.min.js.map +++ b/dist/lazyload.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/lazyload.js"],"names":["root","factory","define","amd","exports","module","LazyLoad","window","_isBot","test","navigator","userAgent","_getTopOffset","element","getBoundingClientRect","top","pageYOffset","ownerDocument","documentElement","clientTop","_isBelowViewport","container","threshold","innerHeight","offsetHeight","_getLeftOffset","left","pageXOffset","clientLeft","_isAtRightOfViewport","documentWidth","innerWidth","_isAboveViewport","_isAtLeftOfViewport","offsetWidth","_isInsideViewport","_callCallback","callback","argument","_createInstance","options","instance","event","CustomEvent","detail","dispatchEvent","_defaultSettings","elements_selector","throttle","data_src","data_srcset","class_loading","class_loaded","class_error","class_initial","skip_invisible","callback_load","callback_error","callback_set","callback_processed","[object Object]","instanceSettings","this","_settings","Object","assign","_queryOriginNode","document","_previousLoopTime","_loopTimeout","_boundHandleScroll","handleScroll","bind","_isFirstLoop","addEventListener","update","srcsetDataAttribute","parent","parentElement","tagName","i","children","length","pictureChild","sourceSrcset","getAttribute","setAttribute","srcDataAttribute","elementSrc","_setSourcesForPicture","imgSrcset","style","backgroundImage","settings","errorCallback","removeEventListener","loadCallback","classList","remove","add","_setSources","elements","_elements","elementsLength","processedIndexes","firstLoop","offsetParent","_showOnAppear","push","wasProcessed","splice","pop","_stopScrollHandler","elementsToPurge","_isHandlingScroll","getTime","Date","now","remainingTime","clearTimeout","_loopThroughElements","setTimeout","Array","prototype","slice","call","querySelectorAll","_purgeElements","_startScrollHandler","autoInitOptions","lazyLoadOptions","optsLength"],"mappings":"CAAC,SAAUA,EAAMC,GACS,kBAAXC,SAAyBA,OAAOC,IACvCD,UAAWD,GACe,gBAAZG,SACdC,OAAOD,QAAUH,IAEjBD,EAAKM,SAAWL,KAEtBM,OAAQ,WAEN,KAAMC,KAAW,YAAcD,UAAW,SAASE,KAAKC,UAAUC,WAE5DC,EAAgB,SAAUC,GAC5B,MAAOA,GAAQC,wBAAwBC,IAAMR,OAAOS,YAAcH,EAAQI,cAAcC,gBAAgBC,WAGtGC,EAAmB,SAAUP,EAASQ,EAAWC,GAInD,OAHcD,IAAcd,OACxBA,OAAOgB,YAAchB,OAAOS,YAC5BJ,EAAcS,GAAaA,EAAUG,eAC1BZ,EAAcC,GAAWS,GAGtCG,EAAiB,SAAUZ,GAC7B,MAAOA,GAAQC,wBAAwBY,KAAOnB,OAAOoB,YAAcd,EAAQI,cAAcC,gBAAgBU,YAGvGC,EAAuB,SAAUhB,EAASQ,EAAWC,GACvD,KAAMQ,GAAgBvB,OAAOwB,UAI7B,QAHcV,IAAcd,OACxBuB,EAAgBvB,OAAOoB,YACvBF,EAAeJ,GAAaS,IACjBL,EAAeZ,GAAWS,GAGvCU,EAAmB,SAAUnB,EAASQ,EAAWC,GAEnD,OADcD,IAAcd,OAAUA,OAAOS,YAAcJ,EAAcS,KAC1DT,EAAcC,GAAWS,EAAYT,EAAQW,cAG1DS,EAAsB,SAAUpB,EAASQ,EAAWC,GAEtD,OADcD,IAAcd,OAAUA,OAAOoB,YAAcF,EAAeJ,KAC3DI,EAAeZ,GAAWS,EAAYT,EAAQqB,a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KAAKO,eACbP,KAAKO,aAAeoD,WAAW,WAC3B3D,KAAKM,kBAAoB+C,IACzBrD,KAAKO,aAAe,KACpBP,KAAK0D,wBACPhD,KAAKV,MAAOwD,QAGlBxD,MAAK0D,uBAIb5D,SAEIE,KAAKwC,UAAYoB,MAAMC,UAAUC,MAAMC,KAAK/D,KAAKI,iBAAiB4D,iBAAiBhE,KAAKC,UAAUhB,oBAClGe,KAAKiE,iBACLjE,KAAK0D,uBACL1D,KAAKkE,sBAGTpE,UACIrD,OAAOwF,oBAAoB,SAAUjC,KAAKQ,oBACtCR,KAAKO,eACLkD,aAAazD,KAAKO,cAClBP,KAAKO,aAAe,MAExBP,KAAKkD,qBACLlD,KAAKwC,UAAY,KACjBxC,KAAKI,iBAAmB,KACxBJ,KAAKC,UAAY,MAKzB,GAAIkE,GAAkB1H,OAAO2H,eAG7B,OAFID,IA/OoB,SAASzF,GAC7B,GAAI2F,GAAa3F,EAAQ0C,MACzB,IAAKiD,EAMD,IAAK,GAAInD,GAAE,EAAGA,EAAEmD,EAAYnD,IACxBzC,EAAgBC,EAAQwC,QAL5BzC,GAAgBC,IA2OeyF,GAEhC3H","file":"lazyload.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/lazyload.js"],"names":["root","factory","define","amd","exports","module","LazyLoad","window","_isBot","test","navigator","userAgent","_getTopOffset","element","getBoundingClientRect","top","pageYOffset","ownerDocument","documentElement","clientTop","_isBelowViewport","container","threshold","innerHeight","offsetHeight","_getLeftOffset","left","pageXOffset","clientLeft","_isAtRightOfViewport","documentWidth","innerWidth","_isAboveViewport","_isAtLeftOfViewport","offsetWidth","_isInsideViewport","_callCallback","callback","argument","_createInstance","options","instance","event","CustomEvent","detail","dispatchEvent","_defaultSettings","elements_selector","throttle","data_src","data_srcset","class_loading","class_loaded","class_error","class_initial","skip_invisible","callback_load","callback_error","callback_set","callback_processed","[object Object]","instanceSettings","this","_settings","Object","assign","_queryOriginNode","document","_previousLoopTime","_loopTimeout","_boundHandleScroll","handleScroll","bind","_isFirstLoop","addEventListener","update","srcsetDataAttribute","parent","parentElement","tagName","i","children","length","pictureChild","sourceSrcset","getAttribute","setAttribute","srcDataAttribute","elementSrc","_setSourcesForPicture","imgSrcset","style","backgroundImage","settings","errorCallback","removeEventListener","loadCallback","classList","remove","add","_setSources","elements","_elements","elementsLength","processedIndexes","firstLoop","offsetParent","_showOnAppear","push","wasProcessed","splice","pop","_stopScrollHandler","elementsToPurge","_isHandlingScroll","getTime","Date","now","remainingTime","clearTimeout","_loopThroughElements","setTimeout","Array","prototype","slice","call","querySelectorAll","_purgeElements","_startScrollHandler","autoInitOptions","lazyLoadOptions","optsLength"],"mappings":"CAAC,SAAUA,EAAMC,GACS,kBAAXC,SAAyBA,OAAOC,IACvCD,UAAWD,GACe,gBAAZG,SACdC,OAAOD,QAAUH,IAEjBD,EAAKM,SAAWL,KAEtBM,OAAQ,WAEN,KAAMC,KAAW,YAAcD,UAAW,SAASE,KAAKC,UAAUC,WAE5DC,EAAgB,SAAUC,GAC5B,MAAOA,GAAQC,wBAAwBC,IAAMR,OAAOS,YAAcH,EAAQI,cAAcC,gBAAgBC,WAGtGC,EAAmB,SAAUP,EAASQ,EAAWC,GAInD,OAHcD,IAAcd,OACxBA,OAAOgB,YAAchB,OAAOS,YAC5BJ,EAAcS,GAAaA,EAAUG,eAC1BZ,EAAcC,GAAWS,GAGtCG,EAAiB,SAAUZ,GAC7B,MAAOA,GAAQC,wBAAwBY,KAAOnB,OAAOoB,YAAcd,EAAQI,cAAcC,gBAAgBU,YAGvGC,EAAuB,SAAUhB,EAASQ,EAAWC,GACvD,KAAMQ,GAAgBvB,OAAOwB,UAI7B,QAHcV,IAAcd,OACxBuB,EAAgBvB,OAAOoB,YACvBF,EAAeJ,GAAaS,IACjBL,EAAeZ,GAAWS,GAGvCU,EAAmB,SAAUnB,EAASQ,EAAWC,GAEnD,OADcD,IAAcd,OAAUA,OAAOS,YAAcJ,EAAcS,KAC1DT,EAAcC,GAAWS,EAA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,kBACvCkD,IAAiB,GAAKA,EAAgBtE,GAClCc,KAAKO,eACLkD,aAAazD,KAAKO,cAClBP,KAAKO,aAAe,MAExBP,KAAKM,kBAAoBiD,EACzBvD,KAAK0D,wBACG1D,KAAKO,eACbP,KAAKO,aAAeoD,WAAW,WAC3B3D,KAAKM,kBAAoB+C,IACzBrD,KAAKO,aAAe,KACpBP,KAAK0D,wBACPhD,KAAKV,MAAOwD,QAGlBxD,MAAK0D,uBAIb5D,SAEIE,KAAKwC,UAAYoB,MAAMC,UAAUC,MAAMC,KAAK/D,KAAKI,iBAAiB4D,iBAAiBhE,KAAKC,UAAUhB,oBAClGe,KAAKiE,iBACLjE,KAAK0D,uBACL1D,KAAKkE,sBAGTpE,UACIrD,OAAOwF,oBAAoB,SAAUjC,KAAKQ,oBACtCR,KAAKO,eACLkD,aAAazD,KAAKO,cAClBP,KAAKO,aAAe,MAExBP,KAAKkD,qBACLlD,KAAKwC,UAAY,KACjBxC,KAAKI,iBAAmB,KACxBJ,KAAKC,UAAY,MAKzB,GAAIkE,GAAkB1H,OAAO2H,eAG7B,OAFID,IA/OoB,SAASzF,GAC7B,GAAI2F,GAAa3F,EAAQ0C,MACzB,IAAKiD,EAMD,IAAK,GAAInD,GAAE,EAAGA,EAAEmD,EAAYnD,IACxBzC,EAAgBC,EAAQwC,QAL5BzC,GAAgBC,IA2OeyF,GAEhC3H","file":"lazyload.min.js"} \ No newline at end of file diff --git a/dist/lazyload.transpiled.js b/dist/lazyload.transpiled.js index de140986..344b0bf1 100644 --- a/dist/lazyload.transpiled.js +++ b/dist/lazyload.transpiled.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; @@ -9,16 +9,16 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } (function (root, factory) { - if (typeof define === 'function' && define.amd) { + if (typeof define === "function" && define.amd) { define([], factory); - } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') { + } else if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object") { module.exports = factory(); } else { root.LazyLoad = factory(); } })(window, function () { - var _isBot = !('onscroll' in window) || /glebot/.test(navigator.userAgent); + var _isBot = !("onscroll" in window) || /glebot/.test(navigator.userAgent); var _getTopOffset = function _getTopOffset(element) { return element.getBoundingClientRect().top + window.pageYOffset - element.ownerDocument.documentElement.clientTop; @@ -62,7 +62,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons /* Creates instance and notifies it through the window element */ var _createInstance = function _createInstance(options) { var instance = new LazyLoad(options); - var event = new CustomEvent('LazyLoad::Initialized', { detail: { instance: instance } }); + var event = new CustomEvent("LazyLoad::Initialized", { detail: { instance: instance } }); window.dispatchEvent(event); }; @@ -116,42 +116,50 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } _createClass(LazyLoad, [{ - key: '_setSourcesForPicture', + key: "_setSourcesForPicture", value: function _setSourcesForPicture(element, srcsetDataAttribute) { var parent = element.parentElement; - if (parent.tagName !== 'PICTURE') { + if (parent.tagName !== "PICTURE") { return; } for (var i = 0; i < parent.children.length; i++) { var pictureChild = parent.children[i]; - if (pictureChild.tagName === 'SOURCE') { - var sourceSrcset = pictureChild.getAttribute('data-' + srcsetDataAttribute); + if (pictureChild.tagName === "SOURCE") { + var sourceSrcset = pictureChild.getAttribute("data-" + srcsetDataAttribute); if (sourceSrcset) { - pictureChild.setAttribute('srcset', sourceSrcset); + pictureChild.setAttribute("srcset", sourceSrcset); } } } } }, { - key: '_setSources', + key: "_setSources", value: function _setSources(element, srcsetDataAttribute, srcDataAttribute) { var tagName = element.tagName; - var elementSrc = element.getAttribute('data-' + srcDataAttribute); + var elementSrc = element.getAttribute("data-" + srcDataAttribute); if (tagName === "IMG") { this._setSourcesForPicture(element, srcsetDataAttribute); - var imgSrcset = element.getAttribute('data-' + srcsetDataAttribute); - if (imgSrcset) element.setAttribute("srcset", imgSrcset); - if (elementSrc) element.setAttribute("src", elementSrc); + var imgSrcset = element.getAttribute("data-" + srcsetDataAttribute); + if (imgSrcset) { + element.setAttribute("srcset", imgSrcset); + } + if (elementSrc) { + element.setAttribute("src", elementSrc); + } return; } if (tagName === "IFRAME") { - if (elementSrc) element.setAttribute("src", elementSrc); + if (elementSrc) { + element.setAttribute("src", elementSrc); + } return; } - if (elementSrc) element.style.backgroundImage = "url(" + elementSrc + ")"; + if (elementSrc) { + element.style.backgroundImage = "url(" + elementSrc + ")"; + } } }, { - key: '_showOnAppear', + key: "_showOnAppear", value: function _showOnAppear(element) { var settings = this._settings; @@ -191,7 +199,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons _callCallback(settings.callback_set, element); } }, { - key: '_loopThroughElements', + key: "_loopThroughElements", value: function _loopThroughElements() { var settings = this._settings, elements = this._elements, @@ -234,7 +242,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } }, { - key: '_purgeElements', + key: "_purgeElements", value: function _purgeElements() { var elements = this._elements, elementsLength = elements.length; @@ -254,7 +262,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } }, { - key: '_startScrollHandler', + key: "_startScrollHandler", value: function _startScrollHandler() { if (!this._isHandlingScroll) { this._isHandlingScroll = true; @@ -262,7 +270,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } }, { - key: '_stopScrollHandler', + key: "_stopScrollHandler", value: function _stopScrollHandler() { if (this._isHandlingScroll) { this._isHandlingScroll = false; @@ -270,7 +278,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } }, { - key: 'handleScroll', + key: "handleScroll", value: function handleScroll() { var _this = this; @@ -303,7 +311,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } }, { - key: 'update', + key: "update", value: function update() { // Converts to array the nodeset obtained querying the DOM from _queryOriginNode with elements_selector this._elements = Array.prototype.slice.call(this._queryOriginNode.querySelectorAll(this._settings.elements_selector)); @@ -312,7 +320,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons this._startScrollHandler(); } }, { - key: 'destroy', + key: "destroy", value: function destroy() { window.removeEventListener("resize", this._boundHandleScroll); if (this._loopTimeout) { diff --git a/dist/lazyload.transpiled.min.js.map b/dist/lazyload.transpiled.min.js.map index 2fc89832..f24b2f13 100644 --- a/dist/lazyload.transpiled.min.js.map +++ b/dist/lazyload.transpiled.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["lazyload.transpiled.js"],"names":["_classCallCheck","instance","Constructor","TypeError","_extends","Object","assign","target","i","arguments","length","source","key","prototype","hasOwnProperty","call","_createClass","defineProperties","props","descriptor","enumerable","configurable","writable","defineProperty","protoProps","staticProps","_typeof","Symbol","iterator","obj","constructor","root","factory","define","amd","exports","module","LazyLoad","window","_isBot","test","navigator","userAgent","_getTopOffset","element","getBoundingClientRect","top","pageYOffset","ownerDocument","documentElement","clientTop","_isBelowViewport","container","threshold","innerHeight","offsetHeight","_getLeftOffset","left","pageXOffset","clientLeft","_isAtRightOfViewport","documentWidth","innerWidth","_isAboveViewport","_isAtLeftOfViewport","offsetWidth","_isInsideViewport","_callCallback","callback","argument","_createInstance","options","event","CustomEvent","detail","dispatchEvent","_defaultSettings","elements_selector","throttle","data_src","data_srcset","class_loading","class_loaded","class_error","class_initial","skip_invisible","callback_load","callback_error","callback_set","callback_processed","instanceSettings","this","_settings","_queryOriginNode","document","_previousLoopTime","_loopTimeout","_boundHandleScroll","handleScroll","bind","_isFirstLoop","addEventListener","update","value","srcsetDataAttribute","parent","parentElement","tagName","children","pictureChild","sourceSrcset","getAttribute","setAttribute","srcDataAttribute","elementSrc","_setSourcesForPicture","imgSrcset","style","backgroundImage","settings","errorCallback","removeEventListener","loadCallback","classList","remove","add","_setSources","elements","_elements","elementsLength","processedIndexes","firstLoop","offsetParent","_showOnAppear","push","wasProcessed","splice","pop","_stopScrollHandler","elementsToPurge","_isHandlingScroll","_this","getTime","Date","now","remainingTime","clearTimeout","_loopThroughElements","setTimeout","Array","slice","querySelectorAll","_purgeElements","_startScrollHandler","autoInitOptions","lazyLoadOptions","optsLength"],"mappings":"AAAA,YAQA,SAASA,iBAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,qCANhH,GAAIC,UAAWC,OAAOC,QAAU,SAAUC,GAAU,IAAK,GAAIC,GAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAAK,CAAE,GAAIG,GAASF,UAAUD,EAAI,KAAK,GAAII,KAAOD,GAAcN,OAAOQ,UAAUC,eAAeC,KAAKJ,EAAQC,KAAQL,EAAOK,GAAOD,EAAOC,IAAY,MAAOL,IAEnPS,aAAe,WAAc,QAASC,GAAiBV,EAAQW,GAAS,IAAK,GAAIV,GAAI,EAAGA,EAAIU,EAAMR,OAAQF,IAAK,CAAE,GAAIW,GAAaD,EAAMV,EAAIW,GAAWC,WAAaD,EAAWC,aAAc,EAAOD,EAAWE,cAAe,EAAU,SAAWF,KAAYA,EAAWG,UAAW,GAAMjB,OAAOkB,eAAehB,EAAQY,EAAWP,IAAKO,IAAiB,MAAO,UAAUjB,EAAasB,EAAYC,GAAiJ,MAA9HD,IAAYP,EAAiBf,EAAYW,UAAWW,GAAiBC,GAAaR,EAAiBf,EAAauB,GAAqBvB,MAE5hBwB,QAA4B,kBAAXC,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIC,cAAgBH,QAAUE,IAAQF,OAAOd,UAAY,eAAkBgB,KAItQ,SAAWE,EAAMC,GACS,kBAAXC,SAAyBA,OAAOC,IACvCD,UAAWD,GACkE,YAAlD,mBAAZG,SAA0B,YAAcT,QAAQS,UAC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AAQI,OAIvBtD,KAAKwD,0BAIbvI,IAAK,SACL2F,MAAO,WAEHZ,KAAKqC,UAAYqB,MAAMxI,UAAUyI,MAAMvI,KAAK4E,KAAKE,iBAAiB0D,iBAAiB5D,KAAKC,UAAUf,oBAClGc,KAAK6D,iBACL7D,KAAKwD,uBACLxD,KAAK8D,yBAGT7I,IAAK,UACL2F,MAAO,WACHjE,OAAOmF,oBAAoB,SAAU9B,KAAKM,oBACtCN,KAAKK,eACLkD,aAAavD,KAAKK,cAClBL,KAAKK,aAAe,MAExBL,KAAK+C,qBACL/C,KAAKqC,UAAY,KACjBrC,KAAKE,iBAAmB,KACxBF,KAAKC,UAAY,SAIlBvD,KAMPqH,EAAkBpH,OAAOqH,eAK7B,OAJID,IAzQkB,SAAyBnF,GAC3C,GAAIqF,GAAarF,EAAQ7D,MACzB,IAAKkJ,EAKD,IAAK,GAAIpJ,GAAI,EAAGA,EAAIoJ,EAAYpJ,IAC5B8D,EAAgBC,EAAQ/D,QAJ5B8D,GAAgBC,IAsQJmF,GAGbrH","file":"lazyload.transpiled.min.js"} \ No newline at end of file +{"version":3,"sources":["lazyload.transpiled.js"],"names":["_classCallCheck","instance","Constructor","TypeError","_extends","Object","assign","target","i","arguments","length","source","key","prototype","hasOwnProperty","call","_createClass","defineProperties","props","descriptor","enumerable","configurable","writable","defineProperty","protoProps","staticProps","_typeof","Symbol","iterator","obj","constructor","root","factory","define","amd","exports","module","LazyLoad","window","_isBot","test","navigator","userAgent","_getTopOffset","element","getBoundingClientRect","top","pageYOffset","ownerDocument","documentElement","clientTop","_isBelowViewport","container","threshold","innerHeight","offsetHeight","_getLeftOffset","left","pageXOffset","clientLeft","_isAtRightOfViewport","documentWidth","innerWidth","_isAboveViewport","_isAtLeftOfViewport","offsetWidth","_isInsideViewport","_callCallback","callback","argument","_createInstance","options","event","CustomEvent","detail","dispatchEvent","_defaultSettings","elements_selector","throttle","data_src","data_srcset","class_loading","class_loaded","class_error","class_initial","skip_invisible","callback_load","callback_error","callback_set","callback_processed","instanceSettings","this","_settings","_queryOriginNode","document","_previousLoopTime","_loopTimeout","_boundHandleScroll","handleScroll","bind","_isFirstLoop","addEventListener","update","value","srcsetDataAttribute","parent","parentElement","tagName","children","pictureChild","sourceSrcset","getAttribute","setAttribute","srcDataAttribute","elementSrc","_setSourcesForPicture","imgSrcset","style","backgroundImage","settings","errorCallback","removeEventListener","loadCallback","classList","remove","add","_setSources","elements","_elements","elementsLength","processedIndexes","firstLoop","offsetParent","_showOnAppear","push","wasProcessed","splice","pop","_stopScrollHandler","elementsToPurge","_isHandlingScroll","_this","getTime","Date","now","remainingTime","clearTimeout","_loopThroughElements","setTimeout","Array","slice","querySelectorAll","_purgeElements","_startScrollHandler","autoInitOptions","lazyLoadOptions","optsLength"],"mappings":"AAAA,YAQA,SAASA,iBAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,qCANhH,GAAIC,UAAWC,OAAOC,QAAU,SAAUC,GAAU,IAAK,GAAIC,GAAI,EAAGA,EAAIC,UAAUC,OAAQF,IAAK,CAAE,GAAIG,GAASF,UAAUD,EAAI,KAAK,GAAII,KAAOD,GAAcN,OAAOQ,UAAUC,eAAeC,KAAKJ,EAAQC,KAAQL,EAAOK,GAAOD,EAAOC,IAAY,MAAOL,IAEnPS,aAAe,WAAc,QAASC,GAAiBV,EAAQW,GAAS,IAAK,GAAIV,GAAI,EAAGA,EAAIU,EAAMR,OAAQF,IAAK,CAAE,GAAIW,GAAaD,EAAMV,EAAIW,GAAWC,WAAaD,EAAWC,aAAc,EAAOD,EAAWE,cAAe,EAAU,SAAWF,KAAYA,EAAWG,UAAW,GAAMjB,OAAOkB,eAAehB,EAAQY,EAAWP,IAAKO,IAAiB,MAAO,UAAUjB,EAAasB,EAAYC,GAAiJ,MAA9HD,IAAYP,EAAiBf,EAAYW,UAAWW,GAAiBC,GAAaR,EAAiBf,EAAauB,GAAqBvB,MAE5hBwB,QAA4B,kBAAXC,SAAo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iB,GAAKA,EAAgBnE,GAClC+D,EAAM7C,eACNkD,aAAaL,EAAM7C,cACnB6C,EAAM7C,aAAe,MAEzB6C,EAAM9C,kBAAoBiD,EAC1BH,EAAMM,wBACEN,EAAM7C,eACd6C,EAAM7C,aAAeoD,WAAW,WAC5BzD,KAAKI,kBAAoB+C,IACzBnD,KAAKK,aAAe,KACpBL,KAAKwD,wBACPhD,KAAK0C,GAAQI,OAIvBtD,KAAKwD,0BAIbvI,IAAK,SACL2F,MAAO,WAEHZ,KAAKqC,UAAYqB,MAAMxI,UAAUyI,MAAMvI,KAAK4E,KAAKE,iBAAiB0D,iBAAiB5D,KAAKC,UAAUf,oBAClGc,KAAK6D,iBACL7D,KAAKwD,uBACLxD,KAAK8D,yBAGT7I,IAAK,UACL2F,MAAO,WACHjE,OAAOmF,oBAAoB,SAAU9B,KAAKM,oBACtCN,KAAKK,eACLkD,aAAavD,KAAKK,cAClBL,KAAKK,aAAe,MAExBL,KAAK+C,qBACL/C,KAAKqC,UAAY,KACjBrC,KAAKE,iBAAmB,KACxBF,KAAKC,UAAY,SAIlBvD,KAMPqH,EAAkBpH,OAAOqH,eAK7B,OAJID,IAjRkB,SAAyBnF,GAC3C,GAAIqF,GAAarF,EAAQ7D,MACzB,IAAKkJ,EAKD,IAAK,GAAIpJ,GAAI,EAAGA,EAAIoJ,EAAYpJ,IAC5B8D,EAAgBC,EAAQ/D,QAJ5B8D,GAAgBC,IA8QJmF,GAGbrH","file":"lazyload.transpiled.min.js"} \ No newline at end of file diff --git a/package.json b/package.json index d63ce53e..3f733107 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vanilla-lazyload", - "version": "6.3.1", + "version": "6.3.2", "description": "A fast, lightweight script to load images as they enter the viewport. SEO friendly, it supports responsive images (both srcset + sizes and picture) and progressive JPEG", "main": "dist/lazyload.transpiled.min.js", "devDependencies": { @@ -12,6 +12,7 @@ "grunt-contrib-jshint": "~1.1.0", "grunt-contrib-uglify": "~2.3.0", "grunt-contrib-watch": "~1.0.0", + "gruntify-eslint": "^3.1.0", "jest": "^19.0.2" }, "scripts": { diff --git a/src/lazyload.js b/src/lazyload.js index dc520ab9..b6c9ace4 100644 --- a/src/lazyload.js +++ b/src/lazyload.js @@ -1,14 +1,14 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { + if (typeof define === "function" && define.amd) { define([], factory); - } else if (typeof exports === 'object') { + } else if (typeof exports === "object") { module.exports = factory(); } else { root.LazyLoad = factory(); } }(window, function () { - const _isBot = !('onscroll' in window) || /glebot/.test(navigator.userAgent); + const _isBot = !("onscroll" in window) || /glebot/.test(navigator.userAgent); const _getTopOffset = function (element) { return element.getBoundingClientRect().top + window.pageYOffset - element.ownerDocument.documentElement.clientTop; @@ -57,7 +57,7 @@ /* Creates instance and notifies it through the window element */ const _createInstance = function(options) { let instance = new LazyLoad(options); - let event = new CustomEvent('LazyLoad::Initialized', {detail: {instance}}); + let event = new CustomEvent("LazyLoad::Initialized", {detail: {instance}}); window.dispatchEvent(event); }; @@ -111,15 +111,15 @@ _setSourcesForPicture(element, srcsetDataAttribute) { const parent = element.parentElement; - if (parent.tagName !== 'PICTURE') { + if (parent.tagName !== "PICTURE") { return; } for (let i = 0; i < parent.children.length; i++) { let pictureChild = parent.children[i]; - if (pictureChild.tagName === 'SOURCE') { - let sourceSrcset = pictureChild.getAttribute('data-' + srcsetDataAttribute); + if (pictureChild.tagName === "SOURCE") { + let sourceSrcset = pictureChild.getAttribute("data-" + srcsetDataAttribute); if (sourceSrcset) { - pictureChild.setAttribute('srcset', sourceSrcset); + pictureChild.setAttribute("srcset", sourceSrcset); } } } @@ -127,19 +127,19 @@ _setSources(element, srcsetDataAttribute, srcDataAttribute) { const tagName = element.tagName; - const elementSrc = element.getAttribute('data-' + srcDataAttribute); + const elementSrc = element.getAttribute("data-" + srcDataAttribute); if (tagName === "IMG") { this._setSourcesForPicture(element, srcsetDataAttribute); - const imgSrcset = element.getAttribute('data-' + srcsetDataAttribute); - if (imgSrcset) element.setAttribute("srcset", imgSrcset); - if (elementSrc) element.setAttribute("src", elementSrc); + const imgSrcset = element.getAttribute("data-" + srcsetDataAttribute); + if (imgSrcset) { element.setAttribute("srcset", imgSrcset); } + if (elementSrc) { element.setAttribute("src", elementSrc); } return; } if (tagName === "IFRAME") { - if (elementSrc) element.setAttribute("src", elementSrc); + if (elementSrc) { element.setAttribute("src", elementSrc); } return; } - if (elementSrc) element.style.backgroundImage = "url(" + elementSrc + ")"; + if (elementSrc) { element.style.backgroundImage = "url(" + elementSrc + ")"; } } _showOnAppear(element) {