Git Product home page Git Product logo

fluidvids's Introduction

fluidvids.js Build Status

Fluidvids is a 1KB standalone module that provides a fluid solution for video embeds. Fluidvids has the ability for custom players to be added as well as support for dynamically injected (XHR/Ajax/createElement) videos.

Live demo of fluidvids.

Methods

init()

Pass in your configuration. That's it.

fluidvids.init({
  selector: ['iframe', 'object'], // runs querySelectorAll()
  players: ['www.youtube.com', 'player.vimeo.com'] // players to support
});

selector

Type: Array Default: ['iframe']

Custom selector(s) that fluidvids will search for in the DOM and make fluid.

players

Type: Array Default: ['www.youtube.com', 'player.vimeo.com']

Internally constructs a strict RegExp which tells fluidvids which videos from specific domains to make fluid. This avoids any unwanted videos being parsed and adds developer flexibility.

render()

Provides dynamic video support. Using render() should only be done when you want to requery the DOM and look for newly added videos, such as document.createElement('iframe');. Fluidvids uses internal object caching to lookup init() configuration, so it's lightning fast.

// run after dynamic elements have been injected
// you'll need to run this each time you need it
fluidvids.render();

Installing with Bower

Use the repository hook:

bower install https://github.com/toddmotto/fluidvids.git

Installing with browserify

Use the repository hook:

npm install toddmotto/fluidvids

Then require fluidvids in your file:

// Note that it is called as a function
var fluidvids = require('fluidvids.js')();

Manual installation

Ensure you're using the files from the dist directory (contains compiled production-ready code). Ensure you place the script before the closing </body> tag.

<body>
  <!-- html above -->
  <script src="dist/fluidvids.js"></script>
  <script>
  // fluidvids module available
  </script>
</body>

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release history

  • 2.4.1
    • Fix bug for class names already existing on host element
    • Update Jasmine test accordingly
  • 2.4.0
    • Fix bug for comparing width/height attrs > 1000
    • Finish all unit tests
    • Move to Gulp
  • 2.3.0
    • Add support for videos where height > width
    • Multiple selector support and CSS change to unrestrict element type
    • Add npm entry point
    • Change apply() to render() for better naming
    • Use while loop for and improved loop perf
  • 2.2.0
    • XHR/Ajax content support via new apply() method to requery DOM
    • Add AMD support
  • 2.1.0
    • Fix IE8 bug
  • 2.0.0
    • Complete rewrite using Module pattern with public methods
    • Better ability to add custom players
    • Add a custom selector
  • 1.2.0
    • Make use of Prototypes
  • 1.1.0
    • Better structure
  • 1.0.0
    • Initial release

fluidvids's People

Contributors

cuth avatar iamlacroix avatar jaydenseric avatar jillesme avatar theanxy avatar toddmotto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluidvids's Issues

Have video not extend further than width

@jaydenseric Made a pull request for this but it was somehow overwritten so it is not there anymore. I also saw that you made some changes. I recreated it. This is what I got and it works. I also added the YouTube privacy version of the url.

(function ( window, document, undefined ) {

    /*
     * Grab all iframes on the page or return
     */
    var iframes = document.getElementsByTagName( 'iframe' );

    /*
     * Loop through the iframes array
     */
    for ( var i = 0; i < iframes.length; i++ ) {

        var iframe = iframes[i],

        /*
         * RegExp, extend this if you need more players
         */
        players = /www.youtube.com|www.youtube-nocookie.com|player.vimeo.com/;

        /*
         * If the RegExp pattern exists within the current iframe
         */
        if ( iframe.src.search( players ) > 0 ) {

            /*
             * Calculate the video ratio based on the iframe's w/h dimensions
             */
            var width             = iframe.width;
            var height            = iframe.height;
            var videoRatio        = ( height / width ) * 100;

            /*
             * Replace the iframe's dimensions and position
             * the iframe absolute, this is the trick to emulate
             * the video ratio
             */
            iframe.style.position = 'absolute';
            iframe.style.top      = '0';
            iframe.style.left     = '0';
            iframe.width          = '100%';
            iframe.height         = '100%';

            /*
             * Wrap the iframe in a new <div> which uses a
             * dynamically fetched padding-top property based
             * on the video's w/h dimensions
             */
            var wrap              = document.createElement( 'div' );
            wrap.className        = 'video-wrap';
            wrap.style.width      = '100%';
            wrap.style.position   = 'relative';
            wrap.style.paddingTop = videoRatio + '%';

            /*
             * Add the iframe inside our newly created <div>
             */
            var iframeParent      = iframe.parentNode;
            iframeParent.insertBefore( wrap, iframe );
            wrap.appendChild( iframe );

            /*
             * Wrap the div in a new <div> which is used
             * to set a max width accordin to the video's dimensions
             */
            var outerWrap        = document.createElement( 'div' );
            outerWrap.className  = 'outer-video-wrap';
            outerWrap.style.maxWidth   = width + 'px';

            /*
             * Add the div wrap inside our newly created <div>
             */
            var wrapParent       = wrap.parentNode;
            wrapParent.insertBefore( outerWrap, wrap );
            outerWrap.appendChild( wrap );

        }

    }

})( window, document );

Console Error: Protocols, domains, and ports must match.

Hi Todd,

I'm seeing this console error since updating to the latest version of Fluid Vids. Any idea what's causing it?

Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://gomakethings.com". Protocols, domains, and ports must match.

Question re fluidvids.render()

