<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>fancybox Archives - Michael Sunarlim</title>
	<atom:link href="https://sunarlim.com/tag/fancybox/feed/" rel="self" type="application/rss+xml" />
	<link>https://sunarlim.com/tag/fancybox/</link>
	<description>Random blurbs about web development, e-commerce and technology</description>
	<lastBuildDate>Sun, 24 Jan 2016 05:31:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.5</generator>

<image>
	<url>https://i0.wp.com/sunarlim.com/wp-content/uploads/2016/07/cropped-MS_Square_512x512.png?fit=32%2C32&#038;ssl=1</url>
	<title>fancybox Archives - Michael Sunarlim</title>
	<link>https://sunarlim.com/tag/fancybox/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">30613895</site>	<item>
		<title>Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</title>
		<link>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/</link>
					<comments>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/#comments</comments>
		
		<dc:creator><![CDATA[Michael]]></dc:creator>
		<pubDate>Sun, 13 Apr 2014 11:49:15 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[fancybox]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[vimeo]]></category>
		<guid isPermaLink="false">https://sunarlim.com/?p=980</guid>

					<description><![CDATA[<p>FancyBox has been my number one preference when I need to implement a jQuery-based lightbox on any web page I am working on. It is the most customizable and extensible jQuery plugin for this function. Since version 2.0, it also introduced a concept of &#8216;helpers&#8217; to reduce the size of the main JS file and... <span class="more"><a class="more-link" href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Continue reading <span class="meta-nav">&#8594;</span></a></span></p>
<p>The post <a href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>FancyBox has been my number one preference when I need to implement a jQuery-based lightbox on any web page I am working on. It is the most customizable and extensible jQuery plugin for this function.</p>
<p>Since version 2.0, it also introduced a concept of &#8216;helpers&#8217; to reduce the size of the main JS file and also to allow developers to play more with its functionality with less risk of breaking the core functions when they are updated. Below I am going to show a little trick to modify FancyBox&#8217;s media helper to allow Vimeo link to auto-close when the video finishes.</p>
<p><span id="more-980"></span></p>
<h3>Vimeo API</h3>
<p>The first step to achieve this is by understanding <a title="Vimeo Player JavaScript API" href="http://developer.vimeo.com/player/js-api" target="_blank">Vimeo Player JavaScript API</a> and how to enable API calling for the videos. To save your time, there are two items you need to note:</p>
<ol>
<li>You need to turn on the API using <code>api=1</code> code and define the player ID ie. <code>player_id=vimeoplayer</code></li>
<li>Use Froogaloop, a JS mini-library written by Vimeo to communicate with their API. It can be downloaded <a title="Froogaloop on GitHub" href="https://github.com/vimeo/player-api/tree/master/javascript" target="_blank">here</a>.</li>
</ol>
<h3>Modifying Fancybox media helper file</h3>
<p>By default, the media helper file from FancyBox does not define the API and player ID. So we need to make minor change with the <code>helpers/jquery.fancybox-media.js</code>:</p>
<pre class="nums:false nums-toggle:false lang:js decode:true">vimeo : {
    matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
    params  : {
        autoplay      : 1,
        hd            : 1,
        show_title    : 1,
        show_byline   : 1,
        show_portrait : 0,
        fullscreen    : 1,
        api           : 1, // enable Vimeo Player API
        player_id     : 'fancybox-vimeo' // define Player ID
    },
    type : 'iframe',
    url  : '//player.vimeo.com/video/$1'
},</pre>
<p>&nbsp;</p>
<p>That&#8217;s it. You may want to save the helper file to another name, like <code>jquery.fancybox-media.custom.js</code></p>
<h3>Putting them together</h3>
<p>First call FancyBox scripts like you usually do, including the customized media helper file and Froogaloop.</p>
<pre class="nums:false nums-toggle:false lang:default decode:true">&lt;link rel="stylesheet" href="/path/to/js/lib/fancybox.v2/jquery.fancybox.css" type="text/css" media="screen" /&gt;
&lt;link rel="stylesheet" href="/path/to/js/lib/fancybox.v2/helpers/jquery.fancybox-buttons.css" type="text/css" media="screen" /&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/fancybox.v2/jquery.fancybox.pack.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/fancybox.v2/helpers/jquery.fancybox-media.custom.js?v=1.0.6"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/jquery.easing.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/js/lib/froogaloop.min.js"&gt;&lt;/script&gt;</pre>
<p>Next, let&#8217;s try to call FancyBox that auto-closes when the video has finished playing:</p>
<pre class="nums:false nums-toggle:false lang:xhtml decode:true  ">&lt;script type="text/javascript"&gt;
$(document).ready(function() {
    $("a#pt6vid").fancybox({
        tpl : {
            iframe   : '&lt;iframe id="fancybox-vimeo" name="fancybox-vimeo" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0"&gt;&lt;/iframe&gt;'
        },
        helpers : {
            media : {} // call media helper
        },
        // below is where we call Vimeo Player API
        afterLoad: function(current, previous) {
            var iframe = $('#fancybox-vimeo')[0],
                    player = $f(iframe);
            // When the player is ready, add listeners for pause, finish, and playProgress
            player.addEvent('ready', function() {
                player.addEvent('finish', function(id) {
                    $.fancybox.close();
                });
            });
        }
    });
});
&lt;/script&gt;</pre>
<p>Done.</p>
<p>The post <a href="https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/">Make Vimeo Lightbox Auto-Closes on Finish Using FancyBox</a> appeared first on <a href="https://sunarlim.com">Michael Sunarlim</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sunarlim.com/2014/04/make-vimeo-lightbox-auto-closes-finish-using-fancybox/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">980</post-id>	</item>
	</channel>
</rss>
