Ahmed Nuaman


builder of internets ~ developer of dreams ~ tamer of Dachshunds

Introducing Vid – A jQuery Plugin For All Your Video Embedding Needs

It all started with a tweet:

@tensafefrogs: Cleaning up the YouTube embed code a bit: http://bit.ly/3oA4yM

I replied to Geoff saying ‘why not use javascript?’ to which he said: ‘because we want to be compatible with many (every) publishing platforms, and many of them don’t allow javascript’.

So that got me thinking, why not create a simple and small jQuery plugin for embedding videos… So I did…

I’ve stuck it up on github, it’s called ‘vid‘ and it’s very simple to use:

< !DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="http://github.com/ahmednuaman/vid/raw/master/jquery.vid.js"></script>
    </head>
    <body>
        <div id="flash" style="width: 500px; height: 400px;"></div>
        <script type="text/javascript">
        <!--
            $(document).ready( function()
            {
                var api = $( '#flash' ).vid({
                    type    : 'youtube',
                    videoId : 'R7yfISlGLNU'
                });
            });
        -->
        </script>
    </body>
</html>

And this gives you (yep, it really is my favourite video):

Cool eh? Not only does it work for YouTube, but also Vimeo, DailyMotion and of course, 1Click2Fame.com (come on, I’m not going to leave my own player out am I?).

Vimeo

< !DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="http://github.com/ahmednuaman/vid/raw/master/jquery.vid.js"></script>
    </head>
    <body>
        <div id="flash" style="width: 500px; height: 400px;"></div>
        <script type="text/javascript">
        <!--
            $(document).ready( function()
            {
                var api = $( '#flash' ).vid({
                    type    : 'vimeo',
                    videoId : '1161962'
                });
            });
        -->
        </script>
    </body>
</html>

DailyMotion

< !DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="http://github.com/ahmednuaman/vid/raw/master/jquery.vid.js"></script>
    </head>
    <body>
        <div id="flash" style="width: 500px; height: 400px;"></div>
        <script type="text/javascript">
        <!--
            $(document).ready( function()
            {
                var api = $( '#flash' ).vid({
                    type    : 'dailymotion',
                    videoId : 'xayowc'
                });
            });
        -->
        </script>
    </body>
</html>

1Click2Fame.com

< !DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="http://github.com/ahmednuaman/vid/raw/master/jquery.vid.js"></script>
    </head>
    <body>
        <div id="flash" style="width: 500px; height: 400px;"></div>
        <script type="text/javascript">
        <!--
            $(document).ready( function()
            {
                var api = $( '#flash' ).vid({
                    type    : '1click2fame',
                    videoId : '1987'
                });
            });
        -->
        </script>
    </body>
</html>

I must say, much love to Jonathan Neal for his jQuery SWFObject plugin, I’m using that here.

So check it out, tell me if you want anything added to it, and fork me! I’m going to be enabling JavaScript API interactions very soon too!

Where have comments gone?

Good question my old fruity. I'm now sticking any post discussions on Google+. Why? Well simply it's better. WordPress's comment system isn't very elegant and nor are ones like Disqus or Livefyre, so to save hassle I've just shipped them off to a social network, like a real boss.

Search

My social skills

Latest blog posts

  • Loading posts...

Subscribe in a reader

Latest tweets

  • Loading tweets...