10 autoscrollElement : '.corpus-app-container', |
10 autoscrollElement : '.corpus-app-container', |
11 previousElement: 0, |
11 previousElement: 0, |
12 autoscroll: true, |
12 autoscroll: true, |
13 timeout: null, |
13 timeout: null, |
14 |
14 |
15 hasSections: Ember.computed('player', 'player.transcript', function() { |
15 transcript: Ember.computed.readOnly('player.transcript'), |
16 var sections = this.get('player.transcript.sections'); |
16 hasSections: Ember.computed('transcript', function() { |
|
17 var sections = this.get('transcript.sections'); |
17 return sections && sections.length > 0; |
18 return sections && sections.length > 0; |
18 }), |
19 }), |
19 |
20 |
20 didReceiveAttrs() { |
21 didReceiveAttrs() { |
21 this._super(...arguments); |
22 this._super(...arguments); |
22 this.set('intervals', new IntervalTree(this.get('player.model.duration_ms')/2)); |
|
23 }, |
23 }, |
24 |
24 |
25 itemObserver: Ember.observer('player.item', function () { |
25 itemObserver: Ember.observer('player.item', function () { |
26 if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
26 if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
27 this.set('autoscroll', true); |
27 this.set('autoscroll', true); |
28 } |
28 } |
29 }), |
29 }), |
30 |
30 |
31 didInsertElement() { |
31 didInsertElement() { |
32 Ember.$('#' + this.elementId).parent().on('scroll', Ember.run.bind(this, this.onScroll)); |
32 Ember.$('#' + this.elementId).parent().on('scroll', Ember.run.bind(this, this.onScroll)); |
|
33 var intervals = new IntervalTree(this.get('player.model.duration_ms')/2); |
|
34 if(this.get('hasSections')) { |
|
35 this.get('transcript.sections').forEach((section, indexSection) => { |
|
36 section.turns.forEach((turn, indexTurn) => { |
|
37 let sentenceId = `#sentence-${indexSection}-${indexTurn}`; |
|
38 intervals.add(turn.begin ,turn.end , sentenceId/*, this.$(sentenceId)*/); |
|
39 }); |
|
40 }); |
|
41 } else { |
|
42 this.get('transcript.annotations').forEach((annotation, index) => { |
|
43 let sentenceId = `#sentence-${index}`; |
|
44 intervals.add(annotation.begin ,annotation.end , sentenceId/*, this.$(sentenceId)*/); |
|
45 }); |
|
46 } |
|
47 this.set('intervals', intervals); |
33 }, |
48 }, |
34 |
49 |
35 onScroll() { |
50 onScroll() { |
36 if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
51 if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { |
37 this.set('autoscroll', false); |
52 this.set('autoscroll', false); |
55 var intervalList = intervals.search(progress); |
70 var intervalList = intervals.search(progress); |
56 if(intervalList.length === 0) { |
71 if(intervalList.length === 0) { |
57 return; |
72 return; |
58 } |
73 } |
59 var target = intervalList[0]; |
74 var target = intervalList[0]; |
60 //var target = this.$('.sentence.active'); |
75 target.object = this.$(target.id); |
61 if(previousElement) { |
76 let previousDomElement = this.$('.sentence.active'); |
62 previousElement.object.removeClass('active'); |
77 |
63 Ember.$(".fa-play",previousElement.object).show(); |
78 if(previousDomElement) { |
|
79 previousDomElement.removeClass('active'); |
|
80 Ember.$(".fa-play",previousDomElement).show(); |
64 } |
81 } |
65 target.object.addClass('active'); |
82 target.object.addClass('active'); |
66 Ember.$(".fa-play",target.object).hide(); |
83 Ember.$(".fa-play",target.object).hide(); |
67 |
84 |
68 |
85 |