[
  {
    "path": ".gitignore",
    "content": "yarn-error.log\nyarn.lock\nnode_modules"
  },
  {
    "path": ".jshintrc",
    "content": "{\n    \"esversion\": 6,\n    \"curly\": true,\n    \"eqeqeq\": true,\n    \"eqnull\": true,\n    \"immed\": true,\n    \"noarg\": true,\n    \"quotmark\": \"double\",\n    \"trailing\": true,\n    \"undef\": true,\n    \"unused\": \"vars\",\n\n    \"node\": true,\n    \"jquery\": true,\n    \"browser\": true,\n\n    \"predef\": [\n        \"define\",\n        \"IntersectionObserver\"\n    ]\n}"
  },
  {
    "path": ".travis.yml",
    "content": "sudo: false\n\nlanguage: node_js\n\nnode_js:\n  - \"7\"\n\ninstall:\n  - npm install\n\nscript:\n  - make travis\n"
  },
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n=====================\n\nCopyright (c) 2007-2019 Mika Tuupola\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "Makefile",
    "content": ".DEFAULT_GOAL := help\n\nhelp:\n\t@echo \"\"\n\t@echo \"Available tasks:\"\n\t@echo \"    lint   Run linter and code style checker\"\n\t@echo \"    unit   Run unit tests and generate coverage\"\n\t@echo \"    test   Run linter and unit tests\"\n\t@echo \"    watch  Run linter and unit tests when any of the source files change\"\n\t@echo \"    deps   Install dependencies\"\n\t@echo \"    build  Build minified version\"\n\t@echo \"    all    Install dependencies and run linter and unit tests\"\n\t@echo \"\"\n\ndeps:\n\tyarn install\n\nlint:\n\tnode_modules/.bin/jshint lazyload.js\n\nunit:\n\t@echo \"No unit tests.\"\n\nwatch:\n\tfind . -name \"*.js\" -not -path \"./node_modules/*\" -o -name \"*.json\" -not -path \"./node_modules/*\" | entr -c make test\n\ntest: lint unit\n\ntravis: lint unit\n\nbuild:\n\tnode_modules/.bin/uglifyjs lazyload.js --compress --mangle --source-map --output lazyload.min.js\n\tsed -i \"1s/^/\\/*! Lazy Load 2.0.0-rc.2 - MIT license - Copyright 2007-2019 Mika Tuupola *\\/\\n/\" lazyload.min.js\n\nall: deps test build\n\n.PHONY: help deps lint test watch build all\n"
  },
  {
    "path": "README.md",
    "content": "# Lazy Load Remastered\n\nLazy Load delays loading of images in long web pages. Images outside of viewport will not be loaded before user scrolls to them. This is opposite of image preloading.\n\nThis is a modern vanilla JavaScript version of the original [Lazy Load](https://github.com/tuupola/jquery_lazyload) plugin. It uses [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to observe when the image enters the browsers viewport. Original code was inspired by [YUI ImageLoader](https://yuilibrary.com/yui/docs/imageloader/) utility by Matt Mlinac. New version loans heavily from a [blog post](https://deanhume.com/Home/BlogPost/lazy-loading-images-using-intersection-observer/10163) by Dean Hume.\n\n## Basic Usage\n\nBy default Lazy Load assumes the URL of the original high resolution image can be found in `data-src` attribute. You can also include an optional low resolution placeholder in the `src` attribute.\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/lazyload@2.0.0-rc.2/lazyload.js\"></script>\n\n<img class=\"lazyload\" data-src=\"img/example.jpg\" width=\"765\" height=\"574\" />\n<img class=\"lazyload\" src=\"img/example-thumb.jpg\" data-src=\"img/example.jpg\" width=\"765\" height=\"574\" />\n```\n\nWith the HTML in place you can then initialize the plugin using the factory method. If you do not pass any settings or image elements it will lazyload all images with class `lazyload`.\n\n```js\nlazyload();\n```\n\nIf you prefer you can explicitly pass the image elements to the factory. Use this for example if you use different class name.\n\n```js\nlet images = document.querySelectorAll(\".branwdo\");\nlazyload(images);\n```\n\nIf you prefer you can also use the plain old constructor.\n\n```js\nlet images = document.querySelectorAll(\".branwdo\");\nnew LazyLoad(images);\n```\n\nThe core IntersectionObserver can be configured by passing an additional argument\n\n```js\nnew LazyLoad(images, {\n     root: null,\n     rootMargin: \"0px\",\n     threshold: 0\n});\n```\n\n## Additional API\n\nTo use the additional API you need to assign the plugin instance to a variable.\n\n```js\nlet lazy = lazyload();\n```\n\nTo force loading of all images use `loadimages()`.\n\n```js\nlazy->loadImages();\n```\n\nTo destroy the plugin and stop lazyloading use `destroy()`.\n\n```js\nlazy->destroy();\n```\n\nNote that `destroy()` does not load the out of viewport images. If you also\nwant to load the images use `loadAndDestroy()`.\n\n```js\nlazy->loadAndDestroy();\n```\n\nAdditional API is not avalaible with the jQuery wrapper.\n\n## jQuery Wrapper\n\nIf you use jQuery there is a wrapper which you can use with the familiar old syntax. Note that to provide BC it uses `data-original` by default. This should be a drop in replacement for the previous version of the plugin.\n\n```html\n<img class=\"lazyload\" data-original=\"img/example.jpg\" width=\"765\" height=\"574\">\n<img class=\"lazyload\" src=\"img/example-thumb.jpg\" data-original=\"img/example.jpg\" width=\"765\" height=\"574\">\n```\n\n```js\n$(\"img.lazyload\").lazyload();\n```\n\n## Cookbook\n\n### Blur Up Images\n\nLow resolution placeholder ie. the \"blur up\" technique. You can see this in action [in this blog entry](https://appelsiini.net/2017/trilateration-with-n-points/). Scroll down to see blur up images.\n\n```html\n<img class=\"lazyload\"\n     src=\"thumbnail.jpg\"\n     data-src=\"original.jpg\"\n     width=\"1024\" height=\"768\" />\n```\n\n```html\n<div class=\"lazyload\"\n     style=\"background-image: url('thumbnail.jpg')\"\n     data-src=\"original.jpg\" />\n```\n\n### Responsive Images\n\nLazyloaded [Responsive images](https://www.smashingmagazine.com/2014/05/responsive-images-done-right-guide-picture-srcset/) are supported via `data-srcset`. If browser does not support `srcset` and there is no polyfill the image from `data-src` will be shown.\n\n```html\n<img class=\"lazyload\"\n     src=\"thumbnail.jpg\"\n     data-src=\"large.jpg\"\n     data-srcset=\"small.jpg 480w, medium.jpg 640w, large.jpg 1024w\"\n     width=\"1024\" height=\"768\" />\n```\n\n```html\n<img class=\"lazyload\"\n     src=\"thumbnail.jpg\"\n     data-src=\"normal.jpg\"\n     data-srcset=\"normal.jpg 1x, retina.jpg 2x\"\n     width=\"1024\" height=\"768\" />\n```\n\n\n### Inlined Placeholder Image\n\nTo reduce the amount of request you can use data uri images as the placeholder.\n\n```html\n<img src=\"data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=\"\n     data-src=\"original.jpg\"\n     width=\"1024\" height=\"768\" />\n```\n\n## Install\n\nThis is still work in progress. You can install beta version with yarn or npm.\n\n```\n$ yarn add lazyload\n$ npm install lazyload\n```\n\n# License\n\nAll code licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php). All images licensed under [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/deed.en_US). In other words you are basically free to do whatever you want. Just don't remove my name from the source.\n\n"
  },
  {
    "path": "lazyload.js",
    "content": "/*!\n * Lazy Load - JavaScript plugin for lazy loading images\n *\n * Copyright (c) 2007-2019 Mika Tuupola\n *\n * Licensed under the MIT license:\n *   http://www.opensource.org/licenses/mit-license.php\n *\n * Project home:\n *   https://appelsiini.net/projects/lazyload\n *\n * Version: 2.0.0-rc.2\n *\n */\n\n(function (root, factory) {\n    if (typeof exports === \"object\") {\n        module.exports = factory(root);\n    } else if (typeof define === \"function\" && define.amd) {\n        define([], factory);\n    } else {\n        root.LazyLoad = factory(root);\n    }\n}) (typeof global !== \"undefined\" ? global : this.window || this.global, function (root) {\n\n    \"use strict\";\n\n    if (typeof define === \"function\" && define.amd){\n        root = window;\n    }\n\n    const defaults = {\n        src: \"data-src\",\n        srcset: \"data-srcset\",\n        selector: \".lazyload\",\n        root: null,\n        rootMargin: \"0px\",\n        threshold: 0\n    };\n\n    /**\n    * Merge two or more objects. Returns a new object.\n    * @private\n    * @param {Boolean}  deep     If true, do a deep (or recursive) merge [optional]\n    * @param {Object}   objects  The objects to merge together\n    * @returns {Object}          Merged values of defaults and options\n    */\n    const extend = function ()  {\n\n        let extended = {};\n        let deep = false;\n        let i = 0;\n        let length = arguments.length;\n\n        /* Check if a deep merge */\n        if (Object.prototype.toString.call(arguments[0]) === \"[object Boolean]\") {\n            deep = arguments[0];\n            i++;\n        }\n\n        /* Merge the object into the extended object */\n        let merge = function (obj) {\n            for (let prop in obj) {\n                if (Object.prototype.hasOwnProperty.call(obj, prop)) {\n                    /* If deep merge and property is an object, merge properties */\n                    if (deep && Object.prototype.toString.call(obj[prop]) === \"[object Object]\") {\n                        extended[prop] = extend(true, extended[prop], obj[prop]);\n                    } else {\n                        extended[prop] = obj[prop];\n                    }\n                }\n            }\n        };\n\n        /* Loop through each object and conduct a merge */\n        for (; i < length; i++) {\n            let obj = arguments[i];\n            merge(obj);\n        }\n\n        return extended;\n    };\n\n    function LazyLoad(images, options) {\n        this.settings = extend(defaults, options || {});\n        this.images = images || document.querySelectorAll(this.settings.selector);\n        this.observer = null;\n        this.init();\n    }\n\n    LazyLoad.prototype = {\n        init: function() {\n\n            /* Without observers load everything and bail out early. */\n            if (!root.IntersectionObserver) {\n                this.loadImages();\n                return;\n            }\n\n            let self = this;\n            let observerConfig = {\n                root: this.settings.root,\n                rootMargin: this.settings.rootMargin,\n                threshold: [this.settings.threshold]\n            };\n\n            this.observer = new IntersectionObserver(function(entries) {\n                Array.prototype.forEach.call(entries, function (entry) {\n                    if (entry.isIntersecting) {\n                        self.observer.unobserve(entry.target);\n                        let src = entry.target.getAttribute(self.settings.src);\n                        let srcset = entry.target.getAttribute(self.settings.srcset);\n                        if (\"img\" === entry.target.tagName.toLowerCase()) {\n                            if (src) {\n                                entry.target.src = src;\n                            }\n                            if (srcset) {\n                                entry.target.srcset = srcset;\n                            }\n                        } else {\n                            entry.target.style.backgroundImage = \"url(\" + src + \")\";\n                        }\n                    }\n                });\n            }, observerConfig);\n\n            Array.prototype.forEach.call(this.images, function (image) {\n                self.observer.observe(image);\n            });\n        },\n\n        loadAndDestroy: function () {\n            if (!this.settings) { return; }\n            this.loadImages();\n            this.destroy();\n        },\n\n        loadImages: function () {\n            if (!this.settings) { return; }\n\n            let self = this;\n            Array.prototype.forEach.call(this.images, function (image) {\n                let src = image.getAttribute(self.settings.src);\n                let srcset = image.getAttribute(self.settings.srcset);\n                if (\"img\" === image.tagName.toLowerCase()) {\n                    if (src) {\n                        image.src = src;\n                    }\n                    if (srcset) {\n                        image.srcset = srcset;\n                    }\n                } else {\n                    image.style.backgroundImage = \"url('\" + src + \"')\";\n                }\n            });\n        },\n\n        destroy: function () {\n            if (!this.settings) { return; }\n            this.observer.disconnect();\n            this.settings = null;\n        }\n    };\n\n    root.lazyload = function(images, options) {\n        return new LazyLoad(images, options);\n    };\n\n    if (root.jQuery) {\n        const $ = root.jQuery;\n        $.fn.lazyload = function (options) {\n            options = options || {};\n            options.attribute = options.attribute || \"data-src\";\n            new LazyLoad($.makeArray(this), options);\n            return this;\n        };\n    }\n\n    return LazyLoad;\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"lazyload\",\n  \"version\": \"2.0.0-rc.2\",\n  \"description\": \"Vanilla JavaScript plugin for lazyloading images\",\n  \"main\": \"lazyload.js\",\n  \"repository\": \"https://github.com/tuupola/lazyload.git\",\n  \"author\": \"Mika Tuupola <tuupola@appelsiini.net>\",\n  \"license\": \"MIT\",\n  \"keywords\": [\n    \"lazyload\"\n  ],\n  \"files\": [\n    \"lazyload.js\",\n    \"lazyload.min.js\"\n  ],\n  \"devDependencies\": {\n    \"jshint\": \"^2.9.5\",\n    \"uglify-es\": \"^3.0.28\"\n  }\n}\n"
  }
]