Skip to content

Commit

Permalink
FLUID-4554: Fixing model of html5Captionator and applier in it
Browse files Browse the repository at this point in the history
  • Loading branch information
anvk committed Feb 17, 2012
1 parent 38c74f4 commit 28e6919
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion demos/VideoPlayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h1>Infusion HTML 5 Video Player</h1>
},
model: {
currentTracks: {
captions: [0]

},
displayCaptions: true
}
Expand Down
5 changes: 1 addition & 4 deletions js/VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
container: "{videoPlayer}.dom.video",
createOnEvent: "onHTML5BrowserDetected",
options: {
model: {
currentCaptions: "{videoPlayer}.model.currentTracks.captions",
displayCaptions: "{videoPlayer}.model.displayCaptions"
},
model: "{videoPlayer}.model",
applier: "{videoPlayer}.applier",
captions: "{videoPlayer}.options.video.captions"
}
Expand Down
23 changes: 13 additions & 10 deletions js/VideoPlayer_html5Captionator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ https://source.fluidproject.org/svn/LICENSE.txt
gradeNames: ["fluid.viewComponent", "autoInit"],
finalInitFunction: "fluid.videoPlayer.html5Captionator.finalInit",
preInitFunction: "fluid.videoPlayer.html5Captionator.preInit",
model: {
currentCaptions: [],
displayCaptions: null
},
model: {},
captions: [],
events: {
onReady: null
},
elPaths: {
currentCaptions: "currentTracks.captions",
displayCaptions: "displayCaptions"
}
});

Expand Down Expand Up @@ -65,33 +66,35 @@ https://source.fluidproject.org/svn/LICENSE.txt
// listener for hiding/showing all captions
that.displayCaptions = function () {
var tracks = that.container[0].tracks;
if (that.model.displayCaptions) {
fluid.videoPlayer.html5Captionator.showCurrentTrack(that.model.currentCaptions, tracks, that.options.captions);
if (fluid.get(that.model, elPaths.displayCaptions)) {
fluid.videoPlayer.html5Captionator.showCurrentTrack(fluid.get(that.model, that.options.elPaths.currentCaptions), tracks, that.options.captions);
} else {
fluid.videoPlayer.html5Captionator.hideAllTracks(tracks);
}
};

// listener for changed selected currentTrack
that.changeCaptions = function () {
fluid.videoPlayer.html5Captionator.showCurrentTrack(that.model.currentCaptions, that.container[0].tracks, that.options.captions);
fluid.videoPlayer.html5Captionator.showCurrentTrack(fluid.get(that.model, that.options.elPaths.currentCaptions), that.container[0].tracks, that.options.captions);
};
};


fluid.videoPlayer.html5Captionator.finalInit = function (that) {
var captions = that.options.captions || [];
var elPaths = that.options.elPaths;

// Before we go any further check if it makes sense to create captionator and bind events
if(captions.length === 0) {
return false;
}

var currentCaptions = that.model.currentCaptions || [];
var currentCaptions = fluid.get(that.model, elPaths.currentCaptions) || [];

// If currentTrack is not specified, then default it to the first track
if (currentCaptions.length === 0) {
that.model.currentCaptions.push(0);
//that.model.currentCaptions.push(0);
that.applier.requestChange(elPaths.currentCaptions, [0]);
}

// Start adding tracks to the video tag
Expand All @@ -100,7 +103,7 @@ https://source.fluidproject.org/svn/LICENSE.txt
var trackTag = $("<track />");
var attributes = fluid.filterKeys(fluid.copy(element), ["kind", "src", "type", "srclang", "label"], false);

if (!($.inArray(key, currentCaptions))) {
if (!($.inArray(key, fluid.get(that.model, that.options.elPaths.currentCaptions)))) {
attributes.default = "true";
}
trackTag.attr(attributes);
Expand Down
4 changes: 2 additions & 2 deletions tests/js/VideoPlayerHTML5CaptionatorTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
var tracks = videoPlayer.html5Captionator.container[0].tracks;

jqUnit.assertEquals("Current track is NOT empty in the html5Captionator model it has only one element in it",
1, videoPlayer.html5Captionator.model.currentCaptions.length);
1, videoPlayer.html5Captionator.model.currentTracks.captions.length);

jqUnit.assertEquals("And this element is the index for the first element in the array of captions",
0, videoPlayer.html5Captionator.model.currentCaptions[0]);
0, videoPlayer.html5Captionator.model.currentTracks.captions[0]);

jqUnit.assertEquals("English subtitles should default to be showing", captionator.TextTrack.SHOWING, tracks[0].mode);
jqUnit.assertEquals("French subtitles are NOT showing", captionator.TextTrack.OFF, tracks[1].mode);
Expand Down

0 comments on commit 28e6919

Please sign in to comment.