Giter Site home page Giter Site logo

firepo / superembed.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from corbindavenport/superembed.js

0.0 2.0 0.0 51 KB

Fluid width for YouTube, Vimeo, Vine, VideoPress, DailyMotion, and more embedded videos.

License: MIT License

JavaScript 86.72% HTML 13.28%

superembed.js's Introduction

SuperEmbed.js

Live demo now available here.

SuperEmbed.js detects embedded videos from YouTube, Vimeo, Vine, VideoPress, DailyMotion, and more on webpages and makes them responsive. Essentially, this means they stretch to fill their container while still maintaining the content's original aspect ratio.

I created SuperEmbed to fix all my issues with existing solutions, including (but not limited to) unnecessary reliance on other libraries, bloated code, and poor fallback support.

Features

  • Works without external libraries like JQuery
  • Responsive videos maintain their original aspect ratio
  • Responsive layout can be forced or blocked with classes applied to the embed code
  • Extremely tiny, the minified version is only 2 KB

Supported Services

Embeded videos from the following sites are supported:

  • YouTube
  • Vimeo
  • Kickstarter
  • CollegeHumor
  • Hulu
  • Flickr
  • Vine
  • VideoPress
  • DailyMotion
  • Twitch.tv
  • Vid.me
  • Facebook
  • Gfycat
  • LiveLeak
  • MySpace
  • Archive.org

Browser support

Chrome Internet Explorer Firefox Safari Opera
4.0+ 9.0+ (see note) 3.5+ 3.2+ 10+

IE9 compatibility requires classList.js, included in the 'extras' folder, to be loaded before SuperEmbed.js. This is not needed for IE10 and up.

How to use

You can put the SuperEmbed script wherever you want on the page:

<script src="superembed.min.js"></script>

Then it will automatically resize any supported embedded videos. That's it.

Note: If you already use JQuery, and you load SuperEmbed sometime after it, SuperEmbed will use JQuery to detect when the page is loaded and the window is resized (instead of DOM JavaScript).

Advanced features

If you want to make an embedded video (or really any element) responsive, but it's not automatically detected by SuperEmbed, you can add the .superembed-force class to it like this:

<iframe src="http://www.example.com/video" class="superembed-force"></iframe>

You can also tell SuperEmbed to not resize a specific embed by adding the .superembed-ignore class, like this:

<iframe src="http://www.example.com/video" class="superembed-ignore"></iframe>

And finally, you can force a 1:1 aspect ratio by adding the .superembed-square class, like this:

<iframe src="http://www.example.com/video" class="superembed-square"></iframe>

New in SuperEmbed.js 3.0:

  • Improved performance and cleaner code
  • Added support for Facebook, Gfycat, LiveLeak, MySpace, and Archive.org embeds

New in SuperEmbed.js 2.3:

  • Now uses getComputedStyle to calculate width and height on supported browsers

New in SuperEmbed.js 2.2:

  • Fixes to avoid conflict with other libraries

New in SuperEmbed.js 2.1:

  • Now optionally uses JQuery for detecting page load and page resize, if JQuery is loaded before SuperEmbed

New in SuperEmbed.js 2.0:

  • Almost completely re-written, resizing is now handled by JS instead of CSS
  • Now videos maintain their original aspect ratio when resized, no more letterboxing
  • Minimum Internet Explorer version dropped to IE 9
  • The .superembed-square class now applies a 1:1 ratio, instead of a 4:3 ratio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

superembed.js's People

Contributors

abdobouna avatar br0ken- avatar corbindavenport avatar

Watchers

 avatar  avatar

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.