From 5418613023b8caf0ed549d9274120b27bfbd1d80 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 7 Aug 2015 13:42:20 +0200 Subject: [PATCH] embedTimeline: fix subtitles (fixes #2823) --- static/js/embedPlayer.js | 16 +--------------- static/js/embedTimeline.js | 2 +- static/js/tv.js | 16 +--------------- static/js/utils.js | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/static/js/embedPlayer.js b/static/js/embedPlayer.js index 004dc941f..69f82ec10 100644 --- a/static/js/embedPlayer.js +++ b/static/js/embedPlayer.js @@ -40,7 +40,7 @@ pandora.ui.embedPlayer = function() { sizes = getSizes(); options.height = sizes.videoHeight; - video.subtitles = getSubtitles(video); + video.subtitles = pandora.getSubtitles(video); if (options.title) { $title = Ox.Element() @@ -339,20 +339,6 @@ pandora.ui.embedPlayer = function() { return Ox.$('').attr({width: width, height: height})[0].toDataURL(); } - function getSubtitles(options) { - return options.subtitlesLayer ? options.annotations.filter(function(layer) { - return layer.id == options.subtitlesLayer; - })[0].items.map(function(subtitle) { - return { - id: subtitle.id, - 'in': subtitle['in'], - out: subtitle.out, - text: subtitle.value.replace(/\n/g, ' ').replace(//g, '\n'), - tracks: subtitle.languages || [Ox.getLanguageNameByCode(pandora.site.language)] - }; - }) : []; - } - function selectAnnotation(data) { if (data.id) { setPosition(Math.max(data['in'], options['in'] || 0)); diff --git a/static/js/embedTimeline.js b/static/js/embedTimeline.js index ac7467b68..31d47ed9a 100644 --- a/static/js/embedTimeline.js +++ b/static/js/embedTimeline.js @@ -65,7 +65,7 @@ pandora.ui.embedTimeline = function() { position: options.position, resolution: Ox.min(pandora.site.video.resolutions), smallTimelineURL: pandora.getMediaURL('/' + ui.item + '/timeline16p.jpg'), - subtitles: video.subtitles, + subtitles: pandora.getSubtitles(video), timeline: ui.videoTimeline, timelines: pandora.site.timelines, video: video.video, diff --git a/static/js/tv.js b/static/js/tv.js index e612018fb..bc8d5278d 100644 --- a/static/js/tv.js +++ b/static/js/tv.js @@ -38,20 +38,6 @@ pandora.ui.tv = function() { }); } - function getSubtitles(options) { - return options.subtitlesLayer ? options.annotations.filter(function(layer) { - return layer.id == options.subtitlesLayer; - })[0].items.map(function(subtitle) { - return { - id: subtitle.id, - 'in': subtitle['in'], - out: subtitle.out, - text: subtitle.value.replace(/\n/g, ' ').replace(//g, '\n'), - tracks: subtitle.languages || [Ox.getLanguageNameByCode(pandora.site.language)] - }; - }) : [] - } - function play() { var $loading = $('') .attr({src: Ox.UI.getImageURL('symbolLoadingAnimated')}) @@ -89,7 +75,7 @@ pandora.ui.tv = function() { position: result.data.position, resolution: pandora.user.ui.videoResolution, scaleToFill: pandora.user.ui.videoScale == 'fill', - subtitles: getSubtitles(videoOptions), + subtitles: pandora.getSubtitles(videoOptions), subtitlesDefaultTrack: Ox.getLanguageNameByCode(pandora.site.language), subtitlesLayer: videoOptions.subtitlesLayer, subtitlesOffset: pandora.user.ui.videoSubtitlesOffset, diff --git a/static/js/utils.js b/static/js/utils.js index ce2d0caec..1ab79c687 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1906,6 +1906,20 @@ pandora.getStatusText = function(data) { return parts.join(', '); }; +pandora.getSubtitles = function(video) { + return video.subtitlesLayer ? video.annotations.filter(function(layer) { + return layer.id == video.subtitlesLayer; + })[0].items.map(function(subtitle) { + return { + id: subtitle.id, + 'in': subtitle['in'], + out: subtitle.out, + text: subtitle.value.replace(/\n/g, ' ').replace(//g, '\n'), + tracks: subtitle.languages || [Ox.getLanguageNameByCode(pandora.site.language)] + }; + }) : []; +}; + pandora.getSubtitlesLayer = function() { return pandora.site.layers.filter(function(layer) { return layer.isSubtitles;