Hi, I'm using the following jQuery click function to swap in a YouTube video for an image using the data-video attribute:

$('img.play-video').click(function(){
        video = '<iframe width=560 height=315 frameborder="0" allowfullscreen src="'+ $(this).attr('data-video') +'"></iframe>';
        $(this).replaceWith(video);          
    });

I'm wondering if I can apply fluidvids to a video inserted in this way, perhaps by using fluidvids.render(), and if so, how I would go about implementing it? Is this something I'd reference in the click function itself? Thanks for any assistance here.

npm installation issue

After installing with npm as stated in the REAME, requiring the package with

var fluidvids = require('fluidvids')();

fails because npm installs the package under node_modules/fluidvids.js just because that's the name of the module in package.json.

https://github.com/toddmotto/fluidvids/blob/master/package.json#L2

This is my workaround:

var fluidvids = require('fluidvids.js/dist/fluidvids')();

I think simply changing the package name in package.json to fluidvids should fix it and be no harm since the package isn't published to npm.


By the way.

๐Ÿ‘ +1 for using the repo hook for bower.
๐Ÿ‘Ž -1 for not publishing to npm.

"main" directive in Bower plugin

Hi again,

it would be nice, if the bower.json would contain a "main" directive (e.g. "main": "dist/fluidvids.js") like the package.json. Makes it easier to fit in common workflows (for example when using such plugins like main-bower-files etc.).

Anyway, thanks for the brilliant script.

no width height

Seems to require a width and height to work properly. Is there anyway to make this not the case?

Multiple Selector Support?

When initializing the script, it would be nice to use it for both objects and iframes (for example, I run a blog that embeds a lot of iframes, but occasionally embeds an video from older media sites (like ABC).

There doesn't seem to be a way to do this currently, so I suppose this is a feature request.

Video controls off page for widescreen displays

I have been trying to solve this for a while with a wordpress theme that uses fluidvids. The full screen display of the video makes the video so large in height the controls are off the page. Is there anyway to change the width of the video to match the aspect ratio of the video and keep the controls on-screen?

make bower.json

Just easier to bower i --save fluidvids than have to look up the repo each time.

Avoid duplicate URL submissions

When using FluidVids to embed any external source, the URL is first populated in the standard way, but then a subsequent call is made to the same URL. A standard Fiddler trace reveals the problem.

For an API call that is dependent on trusted ticket authentication (ie, one-ticket session key), the second call to the URL is invalid.

FWIW, I've been testing this with Tableau Server trusted ticket authentication.

vimeo embedding ?

can fluidvids embed an autoplaying vimeo video with less data transfer than the default vimeo embed ?

Does not work when added in header

I was just testing it out and it did not work for me at first. The reason was that I add the js to the header. I know it is not best practice but I was just testing the code.

Styles in head - WHY

Why does the library add <style> to head ?
You can add a SASS file for example (_fludvids.scss) to the src folder for people to add it to their styles file. Or you can post necessary styles in readme for people to copy/paste them.
Finally, you can post an option for disabling the styles adding to the head.

Please, do smth from that, it is insane to see <style>...</style> in <head> in 2015. Thanks

Match URL without a Protocol?

Love this script btw!

But I'm trying to extend it a bit to make it work with instagram images too. The default instagram embed code does away with having http or https before the url. Would it be possible to modify the regex that you have in place for the players to check for http, https or just ://(instagram.com)?

You should have a default .fluid-vids-ignore class.

I came across your script messing with my already responsive videos. (Actual issue is not on that page). I now have to run JavaScript to remove classes and attributes is sets I guess. I saw this issue #9 but its not helping because I have no control oder the initialization process. Its other peoples WordPress sites and themes/plugins using this script.

I only have control oder HTML output with my plugin so I think you should do something fitfids does, enable users to simply ignore elements by adding .fluid-vids-ignore. I will have to do my manual removal anyway since I cant rely on themes being updated, so I am just suggesting this to help make this project better.

Issues with height of video from youtube

Hello!
I have issues with height of video.

<div class="fluidvids" style="padding-top: 300%;">

padding is huge.
Can you give me advice. How I can fix this issue ?
Thank you!

Google chart iframe

Hi Todd
Thanks for your work, one problem i have is using an iframe embedded from google docs by publishing a pie chart. It works fine in my responsive template, except on mobile phone (IOS).
Should your script work in this situation or is for video feeds only?

Issue with 1280 x 720 Embeds

Hi Todd,

Thanks for the great script! It's nice to have a vanilla js solution. I came across an issue when implementing Fluidvids on a site with many 1280x720 YouTube embeds. While the width is fluid, the height is not adjusted proportionately. I made a pen to demonstrate.

YouTube Embeds Not Playable on iOS

Hi Todd,

I am unable to play YouTube embeds on iOS. I am able to play them just fine on my desktop. If you have an iPhone or iPad, checkout this post for an example. I'm not seeing any errors in the console...

Errors on init with the last two current versions

Hi,

fluidvids is installed as a bower plugin. And gives me errors on initialisation at least with the last two current versions (s. below). v2.2.2 works fine for me.

Console output:
Installed v2.3.0 => Uncaught TypeError: exports.selector.join is not a function
Installed v2.4.1 => Uncaught TypeError: fluidvids.selector.join is not a function

Can anyone confirm this?

Return FluidVids from closure

The script won't work with dynamic content as the closure does not return anything.

eg. window.fluidvids === null // true

The closure function should return Fluidvids.

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.