From a5fe66863eef403ffa4606a22c81ec2a367f1986 Mon Sep 17 00:00:00 2001 From: DawoudSheraz Date: Wed, 27 Feb 2019 11:15:23 +0500 Subject: [PATCH] fix video player speed adjustments --- .../xmodule/js/spec/video/general_spec.js | 2 +- .../xmodule/js/spec/video/initialize_spec.js | 8 ++--- .../js/spec/video/video_player_spec.js | 4 +-- .../xmodule/js/src/video/01_initialize.js | 1 + .../js/src/video/08_video_speed_control.js | 17 ++++++----- .../js/src/video/095_video_context_menu.js | 30 ++++++++++++------- .../xmodule/js/src/video/09_events_plugin.js | 4 +-- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js index 00666cd8a1..54dedecce3 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js @@ -85,7 +85,7 @@ }); it('set current video speed via cookie', function() { - expect(state.speed).toEqual('1.50'); + expect(state.speed).toEqual(1.5); }); }); diff --git a/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js b/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js index f588105e90..8ac70da495 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js @@ -186,7 +186,7 @@ function(Initialize) { $.each(map, function(key, expected) { Initialize.prototype.setSpeed.call(state, key); - expect(state.speed).toBe(expected); + expect(state.speed).toBe(parseFloat(expected)); }); }); }); @@ -205,7 +205,7 @@ function(Initialize) { }); it('set new speed', function() { - expect(state.speed).toEqual('0.75'); + expect(state.speed).toEqual(0.75); }); }); @@ -215,7 +215,7 @@ function(Initialize) { }); it('set speed to 1.0x', function() { - expect(state.speed).toEqual('1.0'); + expect(state.speed).toEqual(1); }); }); @@ -228,7 +228,7 @@ function(Initialize) { $.each(map, function(key, expected) { Initialize.prototype.setSpeed.call(state, key); - expect(state.speed).toBe(expected); + expect(state.speed).toBe(parseFloat(expected)); }); }); }); diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js index 429cdb8247..86c1d5f60f 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js @@ -56,7 +56,7 @@ function(VideoPlayer, HLS, _) { it('create video caption', function() { expect(state.videoCaption).toBeDefined(); - expect(state.speed).toEqual('1.50'); + expect(state.speed).toEqual(1.5); expect(state.config.transcriptTranslationUrl) .toEqual('/transcript/translation/__lang__'); }); @@ -64,7 +64,7 @@ function(VideoPlayer, HLS, _) { it('create video speed control', function() { expect(state.videoSpeedControl).toBeDefined(); expect(state.videoSpeedControl.el).toHaveClass('speeds'); - expect(state.speed).toEqual('1.50'); + expect(state.speed).toEqual(1.5); }); it('create video progress slider', function() { diff --git a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js index abc3c7ccb8..e2e8ad5638 100644 --- a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js @@ -715,6 +715,7 @@ function(VideoPlayer, i18n, moment, _) { newSpeed = map[newSpeed]; this.speed = _.contains(this.speeds, newSpeed) ? newSpeed : '1.0'; } + this.speed = parseFloat(this.speed); } function setAutoAdvance(enabled) { diff --git a/common/lib/xmodule/xmodule/js/src/video/08_video_speed_control.js b/common/lib/xmodule/xmodule/js/src/video/08_video_speed_control.js index 5668bb1360..0380125edb 100644 --- a/common/lib/xmodule/xmodule/js/src/video/08_video_speed_control.js +++ b/common/lib/xmodule/xmodule/js/src/video/08_video_speed_control.js @@ -231,21 +231,22 @@ * not differs from current speed. */ setSpeed: function(speed, silent, forceUpdate) { - if (speed !== this.currentSpeed || forceUpdate) { + var newSpeed = this.state.speedToString(speed); + if (newSpeed !== this.currentSpeed || forceUpdate) { this.speedsContainer .find('li') - .siblings("li[data-speed='" + speed + "']"); + .siblings("li[data-speed='" + newSpeed + "']"); - this.speedButton.find('.value').text(speed + 'x'); - this.currentSpeed = speed; + this.speedButton.find('.value').text(newSpeed + 'x'); + this.currentSpeed = newSpeed; if (!silent) { - this.el.trigger('speedchange', [speed, this.state.speed]); + this.el.trigger('speedchange', [newSpeed, this.state.speed]); } } this.resetActiveSpeed(); - this.setActiveSpeed(speed); + this.setActiveSpeed(newSpeed); }, resetActiveSpeed: function() { @@ -259,13 +260,13 @@ }, setActiveSpeed: function(speed) { - var speedOption = this.speedsContainer.find('li[data-speed="' + speed + '"]'); + var speedOption = this.speedsContainer.find('li[data-speed="' + this.state.speedToString(speed) + '"]'); speedOption.addClass('is-active') .find('.speed-option') .attr('aria-pressed', 'true'); - this.speedButton.attr('title', gettext('Video speed: ') + speed + 'x'); + this.speedButton.attr('title', gettext('Video speed: ') + this.state.speedToString(speed) + 'x'); }, /** diff --git a/common/lib/xmodule/xmodule/js/src/video/095_video_context_menu.js b/common/lib/xmodule/xmodule/js/src/video/095_video_context_menu.js index dadce7945d..7e1ccf4db5 100644 --- a/common/lib/xmodule/xmodule/js/src/video/095_video_context_menu.js +++ b/common/lib/xmodule/xmodule/js/src/video/095_video_context_menu.js @@ -217,7 +217,8 @@ function(Component) { }, appendContent: function(content) { - this.getElement().append(content); + var $content = $(content); + this.getElement().append($content); return this; }, @@ -247,8 +248,8 @@ function(Component) { }, open: function() { - var menu = (this.isRendered) ? this.getElement() : this.populateElement(); - this.container.append(menu); + var $menu = (this.isRendered) ? this.getElement() : this.populateElement(); + this.container.append($menu); AbstractItem.prototype.open.call(this); this.overlay.show(this.container); return this; @@ -355,7 +356,8 @@ function(Component) { }, show: function(container) { - $(container).append(this.getElement()); + var $elem = $(this.getElement()); + $(container).append($elem); this.delegateEvents(); return this; }, @@ -390,7 +392,9 @@ function(Component) { }, createElement: function() { - var $element = $('
  • ', { + var $spanElem, + $listElem, + $element = $('
  • ', { class: ['submenu-item', 'menu-item', this.options.prefix + 'submenu-item'].join(' '), 'aria-expanded': 'false', 'aria-haspopup': 'true', @@ -399,21 +403,25 @@ function(Component) { tabindex: -1 }); - this.label = $('', { + $spanElem = $('', { id: 'submenu-item-label-' + this.id, text: this.options.label - }).appendTo($element); + }); + this.label = $spanElem.appendTo($element); - this.list = $('
      ', { + $listElem = $('
        ', { class: ['submenu', this.options.prefix + 'submenu'].join(' '), role: 'menu' - }).appendTo($element); + }); + + this.list = $listElem.appendTo($element); return $element; }, appendContent: function(content) { - this.list.append(content); + var $content = $(content); + this.list.append($content); return this; }, @@ -628,7 +636,7 @@ function(Component) { }, { label: i18n.Speed, items: _.map(state.speeds, function(speed) { - var isSelected = speed === state.speed; + var isSelected = parseFloat(speed) === state.speed; return {label: speed + 'x', callback: speedCallback, speed: speed, isSelected: isSelected}; }), initialize: function(menuitem) { diff --git a/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js b/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js index 0fc90de6c2..3ed7aba4c1 100644 --- a/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js +++ b/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js @@ -101,8 +101,8 @@ onSpeedChange: function(event, newSpeed, oldSpeed) { this.log('speed_change_video', { current_time: this.getCurrentTime(), - old_speed: oldSpeed, - new_speed: newSpeed + old_speed: this.state.speedToString(oldSpeed), + new_speed: this.state.speedToString(newSpeed) }); },