1 var tagTool = { |
|
2 |
|
3 // Segments: {in (ms), out (ms), tag, user} |
|
4 segments: Array(), |
|
5 currentTags: Array(), |
|
6 |
|
7 tagContainer: "", |
|
8 player: false, |
|
9 showTagInPage: true, |
|
10 showTagInPlayer: true, |
|
11 stopOnSegment: false, |
|
12 |
|
13 playSegment: function(seg, pause) { |
|
14 |
|
15 if (pause == "on") |
|
16 this.stopOnSegment = this.segments[seg].sout; |
|
17 |
|
18 this.player.seek(this.segments[seg].sin / 1000); |
|
19 }, |
|
20 |
|
21 displayTags: function() { |
|
22 |
|
23 if (this.showTagInPage) { |
|
24 taglist=$('<ul></ul>'); |
|
25 for (tag in this.currentTags) |
|
26 $('<li>' + this.currentTags[tag] + '</li>').appendTo(taglist); |
|
27 $(this.tagContainer).html(taglist); |
|
28 } |
|
29 |
|
30 if (this.showTagInPlayer) { |
|
31 if (this.currentTags.length == 0) |
|
32 this.player.getPlugin('content').fadeOut(); |
|
33 else { |
|
34 line = '<p>' + this.currentTags.join('<br>') + '</p>'; |
|
35 this.player.getPlugin('content').animate({height: 15*(this.currentTags.length + 1) + 'px'}); |
|
36 this.player.getPlugin('content').setHtml(line).fadeIn(); |
|
37 } |
|
38 } |
|
39 }, |
|
40 |
|
41 addTag: function(tag) { |
|
42 this.currentTags.push(tag); |
|
43 this.displayTags(); |
|
44 }, |
|
45 |
|
46 removeTag: function(tag) { |
|
47 this.currentTags.splice(this.currentTags.indexOf(tag), 1); |
|
48 this.displayTags(); |
|
49 }, |
|
50 |
|
51 rebuildCurrentTags: function(position) { |
|
52 this.currentTags = new Array(); |
|
53 for (seg in this.segments) { |
|
54 if (this.segments[seg].sin < position && this.segments[seg].sout > position) { |
|
55 this.currentTags.push(this.segments[seg].tag); |
|
56 } |
|
57 } |
|
58 this.displayTags(); |
|
59 }, |
|
60 |
|
61 setupHandlers: function(player) { |
|
62 |
|
63 cuepoints = new Array(); |
|
64 for (seg in this.segments) { |
|
65 cuepoint = {time: this.segments[seg].sin, tag: this.segments[seg].tag}; |
|
66 cuepoints.push(cuepoint); |
|
67 cuepoint = {time: this.segments[seg].sout, tag: this.segments[seg].tag, out: 'true'}; |
|
68 cuepoints.push(cuepoint); |
|
69 } |
|
70 player.onCuepoint(cuepoints, function(clip, cuepoint) { |
|
71 if (cuepoint.out) { |
|
72 tagTool.removeTag(cuepoint.tag); |
|
73 if (tagTool.stopOnSegment == cuepoint.time) { |
|
74 this.pause(); |
|
75 tagTool.stopOnSegment = false; |
|
76 } |
|
77 } else { |
|
78 tagTool.addTag(cuepoint.tag); |
|
79 } |
|
80 }); |
|
81 |
|
82 } |
|
83 } |
|