| 1 |
window.vimeography = window.vimeography || {}; |
| 2 |
|
| 3 |
//http://jsfiddle.net/elijahmanor/MVNBz/22/ |
| 4 |
(function(utilities, $, undefined) { |
| 5 |
|
| 6 |
utilities.enable_byline = 0; |
| 7 |
utilities.enable_title = 0; |
| 8 |
utilities.enable_portrait = 0; |
| 9 |
utilities.enable_autoplay = 0; |
| 10 |
utilities.enable_api = 1; |
| 11 |
|
| 12 |
utilities.player_id = ''; |
| 13 |
|
| 14 |
/** |
| 15 |
* Return the gallery wrapper for the provided ID |
| 16 |
* |
| 17 |
* @since 1.2.3 |
| 18 |
* @param {[type]} id [description] |
| 19 |
* @return {[type]} [description] |
| 20 |
*/ |
| 21 |
utilities.get_gallery = function(id) { |
| 22 |
return $('#vimeography-gallery-' + id); |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* Sets a custom event to trigger when the Vimeo video |
| 27 |
* has ended |
| 28 |
* |
| 29 |
* If any videos exist, add events |
| 30 |
* |
| 31 |
* If no videos, we need to add events when they are finally retrieved |
| 32 |
* |
| 33 |
* @since 1.2.3 |
| 34 |
* @return {[type]} [description] |
| 35 |
*/ |
| 36 |
utilities.enable_playlist = function(gallery_id) { |
| 37 |
$gallery = utilities.get_gallery(gallery_id); |
| 38 |
|
| 39 |
// Wait for the gallery to send a signal |
| 40 |
$gallery.on('vimeography/video/ready', function(){ |
| 41 |
var player = $('#' + utilities.player_id)[0]; |
| 42 |
|
| 43 |
$f(player).addEvent('ready', function(player_id){ |
| 44 |
var froogaloop = $f(player_id); |
| 45 |
|
| 46 |
froogaloop.addEvent('finish', function(player_id){ |
| 47 |
var gallery = utilities.get_gallery(gallery_id); |
| 48 |
gallery.trigger('vimeography/playlist/next'); |
| 49 |
}); |
| 50 |
}); |
| 51 |
}); |
| 52 |
}; |
| 53 |
|
| 54 |
/** |
| 55 |
* [get_video description] |
| 56 |
* @param {[type]} link [description] |
| 57 |
* @return {[type]} [description] |
| 58 |
*/ |
| 59 |
utilities.get_video = function(link) { |
| 60 |
var endpoint = 'https://vimeo.com/api/oembed.json'; |
| 61 |
|
| 62 |
// Put together the URL |
| 63 |
var url = endpoint |
| 64 |
+ '?url=' + encodeURIComponent(link) |
| 65 |
+ '&byline=' + utilities.enable_byline |
| 66 |
+ '&title=' + utilities.enable_title |
| 67 |
+ '&portrait=' + utilities.enable_portrait |
| 68 |
+ '&autoplay=' + utilities.enable_autoplay |
| 69 |
+ '&api=' + utilities.enable_api |
| 70 |
+ '&player_id='+ 'vimeography' + Math.floor(Math.random()*999999) |
| 71 |
+ '&callback=?'; |
| 72 |
|
| 73 |
return $.getJSON(url); |
| 74 |
}; |
| 75 |
|
| 76 |
/** |
| 77 |
* Sets the iframe DOM ID to the same string that was generated |
| 78 |
* during the oEmbed get_video call |
| 79 |
* |
| 80 |
* @param string html Unmodified iframe HTML |
| 81 |
* @return string html iframe HTML with ID added |
| 82 |
*/ |
| 83 |
utilities.set_video_id = function(html) { |
| 84 |
var regex = /player_id=(vimeography\d+)/g; |
| 85 |
var match = regex.exec(html); |
| 86 |
|
| 87 |
var iframe = $(html).filter('iframe')[0]; |
| 88 |
|
| 89 |
utilities.player_id = match[1]; |
| 90 |
iframe.id = utilities.player_id; |
| 91 |
|
| 92 |
return iframe; |
| 93 |
}; |
| 94 |
|
| 95 |
/** |
| 96 |
* [ description] |
| 97 |
* @param {[type]} html [description] |
| 98 |
* @return {[type]} [description] |
| 99 |
*/ |
| 100 |
utilities.add_fancybox_class = function(html) { |
| 101 |
var iframe = $(html).filter('iframe')[0]; |
| 102 |
iframe.className = 'fancybox-iframe'; |
| 103 |
return iframe; |
| 104 |
}; |
| 105 |
|
| 106 |
}( window.vimeography.utilities = window.vimeography.utilities || {}, jQuery )); |