1.1.7 • Published 6 years ago

lazyembed2 v1.1.7

Weekly downloads
15
License
MIT
Repository
github
Last release
6 years ago

LazyEmbed

LazyEmbed is a JavaScript library for loading embeds and individual content on click.

NPM

Install

Install LazyEmbed via npm

npm install lazyembed2

Include in your site

<!DOCTYPE html>
<html>
    <head>
        <!-- ... -->
        <link rel="stylesheet" href="dist/lazyembed.min.css" />
    </head>
    <body>
        <!-- ... -->
        <script src="dist/lazyembed.min.js"></script>
    </body>
</html>

Adjust your markup

Call LazyEmbed

new LazyEmbed();

See example.html for an example.

API

HTML

ArgumentRequiredDescription
data-srcNoThe source of the embedded content. Usually you will use this instead of an iframe's src attribute.
data-placeholderNoAn URI of an image used as placeholder for the embedded content. For example a video thumbnail.

JavaScript

You can pass an object of options to LazyEmbed's constructor.

OptionTypeRequiredDefaultDescription
elementsstring | Countable<HTMLElement>Yes'[data-lazyembed]'The embed elements to lazyload. Either a string used as selector or a countable of HTMLElements implementing a length property.
overlayTextstringYes'Click to load'The text printed on the overlay. Can contain HTML.
overlayBackgroundstringNo-DEPRECATED The background color of the overlay. Can be any CSS color.
overlayColorstringNo-DEPRECATED The overlay's text color. Can be any CSS color.
adoptResponsiveEmbedboolYestrueIf set to true, LazyEmbed tries to adept Bootstrap's embed-responsive class from the embed element.
excludeElementsstringYes'a'A selector defining child elements of the overlay which should not trigger loading the embed content. For example one would not want to trigger the loading when clicking on a link to the privacy policy.
classes.rootstringYes'lazyembed'The class to apply to the outermost LazyEmbed element wrapped around the embed element. When not applying the default class, you have to adjust the CSS.
classes.overlaystringYes'lazyembed__overlay'The class to apply to the overlay element. When not applying the default class, you have to adjust the CSS.
classes.textstringYes'lazyembed__text'The class to apply to the overlay text element. When not applying the default class, you have to adjust the CSS.
classes.placeholderstringYes'lazyembed__placeholder'The class to apply to the placeholder image. When not applying the default class, you have to adjust the CSS.
classes.embedstringYes'lazyembed__embed'The class to apply to the embed element. This class is just for identifying purpose, it doesn't define any styling by default.
onClickfunctionYesEmpty functionA callback function of the following form function(HTMLElement embed), called when the user clicks on the overlay and after the LazyEmbed parts are hidden and the embedded content is requested.
onLoadfunctionYesEmpty functionA callback function of the following form function(HTMLElement embed), bound to the iframe's load event.
onInitfunctionYesEmpty functionA callback function of the following form function(HTMLElement wrapper), called when LazyEmbed has fully initialised the embed element.

Loading individual (non-iframe) content

Omit the data-src attribute and use the onClick option to load the content manually.

Image Proxy

Use the proxy.php file for hiding the user's IP address from the image provider.

Just use the proxy's URI as the data-placeholder attribute's value and pass the image's URI to the proxy's uri parameter (remember to escape the URI). For security reasons you have to whitelist the providers' host names. By default only googleapis.com and ytimg.com are whitelisted, but this list can be easily adjusted. Just have a look on the proxy.php file.

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-alpha.1

6 years ago