author | ymh <ymh.work@gmail.com> |
Fri, 02 Dec 2016 00:22:31 +0100 | |
changeset 454 | 710a2ae08a74 |
parent 347 | 9779512454af |
child 455 | a8bed1c7df8e |
permissions | -rw-r--r-- |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
2 |
|
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
3 |
export default Ember.Component.extend({ |
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
4 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
5 |
classNames: ['transcript-component'], |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
6 |
|
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
7 |
player: Ember.inject.service(), |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
8 |
|
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
9 |
autoscrollElement : '.corpus-app-container', |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
10 |
previousElement: 0, |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
11 |
autoscroll: true, |
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
12 |
timeout: null, |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
13 |
|
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
14 |
hasSections: Ember.computed('player', 'player.transcript', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
15 |
var sections = this.get('player.transcript.sections'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
16 |
return sections && sections.length > 0; |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
17 |
}), |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
18 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
19 |
itemObserver: Ember.observer('player.item', function () { |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
20 |
if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
21 |
this.set('autoscroll', true); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
22 |
} |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
23 |
}), |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
24 |
|
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
25 |
didInsertElement: function() { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
26 |
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
|
27 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
28 |
|
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
29 |
onScroll: function() { |
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
30 |
if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
31 |
this.set('autoscroll', false); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
32 |
} |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
33 |
if(this.elementId) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
34 |
Ember.$('#' + this.elementId).parent().off('scroll'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
35 |
} |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
36 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
37 |
|
454
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
38 |
scroll: Ember.observer('player.progress', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
39 |
var self = this; |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
40 |
var target = this.$('.sentence.active'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
41 |
if(this.get('autoscroll') && target.length && target.attr('id') !== this.get('previousElement')) { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
42 |
Ember.$('#' + self.elementId).parent().off('scroll'); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
43 |
Ember.$(this.get('autoscrollElement')).animate({ |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
44 |
scrollTop: target.offset().top + Ember.$(this.get('autoscrollElement')).scrollTop() - Ember.$(this.get('autoscrollElement')).offset().top - 154 |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
45 |
}, 150, 'swing', function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
46 |
setTimeout(function() { |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
47 |
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
|
48 |
}, 100); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
49 |
}); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
50 |
this.set('previousElement', target.attr('id')); |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
51 |
} |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
52 |
}), |
710a2ae08a74
rework transcript component to correct various bugs
ymh <ymh.work@gmail.com>
parents:
347
diff
changeset
|
53 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
54 |
|
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
55 |
actions: { |
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
56 |
|
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
57 |
play: function(progress) { |
249 | 58 |
this.get('player').trigger('progressupdate', progress); |
248
256272c33349
Transcript sentence lick and play
Chloe Laisne <chloe.laisne@gmail.com>
parents:
247
diff
changeset
|
59 |
this.get('player').set('playing', true); |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
60 |
} |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
61 |
} |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
62 |
|
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
63 |
}); |