| author | Anthony Ly <anthonyly.com@gmail.com> |
| Fri, 07 Jun 2013 16:31:42 +0200 | |
| changeset 101 | e40637c085b0 |
| parent 74 | 22aca5b735a2 |
| permissions | -rw-r--r-- |
| 25 | 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; |
|
| 28 | 14 |
$(this).parents('td').siblings('td').find(".time-tangle").addClass("deactivate"); |
| 25 | 15 |
return false; |
16 |
}); |
|
| 28 | 17 |
|
| 25 | 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 |
}); |
|
| 28 | 33 |
|
34 |
function updateRenderChapter(chapterData){ |
|
35 |
var segment = $('.chapter-segments li#'+chapterData.id), |
|
36 |
wChapterSegmentWrap = $('.chapter-segments').width(), |
|
|
74
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
37 |
wSegmentNew = chapterData.getDuration() * wChapterSegmentWrap / myMedia.duration, |
|
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
38 |
lSegmentNew = chapterData.begin * wChapterSegmentWrap / myMedia.duration, |
| 28 | 39 |
row = $('#row-list-chapter-'+chapterData.id), |
40 |
form = ($('#form-chapter-edit-'+chapterData.id).length) ? $('#form-chapter-edit-'+chapterData.id) : false; |
|
41 |
||
|
74
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
42 |
segment.css({ |
|
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
43 |
width : wSegmentNew, |
|
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
44 |
left : lSegmentNew |
|
22aca5b735a2
edit and preview buttons on project div home page
Anthony Ly <anthonyly.com@gmail.com>
parents:
63
diff
changeset
|
45 |
}); |
| 28 | 46 |
|
47 |
row.find('.begin').text(chapterData.begin); |
|
| 101 | 48 |
console.log(chapterData.getDuration()) |
| 28 | 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){ |
|
| 101 | 62 |
|
63 |
if (val<=chapterAfter.end && val>=chapterBefore.begin && chapterAfter.end-val>secMiniChapter*1000 && val-chapterBefore.begin>secMiniChapter*1000) { |
|
| 28 | 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; |
|
| 25 | 75 |
|
| 28 | 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; |
|
| 101 | 88 |
|
89 |
updateChapterDuration(val, chapterBefore, chapterAfter); |
|
90 |
||
| 28 | 91 |
|
92 |
}); |
|
93 |
/* |
|
| 25 | 94 |
$(".tangle-start") |
95 |
.mouseup(function(evt) { |
|
| 28 | 96 |
|
| 25 | 97 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
98 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
99 |
} |
|
100 |
}) |
|
101 |
.on("valuechange", function(evt, val) { |
|
| 28 | 102 |
|
| 25 | 103 |
if (currentMedia && currentSegment) { |
104 |
currentSegment.setBegin(val); |
|
105 |
} |
|
106 |
}); |
|
| 28 | 107 |
|
| 25 | 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 |
} |
|
| 28 | 123 |
|
124 |
}); */ |