forked from mozilla/popcorn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopcorn.wordriver.unit.js
executable file
·123 lines (100 loc) · 3.31 KB
/
popcorn.wordriver.unit.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
test( "Popcorn wordriver Plugin", function() {
var popped = Popcorn( "#video" ),
expects = 16,
count = 0,
firstTrack,
secondTrack,
firstCue,
secondCue,
thirdCue,
wordriverdiv = document.getElementById( "wordriverdiv" );
expect( expects );
function plus() {
if ( ++count === expects ) {
start();
}
}
stop();
ok( "wordriver" in popped, "wordriver is a method of the popped instance" );
plus();
equal( wordriverdiv.childElementCount, 0, "initially, there is nothing inside the wordriverdiv" );
plus();
popped.wordriver({
start: 0,
end: 2,
text: "hello",
target: "wordriverdiv",
color: "red"
});
firstTrack = popped.getLastTrackEventId();
popped.wordriver({
start: 2,
end: 4,
text: "world",
target: "wordriverdiv",
color: "blue"
});
secondTrack = popped.getLastTrackEventId();
popped.wordriver({
start: 20,
end: 24,
text: "nothing here",
target: "wordriverdiv",
color: "green"
})
.volume( 0 );
popped.cue( 0, function() {
var child = wordriverdiv.children[ 0 ],
subChildren = child.children;
// need to do this here because we fire the event
// as soon as we can, as it starts at 0
firstCue = popped.getLastTrackEventId();
equal( child.childElementCount, 1, "wordriverdiv now has one inner element" );
plus();
equal( subChildren[ 0 ].style.opacity, 1, "first word is visible on the page" );
plus();
equal( subChildren[ 0 ].innerHTML, "hello", "first word content is correct" );
plus();
ok( !subChildren[ 1 ], "second word does not exist yet" );
plus();
popped.removeTrackEvent( firstCue );
});
popped.cue( 2, function() {
var child = wordriverdiv.children[ 0 ],
subChildren = child.children;
equal( child.childElementCount, 2, "wordriverdiv now has two inner elements" );
plus();
equal( subChildren[ 0 ].style.opacity, 0, "first word is not visible on the page" );
plus();
equal( subChildren[ 0 ].innerHTML, "hello", "first word content is correct" );
plus();
equal( subChildren[ 1 ].style.opacity, 1, "second word is visible on the page" );
plus();
equal( subChildren[ 1 ].innerHTML, "world", "second word content is correct" );
plus();
popped.removeTrackEvent( secondCue );
});
secondCue = popped.getLastTrackEventId();
popped.cue( 4, function() {
var child = wordriverdiv.children[ 0 ],
subChildren = child.children;
equal( subChildren[ 0 ].style.opacity, 0, "first word is not visible on the page" );
plus();
equal( subChildren[ 1 ].style.opacity, 0, "second word is not visible on the page" );
plus();
popped.pause().removeTrackEvent( firstTrack );
equal( child.childElementCount, 1, "wordriverdiv now has one inner element" );
plus();
equal( subChildren[ 0 ].innerHTML, "world", "first word content is changed" );
plus();
popped.pause().removeTrackEvent( secondTrack );
equal( wordriverdiv.childElementCount, 0, "wordriverdiv now has no inner element, even though one still exists, but was never called" );
plus();
popped.removeTrackEvent( thirdCue );
});
thirdCue = popped.getLastTrackEventId();
// empty track events should be safe
Popcorn.plugin.debug = true;
popped.wordriver({});
popped.play();
});