### jQuery Lazy - Loader Plugins [![GitHub version](https://badge.fury.io/gh/dkern%2Fjquery.lazy.svg)](http://github.com/dkern/jquery.lazy) [![NPM version](https://badge.fury.io/js/jquery-lazy.svg)](http://www.npmjs.org/package/jquery-lazy) [![Bower version](https://badge.fury.io/bo/jquery-lazy.svg)](http://bower.io/search/?q=jquery-lazy) [![Dependencies Status](https://david-dm.org/dkern/jquery.lazy/status.svg)](https://david-dm.org/dkern/jquery.lazy) [![devDependencies Status](https://david-dm.org/dkern/jquery.lazy/dev-status.svg)](https://david-dm.org/dkern/jquery.lazy?type=dev) --- ### Table of Contents * [Document Note](#document-note) * [About Loader Plugins](#about-loader-plugins) * [Create an own Loader Plugin](#create-an-own-loader-plugin) * [AJAX Loader](#ajax-loader) * [Audio / Video Loader](#audio--video-loader) * [iFrame Loader](#iframe-loader) * [NOOP Loader](#noop-loader) * [Picture Loader](#picture-loader) * [JS / Script Loader](#js--script-loader) * [Vimeo Video Loader](#vimeo-video-loader) * [YouTube Video Loader](#youtube-video-loader) * [Bugs / Feature request](#bugs--feature-request) * [License](#license) * [Donation](#donation) --- ## Document Note This is not the main readme file of this project. Please go to the [project root](https://github.com/dkern/jquery.lazy) and take a look in the [README.md](https://github.com/dkern/jquery.lazy/blob/master/README.md) to learn more about the basics of Lazy. ## About Loader Plugins The loader plugins for Lazy can be used whenever you want to extend the basic functionality by default or globally for many instances of Lazy. Just add the plugins you want to use or a combined file, containing all plugins, to your page and all instances can use the plugins from now on. ```HTML ``` ## Create an own Loader Plugin If you want to, you can easily create own loader plugins. Just use jQuery or Zepto's public function `Lazy` to create and register them. Best practice is to wrap everything by an [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression). ```JS (function($) { $.Lazy("pluginName", function(element, response) { // add your logic here // 'this' is the current instance of Lazy // so it's possible to access all public functions, like: var imageBase = this.config("imageBase"); }); })(window.jQuery || window.Zepto); ``` This loader can now be called on every element with the attribute `data-loader` (_by default_), like: ```HTML
``` It's possible to register a plugin with more than one name / alias. ```JS (function($) { $.Lazy(["pluginName", "anotherPluginName"], function(element, response) { // the plugin is now available by 'data-loader="pluginLoaderName"' // and 'data-loader="anotherLoaderName"' }); })(window.jQuery || window.Zepto); ``` The optional second parameter gives you the ability to register a plugin by default to an element type. When you do this, there is no need to set the `data-loader` attribute on each element you want to use this loader on. But keep in mind, if you register an plugin on often used elements, like `
`, Lazy will try to handle each of them! If you want to do so anyway, use a most specific selector for jQuery or Zepto. ```JS (function($) { $.Lazy("av", ["audio", "video"], function(element, response) { // this plugin will automatically handle '