forked from Khan/khan-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
related-videos.js
82 lines (71 loc) · 2.66 KB
/
related-videos.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Exercises.RelatedVideos = {
anchorElement: function(video) {
var template = Templates.get("video.related-video-link");
return $(template({
href: video.relativeUrl,
video: video
})).data("video", video);
},
render: function(videos) {
if (videos == null) {
videos = [];
}
var container = $(".related-video-box");
var jel = container.find(".related-video-list");
jel.empty();
var self = this;
PackageManager.require("video.css", "video.js").then(function() {
var template = Templates.get("video.thumbnail");
_.each(videos, function(video, i) {
var thumbnailDiv = $(template({
href: video.relativeUrl,
video: video
}));
thumbnailDiv.find("a.related-video")
.data("video", video)
.end();
var inlineLink = self.anchorElement(video)
.addClass("related-video-inline");
$("<li>")
.append(inlineLink)
.append(thumbnailDiv)
.appendTo(jel);
// TODO(alpert): Why create both of these elements to then
// only show one?
if (i > 0) {
thumbnailDiv.hide();
} else {
inlineLink.hide();
}
});
container.toggle(videos.length > 0);
if (videos.length > 0) {
$(Exercises).trigger("relatedVideosRendered");
}
self._bindEvents();
});
},
/**
* Called to initialize related video event handlers.
* Should only be called after video.js package is loaded.
*/
_bindEvents: _.once(function() {
// make caption slide up over the thumbnail on hover
var captionHeight = 45;
var marginTop = 23;
// queue:false to make sure these run simultaneously
var options = {duration: 150, queue: false};
$(".related-video-box")
.delegate(".thumbnail", "mouseenter mouseleave", function(e) {
var isMouseEnter = e.type === "mouseenter";
$(e.currentTarget).find(".thumbnail_label").animate(
{marginTop: marginTop + (isMouseEnter ? 0 : captionHeight)},
options)
.end()
.find(".thumbnail_teaser").animate(
{height: (isMouseEnter ? captionHeight : 0)},
options);
});
ModalVideo.hookup();
})
};