This repository has been archived by the owner on Oct 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
65 lines (60 loc) · 2.45 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//= require ./vendor/jquery/jquery-1.11.0.js
//= require ./vendor/jquery/jquery-migrate-1.2.1.js
//= require ./vendor/jquery/jquery-ui-1.10.4.js
//= require ../govuk_toolkit/javascripts/vendor/jquery/jquery.player.min.js
//= require ../govuk_toolkit/javascripts/govuk/analytics/google-analytics-universal-tracker.js
//= require ../govuk_toolkit/javascripts/govuk/analytics/analytics.js
//= require analytics-init.js
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
}());
jQuery(function($) {
var $yt_links = $(".media-player-link");
// Create players for our youtube links
$.each($yt_links, function(i) {
var $holder = $('<figure class="media-player" />');
var $this = $(this);
$this.parent().replaceWith($holder);
// Find the captions file if it exists
var $mycaptions = $(this).siblings('.captions');
// Work out if we have captions or not
var captionsf = $($mycaptions).length > 0 ? $($mycaptions).attr('href') : null;
// Ensure that we extract the last part of the youtube link (the video id)
// and pass it to the player() method
var href = $(this).attr('href');
var link = href.split("=")[1];
// make sure we fetch the right SSL level
var youTubeURL = (document.location.protocol + '//www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=');
// Initialise the player
$holder.player({
id:'yt'+i,
media:link,
captions:captionsf,
url: youTubeURL,
flashHeight: '323px'
});
// Grab the text if required
var $figcaption = $('<figcaption data-url="' + href + '">' + $this.text() + ':</figcaption>');
if (!$this.hasClass('titled')) {
$figcaption.addClass('hidden');
}
$holder.prepend($figcaption);
});
});