# HG changeset patch # User ymh # Date 1480645851 -3600 # Node ID a8bed1c7df8ea6a23653ceb675598666325b5587 # Parent 710a2ae08a742f70361f4dba16d6381a1b9fa0e7 move the transcript highlight and autoscroll logic to the base component diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/components/transcript-annotation-component.js --- a/cms/app-client/app/components/transcript-annotation-component.js Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/components/transcript-annotation-component.js Fri Dec 02 03:30:51 2016 +0100 @@ -2,7 +2,7 @@ export default Ember.Component.extend({ - classNameBindings: ['isPlaying:active'], + // classNameBindings: ['isPlaying:active'], hasPlayer: Ember.computed.bool('player'), @@ -15,9 +15,16 @@ literal: Ember.computed.readOnly('annotation.literal'), translation: Ember.computed.readOnly('annotation.translation'), - isPlaying: Ember.computed("hasPlayer","player.progress", "begin", "end", function() { - var progress = this.get('player.progress'); - return this.get('hasPlayer') && progress && (progress >= this.get('begin')) && (progress < this.get('end')); - }) + // isPlaying: Ember.computed("hasPlayer","player.progress", "begin", "end", function() { + // var progress = this.get('player.progress'); + // return this.get('hasPlayer') && progress && (progress >= this.get('begin')) && (progress < this.get('end')); + // }), + + didInsertElement: function() { + if(this.get('hasPlayer') && this.get('intervals')) { + this.get('intervals').add(this.get('begin'), this.get('end'), this.get('elementId'), this.$()); + } + }, + }); diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/components/transcript-component.js --- a/cms/app-client/app/components/transcript-component.js Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/components/transcript-component.js Fri Dec 02 03:30:51 2016 +0100 @@ -1,4 +1,5 @@ import Ember from 'ember'; +import IntervalTree from 'interval-tree'; export default Ember.Component.extend({ @@ -16,17 +17,22 @@ return sections && sections.length > 0; }), + didReceiveAttrs() { + this._super(...arguments); + this.set('intervals', new IntervalTree(this.get('player.model.duration_ms')/2)); + }, + itemObserver: Ember.observer('player.item', function () { if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { this.set('autoscroll', true); } }), - didInsertElement: function() { + didInsertElement() { Ember.$('#' + this.elementId).parent().on('scroll', Ember.run.bind(this, this.onScroll)); }, - onScroll: function() { + onScroll() { if ( !(this.get('isDestroyed') || this.get('isDestroying')) ) { this.set('autoscroll', false); } @@ -37,17 +43,39 @@ scroll: Ember.observer('player.progress', function() { var self = this; - var target = this.$('.sentence.active'); - if(this.get('autoscroll') && target.length && target.attr('id') !== this.get('previousElement')) { + var progress = this.get('player.progress'); + var previousElement = this.get('previousElement'); + if(previousElement && progress >= previousElement.start && progress < previousElement.end) { + return; + } + var intervals = this.get('intervals'); + if(!intervals) { + return; + } + var intervalList = intervals.search(progress); + if(intervalList.length === 0) { + return; + } + var target = intervalList[0]; + //var target = this.$('.sentence.active'); + if(previousElement) { + previousElement.object.removeClass('active'); + Ember.$(".fa-play",previousElement.object).show(); + } + target.object.addClass('active'); + Ember.$(".fa-play",target.object).hide(); + + + if(this.get('autoscroll') && target.object.length && (!previousElement || target.id !== previousElement.id)) { Ember.$('#' + self.elementId).parent().off('scroll'); Ember.$(this.get('autoscrollElement')).animate({ - scrollTop: target.offset().top + Ember.$(this.get('autoscrollElement')).scrollTop() - Ember.$(this.get('autoscrollElement')).offset().top - 154 + scrollTop: target.object.offset().top + Ember.$(this.get('autoscrollElement')).scrollTop() - Ember.$(this.get('autoscrollElement')).offset().top - 154 }, 150, 'swing', function() { setTimeout(function() { Ember.$('#' + self.elementId).parent().on('scroll', Ember.run.bind(self, self.onScroll)); }, 100); }); - this.set('previousElement', target.attr('id')); + this.set('previousElement', target); } }), diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/components/transcript-turn-component.js --- a/cms/app-client/app/components/transcript-turn-component.js Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/components/transcript-turn-component.js Fri Dec 02 03:30:51 2016 +0100 @@ -4,15 +4,22 @@ tagName: 'li', classNames: ['sentence'], - classNameBindings: ['isPlaying:active'], + // classNameBindings: ['isPlaying:active'], begin: Ember.computed.readOnly('turn.begin'), end: Ember.computed.readOnly('turn.end'), title: Ember.computed.readOnly('turn.title'), annotations: Ember.computed.readOnly('turn.annotations'), - isPlaying: Ember.computed("player.progress", "begin", "end", function() { - var progress = this.get('player.progress'); - return progress && progress >= this.get('begin') && progress < this.get('end'); - }) + // isPlaying: Ember.computed("player.progress", "begin", "end", function() { + // var progress = this.get('player.progress'); + // return progress && progress >= this.get('begin') && progress < this.get('end'); + // }), + + didInsertElement: function() { + if(this.get('intervals')) { + this.get('intervals').add(this.get('begin'), this.get('end'), this.get('elementId'), this.$()); + } + }, + }); diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/templates/components/transcript-component.hbs --- a/cms/app-client/app/templates/components/transcript-component.hbs Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/templates/components/transcript-component.hbs Fri Dec 02 03:30:51 2016 +0100 @@ -8,12 +8,12 @@
{{#if hasSections }} {{#each player.transcript.sections as |section|}} - {{transcript-section-component section=section player=player play=(action 'play')}} + {{transcript-section-component section=section player=player play=(action 'play') intervals=intervals}} {{/each}} {{else}}
    {{#each player.transcript.annotations as |annotation|}} - {{transcript-annotation-component annotation=annotation player=player play=(action 'play') tagName='li' class='sentence'}} + {{transcript-annotation-component annotation=annotation player=player intervals=intervals play=(action 'play') tagName='li' class='sentence'}} {{/each}}
{{/if}} diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/templates/components/transcript-section-component.hbs --- a/cms/app-client/app/templates/components/transcript-section-component.hbs Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/templates/components/transcript-section-component.hbs Fri Dec 02 03:30:51 2016 +0100 @@ -1,7 +1,7 @@

{{title}}

    {{#each turns as |turn|}} - {{transcript-turn-component turn=turn player=player play=(action play)}} + {{transcript-turn-component turn=turn player=player intervals=intervals play=(action play)}} {{/each}}
diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/app/templates/components/transcript-turn-component.hbs --- a/cms/app-client/app/templates/components/transcript-turn-component.hbs Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/app/templates/components/transcript-turn-component.hbs Fri Dec 02 03:30:51 2016 +0100 @@ -1,6 +1,4 @@ -{{#unless isPlaying}} - Play -{{/unless}} +Play {{#if title}}{{title}}{{/if}} {{#each annotations as |annotation|}} {{transcript-annotation-component annotation=annotation}} diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/ember-cli-build.js --- a/cms/app-client/ember-cli-build.js Fri Dec 02 00:22:31 2016 +0100 +++ b/cms/app-client/ember-cli-build.js Fri Dec 02 03:30:51 2016 +0100 @@ -47,6 +47,8 @@ development: 'bower_components/urijs/src/URI.js', production: 'bower_components/urijs/src/URI.min.js' }); + app.import('bower_components/interval-tree2/dist/interval-tree.js'); + //shims app.import('vendor/shims/ammaps.js', { @@ -69,6 +71,11 @@ 'urijs': [ 'default' ] } }); + app.import('vendor/shims/interval-tree.js', { + exports: { + 'interval-tree': [ 'default' ] + } + }); //social-share-kit app.import('bower_components/social-share-kit/dist/js/social-share-kit.js'); diff -r 710a2ae08a74 -r a8bed1c7df8e cms/app-client/vendor/shims/interval-tree.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/vendor/shims/interval-tree.js Fri Dec 02 03:30:51 2016 +0100 @@ -0,0 +1,9 @@ +(function() { + function vendorModule() { + 'use strict'; + + return { 'default': self['IntervalTree'] }; + } + + define('interval-tree', [], vendorModule); +})();