author | ymh <ymh.work@gmail.com> |
Fri, 02 Dec 2016 03:30:51 +0100 | |
changeset 455 | a8bed1c7df8e |
parent 454 | 710a2ae08a74 |
child 457 | a7a333c0b1eb |
permissions | -rw-r--r-- |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
2 |
import IntervalTree from 'interval-tree'; |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
3 |
|
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
4 |
export default Ember.Component.extend({ |
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
5 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
6 |
classNames: ['transcript-component'], |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
7 |
|
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
8 |
player: Ember.inject.service(), |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
9 |
|
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
10 |
autoscrollElement : '.corpus-app-container', |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
11 |
previousElement: 0, |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
12 |
autoscroll: true, |
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
13 |
timeout: null, |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
14 |
|
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
15 |
hasSections: Ember.computed('player', 'player.transcript', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
16 |
var sections = this.get('player.transcript.sections'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
17 |
return sections && sections.length > 0; |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
18 |
}), |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
19 |
|
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
20 |
didReceiveAttrs() { |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
21 |
this._super(...arguments); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
22 |
this.set('intervals', new IntervalTree(this.get('player.model.duration_ms')/2)); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
23 |
}, |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
24 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
25 |
itemObserver: Ember.observer('player.item', function () { |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
26 |
if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
27 |
this.set('autoscroll', true); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
28 |
} |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
29 |
}), |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
30 |
|
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
31 |
didInsertElement() { |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
32 |
Ember.$('#' + this.elementId).parent().on('scroll', Ember.run.bind(this, this.onScroll)); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
33 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
34 |
|
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
35 |
onScroll() { |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
36 |
if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
37 |
this.set('autoscroll', false); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
38 |
} |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
39 |
if(this.elementId) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
40 |
Ember.$('#' + this.elementId).parent().off('scroll'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
41 |
} |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
42 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
43 |
|
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
44 |
scroll: Ember.observer('player.progress', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
45 |
var self = this; |
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
46 |
var progress = this.get('player.progress'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
47 |
var previousElement = this.get('previousElement'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
48 |
if(previousElement && progress >= previousElement.start && progress < previousElement.end) { |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
49 |
return; |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
50 |
} |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
51 |
var intervals = this.get('intervals'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
52 |
if(!intervals) { |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
53 |
return; |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
54 |
} |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
55 |
var intervalList = intervals.search(progress); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
56 |
if(intervalList.length === 0) { |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
57 |
return; |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
58 |
} |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
59 |
var target = intervalList[0]; |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
60 |
//var target = this.$('.sentence.active'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
61 |
if(previousElement) { |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
62 |
previousElement.object.removeClass('active'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
63 |
Ember.$(".fa-play",previousElement.object).show(); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
64 |
} |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
65 |
target.object.addClass('active'); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
66 |
Ember.$(".fa-play",target.object).hide(); |
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
67 |
|
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
68 |
|
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
69 |
if(this.get('autoscroll') && target.object.length && (!previousElement || target.id !== previousElement.id)) { |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
70 |
Ember.$('#' + self.elementId).parent().off('scroll'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
71 |
Ember.$(this.get('autoscrollElement')).animate({ |
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
72 |
scrollTop: target.object.offset().top + Ember.$(this.get('autoscrollElement')).scrollTop() - Ember.$(this.get('autoscrollElement')).offset().top - 154 |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
73 |
}, 150, 'swing', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
74 |
setTimeout(function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
75 |
Ember.$('#' + self.elementId).parent().on('scroll', Ember.run.bind(self, self.onScroll)); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
76 |
}, 100); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
77 |
}); |
455
a8bed1c7df8e
move the transcript highlight and autoscroll logic to the base component
ymh <ymh.work@gmail.com>
parents:
454
diff
changeset
|
78 |
this.set('previousElement', target); |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
79 |
} |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
80 |
}), |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
81 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
82 |
|
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
83 |
actions: { |
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
84 |
|
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
85 |
play: function(progress) { |
249 | 86 |
this.get('player').trigger('progressupdate', progress); |
248
256272c33349
Transcript sentence lick and play
Chloe Laisne <chloe.laisne@gmail.com>
parents:
247
diff
changeset
|
87 |
this.get('player').set('playing', true); |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
88 |
} |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
89 |
} |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
90 |
|
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
91 |
}); |