Giter Site home page Giter Site logo

miromanestar / youtube-gallery Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 75 KB

A simple script for displaying Youtube playlists in a responsive format.

Home Page: https://miromanestar.com/projects/ytgallery

HTML 2.76% CSS 16.93% JavaScript 80.31%
javascript no-jquery youtube video-gallery youtube-data-api-v3

youtube-gallery's Introduction

Youtube Gallery

No jQuery, no Bootstrap

A while ago, I made a youtube gallery viewer. It worked pretty well, save for several major problems.

  • The first of which was that it polluted the global namespace. var was being used everywhere and everything was defined globally.
  • Second, you could only have one active instance per page at a time as a consequence, since they would all override each other.
  • Third, it required explicit HTML to be created by the user. This was annoying and was also part of the reason you could only have one active instance per page, since the element IDs used for event triggers would conflict.
  • Fourth, it relied on jQuery to work.

This new version solves all those problems. Now, it is initialized entirely programmatically, save for one empty HTML element with an ID provided so that the gallery knows where to place itself in the DOM. It makes absolutely zero use of jQuery, and has no required external dependencies. Everything is encapsulated in a class, and nothing except the primary container utilizes elemnt IDs. Thus, you can have as many instances as required without issue. Finally, it's also much easier to use, as shown below.

How to use

new YTGallery(playlistId, apiKey, elementId, options)

Where playlistId is the youtube playlist ID, apiKey is your youtube API key, and elementId is the id of the element in which you would like the gallery to display.

There's also fancybox support. All you need to do is include fslightbox.js and you're good to go.

YTGallery also takes a fourth parameter as an object which includes optional parameters.

{
    numColumns, //Can be 1-4. Default: 3
    maxResults, //Can be 1-50. Default: 10
    searchEnabled, //Boolean to enable the search input. Default: true
    cacheLife, //In millseconds, specifies the max amount of time before the cache will be rebuilt. Default: 86400000 (1 day)
}

Demo

You can see it on my website here or play with it using your own API key here.

Dependencies

There are no absolute dependencies, but check out fslightbox to enable ligthbox automatically.

Future Plans

I'm thinking of adding my own ligthbox functionality to this so as to remove any external dependencies whatsoever. Furthermore, custom rendering options are also something I'm considering.

youtube-gallery's People

Contributors

miromanestar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

youtube-gallery's Issues

What is playlistId?

Hello. I do not quite understand where to get this playlistId. In your demo, I understand that you have different videos. How does it work? After all, he takes information from the YouTube channel, or am I misunderstanding something?

License?

Hi. Interesting project. How do you plan to license this -- is it free for reuse?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.