author | Chloe Laisne <chloe.laisne@gmail.com> |
Mon, 17 Oct 2016 19:51:14 +0530 | |
changeset 345 | 4b66390442fd |
parent 257 | eba9edbd8f46 |
child 347 | 9779512454af |
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 |
|
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
14 |
itemObserver: Ember.observer('player.item', function () { |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
15 |
this.set('autoscroll', true); |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
16 |
}), |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
17 |
|
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
18 |
didInsertElement: function() { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
19 |
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
|
20 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
21 |
|
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
22 |
onScroll: function() { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
23 |
this.set('autoscroll', false); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
24 |
Ember.$('#' + this.elementId).parent().off('scroll'); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
25 |
}, |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
26 |
|
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
27 |
didUpdate: function() { |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
28 |
var self = this; |
255
ed05b89e3299
Add words to transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
249
diff
changeset
|
29 |
var target = Ember.$('.sentence.active'); |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
30 |
if(this.get('autoscroll') && target.length && target.attr('data-ember-action') !== this.get('previousElement')) { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
31 |
Ember.$('#' + self.elementId).parent().off('scroll'); |
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
32 |
Ember.$(this.get('autoscrollElement')).animate({ |
255
ed05b89e3299
Add words to transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
249
diff
changeset
|
33 |
scrollTop: target.offset().top + Ember.$(this.get('autoscrollElement')).scrollTop() - Ember.$(this.get('autoscrollElement')).offset().top - 154 |
345
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
34 |
}, 150, 'swing', function() { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
35 |
setTimeout(function() { |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
36 |
Ember.$('#' + self.elementId).parent().on('scroll', Ember.run.bind(self, self.onScroll)); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
37 |
}, 100); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
38 |
}); |
4b66390442fd
Cancel auto scroll on manual scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
257
diff
changeset
|
39 |
this.set('previousElement', target.attr('data-ember-action')) |
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
40 |
} |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
41 |
}, |
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
42 |
|
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
43 |
actions: { |
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
44 |
|
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
45 |
play: function(progress) { |
249 | 46 |
this.get('player').trigger('progressupdate', progress); |
248
256272c33349
Transcript sentence lick and play
Chloe Laisne <chloe.laisne@gmail.com>
parents:
247
diff
changeset
|
47 |
this.get('player').set('playing', true); |
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
48 |
} |
247
7a5d729992b8
Design and animate transcript
Chloe Laisne <chloe.laisne@gmail.com>
parents:
246
diff
changeset
|
49 |
|
246
5b7ae96768be
Bsic transcript-component design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
245
diff
changeset
|
50 |
} |
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
51 |
|
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
52 |
}); |