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

async-youtube-video

v1.0.3

Published

Simple async youtube video loader

Downloads

4

Readme

async-youtube-video

Simple async youtube video loading

Attach a YouTube video to an element asynchronously.

Usage

npm install --save-dev async-youtube-video

Include the script on your page

Insert an element with class youtube-iframe-video into your DOM

NB This element will be replaced with the iframe, so ensure you have a wrapping element in your DOM so you can control it.

<div class="video-container">
  <div class="youtube-iframe-video"></div>
</div>

Then initialise

window.onload = function() {
  asyncYoutubeVideo.init({
    targetClass: 'youtube-iframe-video',
    videoId: 'Srmdij0CU1U',
    controls: 1,
    autoplay: 1,
    disablekb: 1,
    fs: 0,
    modestbranding: 1,
    playsinline: 1,
    showinfo: 0,
    origin: 'example.com',
    additionalClasses: 'test-video some-class',
    rel: 0,
    mute: 1,
    loop: 1
  });
}

Required options are videoId, origin and targetClass.

targetClass must match the class of the replacement element in the DOM

Will render

<iframe id="async-youtube-video" src="//www.youtube.com/embed/Srmdij0CU1U?enablejsapi=1&amp;controls=1&amp;autoplay=1&amp;disablekb=1&amp;fs=1&amp;rel=0&amp;modestbranding=1&amp;playsinline=1&amp;showinfo=1&amp;loop=1&amp;origin=http://example.com" frameborder="0" type="text/html" class="test-video some-class async-youtube-video"></iframe>

The options map to YouTube API names for ease of reference.

The names of the variables are somewhat confusing though, so here is a brief rundown.

Youtube API Parameters

Valid values are 1 or 0 unless otherwise stated

  • autoplay - automatically start? optional, default 1
  • controls - whether or not to show controls. optional, default 1
    • 0 - no controls rendered
    • 1 - automatic control rendering
    • 2 - controls always shown
  • disablekb - whether or not to respond to keyboard controls. optional, default 0
  • fs - whether or not to show fullscreen controls (does not start in fs) optional, default 1
  • loop - whether or not to loop the video. optional, default 1
  • modestbranding - whether or not to show a youtube logo. optional, default 0
  • origin - your domain. required
  • playsinline - inline or fullscreen on ios. optional, default 1
  • rel - show related videos? optional, default 0
  • showinfo - show info about the video? optional, default 1

YouTube API parameters not yet supported

  • cc_load_policy - 1 causes subtitles to be shown by default
  • color - colour of the video progress bar
  • end - when to end the video
  • hl - player interface language, ISO 2 letter or full locale en or en-za
  • iv_load_policy - show video annotations?
  • list - type of content to be loaded
  • listType - used with list
  • playlist - comma seperated list of videos
  • start - the time to start the video playback at

Additional parameters not part of the YouTube API

  • mute - whether or not to start the video muted. optional, default 0
  • loop - whether or not to loop the video. optional, default 1

Note

The enablejsapi option is always enabled, and there are no plans to allow that to be configurable.

Width and height iframe attributes are not supported yet

Todo

  • Width and height configuration
  • Start and end time configuration
  • Frameborder configuration (if required)
  • Video controls
  • Playlists
  • The rest of the as-yet unsupported variables described above
    • cc_load_policy
    • color
    • end
    • hl
    • iv_load_policy
    • list
    • listType
    • playlist
    • start

Contributions welcome