-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
105 lines (85 loc) · 2.6 KB
/
demo.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var control, video, position, play;
// Object literal to hold onto our controller classes.
control = {
// Position controller will be used to update the video position indicator.
Position : can.Control({
// Gets called upon instantiation.
init : function(){
// The movie starts at the beginning, so set the indicator to the
// left.
this.moving = $("<div>").css({
position: 'absolute',
left: "0px"
})
// Add it to the DOM.
this.element.css("position","relative")
.append( this.moving );
// Make the indicator square.
this.moving.outerWidth( this.element.height() );
this.moving.outerHeight( this.element.height() );
},
// Templated binding the to Popcorn video object.
"{video.video} timeupdate" : function( video ) {
this.resize()
},
// Calculated and updates the position of the moving indicator.
resize : function(){
var video = this.options.video,
percent = video.currentTime() / video.duration(),
width = this.element.width() - this.moving.outerWidth();
this.moving.css("left", percent*width+"px")
},
// Allows the user to drag the moving indicator to a specific point in
// the video.
"div draginit" : function(el, ev, drag){
this.options.video.pause()
drag.limit(this.element)
},
// When the user stops dragging, update the position and play the video
// from that point.
"div dragend" : function(el, ev, drag){
var video = this.options.video,
width = this.element.width() - this.moving.outerWidth()
percent = parseInt(this.moving.css("left"), 10) / width;
video.currentTime( percent * video.duration() );
video.play()
}
}),
// Play controller manages playing and pausing.
Play : can.Control({
// Set the text of the play button depending on if the video is playing
// already or not.
init : function(){
if ( this.options.video.paused() ) {
this.element.text("▶")
} else {
this.element.text("||")
}
},
// Update button text on play / pause
"{video.video} play" : function() {
this.element.text("||").addClass('stop')
},
"{video.video} pause" : function() {
this.element.text("▶").removeClass('stop')
},
// Play / pause the video on click
click : function() {
if( this.options.video.paused() ) {
this.options.video.play()
} else {
this.options.video.pause()
}
}
})
};
// Grab the popcorn video object.
video = Popcorn("#trailer");
// Instantiate the position and play controllers, passing in the popcorn video
// object.
position = new control.Position("#position", {
video : video
});
play = new control.Play("#play", {
video : video
});