From 244ce3cae2bd1fbf7d4d0be929edd3768d130e51 Mon Sep 17 00:00:00 2001 From: terapyon Date: Wed, 16 Oct 2019 14:43:39 +0900 Subject: [PATCH] bugfix for YouTube speed funciton by https://github.com/edx/edx-platform/pull/19888/files --- .../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 | 32 ++++++++++++------- .../xmodule/js/src/video/09_events_plugin.js | 4 +-- 7 files changed, 39 insertions(+), 29 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 2392fffd6560..c66347973f91 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 39715d99680c..24670518bd4b 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/initialize_spec.js @@ -188,7 +188,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)); }); }); }); @@ -207,7 +207,7 @@ function(Initialize) { }); it('set new speed', function() { - expect(state.speed).toEqual('0.75'); + expect(state.speed).toEqual(0.75); }); }); @@ -217,7 +217,7 @@ function(Initialize) { }); it('set speed to 1.0x', function() { - expect(state.speed).toEqual('1.0'); + expect(state.speed).toEqual(1); }); }); @@ -230,7 +230,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 7588db9ba480..3905b7312914 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 @@ -51,7 +51,7 @@ function(VideoPlayer) { 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__'); }); @@ -59,7 +59,7 @@ function(VideoPlayer) { 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 c9e385ab9d23..e6e1fef79893 100644 --- a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js @@ -688,6 +688,7 @@ function(VideoPlayer, i18n, moment, _) { newSpeed = map[newSpeed]; this.speed = _.contains(this.speeds, newSpeed) ? newSpeed : '1.0'; } + this.speed = parseFloat(this.speed); } function getVideoMetadata(url, callback) { 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 cfc328dea0f9..7ab4229104cb 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 @@ -226,21 +226,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() { @@ -254,13 +255,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 cfffa0a6de15..e22feed8dc59 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 @@ -216,7 +216,8 @@ function(Component) { }, appendContent: function(content) { - this.getElement().append(content); + var $content = $(content); + this.getElement().append($content); return this; }, @@ -246,8 +247,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; @@ -354,7 +355,8 @@ function(Component) { }, show: function(container) { - $(container).append(this.getElement()); + var $elem = $(this.getElement()); + $(container).append($elem); this.delegateEvents(); return this; }, @@ -389,7 +391,10 @@ function(Component) { }, createElement: function() { - var element = $('
  • ', { + var $spanElem, + $listElem, + $element = $('
  • ', { + // var element = $('
  • ', { 'class': ['submenu-item', 'menu-item', this.options.prefix + 'submenu-item'].join(' '), 'aria-expanded': 'false', 'aria-haspopup': 'true', @@ -398,21 +403,24 @@ 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; + return $element; }, appendContent: function(content) { - this.list.append(content); + var $content = $(content); + this.list.append($content); return this; }, @@ -627,7 +635,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 1ffeb49e04e9..ccc3d1ff66ec 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 @@ -100,8 +100,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) }); },