1 /* Tangles */ |
|
2 var tangleMsPerPixel = 100, |
|
3 activeTangle, |
|
4 tangleStartX, |
|
5 tangleStartVal, |
|
6 tangleHasMoved; |
|
7 |
|
8 $('.chapter-widget-info').on('mousedown', '.time-tangle', function(evt){ |
|
9 activeTangle = $(this); |
|
10 activeTangle.addClass("active"); |
|
11 tangleStartVal = +activeTangle.attr("data-milliseconds"); |
|
12 tangleStartX = evt.pageX; |
|
13 tangleHasMoved = false; |
|
14 $(this).parents('td').siblings('td').find(".time-tangle").addClass("deactivate"); |
|
15 return false; |
|
16 }); |
|
17 |
|
18 $(document) |
|
19 .mousemove(function(evt) { |
|
20 if (activeTangle) { |
|
21 tangleHasMoved = true; |
|
22 var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal); |
|
23 activeTangle.trigger("valuechange", newval); |
|
24 return false; |
|
25 } |
|
26 }) |
|
27 .mouseup(function() { |
|
28 if (activeTangle) { |
|
29 $(".time-tangle").removeClass("active deactivate"); |
|
30 activeTangle = undefined; |
|
31 } |
|
32 }); |
|
33 |
|
34 function updateRenderChapter(chapterData){ |
|
35 var segment = $('.chapter-segments li#'+chapterData.id), |
|
36 wChapterSegmentWrap = $('.chapter-segments').width(), |
|
37 wSegmentNew = chapterData.getDuration() * wChapterSegmentWrap / myMedia.duration, |
|
38 lSegmentNew = chapterData.begin * wChapterSegmentWrap / myMedia.duration, |
|
39 row = $('#row-list-chapter-'+chapterData.id), |
|
40 form = ($('#form-chapter-edit-'+chapterData.id).length) ? $('#form-chapter-edit-'+chapterData.id) : false; |
|
41 |
|
42 segment.css({ |
|
43 width : wSegmentNew, |
|
44 left : lSegmentNew |
|
45 }); |
|
46 |
|
47 row.find('.begin').text(chapterData.begin); |
|
48 console.log(chapterData.getDuration()) |
|
49 row.find('.duration').text(chapterData.getDuration()); |
|
50 row.find('.end').text(chapterData.end); |
|
51 |
|
52 if(form){ |
|
53 form.find('.begin').text(chapterData.begin); |
|
54 form.find('.begin').attr('data-milliseconds',chapterData.begin); |
|
55 form.find('.duration').text(chapterData.getDuration()); |
|
56 form.find('.end').text(chapterData.end); |
|
57 form.find('.end').attr('data-milliseconds',chapterData.end); |
|
58 } |
|
59 } |
|
60 |
|
61 function updateChapterDuration(val, chapterBefore, chapterAfter){ |
|
62 |
|
63 if (val<=chapterAfter.end && val>=chapterBefore.begin && chapterAfter.end-val>secMiniChapter*1000 && val-chapterBefore.begin>secMiniChapter*1000) { |
|
64 chapterAfter.setBegin(val); |
|
65 chapterBefore.setEnd(val); |
|
66 |
|
67 updateRenderChapter(chapterAfter); |
|
68 updateRenderChapter(chapterBefore); |
|
69 } |
|
70 } |
|
71 |
|
72 $('.chapter-widget-info').on('valuechange', '.tangle-start', function(evt, val){ |
|
73 var indexChapter = _.indexOf(chapters, currentChapter); |
|
74 if(indexChapter == 0 || chapters.length<=1) return; |
|
75 |
|
76 var chapterBefore = chapters[indexChapter-1], |
|
77 chapterAfter = currentChapter; |
|
78 |
|
79 updateChapterDuration(val, chapterBefore, chapterAfter); |
|
80 }); |
|
81 |
|
82 $('.chapter-widget-info').on('valuechange', '.tangle-end', function(evt, val){ |
|
83 var indexChapter = _.indexOf(chapters, currentChapter); |
|
84 if(indexChapter == chapters.length-1 || chapters.length<=1) return; |
|
85 |
|
86 var chapterAfter = chapters[indexChapter+1], |
|
87 chapterBefore = currentChapter; |
|
88 |
|
89 updateChapterDuration(val, chapterBefore, chapterAfter); |
|
90 |
|
91 |
|
92 }); |
|
93 /* |
|
94 $(".tangle-start") |
|
95 .mouseup(function(evt) { |
|
96 |
|
97 if (!tangleHasMoved && currentMedia && currentSegment) { |
|
98 currentMedia.setCurrentTime(currentSegment.begin); |
|
99 } |
|
100 }) |
|
101 .on("valuechange", function(evt, val) { |
|
102 |
|
103 if (currentMedia && currentSegment) { |
|
104 currentSegment.setBegin(val); |
|
105 } |
|
106 }); |
|
107 |
|
108 $(".tangle-end") |
|
109 .mouseup(function(evt) { |
|
110 if (!tangleHasMoved && currentMedia && currentSegment) { |
|
111 currentMedia.setCurrentTime(currentSegment.end); |
|
112 } |
|
113 }) |
|
114 .on("valuechange", function(evt, val) { |
|
115 if (currentMedia && currentSegment) { |
|
116 currentSegment.setEnd(val); |
|
117 } |
|
118 }); |
|
119 $(".tangle-duration").on("valuechange", function(evt, val) { |
|
120 if (currentMedia && currentSegment) { |
|
121 currentSegment.setDuration(val); |
|
122 } |
|
123 |
|
124 }); */ |
|