npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eneserk/lazyembed

v1.2.0

Published

A library for loading embeds and individual content on click

Downloads

36

Readme

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

Argument | Required | Description -------- | -------- | ----------- data-src | No | The source of the embedded content. Usually you will use this instead of an iframe's src attribute. data-placeholder | No | An 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.

Option | Type | Required | Default | Description ------ | ---- | -------- | ------- | ----------- elements | string | 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. overlayText | string | Yes | 'Click to load' | The text printed on the overlay. Can contain HTML. overlayBackground | string | No | - | DEPRECATED The background color of the overlay. Can be any CSS color. overlayColor | string | No | - | DEPRECATED The overlay's text color. Can be any CSS color. adoptResponsiveEmbed | bool | Yes | true | If set to true, LazyEmbed tries to adept Bootstrap's embed-responsive class from the embed element. excludeElements | string | Yes | '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. includeElements | string | no | null | A selector defining child elements inside the excludeElements-Selector which should trigger the embed content. classes.root | string | Yes | '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.overlay | string | Yes | 'lazyembed__overlay' | The class to apply to the overlay element. When not applying the default class, you have to adjust the CSS. classes.text | string | Yes | 'lazyembed__text' | The class to apply to the overlay text element. When not applying the default class, you have to adjust the CSS. classes.placeholder | string | Yes | 'lazyembed__placeholder' | The class to apply to the placeholder image. When not applying the default class, you have to adjust the CSS. classes.embed | string | Yes | '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. onClick | function | Yes | Empty function | A 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. onLoad | function | Yes | Empty function | A callback function of the following form function(HTMLElement embed), bound to the iframe's load event. onInit | function | Yes | Empty function | A 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.